#ifndef PYTHONIC_NUMPY_ALLCLOSE_HPP #define PYTHONIC_NUMPY_ALLCLOSE_HPP #include "pythonic/include/numpy/allclose.hpp" #include "pythonic/utils/functor.hpp" #include "pythonic/types/ndarray.hpp" #include "pythonic/numpy/abs.hpp" #include "pythonic/numpy/isfinite.hpp" PYTHONIC_NS_BEGIN namespace numpy { namespace { template bool _allclose(I0 begin, I0 end, I1 ibegin, double rtol, double atol, utils::int_<1>) { for (; begin != end; ++begin, ++ibegin) { auto u = *begin; auto v = *ibegin; if (((!functor::isfinite()(u) || !functor::isfinite()(v)) && u != v) || // Infinite && NaN cases functor::abs()(u - v) > (atol + rtol * functor::abs()(v))) { return false; } } return true; } template bool _allclose(I0 begin, I0 end, I1 ibegin, double rtol, double atol, utils::int_) { for (; begin != end; ++begin, ++ibegin) if (!_allclose((*begin).begin(), (*begin).end(), (*ibegin).begin(), rtol, atol, utils::int_())) return false; return true; } } template bool allclose(U const &u, V const &v, double rtol, double atol) { return _allclose(u.begin(), u.end(), v.begin(), rtol, atol, utils::int_()); } } PYTHONIC_NS_END #endif