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