The following array creation functions share similar behavior. All but one
create a new numarray using the data specified by data. If
data is NULL, the routine allocates a buffer internally based on the
array shape and type; internally allocated buffers have undefined contents.
The data type of the created array is specified by type.
There are several functions to create numarrays at the C level:
static PyArrayObject* NA_NewArray(
void *data, NumarrayType type, int ndim, ...)
ndim specifies the rank of the array (number of dimensions), and the
length of each dimension must be given as the remaining (variable length)
list of int parameters. The following example allocates a 100x100
uninitialized array of Int32.
if (!(array = NA_NewArray(NULL, tInt32, 2, 100, 100)))
return NULL;
static PyObject* NA_vNewArray(
void *data, NumarrayType type, int ndim, maybelong *shape)
For NA_vNewArray the length of each dimension must be given in an
array of maybelong pointed to by shape. The following code
allocates a 2x2 array initialized to a copy of the specified data.
int ndim, maybelong *shape, NumarrayType type, void *data, maybelong
byteoffset, maybelong bytestride, int byteorder, int aligned, int
writable)
NA_NewAll is similar to NA_vNewArray except it
provides for the specification of additional parameters. byteoffset
specifies the byte offset from the base of the data array at which the
real data begins. bytestride specifies the miminum stride to
use, the seperation in bytes between adjacent elements in the
array. byteorder takes one of the values NUM_BIG_ENDIAN or
NUM_LITTLE_ENDIAN. writable defines whether the buffer
object associated with the resulting array is readonly or writable.
static PyArrayObject* NA_NewAllStrides(
int ndim, maybelong *shape, maybelong *strides, NumarrayType type, void
*data, maybelong byteoffset, maybelong byteorder, int aligned, int
writable)
NA_NewAllStrides is a variant of NA_vNewAll which
also permits the specification of the array strides. The strides are not
checked for correctness.
static PyArrayObject* NA_NewAllFromBuffer(
int ndim, maybelong *shape, NumarrayType type, PyObject *buffer, maybelong
byteoffset, maybelong bytestride, int byteorder, int aligned, int
writable)
NA_NewAllFromBuffer is similar to NA_NewAll except it
accepts a buffer object rather than a pointer to C data. The buffer
object must support the buffer protocol. If buffer is non-NULL, the
returned array object stores a reference to buffer and locates its
data there. If buffer is specified as NULL, a buffer object and
associated data space are allocated internally and the returned array object
refers to that. It is possible to create a Python buffer object from an
array of C data and then construct a numarray using this function
which refers to the C data without making a copy.
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_IeeeMask32(
Float32 value, Int32 mask)
This function returns 1 IFF Float32 value 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.
NA_IeeeSpecial32 has been deprecated and will eventually be removed.
Bool NA_IeeeMask64(
Float64 value,Int32 mask)
This function returns 1 IFF Float64 value 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.
NA_IeeeSpecial64 has been deprecated and will eventually be removed.
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. The high level interface routines,
e.g. NA_InputArray, call this routine automatically.
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.
unsigned long 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. The array copy is guaranteed
to be well-behaved, i.e. neither byteswapped, misaligned, nor discontiguous.
int NA_copyArray(
PyArrayObject*to, const PyArrayObject *from)
This function returns a copies one array onto another; used in f2py.
int NA_swapAxes(
PyArrayObject*a, int dim1, int dim2)
This function mutates the specified array a to exchange the shape and
strides values for the two dimensions, dim1 and dim2. Negative
dimensions count backwards from the innermost, with -1 being the innermost
dimension. Returns 0 on success and -1 on error.