Created by: luotao1
为softmax python api的输入input加类型检查:
- 检查类型是否为Variable
- 检查数据类型是否为float32和float64
- 在单测中覆盖类型错误和数据类型错误两个异常情况
- 可手动运行示例,看下错误:
import paddle.fluid as fluid
x1 = fluid.create_lod_tensor(np.array([[-1]]), [[1]], fluid.CPUPlace())
fluid.layers.softmax(x1)
# TypeError: The type of ‘input’ in softmax must be Variable, but received <class 'paddle.fluid.core_avx.LoDTensor'>
import paddle.fluid as fluid
x2 = fluid.layers.data(name='x2', shape=[4], dtype="int32")
fluid.layers.softmax(x2)
#TypeError: The data type of ‘input’ in softmax must be float32 or float64, but received int32.
注意:
- 由于softmax的其他参数如use_cudnn, axis比较简单,本PR只检查input
- 需要用单引号把输入'input'括起来,和input区分,避免用户不知道是哪个输入。其他输入名字如X,Y,也需要括起来。