-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Use Pure Python versions of Cython
We can try to teach the Pure Python syntax of Cython instead of the cdef syntax.
Pure Python syntax which allows static Cython type declarations in pure Python code, following PEP-484 type hints and PEP 526 variable annotations.
https://cython.readthedocs.io/en/stable/src/userguide/language_basics.html
Typed memoryviews syntax for Numpy
Also for Numpy arrays we can type declare using data: cython.int[:,:] instead of cdef cnp.ndarray[cnp.int32_t, ndim=2] data. Yes it is not equivalent, but it is elegant and easier to teach.
Typed memoryviews allow efficient access to memory buffers, such as those underlying NumPy arrays, without incurring any Python overhead. Memoryviews are similar to the current NumPy array buffer support (np.ndarray[np.float64_t, ndim=2]), but they have more features and cleaner syntax.
https://cython.readthedocs.io/en/stable/src/userguide/memoryviews.html#memoryviews