12.7 New numarray functions

There are several functions to create numarrays at the C level:

static PyObject* NA_NewArray(void *buffer, NumarrayType type, int ndim, ...)
Create a new numarray from C data buffer. The new array has type type, ndim dimensions, and the length of each dimension must be given as the remaining (variable length) list of int parameters. Data is copied from buffer into the memory object of the new array.

static PyObject* NA_vNewArray(void *buffer, NumarrayType type, int ndim, maybelong *shape)
Create a new numarray from C data buffer. The new array has type type, ndim dimensions, and the length of each dimension must be given as an array of long pointed to by shape. Data is copied from buffer into the memory object of the new array.

static PyObject* NA_NewAll(int ndim, maybelong *shape, NumarrayType type, void *buffer, maybelong byteoffset, maybelong bytestride, int byteorder, int aligned, int writable)
numarray from C data buffer. The new array has type type, ndim dimensions, and the length of each dimensions must be given in shape[ndim]. byteoffset, bytestride specify the data-positions in the C array to use. byteorder and aligned specify the corresponding parameters. byteorder takes one of the values NUM_BIG_ENDIAN or NUM_LITTLE_ENDIAN. writable defines whether the buffer object associated with the resuling array is readonly or writable. Data is copied from buffer into the memory object of the new array.

static PyObject* NA_NewAllStrides(int ndim, maybelong *shape, maybelong *strides, NumarrayType type, void *buffer, maybelong byteoffset, maybelong byteorder, int aligned, int writable)
numarray from C data buffer. The new array has type type, ndim dimensions, and the length of each dimensions must be given in shape[ndim]. The byte offset between successive indices of a dimension is specified by strides[ndim]. byteoffset specifies the offset from the base of the buffer to the zeroth element of the array. byteorder and aligned specify the corresponding parameters. byteorder takes one of the values NUM_BIG_ENDIAN or NUM_LITTLE_ENDIAN. writable defines whether the buffer object associated with the resuling array is readonly or writable. Data is copied from buffer into the memory object of the new array.

int NA_ShapeEqual(PyArrayObject*a,PyArrayObject*b)
This function compares the shapes of two arrays, and returns 1 if they are the same, 0 otherwise.

int NA_ShapeLessThan(PyArrayObject*a,PyArrayObject*b)
This function compares the shapes of two arrays, and returns 1 if each dimension of 'a' is less than the corresponding dimension of 'b', 0 otherwise.

int NA_ByteOrder()
This function returns the system byte order, either NUM_LITTLE_ENDIAN or NUM_BIG_ENDIAN.

Bool NA_IeeeSpecial32(Float32 *f, Int32 *mask)
This function returns 1 IFF Float32 value '*f' matches any of the IEEE special value criteria specified by '*mask'. See ieeespecial.h for the mask bit values which can be or'ed together to specify mask.

Bool NA_IeeeSpecial64(Float64*,Int32*)
This function returns 1 IFF Float64 value '*f' matches any of the IEEE special value criteria specified by '*mask'. See ieeespecial.h for the mask bit values which can be or'ed together to specify mask.

PyArrayObject * NA_updateDataPtr(PyArrayObject *)
This function updates the values derived from the ``_data'' buffer, namely the data pointer and buffer WRITABLE flag bit. This needs to be called upon entering or re-entering C-code from Python, since it is possible for buffer objects to move their data buffers as a result of executing arbitrary Python and hence arbitrary C-code.

char* NA_typeNoToName(int)
NA_typeNoToName translates a NumarrayType into a character string which can be used to display it: e.g. tInt32 converts to the string ``Int32''

PyObject* NA_typeNoToTypeObject(int)
This function converts a NumarrayType C type code into the NumericType object which implements and represents it more fully. tInt32 converts to the type object numarray.Int32.

int NA_typeObjectToTypeNo(PyObject*)
This function converts a numarray type object (e.g. numarray.Int32) into the corresponding NumarrayType (e.g. tInt32) C type code.

PyObject* NA_intTupleFromMaybeLongs(int,maybelong*)
This function creates a tuple of Python ints from an array of C maybelong integers.

long NA_maybeLongsFromIntTuple(int,maybelong*,PyObject*)
This function fills an array of C long integers with the converted values from a tuple of Python ints. It returns the number of conversions, or -1 for error.

long NA_isIntegerSequence(PyObject*)
This function returns 1 iff the single parameter is a sequence of Python integers, and 0 otherwise.

PyObject* NA_setArrayFromSequence(PyArrayObject*,PyObject*)
This function copies the elementwise from a sequence object to a numarray.

int NA_maxType(PyObject*)
This function returns an integer code corresponding to the highest kind of Python numeric object in a sequence. INT(0) LONG(1) FLOAT(2) COMPLEX(3). On error -1 is returned.

PyObject* NA_getPythonScalar(PyArrayObject *a, long offset)
This function returns the Python object corresponding to the single element of the array 'a' at the given byte offset.

int NA_setFromPythonScalar(PyArrayObject *a, long offset, PyObject*value)
This function sets the single element of the array 'a' at the given byte offset to 'value'.

int NA_NDArrayCheck(PyObject*o)
This function returns 1 iff the 'o' is an instance of NDArray or an instance of a subclass of NDArray, and 0 otherwise.

int NA_NumArrayCheck(PyObject*)
This function returns 1 iff the 'o' is an instance of NumArray or an instance of a subclass of NumArray, and 0 otherwise.

int NA_ComplexArrayCheck(PyObject*)
This function returns 1 iff the 'o' is an instance of ComplexArray or an instance of a subclass of ComplexArray, and 0 otherwise.

int NA_elements(PyArrayObject*)
This function returns the total count of elements in an array, essentially the product of the elements of the array's shape.

PyArrayObject * NA_copy(PyArrayObject*)
This function returns a copy of the given array.

int NA_copyArray(PyArrayObject*to, const PyArrayObject *from)
This function returns a copies one array onto another; used in f2py.

Send comments to the NumArray community.