- Timestamp:
- 01/10/13 10:27:27 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
r14221 r14232 137 137 PyObject* array=NULL; 138 138 139 matrix->GetSize(&M,&N); 139 140 buffer=matrix->ToSerial(); 140 matrix->GetSize(&M,&N); 141 141 142 dims[0]=(npy_intp)M; 142 143 dims[1]=(npy_intp)N; … … 154 155 PyObject* array=NULL; 155 156 157 vector->GetSize(&M); 156 158 buffer=vector->ToMPISerial(); 157 vector->GetSize(&M); 159 158 160 dim=(npy_intp)M; 159 161 array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer); … … 165 167 void WriteData(PyObject* py_tuple,int index,SeqMat<int>* matrix){ 166 168 167 //FIXME: convert to double for now168 169 169 int M,N; 170 int* buffer=NULL;170 int* ibuffer=NULL; 171 171 npy_intp dims[2]={0,0}; 172 172 PyObject* array=NULL; 173 173 174 174 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); 185 185 186 186 PyTuple_SetItem(py_tuple, index, array); … … 190 190 void WriteData(PyObject* py_tuple,int index,SeqVec<int>* vector){ 191 191 192 //FIXME: convert to double for now193 194 192 int M; 195 int* buffer=NULL;193 int* ibuffer=NULL; 196 194 npy_intp dim=10; 197 195 PyObject* array=NULL; 198 196 199 197 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); 206 204 207 205 dim=(npy_intp)M; 208 array=PyArray_SimpleNewFromData(1,&dim,NPY_ DOUBLE,bufferdouble);206 array=PyArray_SimpleNewFromData(1,&dim,NPY_INT64,lbuffer); 209 207 210 208 PyTuple_SetItem(py_tuple, index, array); … … 277 275 PyObject* PyArrayFromCopiedData(int dimi,int dimj,int* data){ 278 276 279 //FIXME: convert to double for now 280 281 double* pydata; 277 long* pydata; 282 278 npy_intp pydims[2]={0,0}; 283 279 … … 287 283 pydims[0]=(npy_intp)dimi; 288 284 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.