diff --git a/include/xtensor/core/xmath.hpp b/include/xtensor/core/xmath.hpp index 401de8a73..1644f2dfd 100644 --- a/include/xtensor/core/xmath.hpp +++ b/include/xtensor/core/xmath.hpp @@ -1778,6 +1778,18 @@ namespace xt return xt::all(isclose(std::forward(e1), std::forward(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 + requires std::is_convertible_v + inline auto allclose(E1&& e1, E2&& e2, double rtol, double atol, EqualNan equal_nan) + { + return xt::all(isclose(std::forward(e1), std::forward(e2), rtol, atol, std::move(equal_nan))); + } + /********************** * Reducing functions * **********************/ diff --git a/test/test_xmath.cpp b/test/test_xmath.cpp index 982e71a1a..0182946a8 100644 --- a/test/test_xmath.cpp +++ b/test/test_xmath.cpp @@ -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&; + const auto allclose_function = &allclose; + EXPECT_FALSE(allclose_function(a, b, 1e-05, 1e-08)); } TEST(xmath, isclose_int)