Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexing with slices and integers #2272

Open
ev-br opened this issue Jan 9, 2025 · 2 comments
Open

indexing with slices and integers #2272

ev-br opened this issue Jan 9, 2025 · 2 comments

Comments

@ev-br
Copy link

ev-br commented Jan 9, 2025

Indexing a 2D array with slices seems to work; indexing with integers seems to work; but indexing one dimension with a slice and the other dimension with an integer calls Jack.
MRE:

$ cat expt1.py 
import numpy as np

#pythran export foo(float[:, :], slice, int)
def foo(x, sl, i):
    assert i < x.shape[0]
    assert i < x.shape[1]
    return x[sl, i].copy()

$ pythran --version
0.17.0

$ pythran expt1.py -UNDEBUG

/tmp/tmp6a99679s.cpp: In instantiation of 'struct {anonymous}::__pythran_expt1::foo::type<{anonymous}::pythonic::types::ndarray<double, {anonymous}::pythonic::types::pshape<long int, long int> >, {anonymous}::pythonic::types::slice, long int>':
/tmp/tmp6a99679s.cpp:74:135:   required from here
/tmp/tmp6a99679s.cpp:50:49: error: no match for 'operator[]' (operand types are '{anonymous}::pythonic::types::ndarray<double, {anonymous}::pythonic::types::pshape<long int, long int> >' and 'std::tuple<{anonymous}::pythonic::types::slice, long int>')
   50 |         typedef decltype(std::declval<__type3>()[std::declval<__type8>()]) __type9;
      |                          ~~~~~~~~~~~~~~~~~~~~~~~^
In file included from /home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/types/ndarray.hpp:4,
                 from /home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/types/tuple.hpp:8,
                 from /home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/builtins/bool_.hpp:6,
                 from /home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/types/NoneType.hpp:6,
                 from /home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/types/slice.hpp:5,
                 from /home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/core.hpp:47,
                 from /tmp/tmp6a99679s.cpp:1:
/home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/pythran/pythonic/include/types/ndarray.hpp:433:5: note: candidate: 'template<class S> typename std::enable_if<{anonymous}::pythonic::types::is_slice<Sp>::value, {anonymous}::pythonic::types::numpy_gexpr<const {anonymous}::pythonic::types::ndarray<T, pS>&, typename {anonymous}::pythonic::types::normalized<Sp>::type> >::type {anonymous}::pythonic::types::ndarray<T, pS>::operator[](const S&) const & [with T = double; pS = {anonymous}::pythonic::types::pshape<long int, long int>]'
  433 |     operator[](S const &s) const &;
      |     ^~~~~~~~

... snip ...

/tmp/tmp6a99679s.cpp:58:82: note:   template argument deduction/substitution failed:
At global scope:
cc1plus: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics
WARNING  Compilation error, trying hard to find its origin...
Compilation error, trying hard to find its origin...
WARNING  Nope, I'm going to flood you with C++ errors!
Nope, I'm going to flood you with C++ errors!
CRITICAL Cover me Jack. Jack? Jaaaaack!!!!
E: error: command '/home/br/miniforge3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-c++' failed with exit code 1

@serge-sans-paille
Copy link
Owner

Yeah I think we still don't support that - I'll have a look though. Meanwhile you can use explicit loop, that's less pleasant to the eye but performance why, it'll probably be even better (sadly)

@ev-br
Copy link
Author

ev-br commented Jan 12, 2025

Yes, changing to x[sl][i] seems to work just fine, so low prio.

For context, this came up in scipy/scipy#22298, where scipy/scipy#22298 (comment) looks more like a blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants