c++xtensor

How to use xt::repeat?


I want to get repeated array same way as numpy but xt::repeat returns expression. When I try to cast this expression to array, I'm getting compile error.

xt::array<int> a = {{1, 2}, {3, 4}};
auto r = xt::repeat(a, 3, 1); // r is expression
xt::array<int> b = r; // compile error here

How to repeat array and get result as another array not expression? Maybe I miss something in documentation but I can not find working example.


Solution

  • This is a bug in xtensor. I am working on a patch, for now you can use the following workaround:

    xt::xarray<int> b(r.shape());
    std::copy(r.cbegin(), r.cend(), b.begin());