Michal Majeran
Michal Majeran

Reputation: 41

XTensor: merge a circular buffer of 3d Xtensor arrays into one 4d Xtensor array

I have a circular buffer buffer of xtensor 3d arrays (each buffer element has exactly the shape).

I want to create a 4D xtensor array adapter from the circular buffer so the shape would like that (size of the buffer, first_element_shape(0), first_element_shape(1), first_element_shape(2).

I tried to create it via adapt:

auto shape = _buffer.begin()->shape();
std::array<size_t, 4> final_shape = {_buffer.getSize(), shape[0], shape[1], shape[2]};
// Convert the buffer of xtensor arrays into a single xtensor array
xt::xarray<float> xtView = xt::adapt(_buffer.begin()->data(),
                              _buffer.getSize() * _buffer.begin()->size(), final_shape);

Unfortunately it the shape doesn't like like expected. Any help? Ideally I don't want to make any copy of the data, just create a view.

Upvotes: 0

Views: 27

Answers (0)

Related Questions