You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using cython.final decorator for a cdef class that has a method with an argument of fused type, the generated C code lacks some prefix __pyx_fuse_0 and __pyx_fuse_1 in a few places.
The code compiles without error. But when loading/importing one gets an error:
ImportError: dlopen(XXX.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '___pyx_f_54_cython_magic_570ee92356009cb8197cfd5d5ebfbcc01ad73c1d_6AClass_c_sum'
Code to reproduce the behaviour:
import cython
%load_ext cython
# %%%%cython
import cython
import numpy as np
ctypedef unsignedchar uint8_t
ctypedef unsignedshort uint16_t
ctypedef fused uint_fused:
uint8_t
uint16_t
@cython.final
cdef class AClass:
defcompute_sum(self, a):
if a.dtype == np.float32:
returnself.c_sum[uint8_t](a)
else:
returnself.c_sum[uint16_t](a)
cdef c_sum(self, uint_fused[:] a):
cdef:
int i
uint16_t s =0for i inrange(a.shape[0]):
s += a[i]
return s
# %%
aclass = AClass()
aclass.compute_sum(np.arange(10).astype(np.uint16))
Note that without the @cython.final, everything works as expected without error.
Expected behaviour
No error, result 45.
OS
macOS
Python version
3.11.7
Cython version
3.0.8
Additional context
No response
The text was updated successfully, but these errors were encountered:
I'll try to have a look in the next week or so. I should warn: this fused stuff is usually quite heavy going to debug and fix, so I'm really not going to promise anything quick.
Thanks for having a look.
A striking argument for Cython is allocating numpy arrays in Python and then use memoryviews in Cython, in particular in a prange. Then one quickly wants c++ templates, the next best thing being fused types, last resort tempita.
So the combination of C++ with memoryviews would be super helpful, but the C(++) structure of memoryviews is quite hidden.
TLDR: If Cython works, it‘s very cool. If it doesn’t, try n error can drive you crazy 😜
da-woods
added a commit
to da-woods/cython
that referenced
this issue
Feb 17, 2024
Describe the bug
When using
cython.final
decorator for acdef class
that has a method with an argument of fused type, the generated C code lacks some prefix__pyx_fuse_0
and__pyx_fuse_1
in a few places.The code compiles without error. But when loading/importing one gets an error:
Code to reproduce the behaviour:
Note that without the
@cython.final
, everything works as expected without error.Expected behaviour
No error, result 45.
OS
macOS
Python version
3.11.7
Cython version
3.0.8
Additional context
No response
The text was updated successfully, but these errors were encountered: