typename types::numpy_expr_to_ndarray<F>::type take(types::ndarray<T,N> const & expr, F const& indices) { typename types::numpy_expr_to_ndarray<F>::type out = asarray(indices); auto expr_iter = expr.fbegin(); for(auto out_iter = out.fbegin(), out_end = out.fend(); out_iter != out_end; ++out_iter) *out_iter = *(expr_iter + *out_iter); return out; }
typename types::numpy_expr_to_ndarray<E>::type tile(E const& expr, int reps) { size_t n = expr.flat_size(); typename types::numpy_expr_to_ndarray<E>::type out(types::array<long, 1>{{long(n * reps)}}, __builtin__::None); auto out_iter = out.fbegin(); _tile(expr.begin(), expr.end(), out_iter, utils::int_<types::numpy_expr_to_ndarray<E>::N>()); for(int i = 1; i< reps; ++i) out_iter = std::copy(out.fbegin(), out.fbegin() + n, out_iter); return out; }
typename types::numpy_expr_to_ndarray<E>::type nan_to_num(E const& expr) { typename types::numpy_expr_to_ndarray<E>::type out(expr.shape, __builtin__::None); for(long i=0, n=expr.size(); i<n; ++i) { auto v = expr.at(i); if(nt2::is_inf(v) and nt2::is_positive(v)) out.at(i) = std::numeric_limits<typename types::numpy_expr_to_ndarray<E>::type::dtype>::max(); else if(nt2::is_inf(v) and nt2::is_negative(v)) out.at(i) = -std::numeric_limits<typename types::numpy_expr_to_ndarray<E>::type::dtype>::max(); else if(nt2::is_nan(v)) out.at(i) = 0; else out.at(i) = v; } return out; }
typename types::numpy_expr_to_ndarray<E>::type nan_to_num(E const& expr) { typename types::numpy_expr_to_ndarray<E>::type out(expr.shape, __builtin__::None); _nan_to_num(expr.begin(), expr.end(), out.begin(), utils::int_<types::numpy_expr_to_ndarray<E>::N>()); return out; }