本文整理汇总了C++中types::ndarray::flat_size方法的典型用法代码示例。如果您正苦于以下问题:C++ ndarray::flat_size方法的具体用法?C++ ndarray::flat_size怎么用?C++ ndarray::flat_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types::ndarray
的用法示例。
在下文中一共展示了ndarray::flat_size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: roll
types::ndarray<T,N> roll(types::ndarray<T,N> const& expr, long shift)
{
while(shift<0) shift+=expr.flat_size();
shift %=expr.flat_size();
types::ndarray<T,N> out(expr.shape(), __builtin__::None);
std::copy(expr.fbegin(), expr.fend() - shift, std::copy(expr.fend() - shift, expr.fend(), out.fbegin()));
return out;
}
示例2:
types::ndarray<T, N> _transpose(types::ndarray<T, N> const &a,
long const l[N])
{
auto shape = a.shape();
types::array<long, N> shp;
for (unsigned long i = 0; i < N; ++i)
shp[i] = shape[l[i]];
types::ndarray<T, N> new_array(shp, __builtin__::None);
types::array<long, N> new_strides;
new_strides[N - 1] = 1;
std::transform(new_strides.rbegin(), new_strides.rend() - 1, shp.rbegin(),
new_strides.rbegin() + 1, std::multiplies<long>());
types::array<long, N> old_strides;
old_strides[N - 1] = 1;
std::transform(old_strides.rbegin(), old_strides.rend() - 1,
shape.rbegin(), old_strides.rbegin() + 1,
std::multiplies<long>());
auto iter = a.buffer, iter_end = a.buffer + a.flat_size();
for (long i = 0; iter != iter_end; ++iter, ++i) {
long offset = 0;
for (unsigned long s = 0; s < N; s++)
offset += ((i / old_strides[l[s]]) % shape[l[s]]) * new_strides[s];
new_array.buffer[offset] = *iter;
}
return new_array;
}
示例3: put
types::none_type put(types::ndarray<T, N> &expr, long int ind, T const &v)
{
if (ind >= expr.flat_size() || ind < 0)
throw types::ValueError("indice out of bound");
*(expr.fbegin() + ind) = v;
return __builtin__::None;
}
示例4: outer
types::ndarray<decltype(std::declval<T0>() + std::declval<T1>()),
types::pshape<long, long>>
outer(types::ndarray<T0, pS0> const &a, types::ndarray<T1, pS1> const &b)
{
types::ndarray<decltype(std::declval<T0>() + std::declval<T1>()),
types::pshape<long, long>>
out(types::pshape<long, long>{a.flat_size(), b.flat_size()},
__builtin__::None);
auto iter = out.fbegin();
for (auto iter_a = a.fbegin(), end_a = a.fend(); iter_a != end_a;
++iter_a) {
auto val_a = *iter_a;
iter = std::transform(b.fbegin(), b.fend(), iter,
[=](T1 val) { return val_a * val; });
}
return out;
}
示例5: ValueError
types::list<types::ndarray<T, N>> split(types::ndarray<T, N> const &a,
long nb_split)
{
if (a.flat_size() % nb_split != 0)
throw types::ValueError(
"array split does not result in an equal division");
return array_split(a, nb_split);
}
示例6: decltype
decltype(std::declval<T>() + 1.) median(types::ndarray<T, N> const &arr)
{
size_t n = arr.flat_size();
T *tmp = new T[n];
std::copy(arr.buffer, arr.buffer + n, tmp);
std::sort(tmp, tmp + n);
auto out = (tmp[n / 2] + tmp[(n - 1) / 2]) / double(2);
delete[] tmp;
return out;
}
示例7: repeat
types::ndarray<T, 1> repeat(types::ndarray<T, N> const &expr, int repeats)
{
types::ndarray<T, 1> out(
types::array<long, 1>{{expr.flat_size() * repeats}},
__builtin__::None);
auto out_iter = out.fbegin();
for (auto iter = expr.fbegin(), end = expr.fend(); iter != end; ++iter)
for (int i = 0; i < repeats; ++i)
*out_iter++ = *iter;
return out;
}
示例8: putmask
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;
}
示例9: ValueError
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;
}
示例10: reshape
types::ndarray<T, M> reshape(types::ndarray<T, N> const &expr,
types::array<long, M> const &new_shape)
{
auto where = std::find(new_shape.begin(), new_shape.end(), -1);
if (where != new_shape.end()) {
auto auto_shape = new_shape;
auto_shape[where - new_shape.begin()] =
expr.flat_size() / std::accumulate(new_shape.begin(),
new_shape.end(), -1L,
std::multiplies<long>());
return expr.reshape(auto_shape);
} else
return expr.reshape(new_shape);
}
示例11: resize
types::ndarray<T, M> resize(types::ndarray<T, N> const &expr,
types::array<long, M> const &new_shape)
{
auto where = std::find(new_shape.begin(), new_shape.end(), -1);
if (where != new_shape.end()) {
types::array<long, M> auto_shape(new_shape);
auto_shape[where - new_shape.begin()] =
expr.flat_size() / std::accumulate(new_shape.begin(),
new_shape.end(), -1L,
std::multiplies<long>());
return resize(expr, auto_shape);
}
types::ndarray<T, M> out(new_shape, __builtin__::None);
auto nshape = out.flat_size();
auto n = expr.flat_size();
if (n < nshape) {
auto iter = std::copy(expr.fbegin(), expr.fend(), out.fbegin());
for (long i = 1; i < nshape / n; ++i)
iter = std::copy(out.fbegin(), out.fbegin() + n, iter);
std::copy(out.fbegin(), out.fbegin() + nshape % n, iter);
} else
std::copy(expr.fbegin(), expr.fbegin() + nshape, out.fbegin());
return out;
}
示例12: argsort
types::ndarray<long, N> argsort(types::ndarray<T,N> const& a) {
size_t last_axis = a.shape[N-1];
size_t n = a.flat_size();
types::ndarray<long, N> indices(a.shape, __builtin__::None);
for(long j=0, * iter_indices = indices.buffer, *end_indices = indices.buffer + n;
iter_indices != end_indices;
iter_indices += last_axis, j+=last_axis)
{
// fill with the original indices
std::iota(iter_indices, iter_indices + last_axis, 0L);
// sort the index using the value from a
std::sort(iter_indices, iter_indices + last_axis,
[&a,j](long i1, long i2) {return *(a.fbegin() + j + i1) < *(a.fbegin() + j + i2);});
}
return indices;
}
示例13: decltype
types::ndarray<
typename std::remove_cv<typename std::remove_reference<
decltype(std::declval<T>() +
std::declval<typename utils::nested_container_value_type<
F>::type>())>::type>::type,
1>
append(types::ndarray<T, N> const &nto, F const &data)
{
types::ndarray<typename F::dtype, F::value> ndata(data);
long nsize = nto.flat_size() + ndata.flat_size();
types::ndarray<
typename std::remove_cv<typename std::remove_reference<decltype(
std::declval<T>() +
std::declval<typename utils::nested_container_value_type<
F>::type>())>::type>::type,
1> out(types::make_tuple(nsize), __builtin__::None);
auto out_back = std::copy(nto.fbegin(), nto.fend(), out.fbegin());
std::copy(ndata.fbegin(), ndata.fend(), out_back);
return out;
}
示例14: flatten
types::ndarray<T, 1> flatten(types::ndarray<T, N> const &a)
{
return {a.mem, types::array<long, 1>{{a.flat_size()}}};
}
示例15: tostring
types::str tostring(types::ndarray<T, N> const &expr)
{
return types::str(reinterpret_cast<const char *>(expr.buffer),
expr.flat_size() * sizeof(T));
}