Created by: FDInSky
为uniform_random python api的输入input加类型检查:
检查类型是否为Variable 检查数据类型是否为float32和float64 在单测中覆盖类型错误和数据类型错误两个异常情况 可手动运行示例,看下错误:
main_prog = Program()
start_prog = Program()
with program_guard(main_prog, start_prog):
block = main_prog.global_block()
# the input type of uniform_random must be Variable.
x1 = fluid.create_lod_tensor(np.zeros((4, 784)), [[1, 1, 1, 1]], fluid.CPUPlace())
fluid.layers.uniform_random( x1, block)
# the input dtype of uniform_random must be float16, float32 or float64.
x2 = fluid.layers.data(name='x2', shape=[4, 784], dtype='int32')
fluid.layers.uniform_random(x2, block)