#ifndef PYTHONIC_NUMPY_FLATNONZERO_HPP #define PYTHONIC_NUMPY_FLATNONZERO_HPP #include "pythonic/include/numpy/flatnonzero.hpp" #include "pythonic/numpy/asarray.hpp" PYTHONIC_NS_BEGIN namespace numpy { namespace { template void _flatnonzero(I begin, I end, O &out, long &i, utils::int_<1>) { for (; begin != end; ++begin, ++i) if (*begin) *out++ = i; } template void _flatnonzero(I begin, I end, O &out, long &i, utils::int_) { for (; begin != end; ++begin) _flatnonzero((*begin).begin(), (*begin).end(), out, i, utils::int_()); } } template types::ndarray> flatnonzero(E const &expr) { long n = expr.flat_size(); utils::shared_ref> buffer(n); long *iter = buffer->data; long i = 0; _flatnonzero(expr.begin(), expr.end(), iter, i, utils::int_()); types::pshape shape = iter - buffer->data; return types::ndarray>(std::move(buffer), shape); } } PYTHONIC_NS_END #endif