#ifndef PYTHONIC_NUMPY_ANY_HPP #define PYTHONIC_NUMPY_ANY_HPP #include "pythonic/include/numpy/any.hpp" #include "pythonic/utils/functor.hpp" #include "pythonic/types/ndarray.hpp" #include "pythonic/builtins/ValueError.hpp" #include "pythonic/numpy/add.hpp" PYTHONIC_NS_BEGIN namespace numpy { template bool _any(E const &e, utils::int_<1>) { return std::any_of(e.begin(), e.end(), [](typename E::dtype elt) -> bool { return elt; }); } template bool _any(E const &e, utils::int_) { for (auto &&elt : e) if (_any(elt, utils::int_())) { return true; } return false; } template typename std::enable_if::value, bool>::type any(E const &expr, types::none_type) { return _any(expr, utils::int_()); } template typename std::enable_if< std::is_scalar::value || types::is_complex::value, bool>::type any(E const &expr, types::none_type) { return expr; } template auto any(E const &array, long axis) -> typename std::enable_if::value || types::is_complex::value, decltype(any(array))>::type { if (axis != 0) throw types::ValueError("axis out of bounds"); return any(array); } template auto any(E const &array, long axis) -> typename std::enable_if::type { if (axis != 0) throw types::ValueError("axis out of bounds"); return any(array); } template typename std::enable_if< E::value != 1, types::ndarray>>::type any(E const &array, long axis) { constexpr long N = E::value; using T = typename E::dtype; if (axis < 0 || axis >= long(N)) throw types::ValueError("axis out of bounds"); if (axis == 0) { types::array shp; shp[0] = 1; sutils::copy_shape<1, 0>(shp, array, utils::make_index_sequence()); types::ndarray> out(shp, false); return std::accumulate(array.begin(), array.end(), *out.begin(), numpy::functor::add()); } else { types::array shp; sutils::copy_shape<0, 0>(shp, array, utils::make_index_sequence()); types::ndarray> anyy(shp, builtins::None); std::transform( array.begin(), array.end(), anyy.begin(), [=](types::ndarray> const &other) { return any(other, axis - 1); }); return anyy; } } } PYTHONIC_NS_END #endif