PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
21.66k stars 5.44k forks source link

add type promotion for complex and real number. #63842

Closed zxcd closed 1 week ago

zxcd commented 3 weeks ago

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.

paddle-bot[bot] commented 3 weeks ago

你的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-ci-bot[bot] commented 1 week ago

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.