[MATRIX-SIG] Get array elements in c?

Janko Hauser jhauser@ifm.uni-kiel.de
Sun, 21 Dec 1997 17:28:08 +0100 (CET)


I need to copy an array to this struct:


typedef float   Matrix[4][4];

For this I try to write a function:

#define A_DATA(a) (((PyArrayObject *)a)->data)
#define GET_ARR(ap,op,type,dim) \
  Py_Try(ap=(PyArrayObject
*)PyArray_ContiguousFromObject(op,type,dim,dim))


static void cp_to_Matrix(PyObject *arg, Matrix mat) {
    PyArrayObject *arr;
    int i, j;
    double *data;

    GET_ARR(arr, arg, PyArray_FLOAT, 2);
    data  = (double *)A_DATA(arr);
    for (i=0; i<4; i++){
        for (j=0; j<4; j++){
            mat[i][j] = data[i][j]; /* this is wrong. right? */
        }
    }
    return;
}

Must I address data here linearly? Or is there another way to get the
NumPyArray into the Matrix?

Something similar for 

typedef float   Vector[4];

does function, with some  warnings.

Sorry for my C ignorance (that's why I use Python),

__Janko


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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