From 5c86844c34674e3d580ac2cd12ef171e18130b13 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 23 Aug 2008 23:17:23 +0000 Subject: Move documentation outside of source tree. Remove `doc` import from __init__. --- doc/pyrex/numpyx.pyx | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 doc/pyrex/numpyx.pyx (limited to 'doc/pyrex/numpyx.pyx') diff --git a/doc/pyrex/numpyx.pyx b/doc/pyrex/numpyx.pyx new file mode 100644 index 000000000..068d251f6 --- /dev/null +++ b/doc/pyrex/numpyx.pyx @@ -0,0 +1,101 @@ +# -*- Mode: Python -*- Not really, but close enough +"""WARNING: this code is deprecated and slated for removal soon. See the +doc/cython directory for the replacement, which uses Cython (the actively +maintained version of Pyrex). +""" + +cimport c_python +cimport c_numpy +import numpy + +# Numpy must be initialized +c_numpy.import_array() + +def print_array_info(c_numpy.ndarray arr): + cdef int i + + print '-='*10 + print 'printing array info for ndarray at 0x%0lx'%(arr,) + print 'print number of dimensions:',arr.nd + print 'address of strides: 0x%0lx'%(arr.strides,) + print 'strides:' + for i from 0<=iarr.strides[i] + print 'memory dump:' + print_elements( arr.data, arr.strides, arr.dimensions, + arr.nd, sizeof(double), arr.dtype ) + print '-='*10 + print + +cdef print_elements(char *data, + c_python.Py_intptr_t* strides, + c_python.Py_intptr_t* dimensions, + int nd, + int elsize, + object dtype): + cdef c_python.Py_intptr_t i,j + cdef void* elptr + + if dtype not in [numpy.dtype(numpy.object_), + numpy.dtype(numpy.float64)]: + print ' print_elements() not (yet) implemented for dtype %s'%dtype.name + return + + if nd ==0: + if dtype==numpy.dtype(numpy.object_): + elptr = (data)[0] #[0] dereferences pointer in Pyrex + print ' ',elptr + elif dtype==numpy.dtype(numpy.float64): + print ' ',(data)[0] + elif nd == 1: + for i from 0<=idata)[0] + print ' ',elptr + elif dtype==numpy.dtype(numpy.float64): + print ' ',(data)[0] + data = data + strides[0] + else: + for i from 0<=i