To solve issue #2498, I did some experiments
https://github.com/cython/cython/issues/2498#issuecomment-414543549 with
hiding direct field access in an external extension type (documented
here
https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#external-extension-types).
The idea is to write `a.ndims` in cython (in plain python code), and in
C magically get the attribute lookup converted into a `PyArray_NDIMS(a)`
getter, which could be a macro or a c-function.
The experiments proved fruitful, and garnered some positive feedback so
I am pushing forward.
I would like to get some feedback on syntax before I progress too far.
Should the syntax be extended to support
|ctypedef class numpy.ndarray [object PyArrayObject]: cdef: # Convert
python __getattr__ access to c functions. int ndims PyArray_NDIMS |
or perhaps a decorator, like Python
|ctypedef class numpy.ndarray [object PyArrayObject]: cdef: # Convert
python __getattr__ access to c functions. @property cdef int
ndims(self): return PyArray_NDIMS(self) or something else? The second
seems more wordy but more explicit. I don't know which would be easier
to implement or require more effort to test and maintain. Matti |
_______________________________________________
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel