pythran icon indicating copy to clipboard operation
pythran copied to clipboard

Error triggered when adding a different function

Open Dapid opened this issue 2 years ago • 5 comments

The following code compiles:

import numpy as np

# pythran export compute(float64[:], int)
def compute(vector: np.ndarray, k: int):
    # Select the top-k
    all_indexes = np.argsort(vector)
    sel_indexes = all_indexes[:k]

    return vector[sel_indexes].sum()

But, if we add another function,

#pythran export c2(float64[:, :],  float64[:], int)
def c2(vector2: np.ndarray, bloom2: np.ndarray, k2: int):
    all_indexes = np.argsort(vector2, axis=1)
    return bloom2[all_indexes[:, -k2:]].sum()

Pythran chokes on the first one:

$ pythran _a.py 
WARNING: Compilation error, trying hard to find its origin...
Compilation error, trying hard to find its origin...
CRITICAL: You shall not pass!
E: _a.py:9:11 error: Invalid subscripting of `int` by `slice`
----
    return vector[sel_indexes].sum()
           ^~~~ (o_0)
----

You shall not pass!
E: _a.py:9:11 error: Invalid subscripting of `int` by `slice`
----
    return vector[sel_indexes].sum()
           ^~~~ (o_0)
----

The order of the functions doesn't matter.

Compiling c2 only also fails, with Pythran calling for Jack, and threatening with flooding me with C++ errors, but never following through:

E: error: Command "gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -march=native -O2 -pipe -mtune=native -fPIC -DENABLE_PYTHON_MODULE -D__PYTHRAN__=3 -DPYTHRAN_BLAS_BLAS -I/home/david/.virtualenv/py39/lib/python3.9/site-packages/pythran -I/home/david/.virtualenv/py39/lib64/python3.9/site-packages/numpy/core/include -I/usr/local/include -I/home/david/.virtualenv/py39/include -I/usr/include/python3.9 -c /tmp/tmp49me4yct.cpp -o /tmp/tmpodcacr_f/tmp/tmp49me4yct.o -std=c++11 -fno-math-errno -fvisibility=hidden -fno-wrapv -Wno-unused-function -Wno-int-in-bool-context -Wno-unknown-warning-option -march=native -O2 -pipe -mtune=native" failed with exit status 1

The functions at least are runnable:

compute(np.random.random(100), 10)
c2(np.random.random((500, 100)), np.random.random(1000), 10)

Dapid avatar Aug 09 '22 13:08 Dapid

Forgot to add, the error happens both release and master. gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1) and Python 3.9.13.

Dapid avatar Aug 09 '22 13:08 Dapid

Still present in 0.12.0.

Dapid avatar Sep 28 '22 08:09 Dapid

Thanks for the... reminder :-) Turns out we don't implement np.argsort along axis. I'll have a look :-)

serge-sans-paille avatar Sep 28 '22 09:09 serge-sans-paille

But why does it crash on the other function?

Dapid avatar Sep 28 '22 20:09 Dapid

because type error reporting in pythran is... not that good :-/

serge-sans-paille avatar Sep 28 '22 20:09 serge-sans-paille