pythran icon indicating copy to clipboard operation
pythran copied to clipboard

Indexing mismatch numpy/pythran when indexing 3D array with 2D bool array

Open cycomanic opened this issue 3 years ago • 2 comments

I just encountered an issue with "advanced" indexing. In fact there might be two issues.

The code below yields completely different results for numpy and pythran

#pythran export avgpixel(float64[:,:,3], float64)
def avgpixel(img, avg):
    out = np.zeros_like(img)
    o = np.mean(img, axis=-1)
    out[o>avg] =  255
    return out

I moved the below compile error to #1717 because I'm not sure it directly related.

import numpy as np

#pythran export avgpixel(float64[:,:,3], float64)
def avgpixel(img, avg):
    out = np.zeros_like(img)
    o = np.mean(img, axis=-1)
    idx = np.where(o>avg)
    out[idx] = 255
    return out

I get a compile error in pythran (see below)

In file included from /home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/ndarray.hpp:39:
/home/jschrod/PycharmProjects/pythran/pythran/pythonic/include/types/numpy_gexpr.hpp:533:5: error: static_assert failed due to requirement 'utils::all_of<true, false>::value' "all slices are valid"
    static_assert(
    ^
/tmp/tmp1695bo21.cpp:70:5: note: in instantiation of template class '(anonymous namespace)::pythonic::types::numpy_gexpr<(anonymous namespace)::pythonic::types::ndarray<double, (anonymous namespace)::pythonic::types::array_base<long, 3, (anonymous namespace)::pythonic::types::tuple_version>>, (anonymous namespace)::pythonic::types::contiguous_normalized_slice, (anonymous namespace)::pythonic::types::ndarray<long, (anonymous namespace)::pythonic::types::array_base<long, 1, (anonymous namespace)::pythonic::types::tuple_version>>>' requested here
    out[idx] = 255L;
    ^
/tmp/tmp1695bo21.cpp:81:78: note: in instantiation of function template specialization '__pythran_test_average::avgpixel::operator()<(anonymous namespace)::pythonic::types::ndarray<double, (anonymous namespace)::pythonic::types::pshape<long, long, std::integral_constant<long, 3>>> &, double &>' requested here
                                auto res = __pythran_test_average::avgpixel()(img, avg);
                                                                             ^
1 error generated.
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!!!!

This is on latest master.

cycomanic avatar Jan 29 '21 21:01 cycomanic