types::none_type insert(types::list<T> &seq, long n, F &&value) { n = n % (1 + seq.size()); // +1 because we want to be able to insert at // the end of seq if (n < 0) n += seq.size(); seq.insert(n, std::forward<F>(value)); return __builtin__::None; }
long index(types::list<T> &seq, T const &x) { long index_value = seq.index(x); if (index_value == seq.size()) throw types::ValueError(__builtin__::anonymous::str(x) + " is not in list"); return index_value; }
types::ndarray<T, N> select(types::list<types::ndarray<U, N>> const &condlist, types::list<types::ndarray<T, N>> const &choicelist, T _default) { types::ndarray<T, N> out(choicelist[0].shape(), _default); for (long i = 0; i < out.flat_size(); ++i) for (long j = 0; j < condlist.size(); ++j) if (condlist[j].buffer[i]) { out.buffer[i] = choicelist[j].buffer[i]; break; } return out; }
types::ndarray<typename U::type, U::value> select(types::list<T> const &condlist, types::list<U> const &choicelist, typename U::dtype _default) { constexpr size_t N = U::value; auto &&choicelist0_shape = choicelist[0].shape(); types::ndarray<T, N> out(choicelist0_shape, _default); types::ndarray<T, N> selected(choicelist0_shape(), false); long size = selected.flat_size(); for (long i = 0; i < condlist.size() && size != 0; i++) size = _select(choicelist[i].begin(), choicelist[i].end(), out.begin(), selected.begin(), condlist.begin(), size, utils::int_<N>()); return out; }