Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/xtensor/core/xmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,13 @@ namespace xt
template <class A1, class A2, class A3>
constexpr auto operator()(const A1& v, const A2& lo, const A3& hi) const
{
return xtl::select(v < lo, lo, xtl::select(hi < v, hi, v));
return xtl::select(lo < hi, xtl::select(v < lo, lo, xtl::select(hi < v, hi, v)), hi);
}

template <class A1, class A2, class A3>
constexpr auto simd_apply(const A1& v, const A2& lo, const A3& hi) const
{
return xt_simd::select(v < lo, lo, xt_simd::select(hi < v, hi, v));
return xt_simd::select(lo < hi, xt_simd::select(v < lo, lo, xt_simd::select(hi < v, hi, v)), hi);
}
};

Expand Down
9 changes: 9 additions & 0 deletions test/test_xmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ namespace xt
EXPECT_EQ(res1, clip(opt_a, 2.0, 4.0));
}

TEST(xmath, clip_amin_greater_than_amax)
{
// NumPy-compatible behavior: when a_min > a_max, all values
// are set to a_max (the hi bound).
const xarray<int> arr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const xarray<int> expected = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
EXPECT_EQ(expected, clip(arr, 8, 1));
}

TEST(xmath, sign)
{
shape_type shape = {3, 2};
Expand Down
Loading