[Numpy-discussion] ?Loading double and cdouble in an PyArrayObject?

Francesc Alted falted at openlc.org
Tue Oct 7 10:00:13 CDT 2003


A Dimarts 07 Octubre 2003 18:24, Norman Shelley va escriure:
>
> If cdata is never to be freed, e.g. a Fortran COMMON block, then that is
> the case.
> I with to use PyArray_FromDims() and then load it up with data
>
> I am assuming this may work for doubles (?)
> aPyArrayObject = PyArray_FromDims(1, numData, PyArray_DOUBLE)
> for (i = 0; i < numData; i++) aPyArrayObject.data[i] = doubledata[i];
>
> But then I wondered how to load for COMPLEX?

Perhaps something like:

  struct complex {
    double real;
    double imag;
  } complex;
  complex cdata[100];
  double *data;
  PyArrayObject *array;
  
  array = PyArray_FromDims(1, numData, PyArray_CDOUBLE)
  data = array->data
  for (i = 0; i < numData; i++) {
    *data++ = cdata[i++];
    *data++ = cdata[i];
    }
    
should work (but not tested here). CDOUBLE means double precision complex.

Something similar would work for double precision:

  complex ddata[100];
  double *data;
  PyArrayObject *array;
  
  array = PyArray_FromDims(1, numData, PyArray_DOUBLE)
  data = array->data
  for (i = 0; i < numData; i++) {
    *data++ = cdata[i];
    }

-- 
Francesc Alted





More information about the Numpy-discussion mailing list