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
12 changes: 12 additions & 0 deletions include/xtensor/core/xmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,18 @@ namespace xt
return xt::all(isclose(std::forward<E1>(e1), std::forward<E2>(e2), rtol, atol));
}

// Deduce the flag type so taking the address of the four-argument overload remains unambiguous.
/**
* @overload
* @param equal_nan if true, NaN values at the same position compare equal
*/
template <class E1, class E2, class EqualNan>
requires std::is_convertible_v<EqualNan, bool>
inline auto allclose(E1&& e1, E2&& e2, double rtol, double atol, EqualNan equal_nan)
{
return xt::all(isclose(std::forward<E1>(e1), std::forward<E2>(e2), rtol, atol, std::move(equal_nan)));
}

/**********************
* Reducing functions *
**********************/
Expand Down
8 changes: 8 additions & 0 deletions test/test_xmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,17 @@ namespace xt
b(0, 0) = nan("n");
EXPECT_FALSE(isclose(a, b)(0, 0));
EXPECT_FALSE(isclose(a, b)(0, 0));
EXPECT_FALSE(allclose(a, b, 1e-05, 1e-08, true));
a(0, 0) = nan("n");
EXPECT_FALSE(isclose(a, b)(0, 0));
EXPECT_TRUE(isclose(a, b, 1, 1, true)(0, 0));
EXPECT_FALSE(allclose(a, b));
EXPECT_TRUE(allclose(a, b, 1e-05, 1e-08, true));
EXPECT_FALSE(allclose(a, b, 1e-05, 1e-08, false));

using array_ref = const xarray<double>&;
const auto allclose_function = &allclose<array_ref, array_ref>;
EXPECT_FALSE(allclose_function(a, b, 1e-05, 1e-08));
}

TEST(xmath, isclose_int)
Expand Down