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] Cannot put fused type pointer in return type for cdef'd function with latest cython #5816

Open
david-cortes opened this issue Nov 13, 2023 · 3 comments

Comments

@david-cortes
Copy link

Describe the bug

This sort of code was working fine with earlier versions of cython (I think also with 3.0.0):

ctypedef fused int_t:
    int
    int64_t
    size_t

...
    
cdef int_t* get_ptr_int(np.ndarray[int_t, ndim=1] a):
    if a.shape[0]:
        return &a[0]
    else:
        return NULL

Example in usage:
https://github.com/david-cortes/readsparse/blob/7869e7a4e7097f8f82a8eb25da82c2db6e10738a/readsparse/cpp_interface.pxi#L220

But with Cython 3.0.5, it now throws an error when compiling:

cdef int_t* get_ptr_int(np.ndarray[int_t, ndim=1] a):
                       ^
------------------------------------------------------------

readsparse/cpp_interface.pxi:257:23: Type is not specialized

Instead, one now has to change the type to void* and cast the result in the lines where it is called:

cdef void* get_ptr_int(np.ndarray[int_t, ndim=1] a):
    if a.shape[0]:
        return &a[0]
    else:
        return NULL

...

cdef int_t *ptr = <int_t*>get_ptr_int(x)

Example in usage:
https://github.com/david-cortes/readsparse/blob/c7e04ed66ac1aa91e7eb72231e114f26e8506aa5/readsparse/cpp_interface.pxi#L1101

Code to reproduce the behaviour:

from libc.stdint cimport int64_t
import numpy as np
cimport numpy as np

ctypedef fused int_t:
    int
    int64_t
    size_t
    
cdef int_t* get_ptr_int(np.ndarray[int_t, ndim=1] a):
    if a.shape[0]:
        return &a[0]
    else:
        return NULL

Expected behaviour

Should compile and work as if it were a C++ template

OS

Linux

Python version

3.11

Cython version

3.0.5

Additional context

No response

@da-woods
Copy link
Contributor

Looks to bisect to b480ae6

@da-woods
Copy link
Contributor

This is fixed in #5710

@da-woods
Copy link
Contributor

I'll re-open this since I really meant "This will be fixed by a pending PR", not "this has been fixed already"

@da-woods da-woods reopened this Nov 14, 2023
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