xtensor-stack / xtl

The x template library
BSD 3-Clause "New" or "Revised" License
207 stars 96 forks source link

How is `ravel_index()` supposed to work/be used? #245

Closed wildmichael closed 3 years ago

wildmichael commented 3 years ago

In xstrides.hpp there is the (undocumented) function ravel_index() (as opposed to the documented ravel_indices()). It is also not covered by any unit test, and from my tests, it seems like it's really broken. Calling it like this fails to compile:

xt::svector<size_t> index = { 2, 1, 1 };
xt::svector<size_t> shape = { 10, 20, 30 };
auto rav_index = xt::ravel_index(index, shape, xt::layout_type::row_major);

The relevant part of the error message (g++ 9.3):

xstrides.hpp:504:35: error: invalid static_cast from type ‘const xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>’ to type ‘strides_value_type’ {aka ‘long int’}
  504 |         return ravel_from_strides(static_cast<strides_value_type>(index), strides);
t-bltg commented 3 years ago

@wildmichael, I took your example for test/test_xstrides.cpp should be fixed by https://github.com/xtensor-stack/xtensor/pull/2344.