#ifndef PYTHONIC_NUMPY_PUT_HPP #define PYTHONIC_NUMPY_PUT_HPP #include "pythonic/include/numpy/put.hpp" #include "pythonic/utils/functor.hpp" #include "pythonic/types/ndarray.hpp" #include "pythonic/numpy/asarray.hpp" #include "pythonic/utils/numpy_conversion.hpp" #include "pythonic/builtins/ValueError.hpp" PYTHONIC_NS_BEGIN namespace numpy { template typename std::enable_if::value, types::none_type>::type put(types::ndarray &expr, F const &ind, E const &v) { auto vind = asarray(ind); auto vv = asarray(v); for (long i = 0; i < ind.flat_size(); ++i) { auto val = *(vind.fbegin() + i); if (val >= expr.flat_size() || val < 0) throw types::ValueError("indice out of bound"); *(expr.fbegin() + val) = *(vv.fbegin() + i % vv.flat_size()); } return builtins::None; } template types::none_type put(types::ndarray &expr, long ind, T const &v) { if (ind >= expr.flat_size() || ind < 0) throw types::ValueError("indice out of bound"); *(expr.fbegin() + ind) = v; return builtins::None; } template types::none_type put(E &, M const &, V const &) { throw std::runtime_error("put only partially implemented"); } } PYTHONIC_NS_END #endif