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

Multi-dimensional array slices #2084

Open
radkoff opened this issue Feb 22, 2023 · 0 comments
Open

Multi-dimensional array slices #2084

radkoff opened this issue Feb 22, 2023 · 0 comments

Comments

@radkoff
Copy link

radkoff commented Feb 22, 2023

Hi, thanks for the fast response to my last issue. I might have a few more for you this week.

I'm wondering if pythran supports slicing into multi-dimensional arrays with index numpy arrays? This script:

import numpy as np

#pythran export foo(float[][])
def foo(arr):
    arr2 = np.zeros(arr.shape)
    arr2[np.array([1, 2, 3, 4, 5]), np.array([1, 2, 3, 4, 5])] = 1
    return arr2

Is giving me a couple of compilation errors:

/Users/evan/miniforge3/envs/project/lib/python3.9/site-packages/pythran/pythonic/include/types/numpy_gexpr.hpp:549:5: error: static_assert failed due to requirement 'utils::all_of<true, false>::value' "all slices are valid"
    static_assert(
    ^

/var/folders/l5/210k0yvw8xj04j001s6yhlr00000gq/T/tmpj8b8q34j.cpp:103:277: error: no viable overloaded '='
    arr2[pythonic::types::make_tuple(pythonic::numpy::functor::array{}(pythonic::types::make_tuple(1L, 2L, 3L, 4L, 5L), pythonic::numpy::functor::int64{}), pythonic::numpy::functor::array{}(pythonic::types::make_tuple(1L, 2L, 3L, 4L, 5L), pythonic::numpy::functor::int64{}))] = 1L;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~

Printing arr2[np.array([1, 2, 3, 4, 5]), np.array([1, 2, 3, 4, 5])] instead of using it for an assignment instead gives the error:

/Users/evan/miniforge3/envs/project/lib/python3.9/site-packages/pythran/pythonic/types/ndarray.hpp:1050:38: error: no type named 'dtype' in '(anonymous namespace)::pythonic::types::numpy_gexpr<(anonymous namespace)::pythonic::types::ndarray<double, (anonymous namespace)::pythonic::types::array_base<long, 2, (anonymous namespace)::pythonic::types::tuple_version>>, (anonymous namespace)::pythonic::types::contiguous_normalized_slice, (anonymous namespace)::pythonic::types::ndarray<long long, (anonymous namespace)::pythonic::types::pshape<std::integral_constant<long, 5>>>>'
    return os << ndarray<typename E::dtype, typename E::shape_t>{e};

I'm using the latest code from master, with compile command:

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/evan/miniforge3/envs/project/include -arch arm64 -I/Users/evan/miniforge3/envs/project/include -fPIC -O2 -isystem /Users/evan/miniforge3/envs/project/include -arch arm64 -DENABLE_PYTHON_MODULE -D__PYTHRAN__=3 -DPYTHRAN_BLAS_OPENBLAS -I/usr/local/opt/openblas/include -I/Users/evan/miniforge3/envs/project/lib/python3.9/site-packages/pythran -I/Users/evan/miniforge3/envs/project/lib/python3.9/site-packages/numpy/core/include -I/Users/evan/miniforge3/envs/project/include/python3.9 -c /var/folders/l5/210k0yvw8xj04j001s6yhlr00000gq/T/tmpv4d2hdss.cpp -o /var/folders/l5/210k0yvw8xj04j001s6yhlr00000gq/T/tmpbyr82jsz/var/folders/l5/210k0yvw8xj04j001s6yhlr00000gq/T/tmpv4d2hdss.o -std=c++11 -fno-math-errno -Wno-unused-function
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

1 participant