[Numpy-discussion] Project for Cython integration with NumPy
Stéfan van der Walt
stefan@sun.ac...
Tue Apr 1 15:04:18 CDT 2008
Hi Dag
On Tue, Apr 1, 2008 at 11:06 AM, Dag Sverre Seljebotn
<dagss@student.matnat.uio.no> wrote:
> One more comment about the constructor described on the page above.
> It would be good if we could have the same syntax as the current
> numpy.ndarray, and then simply call through to the underlying C
> constructor. We'd also need zeros, empty, ones_like and some other
> select functions. The goal is to remain as faithful as possible to
> the original API, so that there is hardly a distinction between Python
> and Cython.
>
> This will be automatic from how Cython operates :-) And that is, I think,
> what makes all of this great. Objects are Python objects all the time and by
> default retain all Python implementation, and we only override this
> implementation when the behaviour is retained.
>
> I'll walk through this code line by line:
> cdef c_numpy.ndarray(c_numpy.float, 2) x
> x = exp(4 + numpy.zeros([10, 10], dtype=numpy.float))
> y = x + 3
> print x[1, 3]
> print y[3, 5]
Thanks for this example; I didn't notice that you were making a type
declaration, so my original comment was not valid.
> #3: (x + 3) will treat x as a Python object once again, so y will be an
> untyped variable referencing an ndarray like normal Python.
I can foresee certain situations under which we can predict the type
of the result of operations like this one. Would it be possible to
then handle 'y' as an ndarray as well, instead of reverting to Python
object calls?
Regards
Stéfan
More information about the Numpy-discussion
mailing list