Skip to content

Commit b9a3238

Browse files
Merge pull request serge-sans-paille#1106 from serge-sans-paille/fix/np_remainder
Fix remainder implementation
2 parents d4e1d01 + af3ac25 commit b9a3238

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

pythran/pythonic/include/numpy/remainder.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ PYTHONIC_NS_BEGIN
1212

1313
namespace numpy
1414
{
15+
namespace wrapper
16+
{
17+
template <class T0, class T1>
18+
auto remainder(T0 const &x, T1 const &y)
19+
-> decltype(x - y * xsimd::floor(x / y))
20+
{
21+
return x - y * xsimd::floor(x / y);
22+
}
23+
}
24+
1525
#define NUMPY_NARY_FUNC_NAME remainder
16-
#define NUMPY_NARY_FUNC_SYM xsimd::remainder
26+
#define NUMPY_NARY_FUNC_SYM wrapper::remainder
1727
#include "pythonic/include/types/numpy_nary_expr.hpp"
1828
}
1929
PYTHONIC_NS_END

pythran/pythonic/numpy/remainder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ PYTHONIC_NS_BEGIN
1313
namespace numpy
1414
{
1515
#define NUMPY_NARY_FUNC_NAME remainder
16-
#define NUMPY_NARY_FUNC_SYM xsimd::remainder
16+
#define NUMPY_NARY_FUNC_SYM wrapper::remainder
1717
#include "pythonic/types/numpy_nary_expr.hpp"
1818
}
1919
PYTHONIC_NS_END

pythran/tests/test_numpy_func1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ def test_isclose7(self):
295295
numpy.array([[-1.01, 1e-10+1e-11, -0, 7.],[9., 1e-10, 0., float('NaN')]]),
296296
np_isclose7=[NDArray[float,:], NDArray[float,:,:]])
297297

298+
def test_remainder0(self):
299+
self.run_test("def np_remainder0(u, v): from numpy import remainder; return remainder(u, v)",
300+
numpy.array([9., 9., -9., -9.]),
301+
numpy.array([2., -2., 2., -2.]),
302+
np_remainder0=[NDArray[float,:], NDArray[float,:]])
303+
298304
def test_numpy_ones_list(self):
299305
self.run_test(
300306
"def np_ones_list(u): from numpy import ones; return ones([u,u])",

0 commit comments

Comments
 (0)