types::ndarray<typename __combined<typename types::dtype_of<T>::type, typename types::dtype_of<U>::type>::type, types::pshape<long>> setdiff1d(T const &ar1, U const &ar2, bool assume_unique) { using dtype = typename __combined<typename types::dtype_of<T>::type, typename types::dtype_of<U>::type>::type; auto far1 = numpy::functor::array{}(ar1); auto far2 = numpy::functor::array{}(ar2); if (assume_unique) { std::sort(far1.fbegin(), far1.fend()); std::sort(far2.fbegin(), far2.fend()); dtype *out = (dtype *)malloc(far1.flat_size() * far2.flat_size() * sizeof(dtype)); dtype *out_last = std::set_difference(far1.fbegin(), far1.fend(), far2.fbegin(), far2.fend(), out); auto size = out_last - out; out = (dtype *)realloc(out, size * sizeof(dtype)); return {out, types::pshape<long>(size), types::ownership::owned}; } else { std::sort(far1.fbegin(), far1.fend()); std::sort(far2.fbegin(), far2.fend()); dtype *out = (dtype *)malloc(far1.flat_size() * far2.flat_size() * sizeof(dtype)); dtype *out_last = impl::set_difference_unique( far1.fbegin(), far1.fend(), far2.fbegin(), far2.fend(), out); auto size = out_last - out; out = (dtype *)realloc(out, size * sizeof(dtype)); return {out, types::pshape<long>(size), types::ownership::owned}; } }
types::ndarray<typename types::numpy_expr_to_ndarray<E>::T, 1> ediff1d(E const& expr) { auto arr = asarray(expr); long n = arr.flat_size() -1 ; types::ndarray<typename types::numpy_expr_to_ndarray<E>::T, 1> out(types::make_tuple(n), __builtin__::None); // Compute adjacent difference except for the first element std::adjacent_difference (arr.fbegin() + 1, arr.fend(), out.fbegin()); // First element can be done now (*out.fbegin()) = *(arr.fbegin()+1) - *(arr.fbegin()); return out; }
types::none_type putmask(types::ndarray<T, pS> &expr, E const &mask, F const &values) { auto amask = asarray(mask); auto avalues = asarray(values); auto iexpr = expr.fbegin(); auto n = avalues.flat_size(); for (long i = 0; i < expr.flat_size(); ++i) if (*(amask.fbegin() + i)) *(iexpr + i) = *(avalues.fbegin() + i % n); return __builtin__::None; }
typename std::enable_if<types::is_numexpr_arg<F>::value, types::none_type>::type put(types::ndarray<T, N> &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 __builtin__::None; }
typename numpy_iexpr<Arg>::dtype const *numpy_iexpr<Arg>::fend() { return buffer + flat_size(); }