So, Lisandro has shown that the buffer [] syntax has some problems, and
I'd like to write some on that.
As it is, things are going to work "by accident"; because dtype is
before ndim, you either have non-numerals first or you have a keyword
argument (ndim=2), so any number or nothing following [ means array
notation.
It is technically possible to make the distinction on the base type
instead (but some work to make it happen, it means that the parser
cannot resolve the meaning of the [], I have to postpone it until during
analysis phase and create a "TrailingBracketsTypeNode" -- and because of
the ordering of dtype and ndim, I luckily don't need to).
Still, it feels quite unsatisfying for a syntax -- one could easily be
led to think that
cdef ndarray[int, 2]
means a 1D array of ints with two elements.
So I'm reconsidering some of these options now:
- Follow Dan Gindikin and Pex: Make a new syntax in the Lexicon for
integer literals followed by a "D", as meaning "dimensionality". So you
need to do
cdef ndarray[int, 2D]
As [] tends to mean "array" and the contents "length", this has a
certain appeal, it is more unambigious what it all means.
Another advantage is that this could be hard-linked to the ndim keyword,
so that if you do
cdef class DoubleArray:
__cythonbufferdefaults__ = {'dtype': double}
then one could do
cdef DoubleArray[2D] arr
(This would get really strange without the D suffix.)
- Require that ndim is given by name. The verbosity of this is a big
problem IMO.
- Both? Either [0-9]+D, or ndim=[0-9]+
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev