[MATRIX-SIG] Python/Fortran interface

Konrad Hinsen hinsen@ibs.ibs.fr
Mon, 18 Aug 1997 19:34:43 +0200

> On the more general subject of extending/embedding/interfacing NumPy with
> whatever, does anybody have a reasonably straightforward and concise
> explanation of how NumPy arrays are stored (i.e., an annotated structure
> definition)?  I've looked through the source, plus a fairly substantial

It's a bit messy if you want all the details. In C code, I tend to
limit myself to contiguous arrays, and then life becomes easy.
Here's what you need to know:

Suppose that a is declared as PyArrayObject *. Then we have:

type:                       a->descr->type  (see PyArray_TYPES in arrayobject.h)

number of dimensions:       a->nd

length of first dimension:  a->dimensions[0]
length of second dimension: a->dimensions[1]
length of last dimension:   a->dimensions[a->nd-1]

data:                       a->data

And the data is arranged exactly as in an equally dimensioned static
C array. Note that a->data is declared as char *; you have to cast
it to the type of pointer appropriate for the data before accessing it.

Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-
Institut de Biologie Structurale       | Fax:  +33-
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais

MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org