X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingDataArrayTypemaps.i;h=d1f2da7e148c6f0ac6e222c0843badfa78d83753;hb=5c36866f7cf797b79f705a7c06882f1ad87062c7;hp=5eb5af871494bf13376a01a1ff992d4f8c93a766;hpb=2071ee6120854363d465e0310f47551248257685;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index 5eb5af871..d1f2da7e1 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -399,7 +399,7 @@ int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj) } template -PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr) +PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp) { if(!self->isAllocated()) { @@ -407,7 +407,6 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr) throw INTERP_KERNEL::Exception(oss.str().c_str()); } ParaMEDMEM::MemArray& mem=self->accessToMemArray(); - int nbComp=self->getNumberOfComponents(); if(nbComp==0) { std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !"; @@ -415,7 +414,7 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr) } int nbDims=nbComp==1?1:2; npy_intp dim[2]; - dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp; + dim[0]=(npy_intp)nbTuples; dim[1]=nbComp; const T *bg=self->getConstPointer(); PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast(bg))); if(mem.isDeallocatorCalled()) @@ -451,6 +450,12 @@ PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr) return ret; } +template +PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr) +{ + return ToNumPyArrayUnderground(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents()); +} + SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self); SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self); @@ -694,6 +699,63 @@ static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair >& arr) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !"; + if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + arr.resize(size); + for(int i=0;i& arr) throw(INTERP_KERNEL::Exception) { if(PyList_Check(pyLi)) @@ -952,6 +1014,93 @@ static bool fillStringVector(PyObject *pyLi, std::vector& vec) thro else return false; } +static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector >& arr) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !"; + if(PyList_Check(pyLi)) + { + Py_ssize_t sz=PyList_Size(pyLi); + arr.resize(sz); + for(int i=0;i > >& arr) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !"; + if(PyList_Check(pyLi)) + { + Py_ssize_t sz=PyList_Size(pyLi); + arr.resize(sz); + for(int i=0;i > item; + PyObject *o_0=PyTuple_GetItem(o,0); + if(!PyString_Check(o_0)) + throw INTERP_KERNEL::Exception(msg); + item.first=PyString_AsString(o_0); + PyObject *o_1=PyTuple_GetItem(o,1); + if(!fillStringVector(o_1,item.second)) + throw INTERP_KERNEL::Exception(msg); + arr[i]=item; + } + else + throw INTERP_KERNEL::Exception(msg); + } + } + else if(PyTuple_Check(pyLi)) + { + Py_ssize_t sz=PyTuple_Size(pyLi); + arr.resize(sz); + for(int i=0;i > item; + PyObject *o_0=PyTuple_GetItem(o,0); + if(!PyString_Check(o_0)) + throw INTERP_KERNEL::Exception(msg); + item.first=PyString_AsString(o_0); + PyObject *o_1=PyTuple_GetItem(o,1); + if(!fillStringVector(o_1,item.second)) + throw INTERP_KERNEL::Exception(msg); + arr[i]=item; + } + else + throw INTERP_KERNEL::Exception(msg); + } + } + else + throw INTERP_KERNEL::Exception(msg); +} static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception) {