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

[BUG] numpy types cannot be used for ufunc arguments #6161

Open
maxnoe opened this issue Apr 24, 2024 · 1 comment · May be fixed by #6196
Open

[BUG] numpy types cannot be used for ufunc arguments #6161

maxnoe opened this issue Apr 24, 2024 · 1 comment · May be fixed by #6196
Labels

Comments

@maxnoe
Copy link

maxnoe commented Apr 24, 2024

Describe the bug

Using numpy's C types for ufunc declarations raises a very long error.

Compiling /home/mnoethe/test/cython/test_numpy_ufunc.pyx because it changed.
[1/1] Cythonizing /home/mnoethe/test/cython/test_numpy_ufunc.pyx

Error compiling Cython file:
------------------------------------------------------------
...
from stdlib.stdint import int64_t

np.import_array()

@cython.ufunc
cdef np.int64_t add_one(np.int64_t x):
     ^
------------------------------------------------------------

test_numpy_ufunc.pyx:9:5: Type 'int64_t' cannot be used as a ufunc argument


...

Code to reproduce the behaviour:

#cython: language_level=3
cimport cython
cimport numpy as np

np.import_array()

@cython.ufunc
cdef np.int64_t add_one(np.int64_t x):
    return x + 1

Expected behaviour

Numpy ufuncs work with numpy data types.

OS

Linux, Ubuntu 22.04

Python version

3.11

Cython version

cython 3.0.10 py311hb755f60_0 conda-forge

Additional context

No response

@da-woods
Copy link
Contributor

Thanks for the report. It's good to know what people are trying this and finding the obvious deficiencies :-)

It's slightly harder than it looks. Cython doesn't actually know a lot about integer typedefs - mostly just that it's "some integer" and whether it's signed or not. However, it needs to tell Numpy exactly what type is actually being used. So it either needs some special-casing for these Numpy typedefs, or it needs a clever runtime mechanism to work out what to tell Numpy.

@da-woods da-woods added the numpy label Apr 24, 2024
@maxnoe maxnoe changed the title [BUG] numpy types cannot for ufunc arguments [BUG] numpy types cannot be used for ufunc arguments Apr 24, 2024
@da-woods da-woods linked a pull request May 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants