#ifndef PYTHONIC_NUMPY_NDINDEX_HPP #define PYTHONIC_NUMPY_NDINDEX_HPP #include "pythonic/include/numpy/ndindex.hpp" #include "pythonic/utils/functor.hpp" #include PYTHONIC_NS_BEGIN namespace numpy { template ndindex_iterator::ndindex_iterator() { } template ndindex_iterator::ndindex_iterator(types::array const &shape, long first) : index(first), shape(shape) { } template types::array ndindex_iterator::operator*() const { types::array out; long mult = 1; for (long j = N - 1; j > 0; j--) { out[j] = (index / mult) % shape[j]; mult *= shape[j]; } out[0] = index / mult; return out; } template ndindex_iterator &ndindex_iterator::operator++() { ++index; return *this; } template ndindex_iterator &ndindex_iterator::operator+=(long n) { index += n; return *this; } template bool ndindex_iterator::operator!=(ndindex_iterator const &other) const { return index != other.index; } template bool ndindex_iterator::operator<(ndindex_iterator const &other) const { return index < other.index; } template long ndindex_iterator::operator-(ndindex_iterator const &other) const { return index - other.index; } template _ndindex::_ndindex() { } template _ndindex::_ndindex(types::array const &shape) : ndindex_iterator(shape, 0), shape(shape), end_iter(shape, std::accumulate(shape.begin(), shape.end(), 1L, std::multiplies())) { } template typename _ndindex::iterator &_ndindex::begin() { return *this; } template typename _ndindex::iterator const &_ndindex::begin() const { return *this; } template typename _ndindex::iterator _ndindex::end() const { return end_iter; } template _ndindex ndindex(Types... args) { return {types::make_tuple(args...)}; } template _ndindex ndindex(types::array const &args) { return {args}; } template _ndindex ndindex(types::pshape const &args) { return {args}; } } PYTHONIC_NS_END #endif