Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

add type promotion for complex and real number.

Open zxcd opened this issue 10 months ago • 1 comments

PR Category

Others

PR Types

New features

Description

card-78750

As there were unreasonable type promotion in Paddle, which the previous logic was aligned to the left tensor, like:

a = paddle.ones([3,3], dtype= ''int64")
b = paddle.ones([3,3], dtype = 'float32')
a+b # int64

This behavior will be fixed more in line with mathematical logic, like:

a = paddle.ones([3,3], dtype= ''int64")
b = paddle.ones([3,3], dtype = 'float32')
a+b # float32

Furthermore, after discussion, we will limit the behavior of automatic type promotion to floating-point numbers, and between real and complex numbers in Tensor and Tensor. Tensor and Scalar will still support all dtypes.

## Before:
a = paddle.ones([3,3], dtype= ''int32")
b = paddle.ones([3,3], dtype = 'int64')
a+b # int64

## After:
a = paddle.ones([3,3], dtype= ''int32")
b = paddle.ones([3,3], dtype = 'int64')
a+b # raise TypeError

Those PR https://github.com/PaddlePaddle/Paddle/pull/60638 , https://github.com/PaddlePaddle/Paddle/pull/59518 fixed the behavior in few APIs between floating-point numbers in Tensor and Tensor.

This PR will support all binary operation API, and type promotion between real and complex numbers in Tensor and Tensor. Also the behavior between Tensor and Scalar will be corrected.

zxcd avatar Apr 24 '24 12:04 zxcd

你的PR提交成功,感谢你对开源项目的贡献! 请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。 Your PR has been submitted. Thanks for your contribution! Please wait for the result of CI firstly. See Paddle CI Manual for details.

paddle-bot[bot] avatar Apr 24 '24 12:04 paddle-bot[bot]

Sorry to inform you that 46238aa's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

paddle-ci-bot[bot] avatar May 08 '24 03:05 paddle-ci-bot[bot]