[Numpy-discussion] Cython/NumPy syntax
Dag Sverre Seljebotn
Wed Aug 6 03:04:24 CDT 2008
I'd like input from anyone interested in the following syntax questions.
The current experimental Cython syntax for efficient ndarray indexing
looks like this:
cdef numpy.ndarray[numpy.int64, 2] arr
Issue 1: One can argue that "2" above looks like a length specifier to
Issue 2: This clashes with some forms of C array notation (you can do
"sizeof(int)" or "extern ... def myfunc(int)" in Cython, and though
such syntax is redundant it will stay in order not to break code).
Solving issue #1 helps with #2 as well because without a single integer
literal in it it should look a lot less like an array declaration.
So, some quick proposals:
- Require a "D" suffix for the number of dimensions. This should make it
very clear that the 2 stands for dimensionality and not shape.
cdef numpy.ndarray[numpy.int64, 2D] arr
a) numpy.ndarray[numpy.int64, 2D]
b) numpy.ndarray[numpy.int64 2D]
c) numpy.ndarray[2D numpy.int64]
(Note that I want to leave the way open for adding mode="c" or
mode="fortran", so using a "," seems good for that reason).
- Require an ndim keyword:
cdef numpy.ndarray[numpy.int64, ndim=2]
- Other type of brackets. This boils down to (for various reasons) the
cdef numpy.ndarray<numpy.int64, 2>
(However, one should remember that Cython may want to support using C++
templates at some point).
More information about the Numpy-discussion