fix math_op_path.py when integers, test=develop (#20008)

fix-python-transpose
Zeng Jinle 5 years ago committed by GitHub
parent bb271b6d44
commit 1b7de89455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -143,7 +143,11 @@ def monkey_patch_variable():
reverse=False, reverse=False,
scalar_method=None): scalar_method=None):
def __impl__(self, other_var): def __impl__(self, other_var):
if scalar_method is not None: # FIXME(zjl): elementwise_div between integers cannot be converted to scale,
# which may lose accuracy. This is a hot fix for release 1.6.
if scalar_method is not None and not (
op_type == 'elementwise_div' and
self.dtype in _supported_int_dtype_):
if isinstance(other_var, float): if isinstance(other_var, float):
if self.dtype in _supported_int_dtype_: if self.dtype in _supported_int_dtype_:
assert other_var == int(other_var), \ assert other_var == int(other_var), \

@ -186,6 +186,20 @@ class TestMathOpPatches(unittest.TestCase):
fetch_list=[c]) fetch_list=[c])
self.assertTrue(numpy.allclose(a_np - b_np, c_np)) self.assertTrue(numpy.allclose(a_np - b_np, c_np))
@prog_scope()
def test_integer_div(self):
a = fluid.layers.data(name="a", shape=[1], dtype='int64')
b = a / 7
place = fluid.CPUPlace()
exe = fluid.Executor(place)
a_np = numpy.array([3, 4, 10, 14, 9, 18]).astype('int64')
b_np, = exe.run(fluid.default_main_program(),
feed={"a": a_np},
fetch_list=[b])
b_np_actual = (a_np / 7).astype('int64')
self.assertTrue(numpy.array_equal(b_np, b_np_actual))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save