From 98b59cb82ce4a84d70f65dd7fd9f2ebcafb5daa9 Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Thu, 14 Nov 2019 20:26:32 +0800 Subject: [PATCH] fix elementwise_mod float point kernel. test=develop (#21183) --- paddle/fluid/operators/elementwise/elementwise_mod_op.h | 4 +++- .../paddle/fluid/tests/unittests/test_elementwise_mod_op.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/elementwise/elementwise_mod_op.h b/paddle/fluid/operators/elementwise/elementwise_mod_op.h index e568a5dc72..4306a471b7 100644 --- a/paddle/fluid/operators/elementwise/elementwise_mod_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_mod_op.h @@ -29,7 +29,9 @@ struct ModFunctor { template struct ModFunctorFP { - inline HOSTDEVICE T operator()(T a, T b) const { return std::fmod(a, b); } + inline HOSTDEVICE T operator()(T a, T b) const { + return fmod(b + fmod(a, b), b); + } }; template diff --git a/python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py b/python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py index fcda179a09..c4740e063f 100644 --- a/python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py +++ b/python/paddle/fluid/tests/unittests/test_elementwise_mod_op.py @@ -71,7 +71,7 @@ class TestElementwiseModOpFloat(TestElementwiseModOp): def init_input_output(self): self.x = np.random.uniform(-1000, 1000, [10, 10]).astype(self.dtype) self.y = np.random.uniform(-100, 100, [10, 10]).astype(self.dtype) - self.out = np.fmod(self.x, self.y) + self.out = np.fmod(self.y + np.fmod(self.x, self.y), self.y) def test_check_output(self): self.check_output(atol=2e-5) -- GitLab