#ifndef PYTHONIC_NUMPY_NANMAX_HPP #define PYTHONIC_NUMPY_NANMAX_HPP #include "pythonic/include/numpy/nanmax.hpp" #include "pythonic/builtins/ValueError.hpp" #include "pythonic/numpy/isnan.hpp" #include "pythonic/types/ndarray.hpp" #include "pythonic/utils/functor.hpp" PYTHONIC_NS_BEGIN namespace numpy { namespace { template bool _nanmax(E begin, E end, F &max, utils::int_<1>) { bool found = false; for (; begin != end; ++begin) { auto curr = *begin; if (!functor::isnan()(curr) && curr >= max) { max = curr; found = true; } } return found; } template bool _nanmax(E begin, E end, F &max, utils::int_) { bool found = false; for (; begin != end; ++begin) found |= _nanmax((*begin).begin(), (*begin).end(), max, utils::int_()); return found; } } template typename E::dtype nanmax(E const &expr) { bool found = false; typename E::dtype max = std::numeric_limits::lowest(); found = _nanmax(expr.begin(), expr.end(), max, utils::int_()); if (!found) max = std::numeric_limits::quiet_NaN(); return max; } } PYTHONIC_NS_END #endif