I want to implement np.tile(a[:,0], (len(b), 1)) in cpp xtensor and I got to the following line, with a xarray<float>(N,21) and b xarray<float>(M,21).
xt::xarray<float> res = xt::tile(
xt::reshape_view(
xt::view(a, xt::all(), 0),
{1, static_cast<int>(a.shape(0))}
),
{static_cast<int>(b.shape(0)),1}
);
However whenever I get to M>1 my process dies with std::bad_array_new_length. I verified the shapes of a and b and they are correct. Any idea what might be the problem?
As I didn't understand the problem I tried to extract it in the following helper file:
#include <xtensor/xarray.hpp>
#include <xtensor/xpad.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor/xview.hpp>
int main(){
xt::xarray<float> a = xt::random::rand<float>({2,21});
xt::xarray<float> b = xt::random::rand<float>({2,21});
xt::xarray<float> res = xt::tile(
xt::reshape_view(
xt::view(a, xt::all(), 0),
{1, static_cast<int>(a.shape(0))}
),
{static_cast<int>(b.shape(0)),1}
);
std::cout << res << std::endl;
return 0;
}
which gave me the expected output:
{{ 0.814724, 0.725839},
{ 0.814724, 0.725839}}
So I'm kinda lost now on how to fix this. Would appreciate some hints!