xtensor
xtensor copied to clipboard
When using adapt with strides, the assignment operator doesn't work correctly
When using adapt with strides, the assignment operator doesn't work correctly.
#include <iostream>
#include <xtensor/xadapt.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xtensor.hpp>
#include <xtensor/xview.hpp>
int main() {
xt::xtensor<float, 2> tensor_input = xt::arange(25).reshape({5, 5});
xt::xtensor<float, 2> tensor_output = xt::arange(9).reshape({3, 3});
auto column_output = xt::adapt(tensor_output.data(), 3lu, xt::no_ownership(), std::array{3lu, 1lu}, tensor_output.strides());
const auto* ptr = &tensor_input[{0, 0}];
auto column_input = xt::adapt(ptr + 2, 3lu, xt::no_ownership(), std::array{3lu, 1lu}, tensor_input.strides());
std::cout << "tensor_output before: \n" << tensor_output << "\n";
std::cout << "column_output : \n" << column_output << "\n";
std::cout << "column_input : \n" << column_input << "\n";
// Error: assignes column_input to the first row of tensor_output instead of column
column_output = column_input;
std::cout << "tensor_output after: \n" << tensor_output << "\n";
}
Output:
tensor_output before:
{{ 0., 1., 2.},
{ 3., 4., 5.},
{ 6., 7., 8.}}
column_output :
{{ 0.},
{ 3.},
{ 6.}}
column_input :
{{ 2.},
{ 7.},
{ 12.}}
tensor_output after:
{{ 2., 7., 12.},
{ 3., 4., 5.},
{ 6., 7., 8.}}
Looks like a bug (I can reproduce).
Hi Johan, we have just discovered this again, so just kindly bumping this up...
Hi there, I'm just kindly kindly bumping this up again...
Just kindly bumping this up again. It's a nasty nasty bug, after all... :-) :-)
Just kindly bumping this up again...