xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Using xtensor indices slicing issues

Open james-mxr opened this issue 1 year ago • 1 comments

I'm trying to run a simple code example to test out slicing arrays. However I'm getting both bizarre results and errors:

xt::xarray<double> arr1
                    { {1.0, 2.0, 3.0},
                      {4.0, 5.0, 6.0},
                      {7.0, 8.0, 9.0} };

xt::xtensor<int, 2> index {{0, 0}, {1, 0}, {1, 1}};

xt::xarray<double> v = xt::index_view(arr1, index);
std::cout << v << std::endl;

auto b = xt::index_view(arr1, {{0, 0}, {1, 0}, {1, 1}});
std::cout << b << std::endl; // {1, 4, 5}

Variable v gives me : { 1., 1., 2., 1., 2., 2.}, which I can't make sense of, it's like it's flattening the array and then using the individual indices.

Setting up auto b gives me the following errors,

: error C2668: 'xt::to_array': ambiguous call to overloaded function
: error C2440: '<function-style-cast>': cannot convert from 'xt::xarray_container<xt::uvector<double,std::allocator<T>>,xt::layout_type::row_major,xt::svector<size_t,4,std::allocator<unsigned __int64>,true>,xt::xtensor_expression_tag>' to 'view_type'
: error C3313: 'b': variable cannot have the type 'void'
: error C3536: 'b': cannot be used before it is initialized

james-mxr avatar Jul 12 '22 16:07 james-mxr

I agree that it looks that you might be on to possibly two bugs. In order to debug, it would be very helpful to have the full error stream, or at least the full stream of the relevant part. Now you have removed the headers/lines so one has to go searching. I would also be helpful to open a PR with the two cases added to the tests. From there we can all read the error(s)

tdegeus avatar Jul 26 '22 12:07 tdegeus