Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
issue: #7299
对 pad函数文档描述如下:
mode='constant'
:根据官方文档,pad 长度应为偶数。但根据实际测试,奇数长度也能被接受,只是不会对结果产生影响。如果 pad 长度超过 2*N,不会报错,但超出部分可能不会起作用。
mode='reflect'、replicate 或 circular
:根据官方文档,长度有严格检查,不符合规定的输入,会抛出异常。constant测试结果
奇数长度的
pad
: 当mode='constant'
时,官方文档提到pad
的长度应为偶数,但奇数长度的pad
也是OK的。测试输入pad=[0, 0, 0, 0, 2]
超出最大长度的
pad
: 当pad
的长度超过2*N
时,Paddle 不会报错,但多余的填充不会起作用。例如,pad=[0, 0, 0, 0, 2, 3, 4, 5]
的结果与pad=[0, 0, 0, 0, 2, 3, 4]
的结果相同:所以 Paddle 在内部处理时应该是只使用了前
2*N
个值,多余的填充值直接就被忽略吧(?)reflect、replicate、circular测试结果
测试结果显示,当
mode
为reflect
、replicate
或circular
时,pad
的长度有严格要求,符合原官方文档
说明。错误信息如下:
这表明 Paddle 对这三种模式的
pad
长度有严格的检查,所以相关文档无需修改。Note
constant的奇数和偶数的填充方式好像不同?
偶数长度的 pad:填充会均匀地分布在指定的维度两侧。比如说pad=[0, 0, 0, 0, 2, 3] 会在最后一个维度的前面填充 2 个值,后面填充 3 个值。
奇数长度的 pad: 会自动扩展 pad 的长度到 2*N,并在前面补零。如果pad=[0, 0, 0, 0, 2] 会被扩展为 [0, 0, 0, 0, 2, 0],然后进行填充,相当于把奇数变成偶数再填充的意思。
源码位置:pad源码
对应文档:pad文档
这里是否需要在文档中补充一下? @sunzhongkai588 @DrRyanHuang