Ignore:
Timestamp:
01/10/13 10:27:27 (12 years ago)
Author:
jschierm
Message:

NEW: Modify PythonWriteData to write actual python integers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp

    r14221 r14232  
    137137        PyObject* array=NULL;
    138138
     139        matrix->GetSize(&M,&N);
    139140        buffer=matrix->ToSerial();
    140         matrix->GetSize(&M,&N);
     141
    141142        dims[0]=(npy_intp)M;
    142143        dims[1]=(npy_intp)N;
     
    154155        PyObject* array=NULL;
    155156
     157        vector->GetSize(&M);
    156158        buffer=vector->ToMPISerial();
    157         vector->GetSize(&M);
     159
    158160        dim=(npy_intp)M;
    159161        array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer);
     
    165167void WriteData(PyObject* py_tuple,int index,SeqMat<int>* matrix){
    166168
    167         //FIXME: convert to double for now
    168        
    169169        int M,N;
    170         int* buffer=NULL;
     170        int* ibuffer=NULL;
    171171        npy_intp dims[2]={0,0};
    172172        PyObject* array=NULL;
    173173
    174174        matrix->GetSize(&M,&N);
    175         buffer=matrix->ToSerial();
    176 
    177         /*convert to double*/
    178         double* bufferdouble=xNew<IssmDouble>(M*N);
    179         for(int i=0;i<M*N;i++) bufferdouble[i]=(double)buffer[i];
    180         xDelete<int>(buffer);
    181 
    182         dims[0]=(npy_intp)M;
    183         dims[1]=(npy_intp)N;
    184         array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,bufferdouble);
     175        ibuffer=matrix->ToSerial();
     176
     177        /*convert to long*/
     178        long* lbuffer=xNew<long>(M*N);
     179        for(int i=0;i<M*N;i++) lbuffer[i]=(long)ibuffer[i];
     180        xDelete<int>(ibuffer);
     181
     182        dims[0]=(npy_intp)M;
     183        dims[1]=(npy_intp)N;
     184        array=PyArray_SimpleNewFromData(2,dims,NPY_INT64,lbuffer);
    185185
    186186        PyTuple_SetItem(py_tuple, index, array);
     
    190190void WriteData(PyObject* py_tuple,int index,SeqVec<int>* vector){
    191191
    192         //FIXME: convert to double for now
    193 
    194192        int M;
    195         int* buffer=NULL;
     193        int* ibuffer=NULL;
    196194        npy_intp dim=10;
    197195        PyObject* array=NULL;
    198196
    199197        vector->GetSize(&M);
    200         buffer=vector->ToMPISerial();
    201 
    202         /*convert to double*/
    203         IssmDouble* bufferdouble=xNew<IssmDouble>(M);
    204         for(int i=0;i<M;i++) bufferdouble[i]=(double)buffer[i];
    205         xDelete<int>(buffer);
     198        ibuffer=vector->ToMPISerial();
     199
     200        /*convert to long*/
     201        long* lbuffer=xNew<long>(M);
     202        for(int i=0;i<M;i++) lbuffer[i]=(long)ibuffer[i];
     203        xDelete<int>(ibuffer);
    206204
    207205        dim=(npy_intp)M;
    208         array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,bufferdouble);
     206        array=PyArray_SimpleNewFromData(1,&dim,NPY_INT64,lbuffer);
    209207
    210208        PyTuple_SetItem(py_tuple, index, array);
     
    277275PyObject* PyArrayFromCopiedData(int dimi,int dimj,int* data){
    278276
    279         //FIXME: convert to double for now
    280 
    281         double* pydata;
     277        long* pydata;
    282278        npy_intp pydims[2]={0,0};
    283279
     
    287283        pydims[0]=(npy_intp)dimi;
    288284        pydims[1]=(npy_intp)dimj;
    289         pydata=xNew<IssmDouble>(dimi*dimj);
    290         //memcpy(pydata,data,dimi*dimj*sizeof(int));
    291         for(int i=0;i<dimi*dimj;i++) pydata[i]=(double)data[i];
    292         return PyArray_SimpleNewFromData(2,pydims,NPY_DOUBLE,pydata);
    293 }
    294 /*}}}*/
     285        pydata=xNew<long>(dimi*dimj);
     286        for(int i=0;i<dimi*dimj;i++) pydata[i]=(long)data[i];
     287        return PyArray_SimpleNewFromData(2,pydims,NPY_INT64,pydata);
     288}
     289/*}}}*/
Note: See TracChangeset for help on using the changeset viewer.