[Cython] Type scope vs. runtime scope
Robert Bradshaw
robertwb at math.washington.edu
Tue Aug 5 04:34:42 CEST 2008
On Aug 3, 2008, at 12:44 PM, Dag Sverre Seljebotn wrote:
> In numpy.pxd I want to have this:
>
> ctypedef npy_int64 int64
>
> and be able to use it like this (this is what a NumPy user would
> expect
> to do):
>
> cimport numpy
> cdef numpy.ndarray[numpy.int64, 2] = numpy.zeros([10, 10],
> numpy.int64)
Yes.
> This however creates an error:
> 'int64' is not a constant, variable or function identifier
>
> since int64 is declared as a type in the scope.
Where is this error being thrown from? Perhaps it could/should be
checked after the buffer transforms?
> I've had rather complicated and grand schemes for this earlier, but
> what
> I'll propose this time is much simpler: When not in a "type context"
> (what you are writing cannot possibly be a C type), C types vanish
> from
> the scope/are not considered .. so that the ctypedef numpy.int64
> does not
>
> Warning! In theory, this principle could allow code like
>
> x = 4
> ctypedef int x
> cdef x v = x
I'm not completely following that, but it looks scary.
> If you didn't like this but have time, you could have a look at
>
> http://wiki.cython.org/enhancements/runtimectypes
>
> which is another proposal I could use to achieve my ends, however I'm
> reluctant to think or discuss something going so much into language
> design right now.
I'm not sure I like that proposal either.
- Robert
More information about the Cython-dev
mailing list