On Aug 4, 2008, at 11:36 PM, Dag Sverre Seljebotn wrote:
> Robert Bradshaw wrote:
>> 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?
>
> The problem is that once numpy.int64 is declared as a ctypedef, it
> is not
> longer available to be called at runtime as a python object, so you
> cannot
> get the reference to pass to numpy.zeros.
>
> To be clear, in numpy.pxd it says
>
> cdef extern ... : ctypedef int npy_int64
> ctypedef npy_int64 int64
>
> while some consequence of numpy/__init__.py deep down somewhere is
> assigning something to the int64 attribute of the numpy module.
>
> (This has nothing to do with buffers.)
>
> One solution is requiring people to do "cimport c_numpy", but I'd
> like to
> avoid that as well. Unless this is resolved (on a language design
> level,
> technically it as too many solutions...), I need to figure out a
> way to
> mangle the names without loosing usability too much...
OK, I completely missed the point of what you were trying to do last
time (I blame bad linewrapping in the numpy.zeros function ;-).
What if, when you wrote
ctypedef npy_int64 int64
it would do a check to see if int64 was already defined (as a normal
variable) and if so would attach that information to the type (same
as with extension types that have a dual nature). When used in a
variable context it would extract this information.
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev