[Cython] Type scope vs. runtime scope
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Sun Aug 3 21:44:13 CEST 2008
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)
This however creates an error:
'int64' is not a constant, variable or function identifier
since int64 is declared as a type in the scope.
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
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.
--
Dag Sverre
More information about the Cython-dev
mailing list