[Not Merge] fix cast error of paddle.median #64489
Closed
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.
PR Category
Others
PR Types
Bug fixes
Description
card-73263
修复paddle.median新开发“min”模式中的cast error。
example:
import paddle
input = paddle.to_tensor(data=[1, 4, 6])
result = paddle.median(mode='min', x=input, axis=0)
报错:TypeError: (InvalidType) Type promotion only support calculations between floating-point numbers and between complex and real numbers. But got different data type x: int64, y: float32.(at/paddle/paddle/phi/common/type_promotion.h:159)
min模式中并未对out_tensor做强制cast,但当输入x的dtype为整形时,在后面对nan的处理逻辑中报错如上。为了保持输入输出dtype的一致性,PR并为将out_tensor强制cast为float。而是根据整形数据不可能含有nan,对其做特殊逻辑判断。