This is an archival dump of old wiki content --- see scipy.org for current material

The proposed basearray type does not have a fully-filled type-object structure. In other words, basearray is above all a place-holder and base-type, of which other, more capable array objects can be subtypes of. Besides serving as a base type, the object exports and consumes the array interface.

Alongside basearray and datatype (a descriptor of the type an array carries), an array iterator type is defined to facilitate some procedures. There are also two auxialliary structures and a number of C-API functions.

Ultimately, there are two files to be added: basearray.c and basearray.h.

C structures defined

PyBaseArrayObject

void *data;

Pointer to raw data buffer.

int ndim;

Number of dimensions.

intp *dimensions;

Size in each dimension.

intp *strides;

Bytes to jump to get to the next element in each dimension.

PyDataTypeObject *datatype;

Pointer to data type object describing the data.

int flags;

Flags describing the data buffer

PyObject *base;

This object should be decref'd upon deletion of the array. For creation from a buffer object it points to an object that should be decref'd upon deletion.

PyObject *weakreflist;

For weakreferences.

The flags variable is the bit-wise OR of:

PyDataTypeObject

Describes the type of data the array carries. There are instances of this object for a fixed set of built-in Python types.

PyTypeObject *typeobj

A Python "scalar" type corresonding to the array elements.

char kind;

A character representing the kind of data for this type.

char byteorder;

'<' (big-endian), '<' (little), '|' (not-applicable), or '=' (native).

char hasobject;

Non-zero only if there are object arrays in fields.

int elsize;

The size of each element this data-type represents, in bytes.

int alignment;

For a basic C-type, this holds the alignment needed for the type. For the C-type of a type this data-type object represents the alignment is offsetof(struct{char c; <type> v;},v).

struct _arr_ *subarray;

Non-NULL if the type is a C-contigouus array of some other type.

PyObject *fields;

A dictionary of names and fields - a field is a segment of a larger type that has its own data-type object. This dictionary is keyed by strings representing field names and returns a tuple of the form (data-type, offset[, label]), where data-type is the data-type object describing the type, offset is the offset in bytes to the start of that field, and label is the optional user-name of this field. The reason for having label is that the key might be a Python-acceptable name (such that could be used in attribute access, for example), but label is the definer's "official title", which may contain spaces, units, and so forth.

PyObject *names;

An ordered tuple of field names or NULL if no fields are defined.

PyDataTypeFuncs *funcs;

Table of functions specific for each data-type.

PyDataTypeFuncs

Carries pointers to functions specific to a given datatype object. Currently two such function are included in this structure:

PyBaseArrayIterObject

This iterator structure is usefull for looping over a basearray.

int nd_m1;

Number of dimensions minus 1.

intp index;

Current 1D index into the array.

intp size;

Total size of the array.

intp coordinates[MAX_DIMS];

N-dimensional index into the array.

intp dims_m1[MAX_DIMS];

Size of the array minus 1 in each dimension.

intp strides[MAX_DIMS];

Bytes to jump to get to the next element in each dimension.

intp backstrides[MAX_DIMS];

Bytes to jump from the end of a dimension to its beginning.

intp factors[MAX_DIMS];

Shape factors, for computing an ND index from a 1D index.

PyBaseArrayObject *ao;

The underlying basearray object this iterator refers to.

char *dataptr;

Pointer to the element indicated by this iterator.

Bool contiguous;

True when *ao has the CONTIGUOUS flag set.

PyBaseArrayDims

Auxiliary structure used for interpreting the shape and stride of Python objects when they are converted to useful C objects.

intp *ptr;

Pointer to a list of intp representing array shape or strides.

int len;

The length of the list of integers pointed to above.

PyBaseArrayChunk

Auxiliary structure for representing a memory segment, the equivalent of the Python buffer object.

PyObject *base;

The Python object this memory segment comes from.

void *ptr;

Pointer to the beginning of the memory segment.

intp len;

Length of the segment in bytes.

int flags;

Any data flags that should be used to interpret the memory.

SciPy: BaseArray/CodeDescription (last edited 2015-10-24 17:48:27 by anonymous)