xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

When using adapt with strides, the assignment operator doesn't work correctly

Open vakokako opened this issue 4 years ago • 5 comments

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.}}

vakokako avatar Mar 17 '21 16:03 vakokako

Looks like a bug (I can reproduce).

JohanMabille avatar Mar 23 '21 05:03 JohanMabille

Hi Johan, we have just discovered this again, so just kindly bumping this up...

vakokako avatar Aug 11 '21 10:08 vakokako

Hi there, I'm just kindly kindly bumping this up again...

emmenlau avatar Dec 17 '21 10:12 emmenlau

Just kindly bumping this up again. It's a nasty nasty bug, after all... :-) :-)

emmenlau avatar May 03 '23 13:05 emmenlau

Just kindly bumping this up again...

emmenlau avatar Jan 24 '24 12:01 emmenlau