pDynamo makes extensive use of various types of numerical array and has its own C library that implements them. It does not employ the Python numpy
library, principally because the latter does not provide a clear separation between Python and C code. However, there is no reason why users should not use numpy in their pDynamo scripts and, indeed, it is probably advantageous to do so if complicated array operations are to be performed.
Nevertheless, for many purposes, pDynamo's inbuilt arrays should be sufficient. Currently these consist of:
- One, two and N-dimensional arrays of various types. As examples, the arrays of pDynamo's
Real type are named
- Some specialized forms of
Real matrix, including
Real arrays devoted to coordinate manipulation, notably
Array types conform to the following notation:
- extent is the number of items along a particular dimension of the array.
- item is an element in the array.
- rank is the number of dimensions in the array.
- shape is the ensemble of extents for all the array's dimensions.
- size is the total number of items in the array.
Individual items in an array can be accessed in standard Python fashion using square brackets. Indexing starts at 0, with negative indices denoting indexing from the end of an array dimension. An integer is required for each dimension in the array, otherwise an error is raised.
In addition, the
objects permit slicing, again using standard Python terminology, with an integer or a slice specified for each array dimension. It is important to note that slicing does not generate a new array, but instead returns a minimal-rank view
of the underlying parent object.
object is composite, behaving in some respects like a
object of shape
, and in others like a one-dimensional array of
objects. To reflect this dual behavior, Coordinates3 objects may be sliced like
objects, but they may also be indexed with only a single integer or slice. If an integer is used a
view of the appropriate row in the
matrix will be returned, whereas a slice gives a
view of the underlying data.
Array views behave identically in most ways to arrays of the corresponding type, although there are some subtleties to consider when cloning and pickling. Thus, shallow cloning and pickling preserves the view, in the sense that the relation between the parent and view is maintained, whereas deep cloning generates a non-view array clone of the viewed data.