Hi,
I'm reading through numpy.pxd and trying to understand the following:
ctypedef class numpy.ndarray [object PyArrayObject]
Probably, I have made some wrong conclusions and was hoping for an
explanation. Sorry if these are simple questions, but I wasn't able
to find info on this in the docs (links are appreciated).
0) What does the above statement mean, in words?
1) Previously, I thought I understood what the keyword "object"
meant. I believed it to be a synonmyn for PyObject*, but the above
usage makes me question that conclusion. So what is "object" really?
2) In the above, I am having trouble seeing what is the original type
and the new type, as in "typedef oldtypename newtypename". When I
read the above code, it seems as if there is no "second argument".
Help.
Relatedly, I was wondering how best to use an object member. For instance,
cdef Klass:
cdef object x
def __init__(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x):
self.x = x
def func(self):
cdef np.ndarray[FTYPE_t, ndim=1, mode="c"] x = self.x
# ...use x instead of self.x for fast access so that
# (self.x.shape[0] is operating on a Python tuple)
When I examine the C code, I see that x (the __init__ method parameter) has
type PyArrayObject* while self.x has PyObject*. No problem. In func(),
if I want to have fast access to self.x, is the recommended
way to do this as I did above? I wasn't sure if I should instead do
something like:
def func(self):
cdef PyArrayObject* x = <PyArrayObject *>(self.x)
# ...use x instead of self.x for fast access
Thanks in advance.
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev