1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
22 #define __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
24 #include "InterpKernelAutoPtr.hxx"
27 * This method is an extention of PySlice_GetIndices but less
28 * open than PySlice_GetIndicesEx that accepts too many situations.
30 void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
32 int ret(PySlice_GetIndices(slice,length,start,stop,step));
35 if(*step>0 && *start==*stop && length==*start)
37 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
41 * This method allows to retrieve slice info from \a slice.
43 void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
45 int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
48 if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
50 std::ostringstream oss;
51 oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
52 throw INTERP_KERNEL::Exception(oss.str().c_str());
54 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
57 int InterpreteNegativeInt(int val, int nbelem)
61 int newVal(nbelem+val);
64 std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
65 throw INTERP_KERNEL::Exception(oss.str().c_str());
74 #include <numpy/arrayobject.h>
75 #if NPY_API_VERSION <= 0x00000006
76 # define MED_NUMPY_OWNDATA NPY_OWNDATA
78 # define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
81 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
82 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
83 // if no more alive the "standart" DataArray deallocator is called.
84 void numarrdeal(void *pt, void *wron)
86 void **wronc=(void **)wron;
87 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
88 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
92 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
93 objC->flags|=MED_NUMPY_OWNDATA;
94 Py_XDECREF(weakRefOnOwner);
99 typedef void (*MyDeallocator)(void *,void *);
100 MyDeallocator deall=(MyDeallocator)wronc[1];
102 Py_XDECREF(weakRefOnOwner);
107 template<class MCData>
108 struct PyCallBackDataArraySt {
113 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
114 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
115 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
119 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
121 static PyObject *callbackmcdataarraychar___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
123 PyCallBackDataArrayChar *self = (PyCallBackDataArrayChar *) ( type->tp_alloc(type, 0) );
124 return (PyObject *)self;
127 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
129 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
130 return (PyObject *)self;
133 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
135 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
136 return (PyObject *)self;
139 static void callbackmcdataarray_dealloc(PyObject *self)
141 Py_TYPE(self)->tp_free(self);
145 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
146 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
147 static PyObject *callbackmcdataarraychar_call(PyCallBackDataArrayChar *self, PyObject *args, PyObject *kw)
151 MEDCoupling::MemArray<char>& mma=self->_pt_mc->accessToMemArray();
158 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
159 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
160 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
164 MEDCoupling::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
171 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
172 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
173 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
177 MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
185 PyTypeObject PyCallBackDataArrayChar_RefType = {
186 PyVarObject_HEAD_INIT(&PyType_Type, 0)
187 "callbackmcdataarraychar",
188 sizeof(PyCallBackDataArrayChar),
190 callbackmcdataarray_dealloc, /*tp_dealloc*/
197 0, /*tp_as_sequence*/
200 (ternaryfunc)callbackmcdataarraychar_call, /*tp_call*/
205 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
209 0, /*tp_richcompare*/
210 0, /*tp_weaklistoffset*/
221 callbackmcdataarray___init__, /*tp_init*/
222 PyType_GenericAlloc, /*tp_alloc*/
223 callbackmcdataarraychar___new__, /*tp_new*/
224 PyObject_GC_Del, /*tp_free*/
228 PyTypeObject PyCallBackDataArrayInt_RefType = {
229 PyVarObject_HEAD_INIT(&PyType_Type, 0)
230 "callbackmcdataarrayint",
231 sizeof(PyCallBackDataArrayInt),
233 callbackmcdataarray_dealloc, /*tp_dealloc*/
240 0, /*tp_as_sequence*/
243 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
248 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
252 0, /*tp_richcompare*/
253 0, /*tp_weaklistoffset*/
264 callbackmcdataarray___init__, /*tp_init*/
265 PyType_GenericAlloc, /*tp_alloc*/
266 callbackmcdataarrayint___new__, /*tp_new*/
267 PyObject_GC_Del, /*tp_free*/
270 PyTypeObject PyCallBackDataArrayDouble_RefType = {
271 PyVarObject_HEAD_INIT(&PyType_Type, 0)
272 "callbackmcdataarraydouble",
273 sizeof(PyCallBackDataArrayDouble),
275 callbackmcdataarray_dealloc, /*tp_dealloc*/
282 0, /*tp_as_sequence*/
285 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
290 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
294 0, /*tp_richcompare*/
295 0, /*tp_weaklistoffset*/
306 callbackmcdataarray___init__, /*tp_init*/
307 PyType_GenericAlloc, /*tp_alloc*/
308 callbackmcdataarraydouble___new__, /*tp_new*/
309 PyObject_GC_Del, /*tp_free*/
312 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
313 // in input when an another DataArray is already client of this.
314 template<class MCData>
315 void numarrdeal2(void *pt, void *obj)
317 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
318 void **obj1=(void **)obj;
319 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
320 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
322 Py_XDECREF(weakRefOnOwner);
327 template<class MCData, class T>
328 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
330 int ndim=PyArray_NDIM(elt0);
331 if(ndim!=1 && ndim!=2)
332 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
333 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
335 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
336 throw INTERP_KERNEL::Exception(oss.str().c_str());
338 npy_intp sz0=PyArray_DIM(elt0,0);
339 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
341 int itemSize=PyArray_ITEMSIZE(elt0);
342 if(itemSize!=sizeof(T))
344 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
345 throw INTERP_KERNEL::Exception(oss.str().c_str());
347 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
348 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
350 if(itemSize!=PyArray_STRIDE(elt0,1))
351 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays for component #1 !");
352 const char *data=PyArray_BYTES(elt0);
353 typename MEDCoupling::MCAuto<MCData> ret=MCData::New();
354 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
356 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
357 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
358 int mask=MED_NUMPY_OWNDATA; mask=~mask;
360 PyObject *deepestObj=elt0;
361 PyObject *base=elt0C->base;
362 if(base) deepestObj=base;
363 bool isSpetialCase(false);
366 if(PyArray_Check(base))
368 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
369 eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
372 if(base) deepestObj=base;
381 {// this case is present for numpy arrayint coming from load of pickelized string. The owner of elt0 is not an array -> A copy is requested.
382 std::size_t nbOfElems(sz0*sz1);
383 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
384 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
385 ret->useArray(dataCpy,true,MEDCoupling::C_DEALLOC,sz0,sz1);
388 typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
391 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
393 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
394 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
395 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
396 mma.setParameterForDeallocator(objs);
397 mma.setSpecificDeallocator(numarrdeal2<MCData>);
398 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
402 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
403 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
404 typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::CDeallocator);
405 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
406 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
407 mma.setParameterForDeallocator(objs);
408 mma.setSpecificDeallocator(numarrdeal);
411 else if(PyArray_ISBEHAVED_RO(elt0))
412 ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::CPP_DEALLOC,sz0,sz1);
417 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
420 PyErr_SetString(PyExc_ValueError,
421 "Cannot set the NumPy array 'base' "
422 "dependency to NULL after initialization");
426 * Allow the base to be set only once. Once the object which
427 * owns the data is set, it doesn't make sense to change it.
429 if (PyArray_BASE(arr) != NULL) {
431 PyErr_SetString(PyExc_ValueError,
432 "Cannot set the NumPy array 'base' "
433 "dependency more than once");
438 * Don't allow infinite chains of views, always set the base
439 * to the first owner of the data.
440 * That is, either the first object which isn't an array,
441 * or the first object which owns its own data.
444 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
445 PyArrayObject *obj_arr = (PyArrayObject *)obj;
449 /* If this array owns its own data, stop collapsing */
450 if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
454 tmp = PyArray_BASE(obj_arr);
455 /* If there's no base, stop collapsing */
459 /* Stop the collapse new base when the would not be of the same
460 * type (i.e. different subclass).
462 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
472 /* Disallow circular references */
473 if ((PyObject *)arr == obj) {
475 PyErr_SetString(PyExc_ValueError,
476 "Cannot create a circular NumPy array 'base' dependency");
485 template<class MCData, class T>
486 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
488 if(!self->isAllocated())
490 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
491 throw INTERP_KERNEL::Exception(oss.str().c_str());
493 MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
496 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
497 throw INTERP_KERNEL::Exception(oss.str().c_str());
499 int nbDims=nbComp==1?1:2;
501 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
502 const T *bg=self->getConstPointer();
503 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
504 if(mem.isDeallocatorCalled())
506 if(mem.getDeallocator()!=numarrdeal)
507 {// case for the first call of toNumPyArray
508 PyObject *ref(PyWeakref_NewRef(ret,NULL));
509 typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
510 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
511 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
512 mem.setParameterForDeallocator(objs);
513 mem.setSpecificDeallocator(numarrdeal);
517 {// case for the second and other call of toNumPyArray
518 void **objs=(void **)mem.getParameterForDeallocator();
519 PyObject *weakRefOnOwner=(PyObject *)objs[0];
520 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
522 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
524 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
527 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
528 Py_XDECREF(weakRefOnOwner);
529 PyObject *ref=PyWeakref_NewRef(ret,NULL);
537 template<class MCData, class T>
538 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
540 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
543 SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
544 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
546 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
548 int nbRows((int)m.size());
549 MEDCoupling::MCAuto<MEDCoupling::DataArrayInt> indPtr(MEDCoupling::DataArrayInt::New()),indices(MEDCoupling::DataArrayInt::New());
550 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
551 indPtr->alloc(nbRows+1,1);
552 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
554 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
556 sz2+=(int)(*it0).size();
559 indices->alloc(sz2,1); data->alloc(sz2,1);
560 int *indices_ptr(indices->getPointer());
561 double *data_ptr(data->getPointer());
562 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
563 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
565 *indices_ptr=(*it1).first;
566 *data_ptr=(*it1).second;
568 PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt_toNumPyArray(indPtr));
570 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
571 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
572 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
573 PyObject *tmp1(PyString_FromString("shape"));
574 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
575 PyObject* pdict=PyDict_New();
576 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
577 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
579 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
580 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
582 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
583 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
584 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
590 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
598 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
599 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
600 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
601 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
603 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
607 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
615 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
616 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
617 if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
618 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
619 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
620 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
621 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
622 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
624 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
628 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
630 PyObject *ret=PyList_New(size);
631 for(int i=0;i<size;i++)
632 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
636 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
639 PyObject *ret=PyList_New(size);
640 for(int i=0;i<size;i++)
641 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
645 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
648 PyObject *ret=PyList_New(size);
649 std::set<int>::const_iterator it=v.begin();
650 for(int i=0;i<size;i++,it++)
651 PyList_SetItem(ret,i,PyInt_FromLong(*it));
655 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
657 PyObject *ret=PyList_New(nbOfTuples);
658 for(int i=0;i<nbOfTuples;i++)
660 PyObject *t=PyTuple_New(nbOfComp);
661 for(int j=0;j<nbOfComp;j++)
662 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
663 PyList_SetItem(ret,i,t);
668 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
670 if(PyList_Check(pyLi))
672 *size=PyList_Size(pyLi);
673 int *tmp=new int[*size];
674 for(int i=0;i<*size;i++)
676 PyObject *o=PyList_GetItem(pyLi,i);
679 int val=(int)PyInt_AS_LONG(o);
685 throw INTERP_KERNEL::Exception("list must contain integers only");
690 else if(PyTuple_Check(pyLi))
692 *size=PyTuple_Size(pyLi);
693 int *tmp=new int[*size];
694 for(int i=0;i<*size;i++)
696 PyObject *o=PyTuple_GetItem(pyLi,i);
699 int val=(int)PyInt_AS_LONG(o);
705 throw INTERP_KERNEL::Exception("tuple must contain integers only");
712 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
716 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
718 PyObject *ret=PyList_New(arr.size());
719 for(std::size_t i=0;i<arr.size();i++)
721 PyObject *t=PyTuple_New(2);
722 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
723 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
724 PyList_SetItem(ret,i,t);
729 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
731 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
732 if(PyList_Check(pyLi))
734 int size=PyList_Size(pyLi);
736 for(int i=0;i<size;i++)
738 PyObject *o=PyList_GetItem(pyLi,i);
741 int sz2=PyTuple_Size(o);
743 throw INTERP_KERNEL::Exception(msg);
744 PyObject *o_0=PyTuple_GetItem(o,0);
745 if(!PyInt_Check(o_0))
746 throw INTERP_KERNEL::Exception(msg);
747 PyObject *o_1=PyTuple_GetItem(o,1);
748 if(!PyInt_Check(o_1))
749 throw INTERP_KERNEL::Exception(msg);
750 arr[i].first=(int)PyInt_AS_LONG(o_0);
751 arr[i].second=(int)PyInt_AS_LONG(o_1);
754 throw INTERP_KERNEL::Exception(msg);
757 else if(PyTuple_Check(pyLi))
759 int size=PyTuple_Size(pyLi);
761 for(int i=0;i<size;i++)
763 PyObject *o=PyTuple_GetItem(pyLi,i);
766 int sz2=PyTuple_Size(o);
768 throw INTERP_KERNEL::Exception(msg);
769 PyObject *o_0=PyTuple_GetItem(o,0);
770 if(!PyInt_Check(o_0))
771 throw INTERP_KERNEL::Exception(msg);
772 PyObject *o_1=PyTuple_GetItem(o,1);
773 if(!PyInt_Check(o_1))
774 throw INTERP_KERNEL::Exception(msg);
775 arr[i].first=(int)PyInt_AS_LONG(o_0);
776 arr[i].second=(int)PyInt_AS_LONG(o_1);
779 throw INTERP_KERNEL::Exception(msg);
783 throw INTERP_KERNEL::Exception(msg);
786 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
788 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
789 if(PyList_Check(pyLi))
791 int size=PyList_Size(pyLi);
793 for(int i=0;i<size;i++)
795 PyObject *o=PyList_GetItem(pyLi,i);
798 int sz2=PyTuple_Size(o);
800 throw INTERP_KERNEL::Exception(msg);
801 PyObject *o_0=PyTuple_GetItem(o,0);
802 if(!PyString_Check(o_0))
803 throw INTERP_KERNEL::Exception(msg);
804 PyObject *o_1=PyTuple_GetItem(o,1);
805 if(!PyInt_Check(o_1))
806 throw INTERP_KERNEL::Exception(msg);
807 arr[i].first=PyString_AsString(o_0);
808 arr[i].second=(int)PyInt_AS_LONG(o_1);
811 throw INTERP_KERNEL::Exception(msg);
814 else if(PyTuple_Check(pyLi))
816 int size=PyTuple_Size(pyLi);
818 for(int i=0;i<size;i++)
820 PyObject *o=PyTuple_GetItem(pyLi,i);
823 int sz2=PyTuple_Size(o);
825 throw INTERP_KERNEL::Exception(msg);
826 PyObject *o_0=PyTuple_GetItem(o,0);
827 if(!PyString_Check(o_0))
828 throw INTERP_KERNEL::Exception(msg);
829 PyObject *o_1=PyTuple_GetItem(o,1);
830 if(!PyInt_Check(o_1))
831 throw INTERP_KERNEL::Exception(msg);
832 arr[i].first=PyString_AsString(o_0);
833 arr[i].second=(int)PyInt_AS_LONG(o_1);
836 throw INTERP_KERNEL::Exception(msg);
840 throw INTERP_KERNEL::Exception(msg);
843 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
845 if(PyList_Check(pyLi))
847 int size=PyList_Size(pyLi);
849 for(int i=0;i<size;i++)
851 PyObject *o=PyList_GetItem(pyLi,i);
854 int val=(int)PyInt_AS_LONG(o);
858 throw INTERP_KERNEL::Exception("list must contain integers only");
861 else if(PyTuple_Check(pyLi))
863 int size=PyTuple_Size(pyLi);
865 for(int i=0;i<size;i++)
867 PyObject *o=PyTuple_GetItem(pyLi,i);
870 int val=(int)PyInt_AS_LONG(o);
874 throw INTERP_KERNEL::Exception("tuple must contain integers only");
879 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
883 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
886 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
888 if(PyList_Check(pyLi))
890 int size=PyList_Size(pyLi);
891 for(int i=0;i<size;i++)
893 PyObject *o=PyList_GetItem(pyLi,i);
896 int val=(int)PyInt_AS_LONG(o);
901 std::vector<int> arr2;
902 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
903 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
905 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
906 throw INTERP_KERNEL::Exception(oss.str().c_str());
908 arr.insert(arr.end(),arr2.begin(),arr2.end());
912 else if(PyTuple_Check(pyLi))
914 int size=PyTuple_Size(pyLi);
915 for(int i=0;i<size;i++)
917 PyObject *o=PyTuple_GetItem(pyLi,i);
920 int val=(int)PyInt_AS_LONG(o);
925 std::vector<int> arr2;
926 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
927 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
929 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
930 throw INTERP_KERNEL::Exception(oss.str().c_str());
932 arr.insert(arr.end(),arr2.begin(),arr2.end());
937 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
940 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
944 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
945 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
947 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
948 oss << " whereas nb of components expected is " << nbOfComp << " !";
949 throw INTERP_KERNEL::Exception(oss.str().c_str());
956 if((nbOfTuples!=size1 || nbOfComp!=size2))
958 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
960 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
961 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
962 throw INTERP_KERNEL::Exception(oss.str().c_str());
968 if(nbOfTuples==size1)
972 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
973 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
974 throw INTERP_KERNEL::Exception(oss.str().c_str());
980 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
982 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
983 if(PyInt_Check(pyLi))
985 long val=PyInt_AS_LONG(pyLi);
990 throw INTERP_KERNEL::Exception(MSG);
993 else if(PyList_Check(pyLi))
995 int size=PyList_Size(pyLi);
997 for(int i=0;i<size;i++)
999 PyObject *o=PyList_GetItem(pyLi,i);
1001 fillArrayWithPyListInt3(o,tmp1,ret);
1009 throw INTERP_KERNEL::Exception(MSG);
1012 else if(PyTuple_Check(pyLi))
1014 int size=PyTuple_Size(pyLi);
1016 for(int i=0;i<size;i++)
1018 PyObject *o=PyTuple_GetItem(pyLi,i);
1020 fillArrayWithPyListInt3(o,tmp1,ret);
1028 throw INTERP_KERNEL::Exception(MSG);
1032 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
1035 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1037 std::vector<int> ret;
1038 int size1=-1,size2=-1;
1039 if(PyList_Check(pyLi))
1041 size1=PyList_Size(pyLi);
1042 for(int i=0;i<size1;i++)
1044 PyObject *o=PyList_GetItem(pyLi,i);
1045 fillArrayWithPyListInt3(o,size2,ret);
1050 else if(PyTuple_Check(pyLi))
1052 size1=PyTuple_Size(pyLi);
1053 for(int i=0;i<size1;i++)
1055 PyObject *o=PyTuple_GetItem(pyLi,i);
1056 fillArrayWithPyListInt3(o,size2,ret);
1062 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
1064 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1068 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
1070 if(PyList_Check(pyLi))
1072 Py_ssize_t sz=PyList_Size(pyLi);
1074 for(int i=0;i<sz;i++)
1076 PyObject *o=PyList_GetItem(pyLi,i);
1077 if(PyString_Check(o))
1078 vec[i]=PyString_AsString(o);
1084 else if(PyTuple_Check(pyLi))
1086 Py_ssize_t sz=PyTuple_Size(pyLi);
1088 for(int i=0;i<sz;i++)
1090 PyObject *o=PyTuple_GetItem(pyLi,i);
1091 if(PyString_Check(o))
1092 vec[i]=PyString_AsString(o);
1101 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
1103 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1104 if(PyList_Check(pyLi))
1106 Py_ssize_t sz=PyList_Size(pyLi);
1108 for(int i=0;i<sz;i++)
1110 PyObject *o=PyList_GetItem(pyLi,i);
1111 if(!fillStringVector(o,arr[i]))
1112 throw INTERP_KERNEL::Exception(msg);
1115 else if(PyTuple_Check(pyLi))
1117 Py_ssize_t sz=PyTuple_Size(pyLi);
1119 for(int i=0;i<sz;i++)
1121 PyObject *o=PyTuple_GetItem(pyLi,i);
1122 if(!fillStringVector(o,arr[i]))
1123 throw INTERP_KERNEL::Exception(msg);
1127 throw INTERP_KERNEL::Exception(msg);
1130 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
1132 if(PyList_Check(pyLi))
1134 Py_ssize_t sz=PyList_Size(pyLi);
1136 for(int i=0;i<sz;i++)
1138 PyObject *o=PyList_GetItem(pyLi,i);
1140 vec[i]=PyInt_AS_LONG(o);
1146 else if(PyTuple_Check(pyLi))
1148 Py_ssize_t sz=PyTuple_Size(pyLi);
1150 for(int i=0;i<sz;i++)
1152 PyObject *o=PyTuple_GetItem(pyLi,i);
1154 vec[i]=PyInt_AS_LONG(o);
1164 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
1166 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1167 if(PyList_Check(pyLi))
1169 Py_ssize_t sz=PyList_Size(pyLi);
1171 for(int i=0;i<sz;i++)
1173 PyObject *o=PyList_GetItem(pyLi,i);
1174 if(!fillIntVector(o,arr[i]))
1175 throw INTERP_KERNEL::Exception(msg);
1178 else if(PyTuple_Check(pyLi))
1180 Py_ssize_t sz=PyTuple_Size(pyLi);
1182 for(int i=0;i<sz;i++)
1184 PyObject *o=PyTuple_GetItem(pyLi,i);
1185 if(!fillIntVector(o,arr[i]))
1186 throw INTERP_KERNEL::Exception(msg);
1190 throw INTERP_KERNEL::Exception(msg);
1193 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1195 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1196 if(PyList_Check(pyLi))
1198 Py_ssize_t sz=PyList_Size(pyLi);
1200 for(int i=0;i<sz;i++)
1202 PyObject *o=PyList_GetItem(pyLi,i);
1203 if(PyTuple_Check(o))
1205 int sz2=PyTuple_Size(o);
1207 throw INTERP_KERNEL::Exception(msg);
1208 std::pair<std::string, std::vector<std::string> > item;
1209 PyObject *o_0=PyTuple_GetItem(o,0);
1210 if(!PyString_Check(o_0))
1211 throw INTERP_KERNEL::Exception(msg);
1212 item.first=PyString_AsString(o_0);
1213 PyObject *o_1=PyTuple_GetItem(o,1);
1214 if(!fillStringVector(o_1,item.second))
1215 throw INTERP_KERNEL::Exception(msg);
1219 throw INTERP_KERNEL::Exception(msg);
1222 else if(PyTuple_Check(pyLi))
1224 Py_ssize_t sz=PyTuple_Size(pyLi);
1226 for(int i=0;i<sz;i++)
1228 PyObject *o=PyTuple_GetItem(pyLi,i);
1229 if(PyTuple_Check(o))
1231 int sz2=PyTuple_Size(o);
1233 throw INTERP_KERNEL::Exception(msg);
1234 std::pair<std::string, std::vector<std::string> > item;
1235 PyObject *o_0=PyTuple_GetItem(o,0);
1236 if(!PyString_Check(o_0))
1237 throw INTERP_KERNEL::Exception(msg);
1238 item.first=PyString_AsString(o_0);
1239 PyObject *o_1=PyTuple_GetItem(o,1);
1240 if(!fillStringVector(o_1,item.second))
1241 throw INTERP_KERNEL::Exception(msg);
1245 throw INTERP_KERNEL::Exception(msg);
1249 throw INTERP_KERNEL::Exception(msg);
1252 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1254 PyObject *ret=PyList_New(size);
1255 for(int i=0;i<size;i++)
1256 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1260 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1263 PyObject *ret=PyList_New(size);
1264 for(int i=0;i<size;i++)
1265 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1269 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1271 PyObject *ret=PyList_New(nbOfTuples);
1272 for(int i=0;i<nbOfTuples;i++)
1274 PyObject *t=PyTuple_New(nbOfComp);
1275 for(int j=0;j<nbOfComp;j++)
1276 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1277 PyList_SetItem(ret,i,t);
1282 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1284 PyObject *ret=PyList_New(nbOfTuples);
1285 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1286 for(int i=0;i<nbOfTuples;i++)
1288 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1289 PyList_SetItem(ret,i,PyString_FromString(tmp));
1294 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1296 if(PyList_Check(pyLi))
1298 *size=PyList_Size(pyLi);
1299 double *tmp=(double *)malloc((*size)*sizeof(double));
1300 for(int i=0;i<*size;i++)
1302 PyObject *o=PyList_GetItem(pyLi,i);
1303 if(PyFloat_Check(o))
1305 double val=PyFloat_AS_DOUBLE(o);
1308 else if(PyInt_Check(o))
1310 long val0=PyInt_AS_LONG(o);
1317 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1322 else if(PyTuple_Check(pyLi))
1324 *size=PyTuple_Size(pyLi);
1325 double *tmp=(double *)malloc((*size)*sizeof(double));
1326 for(int i=0;i<*size;i++)
1328 PyObject *o=PyTuple_GetItem(pyLi,i);
1329 if(PyFloat_Check(o))
1331 double val=PyFloat_AS_DOUBLE(o);
1334 else if(PyInt_Check(o))
1336 long val0=PyInt_AS_LONG(o);
1343 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1349 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1352 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1354 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1355 if(PyFloat_Check(pyLi))
1361 throw INTERP_KERNEL::Exception(MSG);
1362 double val=PyFloat_AS_DOUBLE(pyLi);
1365 else if(PyInt_Check(pyLi))
1367 long val0=PyInt_AS_LONG(pyLi);
1373 throw INTERP_KERNEL::Exception(MSG);
1376 else if(PyList_Check(pyLi))
1378 int size=PyList_Size(pyLi);
1380 for(int i=0;i<size;i++)
1382 PyObject *o=PyList_GetItem(pyLi,i);
1384 fillArrayWithPyListDbl3(o,tmp1,ret);
1392 throw INTERP_KERNEL::Exception(MSG);
1395 else if(PyTuple_Check(pyLi))
1397 int size=PyTuple_Size(pyLi);
1399 for(int i=0;i<size;i++)
1401 PyObject *o=PyTuple_GetItem(pyLi,i);
1403 fillArrayWithPyListDbl3(o,tmp1,ret);
1411 throw INTERP_KERNEL::Exception(MSG);
1415 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1418 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1420 std::vector<double> ret;
1421 int size1=-1,size2=-1;
1422 if(PyList_Check(pyLi))
1424 size1=PyList_Size(pyLi);
1425 for(int i=0;i<size1;i++)
1427 PyObject *o=PyList_GetItem(pyLi,i);
1428 fillArrayWithPyListDbl3(o,size2,ret);
1433 else if(PyTuple_Check(pyLi))
1435 size1=PyTuple_Size(pyLi);
1436 for(int i=0;i<size1;i++)
1438 PyObject *o=PyTuple_GetItem(pyLi,i);
1439 fillArrayWithPyListDbl3(o,size2,ret);
1445 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1447 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1451 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1453 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1456 if(PyList_Check(pyLi))
1458 int size=PyList_Size(pyLi);
1460 for(int i=0;i<size;i++)
1462 PyObject *obj=PyList_GetItem(pyLi,i);
1463 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1464 if(!SWIG_IsOK(status))
1466 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1467 throw INTERP_KERNEL::Exception(oss.str().c_str());
1469 T arg=reinterpret_cast< T >(argp);
1473 else if(PyTuple_Check(pyLi))
1475 int size=PyTuple_Size(pyLi);
1477 for(int i=0;i<size;i++)
1479 PyObject *obj=PyTuple_GetItem(pyLi,i);
1480 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1481 if(!SWIG_IsOK(status))
1483 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1484 throw INTERP_KERNEL::Exception(oss.str().c_str());
1486 T arg=reinterpret_cast< T >(argp);
1490 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1493 T arg=reinterpret_cast< T >(argp);
1497 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1501 * if python int -> cpp int sw=1
1502 * if python list[int] -> cpp vector<int> sw=2
1503 * if python tuple[int] -> cpp vector<int> sw=2
1504 * if python DataArrayInt -> cpp DataArrayInt sw=3
1505 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1507 * switch between (int,vector<int>,DataArrayInt)
1509 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1512 if(PyInt_Check(value))
1514 iTyypp=(int)PyInt_AS_LONG(value);
1518 if(PyTuple_Check(value))
1520 int size=PyTuple_Size(value);
1521 stdvecTyypp.resize(size);
1522 for(int i=0;i<size;i++)
1524 PyObject *o=PyTuple_GetItem(value,i);
1526 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1529 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1530 throw INTERP_KERNEL::Exception(oss.str().c_str());
1536 if(PyList_Check(value))
1538 int size=PyList_Size(value);
1539 stdvecTyypp.resize(size);
1540 for(int i=0;i<size;i++)
1542 PyObject *o=PyList_GetItem(value,i);
1544 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1547 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1548 throw INTERP_KERNEL::Exception(oss.str().c_str());
1555 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1556 if(SWIG_IsOK(status))
1558 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1562 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1563 if(SWIG_IsOK(status))
1565 daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1569 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1573 * if python double -> cpp double sw=1
1574 * if python int -> cpp double sw=1
1575 * if python list[double] -> cpp vector<double> sw=2
1576 * if python list[int] -> cpp vector<double> sw=2
1577 * if python tuple[double] -> cpp vector<double> sw=2
1578 * if python tuple[int] -> cpp vector<double> sw=2
1579 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1581 * switch between (int,vector<int>,DataArrayInt)
1583 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1586 if(PyFloat_Check(value))
1588 iTyypp=PyFloat_AS_DOUBLE(value);
1592 if(PyInt_Check(value))
1594 iTyypp=(double)PyInt_AS_LONG(value);
1598 if(PyTuple_Check(value))
1600 int size=PyTuple_Size(value);
1601 stdvecTyypp.resize(size);
1602 for(int i=0;i<size;i++)
1604 PyObject *o=PyTuple_GetItem(value,i);
1605 if(PyFloat_Check(o))
1606 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1607 else if(PyInt_Check(o))
1608 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1611 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1612 throw INTERP_KERNEL::Exception(oss.str().c_str());
1618 if(PyList_Check(value))
1620 int size=PyList_Size(value);
1621 stdvecTyypp.resize(size);
1622 for(int i=0;i<size;i++)
1624 PyObject *o=PyList_GetItem(value,i);
1625 if(PyFloat_Check(o))
1626 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1627 else if(PyInt_Check(o))
1628 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1631 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1632 throw INTERP_KERNEL::Exception(oss.str().c_str());
1639 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
1640 if(!SWIG_IsOK(status))
1641 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1642 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
1647 * if python double -> cpp double sw=1
1648 * if python int -> cpp double sw=1
1649 * if python list[double] -> cpp vector<double> sw=2
1650 * if python list[int] -> cpp vector<double> sw=2
1651 * if python tuple[double] -> cpp vector<double> sw=2
1652 * if python tuple[int] -> cpp vector<double> sw=2
1653 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1655 * switch between (int,vector<int>,DataArrayInt)
1657 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1660 if(PyFloat_Check(value))
1662 iTyypp=PyFloat_AS_DOUBLE(value);
1666 if(PyInt_Check(value))
1668 iTyypp=(double)PyInt_AS_LONG(value);
1672 if(PyTuple_Check(value))
1674 int size=PyTuple_Size(value);
1675 stdvecTyypp.resize(size);
1676 for(int i=0;i<size;i++)
1678 PyObject *o=PyTuple_GetItem(value,i);
1679 if(PyFloat_Check(o))
1680 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1681 else if(PyInt_Check(o))
1682 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1685 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1686 throw INTERP_KERNEL::Exception(oss.str().c_str());
1692 if(PyList_Check(value))
1694 int size=PyList_Size(value);
1695 stdvecTyypp.resize(size);
1696 for(int i=0;i<size;i++)
1698 PyObject *o=PyList_GetItem(value,i);
1699 if(PyFloat_Check(o))
1700 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1701 else if(PyInt_Check(o))
1702 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1705 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1706 throw INTERP_KERNEL::Exception(oss.str().c_str());
1713 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1714 if(!SWIG_IsOK(status))
1715 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1716 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1721 * if python int -> cpp int sw=1
1722 * if python list[int] -> cpp vector<int> sw=2
1723 * if python tuple[int] -> cpp vector<int> sw=2
1724 * if python slicp -> cpp pair sw=3 (begin,end,step)
1725 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1727 * switch between (int,vector<int>,DataArrayInt)
1729 static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1731 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1733 if(PyInt_Check(value))
1735 iTyypp=(int)PyInt_AS_LONG(value);
1739 if(PyTuple_Check(value))
1741 int size=PyTuple_Size(value);
1742 stdvecTyypp.resize(size);
1743 for(int i=0;i<size;i++)
1745 PyObject *o=PyTuple_GetItem(value,i);
1747 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1750 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1751 throw INTERP_KERNEL::Exception(oss.str().c_str());
1757 if(PyList_Check(value))
1759 int size=PyList_Size(value);
1760 stdvecTyypp.resize(size);
1761 for(int i=0;i<size;i++)
1763 PyObject *o=PyList_GetItem(value,i);
1765 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1768 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1769 throw INTERP_KERNEL::Exception(oss.str().c_str());
1775 if(PySlice_Check(value))
1777 Py_ssize_t strt=2,stp=2,step=2;
1778 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1779 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1782 p.second.second=step;
1787 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1788 if(SWIG_IsOK(status))
1790 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1793 std::ostringstream oss; oss << msg << " Instance in null !";
1794 throw INTERP_KERNEL::Exception(oss.str().c_str());
1799 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1800 if(SWIG_IsOK(status))
1802 MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1805 std::ostringstream oss; oss << msg << " Instance in null !";
1806 throw INTERP_KERNEL::Exception(oss.str().c_str());
1808 stdvecTyypp.resize(tmp->getNumberOfCompo());
1809 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1813 throw INTERP_KERNEL::Exception(msg);
1817 * Idem than convertObjToPossibleCpp2
1819 static void convertObjToPossibleCpp2WithNegIntInterp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1821 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1824 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1829 * if python int -> cpp int sw=1
1830 * if python tuple[int] -> cpp vector<int> sw=2
1831 * if python list[int] -> cpp vector<int> sw=2
1832 * if python slice -> cpp pair sw=3
1833 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1835 static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1838 if(PyInt_Check(value))
1840 iTyypp=(int)PyInt_AS_LONG(value);
1844 if(PyTuple_Check(value))
1846 int size=PyTuple_Size(value);
1847 stdvecTyypp.resize(size);
1848 for(int i=0;i<size;i++)
1850 PyObject *o=PyTuple_GetItem(value,i);
1852 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1855 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1856 throw INTERP_KERNEL::Exception(oss.str().c_str());
1862 if(PyList_Check(value))
1864 int size=PyList_Size(value);
1865 stdvecTyypp.resize(size);
1866 for(int i=0;i<size;i++)
1868 PyObject *o=PyList_GetItem(value,i);
1870 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1873 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1874 throw INTERP_KERNEL::Exception(oss.str().c_str());
1880 if(PySlice_Check(value))
1882 Py_ssize_t strt=2,stp=2,step=2;
1883 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1884 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1887 p.second.second=step;
1892 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1893 if(!SWIG_IsOK(status))
1894 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1895 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1900 * if python string with size one -> cpp char sw=1
1901 * if python string with size different from one -> cpp string sw=2
1902 * if python tuple[string] or list[string] -> vector<string> sw=3
1903 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1904 * switch between (int,string,vector<string>,DataArrayChar)
1906 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1908 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1910 if(PyString_Check(value))
1912 const char *pt=PyString_AsString(value);
1913 Py_ssize_t sz=PyString_Size(value);
1927 if(PyTuple_Check(value))
1929 int size=PyTuple_Size(value);
1930 vsType.resize(size);
1931 for(int i=0;i<size;i++)
1933 PyObject *o=PyTuple_GetItem(value,i);
1934 if(PyString_Check(o))
1935 vsType[i]=PyString_AsString(o);
1938 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1939 throw INTERP_KERNEL::Exception(oss.str().c_str());
1945 if(PyList_Check(value))
1947 int size=PyList_Size(value);
1948 vsType.resize(size);
1949 for(int i=0;i<size;i++)
1951 PyObject *o=PyList_GetItem(value,i);
1952 if(PyString_Check(o))
1953 vsType[i]=PyString_AsString(o);
1956 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1957 throw INTERP_KERNEL::Exception(oss.str().c_str());
1964 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
1965 if(SWIG_IsOK(status))
1967 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
1970 std::ostringstream oss; oss << msg << " Instance in null !";
1971 throw INTERP_KERNEL::Exception(oss.str().c_str());
1976 throw INTERP_KERNEL::Exception(msg);
1980 * if value int -> cpp it sw=1
1981 * if value list[int] -> vt sw=2
1982 * if value tuple[int] -> vt sw=2
1983 * if value slice -> pt sw=3
1984 * if value DataArrayInt -> dt sw=4
1985 * if value tuple [int,int] -> cpp it,ip sw=5
1986 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1987 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1988 * if value tuple [slice,int] -> cpp pt,ip sw=7
1989 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1990 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1991 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1992 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1993 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1994 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1995 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1996 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1997 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1998 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1999 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2000 * if value tuple [int,slice] -> cpp it,pc sw=13
2001 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2002 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2003 * if value tuple [slice,slice] -> cpp pt,pc sw=15
2004 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2006 * switch between (int,vector<int>,DataArrayInt)
2008 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
2009 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
2010 MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
2012 if(!PyTuple_Check(value))
2014 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2019 int sz=PyTuple_Size(value);
2021 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2022 PyObject *ob0=PyTuple_GetItem(value,0);
2024 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2025 PyObject *ob1=PyTuple_GetItem(value,1);
2026 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2032 * if value int -> cpp val sw=1
2033 * if value double -> cpp val sw=1
2034 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2035 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2036 * if value list[int,double] -> cpp std::vector<double> sw=4
2037 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2039 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
2042 if(PyFloat_Check(value))
2044 val=PyFloat_AS_DOUBLE(value);
2048 if(PyInt_Check(value))
2050 val=(double)PyInt_AS_LONG(value);
2054 if(PyTuple_Check(value))
2056 int size=PyTuple_Size(value);
2058 for(int i=0;i<size;i++)
2060 PyObject *o=PyTuple_GetItem(value,i);
2061 if(PyFloat_Check(o))
2062 f[i]=PyFloat_AS_DOUBLE(o);
2063 else if(PyInt_Check(o))
2064 f[i]=(double)PyInt_AS_LONG(o);
2067 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2068 throw INTERP_KERNEL::Exception(oss.str().c_str());
2074 if(PyList_Check(value))
2076 int size=PyList_Size(value);
2078 for(int i=0;i<size;i++)
2080 PyObject *o=PyList_GetItem(value,i);
2081 if(PyFloat_Check(o))
2082 f[i]=PyFloat_AS_DOUBLE(o);
2083 else if(PyInt_Check(o))
2084 f[i]=(double)PyInt_AS_LONG(o);
2087 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2088 throw INTERP_KERNEL::Exception(oss.str().c_str());
2095 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2096 if(SWIG_IsOK(status))
2098 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2102 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2103 if(SWIG_IsOK(status))
2105 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2109 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2113 * if value int -> cpp val sw=1
2114 * if value double -> cpp val sw=1
2115 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2116 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2117 * if value list[int,double] -> cpp std::vector<double> sw=4
2118 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2120 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2121 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
2124 if(PyFloat_Check(value))
2126 val=PyFloat_AS_DOUBLE(value);
2128 if(nbTuplesExpected*nbCompExpected!=1)
2130 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2131 throw INTERP_KERNEL::Exception(oss.str().c_str());
2135 if(PyInt_Check(value))
2137 val=(double)PyInt_AS_LONG(value);
2139 if(nbTuplesExpected*nbCompExpected!=1)
2141 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2142 throw INTERP_KERNEL::Exception(oss.str().c_str());
2146 if(PyTuple_Check(value) || PyList_Check(value))
2150 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2151 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2156 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2159 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2160 if(SWIG_IsOK(status))
2162 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2166 if(d->getNumberOfTuples()==nbTuplesExpected)
2168 if(d->getNumberOfComponents()==nbCompExpected)
2170 return d->getConstPointer();
2174 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2175 throw INTERP_KERNEL::Exception(oss.str().c_str());
2180 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2181 throw INTERP_KERNEL::Exception(oss.str().c_str());
2188 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2189 throw INTERP_KERNEL::Exception(oss.str().c_str());
2195 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2196 if(SWIG_IsOK(status))
2198 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2200 if(e->getNumberOfCompo()==nbCompExpected)
2202 if(nbTuplesExpected==1)
2203 return e->getConstPointer();
2206 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2207 throw INTERP_KERNEL::Exception(oss.str().c_str());
2212 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2213 throw INTERP_KERNEL::Exception(oss.str().c_str());
2216 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2220 * if value int -> cpp val sw=1
2221 * if value double -> cpp val sw=1
2222 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2223 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2224 * if value list[int,double] -> cpp std::vector<double> sw=4
2225 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2227 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2228 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2231 if(PyFloat_Check(value))
2233 val=PyFloat_AS_DOUBLE(value);
2235 if(nbCompExpected!=1)
2237 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2238 throw INTERP_KERNEL::Exception(oss.str().c_str());
2243 if(PyInt_Check(value))
2245 val=(double)PyInt_AS_LONG(value);
2247 if(nbCompExpected!=1)
2249 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2250 throw INTERP_KERNEL::Exception(oss.str().c_str());
2255 if(PyTuple_Check(value))
2257 int size=PyTuple_Size(value);
2259 for(int i=0;i<size;i++)
2261 PyObject *o=PyTuple_GetItem(value,i);
2262 if(PyFloat_Check(o))
2263 f[i]=PyFloat_AS_DOUBLE(o);
2264 else if(PyInt_Check(o))
2265 f[i]=(double)PyInt_AS_LONG(o);
2268 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2269 throw INTERP_KERNEL::Exception(oss.str().c_str());
2273 if(size%nbCompExpected!=0)
2275 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2276 throw INTERP_KERNEL::Exception(oss.str().c_str());
2278 nbTuples=size/nbCompExpected;
2281 if(PyList_Check(value))
2283 int size=PyList_Size(value);
2285 for(int i=0;i<size;i++)
2287 PyObject *o=PyList_GetItem(value,i);
2288 if(PyFloat_Check(o))
2289 f[i]=PyFloat_AS_DOUBLE(o);
2290 else if(PyInt_Check(o))
2291 f[i]=(double)PyInt_AS_LONG(o);
2294 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2295 throw INTERP_KERNEL::Exception(oss.str().c_str());
2299 if(size%nbCompExpected!=0)
2301 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2302 throw INTERP_KERNEL::Exception(oss.str().c_str());
2304 nbTuples=size/nbCompExpected;
2308 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2309 if(SWIG_IsOK(status))
2311 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2315 if(d->getNumberOfComponents()==nbCompExpected)
2317 nbTuples=d->getNumberOfTuples();
2318 return d->getConstPointer();
2322 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2323 throw INTERP_KERNEL::Exception(oss.str().c_str());
2330 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2331 throw INTERP_KERNEL::Exception(oss.str().c_str());
2334 { nbTuples=0; return 0; }
2337 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2338 if(SWIG_IsOK(status))
2340 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2344 if(e->getNumberOfCompo()==nbCompExpected)
2347 return e->getConstPointer();
2351 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2352 throw INTERP_KERNEL::Exception(oss.str().c_str());
2359 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2360 throw INTERP_KERNEL::Exception(oss.str().c_str());
2363 { nbTuples=0; return 0; }
2366 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2370 * if value int -> cpp val sw=1
2371 * if value double -> cpp val sw=1
2372 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2373 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2374 * if value list[int,double] -> cpp std::vector<double> sw=4
2375 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2377 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2378 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2380 MEDCoupling::DataArrayDouble *d=0;
2381 MEDCoupling::DataArrayDoubleTuple *e=0;
2383 if(PyFloat_Check(value))
2385 val=PyFloat_AS_DOUBLE(value);
2390 if(PyInt_Check(value))
2392 val=(double)PyInt_AS_LONG(value);
2397 if(PyTuple_Check(value))
2399 int size=PyTuple_Size(value);
2401 for(int i=0;i<size;i++)
2403 PyObject *o=PyTuple_GetItem(value,i);
2404 if(PyFloat_Check(o))
2405 f[i]=PyFloat_AS_DOUBLE(o);
2406 else if(PyInt_Check(o))
2407 f[i]=(double)PyInt_AS_LONG(o);
2410 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2411 throw INTERP_KERNEL::Exception(oss.str().c_str());
2418 if(PyList_Check(value))
2420 int size=PyList_Size(value);
2422 for(int i=0;i<size;i++)
2424 PyObject *o=PyList_GetItem(value,i);
2425 if(PyFloat_Check(o))
2426 f[i]=PyFloat_AS_DOUBLE(o);
2427 else if(PyInt_Check(o))
2428 f[i]=(double)PyInt_AS_LONG(o);
2431 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2432 throw INTERP_KERNEL::Exception(oss.str().c_str());
2440 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2441 if(SWIG_IsOK(status))
2443 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2447 if(d->getNumberOfComponents()==1)
2449 nbTuples=d->getNumberOfTuples();
2450 return d->getConstPointer();
2454 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2455 throw INTERP_KERNEL::Exception(oss.str().c_str());
2462 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2463 throw INTERP_KERNEL::Exception(oss.str().c_str());
2466 { nbTuples=0; return 0; }
2469 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2470 if(SWIG_IsOK(status))
2472 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2476 nbTuples=e->getNumberOfCompo();
2477 return e->getConstPointer();
2483 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2484 throw INTERP_KERNEL::Exception(oss.str().c_str());
2487 { nbTuples=0; return 0; }
2490 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2494 * if python int -> cpp int sw=1
2495 * if python list[int] -> cpp vector<int> sw=2
2496 * if python tuple[int] -> cpp vector<int> sw=2
2497 * if python DataArrayInt -> cpp DataArrayInt sw=3
2498 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2500 * switch between (int,vector<int>,DataArrayInt)
2502 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2505 if(PyInt_Check(value))
2507 iTyypp=(int)PyInt_AS_LONG(value);
2511 if(PyTuple_Check(value))
2513 int size=PyTuple_Size(value);
2514 stdvecTyypp.resize(size);
2515 for(int i=0;i<size;i++)
2517 PyObject *o=PyTuple_GetItem(value,i);
2519 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2522 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2523 throw INTERP_KERNEL::Exception(oss.str().c_str());
2527 return &stdvecTyypp[0];
2529 if(PyList_Check(value))
2531 int size=PyList_Size(value);
2532 stdvecTyypp.resize(size);
2533 for(int i=0;i<size;i++)
2535 PyObject *o=PyList_GetItem(value,i);
2537 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2540 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2541 throw INTERP_KERNEL::Exception(oss.str().c_str());
2545 return &stdvecTyypp[0];
2548 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2549 if(SWIG_IsOK(status))
2551 MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
2554 sw=3; sz=daIntTyypp->getNbOfElems();
2555 return daIntTyypp->begin();
2563 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
2564 if(SWIG_IsOK(status))
2566 MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
2567 sw=4; sz=daIntTuple->getNumberOfCompo();
2568 return daIntTuple->getConstPointer();
2570 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2573 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2576 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2577 if(!SWIG_IsOK(status))
2579 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2580 if(!SWIG_IsOK(status))
2582 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2583 if(!SWIG_IsOK(status))
2585 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2586 if(!SWIG_IsOK(status))
2588 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2589 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2590 throw INTERP_KERNEL::Exception(oss.str().c_str());
2595 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2598 static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
2600 if(!PyTuple_Check(args))
2602 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2603 throw INTERP_KERNEL::Exception(oss.str().c_str());
2605 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2606 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2607 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2609 PyObject *tmp0(PyTuple_New(1));
2610 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2611 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2613 Py_DECREF(selfMeth);
2614 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==0 )
2615 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2616 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2617 PyObject *tmp3(PyTuple_New(0));
2618 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2621 Py_DECREF(initMeth);
2626 static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(PyObject *cls, PyObject *args, const char *clsName)
2628 if(!PyTuple_Check(args))
2630 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2631 throw INTERP_KERNEL::Exception(oss.str().c_str());
2633 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2634 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2635 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2637 PyObject *tmp0(PyTuple_New(1));
2638 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2639 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2641 Py_DECREF(selfMeth);
2642 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 )
2643 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2644 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2645 PyObject *zeNumpyRepr(0);
2647 PyObject *tmp1(PyInt_FromLong(0));
2648 zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed
2652 PyObject *tmp3(PyTuple_New(1));
2653 PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
2654 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2658 Py_DECREF(initMeth);