# -*- 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