Created by: zhaoyuchen2018
为squeeze python api的输入input加类型检查:
- 检查类型是否为Variable
- 检查数据类型是否为float16
- 在单测中覆盖类型错误和数据类型错误两个异常情况 可手动运行示例,看下错误:
import paddle.fluid as fluid
x1 = fluid.create_lod_tensor(np.array([[-1]]), [[1]], fluid.CPUPlace())
fluid.layers.squeeze(x1)
# TypeError: The type of ‘input’ in squeeze 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="float16")
fluid.layers.squeeze(x2)
#TypeError: The data type of ‘input’ in squeeze must be int8, int32, int64, float32 or float64, but received float16.
注意:
需要用单引号把输入'input'括起来,和input区分,避免用户不知道是哪个输入。其他输入名字如X,Y,也需要括起来。
test=develop