pythran
pythran copied to clipboard
Multi-dimensional indexing does not work correctly
Split from #1714
I get a compile error when trying to index an array with a tuple.
Example code:
#pythran export indexing(float64[:,:,3], (int[], int[]))
def indexing(img, idx):
return img[idx]
Compiler error (gcc):
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp: In instantiation of ‘struct {anonymous}::pythonic::types::numpy_gexpr<{anonymous}::pythonic::types::ndarray<double, {anonymous}::pythonic::types::array_base<long int, 3, {anonymous}::pythonic::types::tuple_version> >, {anonymous}::pythonic::types::contiguous_normalized_slice, {anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >’:
/tmp/tmpv6req14z.cpp:42:685: required from here
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:536:71: error: static assertion failed: all slices are valid
536 | std::is_same<S, normalized_slice>::value)...>::value,
| ^~~~~
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp: In instantiation of ‘constexpr const size_t {anonymous}::pythonic::types::count_long<{anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >::value’:
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:166:24: recursively required from ‘constexpr const size_t {anonymous}::pythonic::types::count_long<{anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >::value’
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:166:24: required from ‘constexpr const size_t {anonymous}::pythonic::types::count_long<{anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >::value’
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:166:54: required from ‘constexpr const size_t {anonymous}::pythonic::types::count_long<{anonymous}::pythonic::types::contiguous_normalized_slice, {anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >::value’
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:557:69: required from ‘constexpr const size_t {anonymous}::pythonic::types::numpy_gexpr<{anonymous}::pythonic::types::ndarray<double, {anonymous}::pythonic::types::array_base<long int, 3, {anonymous}::pythonic::types::tuple_version> >, {anonymous}::pythonic::types::contiguous_normalized_slice, {anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >::value’
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:578:52: required from ‘struct {anonymous}::pythonic::types::numpy_gexpr<{anonymous}::pythonic::types::ndarray<double, {anonymous}::pythonic::types::array_base<long int, 3, {anonymous}::pythonic::types::tuple_version> >, {anonymous}::pythonic::types::contiguous_normalized_slice, {anonymous}::pythonic::types::ndarray<long int, {anonymous}::pythonic::types::pshape<long int> > >’
/tmp/tmpv6req14z.cpp:42:685: required from here
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:166:24: fatal error: template instantiation depth exceeds maximum of 900 (use ‘-ftemplate-depth=’ to increase the maximum)
166 | count_long<T>::value + count_long<Types...>::value;
| ^~~~~
compilation terminated.
WARNING: Compilation error, trying hard to find its origin...
WARNING: Nop, I'm going to flood you with C++ errors!
CRITICAL: Cover me Jack. Jack? Jaaaaack!!!!
Initially I thought this was related to a having only two elements of the tuple for a 3D array, but the following also yields the same error:
#pythran export index2(float64[:,:], (int[],int[]))
def index2(img, idx):
return img[idx]
I suspect that this is the same error as #1664. I can simplify to:
#pythran export draw_line(int64[][], int64[])
def draw_line(grid, x):
grid[:,x] = 1
return grid
which results in teh same compile error as above.
On the other hand
#pythran export draw_line(int64[][], int64[])
def draw_line(grid, x):
grid[x,:] = 1
return grid
compiles but does not modify grid, so gives an incorrect result.
Finally
#pythran export draw_line(int64[][], int64[])
def draw_line(grid, x):
grid[x] = 1
return grid
does the right thing.
I've looked at ~numpy_gexpr.hpp~ but that goes beyond my cpp skillset.