Skip to content

Commit

Permalink
Adapt signbit implementation to xsimd update
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed May 3, 2024
1 parent 3d82ccb commit b37f584
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
16 changes: 13 additions & 3 deletions pythran/pythonic/include/numpy/signbit.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef PYTHONIC_INCLUDE_NUMPY_SIGNBIT_HPP
#define PYTHONIC_INCLUDE_NUMPY_SIGNBIT_HPP

#include "pythonic/include/utils/functor.hpp"
#include "pythonic/include/types/ndarray.hpp"
#include "pythonic/include/utils/functor.hpp"
#include "pythonic/include/utils/numpy_traits.hpp"

#include <xsimd/xsimd.hpp>
Expand All @@ -11,10 +11,20 @@ PYTHONIC_NS_BEGIN

namespace numpy
{

namespace details
{
template <class T>
auto signbit(T val) -> decltype(xsimd::signbit(val) == T(1))
{
return xsimd::signbit(val) == T(1);
}
} // namespace details

#define NUMPY_NARY_FUNC_NAME signbit
#define NUMPY_NARY_FUNC_SYM xsimd::signbit
#define NUMPY_NARY_FUNC_SYM details::signbit
#include "pythonic/include/types/numpy_nary_expr.hpp"
}
} // namespace numpy
PYTHONIC_NS_END

#endif
6 changes: 3 additions & 3 deletions pythran/pythonic/numpy/signbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "pythonic/include/numpy/signbit.hpp"

#include "pythonic/utils/functor.hpp"
#include "pythonic/types/ndarray.hpp"
#include "pythonic/utils/functor.hpp"
#include "pythonic/utils/numpy_traits.hpp"

PYTHONIC_NS_BEGIN
Expand All @@ -13,9 +13,9 @@ namespace numpy
{

#define NUMPY_NARY_FUNC_NAME signbit
#define NUMPY_NARY_FUNC_SYM xsimd::signbit
#define NUMPY_NARY_FUNC_SYM details::signbit
#include "pythonic/types/numpy_nary_expr.hpp"
}
} // namespace numpy
PYTHONIC_NS_END

#endif
2 changes: 1 addition & 1 deletion pythran/pythonic/types/vectorizable_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace types
struct is_vector_op {

// vectorize everything but these ops. They require special handling for
// vectorization, && SG did not invest enough time in those
// vectorization, and SG did not invest enough time in those
static const bool value =
!std::is_same<O, operator_::functor::mod>::value &&
(!std::is_same<O, operator_::functor::div>::value ||
Expand Down
8 changes: 7 additions & 1 deletion pythran/tests/test_numpy_ufunc_unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@


class TestNumpyUFuncUnary(TestEnv):
pass

def test_signbit0(self):
self.run_test(
"def signbit0(x): import numpy as np; return np.signbit(x)",
-numpy.nan,
signbit0=[float])



# automatic generation of basic test cases for ufunc
Expand Down

0 comments on commit b37f584

Please sign in to comment.