Salome HOME
5e9e6a9961e30954fbd50e4c2ceb2ba3e9ea139c
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
22 #define __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
23
24 #if PY_VERSION_HEX >= 0x03000000
25 #define PyInt_AS_LONG PyLong_AS_LONG
26 #endif
27
28 #include "InterpKernelAutoPtr.hxx"
29 #include "MEDCouplingDataArrayTraits.hxx"
30 #include "MCType.hxx"
31
32 #include <sstream>
33
34 using namespace MEDCoupling;
35
36 template<class T>
37 struct SWIGTITraits
38 { };
39
40 template<>
41 struct SWIGTITraits<double>
42 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
43
44 template<>
45 struct SWIGTITraits<float>
46 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
47
48 template<>
49 struct SWIGTITraits<Int32>
50 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
51
52 template<>
53 struct SWIGTITraits<Int64>
54 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
55
56 swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
57 swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
58 swig_type_info *SWIGTITraits<Int32>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt32 is null when called here ! Postpone initialization at inlined initializeMe()
59 swig_type_info *SWIGTITraits<Int64>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt64 is null when called here ! Postpone initialization at inlined initializeMe()
60 swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
61 swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
62 swig_type_info *SWIGTITraits<Int32>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt32 is null when called here ! Postpone initialization at inlined initializeMe()
63 swig_type_info *SWIGTITraits<Int64>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt64 is null when called here ! Postpone initialization at inlined initializeMe()
64
65 static PyObject *convertArray(MEDCoupling::DataArray *array, int owner)
66 {
67   PyObject *ret(NULL);
68   if(!array)
69     {
70       Py_XINCREF(Py_None);
71       return Py_None;
72     }
73   if(dynamic_cast<MEDCoupling::DataArrayDouble *>(array))
74     ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
75   if(dynamic_cast<MEDCoupling::DataArrayInt32 *>(array))
76     ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt32,owner);
77   if(dynamic_cast<MEDCoupling::DataArrayInt64 *>(array))
78     ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt64,owner);
79   if(dynamic_cast<MEDCoupling::DataArrayFloat *>(array))
80     ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
81   if(!ret)
82     throw INTERP_KERNEL::Exception("Not recognized type of array on downcast !");
83   return ret;
84 }
85
86 /*!
87  * This method is an extension of PySlice_GetIndices but less
88  * open than PySlice_GetIndicesEx that accepts too many situations.
89  */
90 void GetIndicesOfSlice(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
91 {
92   int ret(PySlice_GetIndices(
93 #if PY_VERSION_HEX >= 0x03000000
94         slice,
95 #else
96         reinterpret_cast<PySliceObject *>(slice),
97 #endif
98         length,start,stop,step));
99   if(ret==0)
100     return ;
101   if(*step>0 && *start==*stop && length==*start)
102     return ;
103   throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
104 }
105
106 /*!
107  * This method allows to retrieve slice info from \a slice.
108  */
109 void GetIndicesOfSliceExplicitely(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
110 {
111   int ret(PySlice_GetIndices(
112 #if PY_VERSION_HEX >= 0x03000000
113         slice,
114 #else
115         reinterpret_cast<PySliceObject *>(slice),
116 #endif
117         std::numeric_limits<int>::max(),start,stop,step));
118   if(ret==0)
119     {
120       if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
121         return ;
122       std::ostringstream oss;
123       oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
124       throw INTERP_KERNEL::Exception(oss.str().c_str());
125     }
126   throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
127 }
128
129 int InterpreteNegativeInt(long val, mcIdType nbelem)
130 {
131   if(val<0)
132     {
133       int newVal((int)(nbelem+val));
134       if(newVal<0)
135         {
136           std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
137           throw INTERP_KERNEL::Exception(oss.str().c_str());
138         }
139       return newVal;
140     }
141   else
142     return (int)val;
143 }
144
145 #ifdef WITH_NUMPY
146 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
147 // in input when an another DataArray is already client of this.
148 template<class MCData>
149 void numarrdeal2(void *pt, void *obj)
150 {
151   typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
152   void **obj1=(void **)obj;
153   PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
154   PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
155   cbdaic->_pt_mc=0;
156   Py_XDECREF(weakRefOnOwner);
157   Py_XDECREF(cbdaic);
158   delete [] obj1;
159 }
160
161 template<class MCData, class T>
162 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
163 {
164   int ndim=PyArray_NDIM(elt0);
165   if(ndim!=1 && ndim!=2)
166     throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
167   if(PyArray_DESCR(elt0)->type_num != npyObjectType)
168     {
169       std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
170 #ifdef _DEBUG_
171       oss << " type_num == " << PyArray_DESCR(elt0)->type_num;
172 #endif
173       throw INTERP_KERNEL::Exception(oss.str().c_str());
174     }
175   npy_intp sz0=PyArray_DIM(elt0,0);
176   npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
177   //
178   int itemSize=PyArray_ITEMSIZE(elt0);
179   if(itemSize!=sizeof(T))
180     {
181       std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
182       throw INTERP_KERNEL::Exception(oss.str().c_str());
183     }
184   if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
185     throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
186   if(ndim==2)
187     if(itemSize!=PyArray_STRIDE(elt0,1))
188       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 !");
189   const char *data=PyArray_BYTES(elt0);
190   typename MEDCoupling::MCAuto<MCData> ret=MCData::New();
191   if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
192     {
193       PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
194       PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
195       int mask=MED_NUMPY_OWNDATA; mask=~mask;
196       elt0C->flags&=mask;
197       PyObject *deepestObj=elt0;
198       PyObject *base=elt0C->base;
199       if(base) deepestObj=base;
200       bool isSpetialCase(false);
201       while(base)
202         {
203           if(PyArray_Check(base))
204             {
205               PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
206               eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
207               baseC->flags&=mask;
208               base=baseC->base;
209               if(base) deepestObj=base;
210             }
211           else
212             {
213               isSpetialCase=true;
214               break;
215             }
216         }
217       if(isSpetialCase)
218         {// 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.
219           std::size_t nbOfElems(sz0*sz1);
220           T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
221           std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
222           ret->useArray(dataCpy,true,MEDCoupling::DeallocType::C_DEALLOC,sz0,sz1);
223           return ret.retn();
224         }
225       typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
226       if(eltOwning==NULL)
227         {
228           PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
229           cb->_pt_mc=ret;
230           ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::DeallocType::C_DEALLOC,sz0,sz1);
231           PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
232           void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
233           mma.setParameterForDeallocator(objs);
234           mma.setSpecificDeallocator(numarrdeal2<MCData>);
235           //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayIdType instance) ! Release it, or perform a copy on the input array !");
236         }
237       else
238         {
239           ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::DeallocType::C_DEALLOC_WITH_OFFSET,sz0,sz1);
240           PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
241           typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::COffsetDeallocator);
242           void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
243           const char *dataEltOwning(PyArray_BYTES(eltOwning));//In case of input array is a sub array of a 2D,3D... array there is an offset
244           int64_t offset(0);
245           if(data!=dataEltOwning)
246             {
247               offset=data>dataEltOwning?-((int64_t)(std::distance(dataEltOwning,data))):(int64_t)std::distance(data,dataEltOwning);
248             }
249           void **objs=new void *[3]; objs[0]=ref; objs[1]=*tmp2; objs[2]=new int64_t(offset);
250           mma.setParameterForDeallocator(objs);
251           mma.setSpecificDeallocator(numarrdeal);
252         }
253     }
254   else if(PyArray_ISBEHAVED_RO(elt0))
255     ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::DeallocType::CPP_DEALLOC,sz0,sz1);
256   return ret.retn();
257 }
258
259
260 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
261 {
262     if (obj == NULL) {
263         PyErr_SetString(PyExc_ValueError,
264                 "Cannot set the NumPy array 'base' "
265                 "dependency to NULL after initialization");
266         return -1;
267     }
268     /*
269      * Allow the base to be set only once. Once the object which
270      * owns the data is set, it doesn't make sense to change it.
271      */
272     if (PyArray_BASE(arr) != NULL) {
273         Py_DECREF(obj);
274         PyErr_SetString(PyExc_ValueError,
275                 "Cannot set the NumPy array 'base' "
276                 "dependency more than once");
277         return -1;
278     }
279
280     /*
281      * Don't allow infinite chains of views, always set the base
282      * to the first owner of the data.
283      * That is, either the first object which isn't an array,
284      * or the first object which owns its own data.
285      */
286
287     while (PyArray_Check(obj) && (PyObject *)arr != obj) {
288         PyArrayObject *obj_arr = (PyArrayObject *)obj;
289         PyObject *tmp;
290
291
292         /* If this array owns its own data, stop collapsing */
293         if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
294             break;
295         }
296
297         tmp = PyArray_BASE(obj_arr);
298         /* If there's no base, stop collapsing */
299         if (tmp == NULL) {
300             break;
301         }
302         /* Stop the collapse new base when the would not be of the same
303          * type (i.e. different subclass).
304          */
305         if (Py_TYPE(tmp) != Py_TYPE(arr)) {
306             break;
307         }
308
309
310         Py_INCREF(tmp);
311         Py_DECREF(obj);
312         obj = tmp;
313     }
314
315     /* Disallow circular references */
316     if ((PyObject *)arr == obj) {
317         Py_DECREF(obj);
318         PyErr_SetString(PyExc_ValueError,
319                 "Cannot create a circular NumPy array 'base' dependency");
320         return -1;
321     }
322
323     arr->base = obj;
324
325     return 0;
326 }
327
328 template<class MCData, class T>
329 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, mcIdType nbTuples, std::size_t nbComp)
330 {
331   if(!self->isAllocated())
332     {
333       std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
334       throw INTERP_KERNEL::Exception(oss.str().c_str());
335     }
336   MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
337   if(nbComp==0)
338     {
339       std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
340       throw INTERP_KERNEL::Exception(oss.str().c_str());
341     }
342   int nbDims=nbComp==1?1:2;
343   npy_intp dim[2];
344   dim[0]=(npy_intp)nbTuples; dim[1]=(npy_intp)nbComp;
345   const T *bg=self->getConstPointer();
346   PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
347   if(mem.isDeallocatorCalled())
348     {
349       if(mem.getDeallocator()!=numarrdeal)
350         {// case for the first call of toNumPyArray
351           PyObject *ref(PyWeakref_NewRef(ret,NULL));
352           typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
353           void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
354           void **objs=new void *[3]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2; objs[2]=new int64_t(0);
355           mem.setParameterForDeallocator(objs);
356           mem.setSpecificDeallocator(numarrdeal);
357           return ret;
358         }
359       else
360         {// case for the second and other call of toNumPyArray
361           void **objs=(void **)mem.getParameterForDeallocator();
362           PyObject *weakRefOnOwner=(PyObject *)objs[0];
363           PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
364           if(obj!=Py_None)
365             {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
366               Py_XINCREF(obj);
367               NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
368             }
369           else
370             {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
371               Py_XDECREF(weakRefOnOwner);
372               PyObject *ref=PyWeakref_NewRef(ret,NULL);
373               objs[0]=ref;
374             }
375         }
376     }
377   return ret;
378 }
379
380 template<class MCData, class T>
381 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
382 {
383   return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
384 }
385
386 SWIGINTERN PyObject *MEDCoupling_DataArrayInt32_toNumPyArray(MEDCoupling::DataArrayInt32 *self);
387 SWIGINTERN PyObject *MEDCoupling_DataArrayInt64_toNumPyArray(MEDCoupling::DataArrayInt64 *self);
388 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
389
390 #endif
391
392 #ifdef WITH_SCIPY
393 PyObject *ToCSRMatrix(const std::vector<std::map<mcIdType,double> >& m, mcIdType nbCols)
394 {
395   mcIdType nbRows((mcIdType)m.size());
396   MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> indPtr(MEDCoupling::DataArrayIdType::New()),indices(MEDCoupling::DataArrayIdType::New());
397   MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
398   indPtr->alloc(nbRows+1,1);
399   mcIdType *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
400   mcIdType sz2(0);
401   for(std::vector<std::map<mcIdType,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
402     {
403       sz2+=(mcIdType)(*it0).size();
404       *intPtr_ptr=sz2;
405     }
406   indices->alloc(sz2,1); data->alloc(sz2,1);
407   mcIdType *indices_ptr(indices->getPointer());
408   double *data_ptr(data->getPointer());
409   for(std::vector<std::map<mcIdType,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
410     for(std::map<mcIdType,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
411       {
412         *indices_ptr=(*it1).first;
413         *data_ptr=(*it1).second;
414       }
415 #ifndef MEDCOUPLING_USE_64BIT_IDS
416   PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt32_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt32_toNumPyArray(indPtr));
417 #else
418   PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt64_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt64_toNumPyArray(indPtr));
419 #endif
420   //
421   PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
422   PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
423   PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
424   PyObject *tmp1(PyString_FromString("shape"));
425   PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
426   PyObject* pdict=PyDict_New();
427   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
428   PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
429   if(!tmp)
430     throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
431   PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
432   if(!csrMatrixCls)
433     throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
434   PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
435   Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
436   return ret;
437 }
438
439 #endif
440
441 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner)
442 {
443   PyObject *ret=0;
444   if(!dac)
445     {
446       Py_XINCREF(Py_None);
447       return Py_None;
448     }
449   if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
450     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
451   if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
452     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
453   if(!ret)
454     throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
455   return ret;
456 }
457
458 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner)
459 {
460   PyObject *ret=0;
461   if(!dac)
462     {
463       Py_XINCREF(Py_None);
464       return Py_None;
465     }
466   if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
467     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
468   if(dynamic_cast<MEDCoupling::DataArrayInt32 *>(dac))
469     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt32,owner);
470   if(dynamic_cast<MEDCoupling::DataArrayInt64 *>(dac))
471     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt64,owner);
472   if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
473     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
474   if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
475     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
476   if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
477     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
478   if(!ret)
479     throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
480   return ret;
481 }
482
483 template<class T>
484 static PyObject *convertIntArrToPyList(const T *ptr, mcIdType size)
485 {
486   PyObject *ret=PyList_New(size);
487   for(T i=0;i<size;i++)
488     PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
489   return ret;
490 }
491
492 template<class T>
493 static PyObject *convertIntArrToPyList2(const std::vector<T>& v)
494 {
495   std::size_t size=v.size();
496   PyObject *ret=PyList_New(size);
497   for(std::size_t i=0;i<size;i++)
498     PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
499   return ret;
500 }
501
502 template<class T>
503 static PyObject *convertIntArrToPyList3(const std::set<T>& v)
504 {
505   std::size_t size=v.size();
506   PyObject *ret=PyList_New(size);
507   typename std::set<T>::const_iterator it=v.begin();
508   for(std::size_t i=0;i<size;i++,it++)
509     PyList_SetItem(ret,i,PyInt_FromLong(*it));
510   return ret;
511 }
512
513 static bool convertPyObjectToStrNT(PyObject *obj, std::string& ret)
514 {
515   if(PyString_Check(obj))
516     {
517       ret=PyString_AsString(obj);
518       return true;
519     }
520 #if PY_VERSION_HEX >= 0x03000000
521   else if(PyUnicode_Check(obj))
522     {
523       ret=PyUnicode_AsUTF8(obj);
524       return true;
525     }
526 #endif
527   return false;
528 }
529
530 static std::string convertPyObjectToStr(PyObject *obj, const char *msg=NULL)
531 {
532   std::string ret;
533   if(PyString_Check(obj))
534     ret=PyString_AsString(obj);
535 #if PY_VERSION_HEX >= 0x03000000
536   else if(PyUnicode_Check(obj))
537     ret=PyUnicode_AsUTF8(obj);
538 #endif
539   else
540     {
541       std::ostringstream oss;
542       if(msg)
543         oss << msg;
544       else
545         oss << "PyWrap convertPyObjectToStr : expect a string like py object !";
546       throw INTERP_KERNEL::Exception(oss.str());
547     }
548   return ret;
549 }
550
551 template<class T>
552 static PyObject *convertIntArrToPyListOfTuple(const T *vals, mcIdType nbOfComp, mcIdType nbOfTuples)
553 {
554   PyObject *ret=PyList_New(nbOfTuples);
555   for(T i=0;i<nbOfTuples;i++)
556     {
557       PyObject *t=PyTuple_New(nbOfComp);
558       for(T j=0;j<nbOfComp;j++)
559         PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
560       PyList_SetItem(ret,i,t);
561     }
562   return ret;
563 }
564
565 template< class T = mcIdType >
566 static T *convertPyToNewIntArr2(PyObject *pyLi, mcIdType *size)
567 {
568   if(PyList_Check(pyLi))
569     {
570       *size=ToIdType(PyList_Size(pyLi));
571       T *tmp=new T[*size];
572       for(mcIdType i=0;i<*size;i++)
573         {
574           PyObject *o=PyList_GetItem(pyLi,i);
575           if(PyInt_Check(o))
576             {
577               T val=(T)PyInt_AS_LONG(o);
578               tmp[i]=val;
579             }
580           else
581             {
582               delete [] tmp;
583               throw INTERP_KERNEL::Exception("list must contain integers only");
584             }
585         }
586       return tmp;
587     }
588   else if(PyTuple_Check(pyLi))
589     {
590       *size=ToIdType(PyTuple_Size(pyLi));
591       T *tmp=new T[*size];
592       for(mcIdType i=0;i<*size;i++)
593         {
594           PyObject *o=PyTuple_GetItem(pyLi,i);
595           if(PyInt_Check(o))
596             {
597               T val=(T)PyInt_AS_LONG(o);
598               tmp[i]=val;
599             }
600           else
601             {
602               delete [] tmp;
603               throw INTERP_KERNEL::Exception("tuple must contain integers only");
604             }
605         }
606       return tmp;
607     }
608   else
609     {
610       throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
611     }
612 }
613
614 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<mcIdType,mcIdType> >& arr)
615 {
616   PyObject *ret=PyList_New(arr.size());
617   for(std::size_t i=0;i<arr.size();i++)
618     {
619       PyObject *t=PyTuple_New(2);
620       PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
621       PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
622       PyList_SetItem(ret,i,t);
623     }
624   return ret;
625 }
626
627 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<mcIdType,mcIdType> >& arr)
628 {
629   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
630   if(PyList_Check(pyLi))
631     {
632       std::size_t size=PyList_Size(pyLi);
633       arr.resize(size);
634       for(std::size_t i=0;i<size;i++)
635         {
636           PyObject *o=PyList_GetItem(pyLi,i);
637           if(PyTuple_Check(o))
638             {
639               std::size_t sz2=PyTuple_Size(o);
640               if(sz2!=2)
641                 throw INTERP_KERNEL::Exception(msg);
642               PyObject *o_0=PyTuple_GetItem(o,0);
643               if(!PyInt_Check(o_0))
644                 throw INTERP_KERNEL::Exception(msg);
645               PyObject *o_1=PyTuple_GetItem(o,1);
646               if(!PyInt_Check(o_1))
647                 throw INTERP_KERNEL::Exception(msg);
648               arr[i].first=(mcIdType)PyInt_AS_LONG(o_0);
649               arr[i].second=(mcIdType)PyInt_AS_LONG(o_1);
650             }
651           else
652             throw INTERP_KERNEL::Exception(msg);
653         }
654     }
655   else if(PyTuple_Check(pyLi))
656     {
657       std::size_t size=PyTuple_Size(pyLi);
658       arr.resize(size);
659       for(std::size_t i=0;i<size;i++)
660         {
661           PyObject *o=PyTuple_GetItem(pyLi,i);
662           if(PyTuple_Check(o))
663             {
664               std::size_t sz2=PyTuple_Size(o);
665               if(sz2!=2)
666                 throw INTERP_KERNEL::Exception(msg);
667               PyObject *o_0=PyTuple_GetItem(o,0);
668               if(!PyInt_Check(o_0))
669                 throw INTERP_KERNEL::Exception(msg);
670               PyObject *o_1=PyTuple_GetItem(o,1);
671               if(!PyInt_Check(o_1))
672                 throw INTERP_KERNEL::Exception(msg);
673               arr[i].first=(mcIdType)PyInt_AS_LONG(o_0);
674               arr[i].second=(mcIdType)PyInt_AS_LONG(o_1);
675             }
676           else
677             throw INTERP_KERNEL::Exception(msg);
678         }
679     }
680   else
681     throw INTERP_KERNEL::Exception(msg);
682 }
683
684 static void convertPyToVectorVectorPairInt(PyObject *pyLi, std::vector< std::vector< std::pair<mcIdType,mcIdType> > >& arr)
685 {
686   const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
687   if(PyList_Check(pyLi))
688     {
689       std::size_t size=PyList_Size(pyLi);
690       arr.resize(size);
691       for(std::size_t i = 0 ; i < size ; ++i)
692         convertPyToVectorPairInt(PyList_GetItem(pyLi,i),arr[i]);
693     }
694   else if(PyTuple_Check(pyLi))
695     {
696       std::size_t size=PyTuple_Size(pyLi);
697       arr.resize(size);
698       for(std::size_t i = 0 ; i < size ; ++i)
699         convertPyToVectorPairInt(PyTuple_GetItem(pyLi,i),arr[i]);
700     }
701   else
702     throw INTERP_KERNEL::Exception(msg);
703 }
704
705 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
706 {
707   const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
708   if(PyList_Check(pyLi))
709     {
710       std::size_t size=PyList_Size(pyLi);
711       arr.resize(size);
712       for(std::size_t i=0;i<size;i++)
713         {
714           PyObject *o=PyList_GetItem(pyLi,i);
715           if(PyTuple_Check(o))
716             {
717               std::size_t sz2=PyTuple_Size(o);
718               if(sz2!=2)
719                 throw INTERP_KERNEL::Exception(msg);
720               PyObject *o_0=PyTuple_GetItem(o,0);
721               PyObject *o_1=PyTuple_GetItem(o,1);
722               arr[i].first=convertPyObjectToStr(o_0,msg);
723               if(!PyInt_Check(o_1))
724                 throw INTERP_KERNEL::Exception(msg);
725               arr[i].second=(int)PyInt_AS_LONG(o_1);
726             }
727           else
728             throw INTERP_KERNEL::Exception(msg);
729         }
730     }
731   else if(PyTuple_Check(pyLi))
732     {
733       std::size_t size=PyTuple_Size(pyLi);
734       arr.resize(size);
735       for(std::size_t i=0;i<size;i++)
736         {
737           PyObject *o=PyTuple_GetItem(pyLi,i);
738           if(PyTuple_Check(o))
739             {
740               std::size_t sz2=PyTuple_Size(o);
741               if(sz2!=2)
742                 throw INTERP_KERNEL::Exception(msg);
743               PyObject *o_0=PyTuple_GetItem(o,0);
744               PyObject *o_1=PyTuple_GetItem(o,1);
745               arr[i].first=convertPyObjectToStr(o_0,msg);
746               if(!PyInt_Check(o_1))
747                 throw INTERP_KERNEL::Exception(msg);
748               arr[i].second=(int)PyInt_AS_LONG(o_1);
749             }
750           else
751             throw INTERP_KERNEL::Exception(msg);
752         }
753     }
754   else
755     throw INTERP_KERNEL::Exception(msg);
756 }
757
758 template<class T>
759 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<T>& arr)
760 {
761   if(PyList_Check(pyLi))
762     {
763       std::size_t size=PyList_Size(pyLi);
764       arr.resize(size);
765       for(std::size_t i=0;i<size;i++)
766         {
767           PyObject *o=PyList_GetItem(pyLi,i);
768           if(PyInt_Check(o))
769             {
770               T val=(T)PyInt_AS_LONG(o);
771               arr[i]=val;
772             }
773           else
774             throw INTERP_KERNEL::Exception("list must contain integers only");
775         }
776     }
777   else if(PyTuple_Check(pyLi))
778     {
779       std::size_t size=PyTuple_Size(pyLi);
780       arr.resize(size);
781       for(std::size_t i=0;i<size;i++)
782         {
783           PyObject *o=PyTuple_GetItem(pyLi,i);
784           if(PyInt_Check(o))
785             {
786               T val=(T)PyInt_AS_LONG(o);
787               arr[i]=val;
788             }
789           else
790             throw INTERP_KERNEL::Exception("tuple must contain integers only");
791         }
792     }
793   else
794     {
795       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
796     }
797 }
798
799 static void convertPyToNewIntArr4(PyObject *pyLi, mcIdType recurseLev, mcIdType nbOfSubPart, std::vector<mcIdType>& arr)
800 {
801   if(recurseLev<0)
802     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
803   arr.clear();
804   if(PyList_Check(pyLi))
805     {
806       std::size_t size=PyList_Size(pyLi);
807       for(std::size_t i=0;i<size;i++)
808         {
809           PyObject *o=PyList_GetItem(pyLi,i);
810           if(PyInt_Check(o))
811             {
812               mcIdType val=(mcIdType)PyInt_AS_LONG(o);
813               arr.push_back(val);
814             }
815           else
816             {
817               std::vector<mcIdType> arr2;
818               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
819               if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
820                   {
821                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
822                     throw INTERP_KERNEL::Exception(oss.str().c_str());
823                   }
824               arr.insert(arr.end(),arr2.begin(),arr2.end());
825             }
826         }
827     }
828   else if(PyTuple_Check(pyLi))
829     {
830       std::size_t size=PyTuple_Size(pyLi);
831       for(std::size_t i=0;i<size;i++)
832         {
833           PyObject *o=PyTuple_GetItem(pyLi,i);
834           if(PyInt_Check(o))
835             {
836               mcIdType val=ToIdType(PyInt_AS_LONG(o));
837               arr.push_back(val);
838             }
839           else
840             {
841               std::vector<mcIdType> arr2;
842               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
843               if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
844                   {
845                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
846                     throw INTERP_KERNEL::Exception(oss.str().c_str());
847                   }
848               arr.insert(arr.end(),arr2.begin(),arr2.end());
849             }
850         }
851     }
852   else
853     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
854 }
855
856 static void checkFillArrayWithPyList(mcIdType size1, mcIdType size2, mcIdType& nbOfTuples, mcIdType& nbOfComp)
857 {
858   if(nbOfTuples==-1)
859     {
860       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
861       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
862           {
863             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
864             oss << " whereas nb of components expected is " << nbOfComp << " !";
865             throw INTERP_KERNEL::Exception(oss.str().c_str());
866           } }
867     }
868   else
869     {
870       if(nbOfComp!=-1)
871         {
872           if((nbOfTuples!=size1 || nbOfComp!=size2))
873             {
874               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
875                 {
876                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
877                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
878                   throw INTERP_KERNEL::Exception(oss.str().c_str());
879                 }
880             }
881         }
882       else
883         {
884           if(nbOfTuples==size1)
885             nbOfComp=size2;
886           else
887             {
888               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
889               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
890               throw INTERP_KERNEL::Exception(oss.str().c_str());
891             }
892         }
893     }
894 }
895
896 template< class T >
897 static void fillArrayWithPyListInt3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<T>& ret)
898 {
899   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
900   if(PyInt_Check(pyLi))
901     {
902       T val=(T)PyInt_AS_LONG(pyLi);
903       if(nbOfElt==-1)
904         nbOfElt=1;
905       else
906         if(nbOfElt!=1)
907           throw INTERP_KERNEL::Exception(MSG);
908       ret.push_back(val);
909     }
910   else if(PyList_Check(pyLi))
911     {
912       std::size_t size=PyList_Size(pyLi);
913       mcIdType tmp=0;
914       for(std::size_t i=0;i<size;i++)
915         {
916           PyObject *o=PyList_GetItem(pyLi,i);
917           mcIdType tmp1=-1;
918           fillArrayWithPyListInt3(o,tmp1,ret);
919           tmp+=tmp1;
920         }
921       if(nbOfElt==-1)
922         nbOfElt=tmp;
923       else
924         {
925           if(nbOfElt!=tmp)
926             throw INTERP_KERNEL::Exception(MSG);
927         }
928     }
929   else if(PyTuple_Check(pyLi))
930     {
931       std::size_t size=PyTuple_Size(pyLi);
932       mcIdType tmp=0;
933       for(std::size_t i=0;i<size;i++)
934         {
935           PyObject *o=PyTuple_GetItem(pyLi,i);
936           mcIdType tmp1=-1;
937           fillArrayWithPyListInt3(o,tmp1,ret);
938           tmp+=tmp1;
939         }
940       if(nbOfElt==-1)
941         nbOfElt=tmp;
942       else
943         {
944           if(nbOfElt!=tmp)
945             throw INTERP_KERNEL::Exception(MSG);
946         }
947     }
948   else
949     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
950 }
951
952 template< class T = mcIdType >
953 static std::vector<T> fillArrayWithPyListInt2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
954 {
955   std::vector<T> ret;
956   mcIdType size1=-1,size2=-1;
957   if(PyList_Check(pyLi))
958     {
959       size1=ToIdType(PyList_Size(pyLi));
960       for(mcIdType i=0;i<size1;i++)
961         {
962           PyObject *o=PyList_GetItem(pyLi,i);
963           fillArrayWithPyListInt3(o,size2,ret);
964         }
965       if(size1==0)
966         size2=1;
967     }
968   else if(PyTuple_Check(pyLi))
969     {
970       size1=ToIdType(PyTuple_Size(pyLi));
971       for(mcIdType i=0;i<size1;i++)
972         {
973           PyObject *o=PyTuple_GetItem(pyLi,i);
974           fillArrayWithPyListInt3(o,size2,ret);
975         }
976       if(size1==0)
977         size2=1;
978     }
979   else
980     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
981   //
982   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
983   return ret;
984 }
985
986 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
987 {
988   if(PyList_Check(pyLi))
989     {
990       Py_ssize_t sz=PyList_Size(pyLi);
991       vec.resize(sz);
992       for(mcIdType i=0;i<sz;i++)
993         {
994           PyObject *o=PyList_GetItem(pyLi,i);
995           if(!convertPyObjectToStrNT(o,vec[i]))
996             return false;
997         }
998       return true;
999     }
1000   else if(PyTuple_Check(pyLi))
1001     {
1002       Py_ssize_t sz=PyTuple_Size(pyLi);
1003       vec.resize(sz);
1004       for(mcIdType i=0;i<sz;i++)
1005         {
1006           PyObject *o=PyTuple_GetItem(pyLi,i);
1007           if(!convertPyObjectToStrNT(o,vec[i]))
1008             return false;
1009         }
1010       return true;
1011     }
1012   else
1013     return false;
1014 }
1015 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
1016 {
1017   const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1018   if(PyList_Check(pyLi))
1019     {
1020       Py_ssize_t sz=PyList_Size(pyLi);
1021       arr.resize(sz);
1022       for(mcIdType i=0;i<sz;i++)
1023         {
1024           PyObject *o=PyList_GetItem(pyLi,i);
1025           if(!fillStringVector(o,arr[i]))
1026             throw INTERP_KERNEL::Exception(msg);
1027         }
1028     }
1029   else if(PyTuple_Check(pyLi))
1030     {
1031       Py_ssize_t sz=PyTuple_Size(pyLi);
1032       arr.resize(sz);
1033       for(mcIdType i=0;i<sz;i++)
1034         {
1035           PyObject *o=PyTuple_GetItem(pyLi,i);
1036           if(!fillStringVector(o,arr[i]))
1037             throw INTERP_KERNEL::Exception(msg);
1038         }
1039     }
1040   else
1041     throw INTERP_KERNEL::Exception(msg);
1042 }
1043
1044 static bool fillIntVector(PyObject *pyLi, std::vector<mcIdType>& vec)
1045 {
1046   if(PyList_Check(pyLi))
1047     {
1048       Py_ssize_t sz=PyList_Size(pyLi);
1049       vec.resize(sz);
1050       for(mcIdType i=0;i<sz;i++)
1051         {
1052           PyObject *o=PyList_GetItem(pyLi,i);
1053           if(PyInt_Check(o))
1054             vec[i]=ToIdType(PyInt_AS_LONG(o));
1055           else
1056             return false;
1057         }
1058       return true;
1059     }
1060   else if(PyTuple_Check(pyLi))
1061     {
1062       Py_ssize_t sz=PyTuple_Size(pyLi);
1063       vec.resize(sz);
1064       for(mcIdType i=0;i<sz;i++)
1065         {
1066           PyObject *o=PyTuple_GetItem(pyLi,i);
1067           if(PyInt_Check(o))
1068             vec[i]=ToIdType(PyInt_AS_LONG(o));
1069           else
1070             return false;
1071         }
1072       return true;
1073     }
1074   else
1075     return false;
1076 }
1077
1078 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<mcIdType> >& arr)
1079 {
1080   const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1081   if(PyList_Check(pyLi))
1082     {
1083       Py_ssize_t sz=PyList_Size(pyLi);
1084       arr.resize(sz);
1085       for(mcIdType i=0;i<sz;i++)
1086         {
1087           PyObject *o=PyList_GetItem(pyLi,i);
1088           if(!fillIntVector(o,arr[i]))
1089             throw INTERP_KERNEL::Exception(msg);
1090         }
1091     }
1092   else if(PyTuple_Check(pyLi))
1093     {
1094       Py_ssize_t sz=PyTuple_Size(pyLi);
1095       arr.resize(sz);
1096       for(mcIdType i=0;i<sz;i++)
1097         {
1098           PyObject *o=PyTuple_GetItem(pyLi,i);
1099           if(!fillIntVector(o,arr[i]))
1100             throw INTERP_KERNEL::Exception(msg);
1101         }
1102     }
1103   else
1104     throw INTERP_KERNEL::Exception(msg);
1105 }
1106
1107 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
1108 {
1109   const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1110   if(PyList_Check(pyLi))
1111     {
1112       Py_ssize_t sz=PyList_Size(pyLi);
1113       arr.resize(sz);
1114       for(mcIdType i=0;i<sz;i++)
1115         {
1116           PyObject *o=PyList_GetItem(pyLi,i);
1117           if(PyTuple_Check(o))
1118             {
1119               std::size_t sz2=PyTuple_Size(o);
1120               if(sz2!=2)
1121                 throw INTERP_KERNEL::Exception(msg);
1122               std::pair<std::string, std::vector<std::string> > item;
1123               PyObject *o_0=PyTuple_GetItem(o,0);
1124               item.first=convertPyObjectToStr(o_0,msg);
1125               PyObject *o_1=PyTuple_GetItem(o,1);
1126               if(!fillStringVector(o_1,item.second))
1127                 throw INTERP_KERNEL::Exception(msg);
1128               arr[i]=item;
1129             }
1130           else
1131             throw INTERP_KERNEL::Exception(msg);
1132         }
1133     }
1134   else if(PyTuple_Check(pyLi))
1135     {
1136       Py_ssize_t sz=PyTuple_Size(pyLi);
1137       arr.resize(sz);
1138       for(Py_ssize_t i=0;i<sz;i++)
1139         {
1140           PyObject *o=PyTuple_GetItem(pyLi,i);
1141           if(PyTuple_Check(o))
1142             {
1143               std::size_t sz2=PyTuple_Size(o);
1144               if(sz2!=2)
1145                 throw INTERP_KERNEL::Exception(msg);
1146               std::pair<std::string, std::vector<std::string> > item;
1147               PyObject *o_0=PyTuple_GetItem(o,0);
1148               item.first=convertPyObjectToStr(o_0,msg);
1149               PyObject *o_1=PyTuple_GetItem(o,1);
1150               if(!fillStringVector(o_1,item.second))
1151                 throw INTERP_KERNEL::Exception(msg);
1152               arr[i]=item;
1153             }
1154           else
1155             throw INTERP_KERNEL::Exception(msg);
1156         }
1157     }
1158   else
1159     throw INTERP_KERNEL::Exception(msg);
1160 }
1161
1162 template<class T>
1163 PyObject *convertDblArrToPyList(const T *ptr, std::size_t size)
1164 {
1165   PyObject *ret(PyList_New(size));
1166   for(std::size_t i=0;i<size;i++)
1167     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1168   return ret;
1169 }
1170
1171 static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
1172 {
1173   std::size_t size(v.size());
1174   PyObject *ret(PyList_New(size));
1175   for(std::size_t i=0;i<size;i++)
1176     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1177   return ret;
1178 }
1179
1180 template<class T>
1181 PyObject *convertDblArrToPyListOfTuple(const T *vals, std::size_t nbOfComp, mcIdType nbOfTuples)
1182 {
1183   PyObject *ret(PyList_New(nbOfTuples));
1184   for(mcIdType i=0;i<nbOfTuples;i++)
1185     {
1186       PyObject *t=PyTuple_New(nbOfComp);
1187       for(std::size_t j=0;j<nbOfComp;j++)
1188         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1189       PyList_SetItem(ret,i,t);
1190     }
1191   return ret;
1192 }
1193
1194 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, mcIdType nbOfTuples)
1195 {
1196   PyObject *ret=PyList_New(nbOfTuples);
1197   INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1198   for(mcIdType i=0;i<nbOfTuples;i++)
1199     {
1200       std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1201       PyList_SetItem(ret,i,PyString_FromString(tmp));
1202     }
1203   return ret;
1204 }
1205
1206 static double *convertPyToNewDblArr2(PyObject *pyLi, mcIdType *size)
1207 {
1208   if(PyList_Check(pyLi))
1209     {
1210       *size=ToIdType(PyList_Size(pyLi));
1211       double *tmp=(double *)malloc((*size)*sizeof(double));
1212       for(mcIdType i=0;i<*size;i++)
1213         {
1214           PyObject *o=PyList_GetItem(pyLi,i);
1215           if(PyFloat_Check(o))
1216             {
1217               double val=PyFloat_AS_DOUBLE(o);
1218               tmp[i]=val;
1219             }
1220           else if(PyInt_Check(o))
1221             {
1222               long val0=PyInt_AS_LONG(o);
1223               double val=(double)val0;
1224               tmp[i]=val;
1225             }
1226           else
1227             {
1228               free(tmp);
1229               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1230             }
1231         }
1232       return tmp;
1233     }
1234   else if(PyTuple_Check(pyLi))
1235     {
1236       *size=ToIdType(PyTuple_Size(pyLi));
1237       double *tmp=(double *)malloc((*size)*sizeof(double));
1238       for(mcIdType i=0;i<*size;i++)
1239         {
1240           PyObject *o=PyTuple_GetItem(pyLi,i);
1241           if(PyFloat_Check(o))
1242             {
1243               double val=PyFloat_AS_DOUBLE(o);
1244               tmp[i]=val;
1245             }
1246           else if(PyInt_Check(o))
1247             {
1248               long val0=PyInt_AS_LONG(o);
1249               double val=(double)val0;
1250               tmp[i]=val;
1251             }
1252           else
1253             {
1254               free(tmp);
1255               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1256             }
1257         }
1258       return tmp;
1259     }
1260   else
1261     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1262 }
1263
1264 static void fillArrayWithPyListDbl3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<double>& ret)
1265 {
1266   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1267   if(PyFloat_Check(pyLi))
1268     {
1269       if(nbOfElt==-1)
1270         nbOfElt=1;
1271       else
1272         if(nbOfElt!=1)
1273           throw INTERP_KERNEL::Exception(MSG);
1274       double val=PyFloat_AS_DOUBLE(pyLi);
1275       ret.push_back(val);
1276     }
1277   else if(PyInt_Check(pyLi))
1278     {
1279       mcIdType val0=ToIdType(PyInt_AS_LONG(pyLi));
1280       double val=(double)val0;
1281       if(nbOfElt==-1)
1282         nbOfElt=1;
1283       else
1284         if(nbOfElt!=1)
1285           throw INTERP_KERNEL::Exception(MSG);
1286       ret.push_back(val);
1287     }
1288   else if(PyList_Check(pyLi))
1289     {
1290       std::size_t size=PyList_Size(pyLi);
1291       mcIdType tmp=0;
1292       for(std::size_t i=0;i<size;i++)
1293         {
1294           PyObject *o=PyList_GetItem(pyLi,i);
1295           mcIdType tmp1=-1;
1296           fillArrayWithPyListDbl3(o,tmp1,ret);
1297           tmp+=tmp1;
1298         }
1299       if(nbOfElt==-1)
1300         nbOfElt=tmp;
1301       else
1302         {
1303           if(nbOfElt!=tmp)
1304             throw INTERP_KERNEL::Exception(MSG);
1305         }
1306     }
1307   else if(PyTuple_Check(pyLi))
1308     {
1309       std::size_t size=PyTuple_Size(pyLi);
1310       mcIdType tmp=0;
1311       for(std::size_t i=0;i<size;i++)
1312         {
1313           PyObject *o=PyTuple_GetItem(pyLi,i);
1314           mcIdType tmp1=-1;
1315           fillArrayWithPyListDbl3(o,tmp1,ret);
1316           tmp+=tmp1;
1317         }
1318       if(nbOfElt==-1)
1319         nbOfElt=tmp;
1320       else
1321         {
1322           if(nbOfElt!=tmp)
1323             throw INTERP_KERNEL::Exception(MSG);
1324         }
1325     }
1326   else
1327     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1328 }
1329
1330 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
1331 {
1332   std::vector<double> ret;
1333   std::size_t size1=-1;
1334   mcIdType size2=-1;
1335   if(PyList_Check(pyLi))
1336     {
1337       size1=PyList_Size(pyLi);
1338       for(std::size_t i=0;i<size1;i++)
1339         {
1340           PyObject *o=PyList_GetItem(pyLi,i);
1341           fillArrayWithPyListDbl3(o,size2,ret);
1342         }
1343       if(size1==0)
1344         size2=1;
1345     }
1346   else if(PyTuple_Check(pyLi))
1347     {
1348       size1=PyTuple_Size(pyLi);
1349       for(std::size_t i=0;i<size1;i++)
1350         {
1351           PyObject *o=PyTuple_GetItem(pyLi,i);
1352           fillArrayWithPyListDbl3(o,size2,ret);
1353         }
1354       if(size1==0)
1355         size2=1;
1356     }
1357   else
1358     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1359   //
1360   checkFillArrayWithPyList(ToIdType(size1),ToIdType(size2),nbOfTuples,nbOfComp);
1361   return ret;
1362 }
1363
1364 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1365 template<class T>
1366 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1367 {
1368   void *argp=0;
1369   if(PyList_Check(pyLi))
1370     {
1371       std::size_t size=PyList_Size(pyLi);
1372       ret.resize(size);
1373       for(std::size_t i=0;i<size;i++)
1374         {
1375           PyObject *obj=PyList_GetItem(pyLi,i);
1376           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1377           if(!SWIG_IsOK(status))
1378             {
1379               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1380               throw INTERP_KERNEL::Exception(oss.str().c_str());
1381             }
1382           T arg=reinterpret_cast< T >(argp);
1383           ret[i]=arg;
1384         }
1385     }
1386   else if(PyTuple_Check(pyLi))
1387     {
1388       std::size_t size=PyTuple_Size(pyLi);
1389       ret.resize(size);
1390       for(std::size_t i=0;i<size;i++)
1391         {
1392           PyObject *obj=PyTuple_GetItem(pyLi,i);
1393           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1394           if(!SWIG_IsOK(status))
1395             {
1396               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1397               throw INTERP_KERNEL::Exception(oss.str().c_str());
1398             }
1399           T arg=reinterpret_cast< T >(argp);
1400           ret[i]=arg;
1401         }
1402     }
1403   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1404     {
1405       ret.resize(1);
1406       T arg=reinterpret_cast< T >(argp);
1407       ret[0]=arg;
1408     }
1409   else
1410     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1411 }
1412
1413 //convertFromVectorAutoObjToPyObj<MEDCoupling::MEDCouplingUMesh>(inpv,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh)
1414 template<class T>
1415 static PyObject *convertFromVectorAutoObjToPyObj(std::vector< MCAuto<T> >& inpVector, swig_type_info *ty)
1416 {
1417   std::size_t sz(inpVector.size());
1418   PyObject *ret = PyList_New(sz);
1419   for(std::size_t i=0;i<sz;++i)
1420     PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(inpVector[i].retn()),ty, SWIG_POINTER_OWN | 0 ));
1421   return ret;
1422 }
1423
1424 /*!
1425  * if python int -> cpp int sw=1
1426  * if python list[int] -> cpp vector<int> sw=2
1427  * if python tuple[int] -> cpp vector<int> sw=2
1428  * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1429  * if python DataArrayIntTuple -> cpp DataArrayIdTypeTuple sw=4
1430  *
1431  * switch between (int,vector<int>,DataArrayIdType)
1432  */
1433 template< class T, class ARRAY >
1434 static void convertIntStarLikePyObjToCpp(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, ARRAY *& daIntTyypp, typename MEDCoupling::Traits< T >::ArrayTuple *&daIntTuple)
1435 {
1436   sw=-1;
1437   if(PyInt_Check(value))
1438     {
1439       iTyypp=(T)PyInt_AS_LONG(value);
1440       sw=1;
1441       return;
1442     }
1443   if(PyTuple_Check(value))
1444     {
1445       std::size_t size=PyTuple_Size(value);
1446       stdvecTyypp.resize(size);
1447       for(std::size_t i=0;i<size;i++)
1448         {
1449           PyObject *o=PyTuple_GetItem(value,i);
1450           if(PyInt_Check(o))
1451             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1452           else
1453             {
1454               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1455               throw INTERP_KERNEL::Exception(oss.str().c_str());
1456             }
1457         }
1458       sw=2;
1459       return;
1460     }
1461   if(PyList_Check(value))
1462     {
1463       std::size_t size=PyList_Size(value);
1464       stdvecTyypp.resize(size);
1465       for(std::size_t i=0;i<size;i++)
1466         {
1467           PyObject *o=PyList_GetItem(value,i);
1468           if(PyInt_Check(o))
1469             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1470           else
1471             {
1472               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1473               throw INTERP_KERNEL::Exception(oss.str().c_str());
1474             }
1475         }
1476       sw=2;
1477       return;
1478     }
1479   void *argp;
1480   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1481   if(SWIG_IsOK(status))
1482     {
1483       daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1484       sw=3;
1485       return;
1486     }
1487   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1488   if(SWIG_IsOK(status))
1489     {
1490       daIntTuple=reinterpret_cast< typename MEDCoupling::Traits< T >::ArrayTuple * >(argp);
1491       sw=4;
1492       return ;
1493     }
1494   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1495 }
1496
1497 /*!
1498  * if python int -> cpp int sw=1
1499  * if python list[int] -> cpp vector<int> sw=2
1500  * if python tuple[int] -> cpp vector<int> sw=2
1501  * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1502  * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4
1503  *
1504  * switch between (int,vector<int>,DataArrayIdType)
1505  */
1506 template< class T >
1507 static const T *convertIntStarLikePyObjToCppIntStar(PyObject *value, mcIdType& sw, mcIdType& sz, T& iTyypp, std::vector<T>& stdvecTyypp)
1508 {
1509   sw=-1;
1510   if(PyInt_Check(value))
1511     {
1512       iTyypp=(T)PyInt_AS_LONG(value);
1513       sw=1; sz=1;
1514       return &iTyypp;
1515     }
1516   if(PyTuple_Check(value))
1517     {
1518       std::size_t size=PyTuple_Size(value);
1519       stdvecTyypp.resize(size);
1520       for(std::size_t i=0;i<size;i++)
1521         {
1522           PyObject *o=PyTuple_GetItem(value,i);
1523           if(PyInt_Check(o))
1524             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1525           else
1526             {
1527               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1528               throw INTERP_KERNEL::Exception(oss.str().c_str());
1529             }
1530         }
1531       sw=2; sz=ToIdType(size);
1532       return &stdvecTyypp[0];
1533     }
1534   if(PyList_Check(value))
1535     {
1536       std::size_t size=PyList_Size(value);
1537       stdvecTyypp.resize(size);
1538       for(std::size_t i=0;i<size;i++)
1539         {
1540           PyObject *o=PyList_GetItem(value,i);
1541           if(PyInt_Check(o))
1542             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1543           else
1544             {
1545               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1546               throw INTERP_KERNEL::Exception(oss.str().c_str());
1547             }
1548         }
1549       sw=2; sz=ToIdType(size);
1550       return &stdvecTyypp[0];
1551     }
1552   void *argp;
1553   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI,0|0);
1554   if(SWIG_IsOK(status))
1555     {
1556       typedef typename MEDCoupling::Traits< T >::ArrayType ARRAY;
1557       ARRAY *daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1558       if(daIntTyypp)
1559         {
1560           sw=3; sz=daIntTyypp->getNbOfElems();
1561           return daIntTyypp->begin();
1562         }
1563       else
1564         {
1565           sz=0;
1566           return 0;
1567         }
1568     }
1569   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1570   if(SWIG_IsOK(status))
1571     {
1572       typedef typename MEDCoupling::Traits< T >::ArrayTuple ARRAYTUPLE;
1573       ARRAYTUPLE *daIntTuple=reinterpret_cast< ARRAYTUPLE * >(argp);
1574       sw=4; sz=ToIdType(daIntTuple->getNumberOfCompo());
1575       return daIntTuple->getConstPointer();
1576     }
1577   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1578 }
1579
1580 /*!
1581  * if python double -> cpp double sw=1
1582  * if python int -> cpp double sw=1
1583  * if python list[double] -> cpp vector<double> sw=2
1584  * if python list[int] -> cpp vector<double> sw=2
1585  * if python tuple[double] -> cpp vector<double> sw=2
1586  * if python tuple[int] -> cpp vector<double> sw=2
1587  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1588  *
1589  * switch between (int,vector<int>,DataArrayIdType)
1590  */
1591 template<class T>
1592 void considerPyObjAsATStarLikeObject(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1593 {
1594   sw=-1;
1595   if(PyFloat_Check(value))
1596     {
1597       iTyypp=(T)PyFloat_AS_DOUBLE(value);
1598       sw=1;
1599       return;
1600     }
1601   if(PyInt_Check(value))
1602     {
1603       iTyypp=(T)PyInt_AS_LONG(value);
1604       sw=1;
1605       return;
1606     }
1607   if(PyTuple_Check(value))
1608     {
1609       std::size_t size=PyTuple_Size(value);
1610       stdvecTyypp.resize(size);
1611       for(std::size_t i=0;i<size;i++)
1612         {
1613           PyObject *o=PyTuple_GetItem(value,i);
1614           if(PyFloat_Check(o))
1615             stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1616           else if(PyInt_Check(o))
1617             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1618           else
1619             {
1620               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1621               throw INTERP_KERNEL::Exception(oss.str().c_str());
1622             }
1623         }
1624       sw=2;
1625       return;
1626     }
1627   if(PyList_Check(value))
1628     {
1629       std::size_t size=PyList_Size(value);
1630       stdvecTyypp.resize(size);
1631       for(std::size_t i=0;i<size;i++)
1632         {
1633           PyObject *o=PyList_GetItem(value,i);
1634           if(PyFloat_Check(o))
1635             stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1636           else if(PyInt_Check(o))
1637             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1638           else
1639             {
1640               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1641               throw INTERP_KERNEL::Exception(oss.str().c_str());
1642             }
1643         }
1644       sw=2;
1645       return;
1646     }
1647   void *argp;
1648   int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1649   if(!SWIG_IsOK(status))
1650     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1651   daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1652   sw=3;
1653 }
1654
1655 /*!
1656  * if python double -> cpp double sw=1
1657  * if python int -> cpp double sw=1
1658  * if python list[double] -> cpp vector<double> sw=2
1659  * if python list[int] -> cpp vector<double> sw=2
1660  * if python tuple[double] -> cpp vector<double> sw=2
1661  * if python tuple[int] -> cpp vector<double> sw=2
1662  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1663  *
1664  * switch between (int,vector<int>,DataArrayIdType)
1665  */
1666 static void convertDoubleStarLikePyObjToCpp(PyObject *value, mcIdType& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1667 {
1668   sw=-1;
1669   if(PyFloat_Check(value))
1670     {
1671       iTyypp=PyFloat_AS_DOUBLE(value);
1672       sw=1;
1673       return;
1674     }
1675   if(PyInt_Check(value))
1676     {
1677       iTyypp=(double)PyInt_AS_LONG(value);
1678       sw=1;
1679       return;
1680     }
1681   if(PyTuple_Check(value))
1682     {
1683       std::size_t size=PyTuple_Size(value);
1684       stdvecTyypp.resize(size);
1685       for(std::size_t i=0;i<size;i++)
1686         {
1687           PyObject *o=PyTuple_GetItem(value,i);
1688           if(PyFloat_Check(o))
1689             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1690           else if(PyInt_Check(o))
1691             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1692           else
1693             {
1694               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1695               throw INTERP_KERNEL::Exception(oss.str().c_str());
1696             }
1697         }
1698       sw=2;
1699       return;
1700     }
1701   if(PyList_Check(value))
1702     {
1703       std::size_t size=PyList_Size(value);
1704       stdvecTyypp.resize(size);
1705       for(std::size_t i=0;i<size;i++)
1706         {
1707           PyObject *o=PyList_GetItem(value,i);
1708           if(PyFloat_Check(o))
1709             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1710           else if(PyInt_Check(o))
1711             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1712           else
1713             {
1714               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1715               throw INTERP_KERNEL::Exception(oss.str().c_str());
1716             }
1717         }
1718       sw=2;
1719       return;
1720     }
1721   void *argp;
1722   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1723   if(!SWIG_IsOK(status))
1724     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1725   daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1726   sw=3;
1727 }
1728
1729 template<class T>
1730 void convertFPStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
1731 {
1732   sw=-1;
1733   if(PyFloat_Check(value))
1734     {
1735       val=(T)PyFloat_AS_DOUBLE(value);
1736       sw=1;
1737       return;
1738     }
1739   if(PyInt_Check(value))
1740     {
1741       val=(T)PyInt_AS_LONG(value);
1742       sw=1;
1743       return;
1744     }
1745   if(PyTuple_Check(value))
1746     {
1747       std::size_t size=PyTuple_Size(value);
1748       f.resize(size);
1749       for(std::size_t i=0;i<size;i++)
1750         {
1751           PyObject *o=PyTuple_GetItem(value,i);
1752           if(PyFloat_Check(o))
1753             f[i]=(T)PyFloat_AS_DOUBLE(o);
1754           else if(PyInt_Check(o))
1755             f[i]=(T)PyInt_AS_LONG(o);
1756           else
1757             {
1758               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1759               throw INTERP_KERNEL::Exception(oss.str().c_str());
1760             }
1761         }
1762       sw=4;
1763       return;
1764     }
1765   if(PyList_Check(value))
1766     {
1767       std::size_t size=PyList_Size(value);
1768       f.resize(size);
1769       for(std::size_t i=0;i<size;i++)
1770         {
1771           PyObject *o=PyList_GetItem(value,i);
1772           if(PyFloat_Check(o))
1773             f[i]=(T)PyFloat_AS_DOUBLE(o);
1774           else if(PyInt_Check(o))
1775             f[i]=(T)PyInt_AS_LONG(o);
1776           else
1777             {
1778               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1779               throw INTERP_KERNEL::Exception(oss.str().c_str());
1780             }
1781         }
1782       sw=4;
1783       return;
1784     }
1785   void *argp;
1786   int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1787   if(SWIG_IsOK(status))
1788     {
1789       d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1790       sw=2;
1791       return ;
1792     }
1793   status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1794   if(SWIG_IsOK(status))
1795     {
1796       e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1797       sw=3;
1798       return ;
1799     }
1800   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1801 }
1802
1803 /*!
1804  * if value int -> cpp val sw=1
1805  * if value double -> cpp val sw=1
1806  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1807  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1808  * if value list[int,double] -> cpp std::vector<double> sw=4
1809  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1810  */
1811 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1812 {
1813   convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1814 }
1815
1816 /*!
1817  * if value int -> cpp val sw=1
1818  * if value double -> cpp val sw=1
1819  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1820  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1821  * if value list[int,double] -> cpp std::vector<double> sw=4
1822  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1823  */
1824 static void convertFloatStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
1825 {
1826   convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
1827 }
1828
1829 /*!
1830  * if python int -> cpp int sw=1
1831  * if python list[int] -> cpp vector<int> sw=2
1832  * if python tuple[int] -> cpp vector<int> sw=2
1833  * if python slicp -> cpp pair sw=3 (begin,end,step)
1834  * if python DataArrayIdType -> cpp DataArrayIdType sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1835  *
1836  * switch between (int,vector<int>,DataArrayIdType)
1837  */
1838 template<class T, class ARRAY>
1839 static void convertIntStarOrSliceLikePyObjToCpp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1840 {
1841   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdType, DataArrayIdTypeTuple";
1842   sw=-1;
1843   if(PyInt_Check(value))
1844     {
1845       iTyypp=(T)PyInt_AS_LONG(value);
1846       sw=1;
1847       return;
1848     }
1849   if(PyTuple_Check(value))
1850     {
1851       std::size_t size=PyTuple_Size(value);
1852       stdvecTyypp.resize(size);
1853       for(std::size_t i=0;i<size;i++)
1854         {
1855           PyObject *o=PyTuple_GetItem(value,i);
1856           if(PyInt_Check(o))
1857             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1858           else
1859             {
1860               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1861               throw INTERP_KERNEL::Exception(oss.str().c_str());
1862             }
1863         }
1864       sw=2;
1865       return;
1866     }
1867   if(PyList_Check(value))
1868     {
1869       std::size_t size=PyList_Size(value);
1870       stdvecTyypp.resize(size);
1871       for(std::size_t i=0;i<size;i++)
1872         {
1873           PyObject *o=PyList_GetItem(value,i);
1874           if(PyInt_Check(o))
1875             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1876           else
1877             {
1878               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1879               throw INTERP_KERNEL::Exception(oss.str().c_str());
1880             }
1881         }
1882       sw=2;
1883       return;
1884     }
1885   if(PySlice_Check(value))
1886     {
1887       Py_ssize_t strt=2,stp=2,step=2;
1888       GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1889       p.first=ToIdType(strt);
1890       p.second.first=ToIdType(stp);
1891       p.second.second=ToIdType(step);
1892       sw=3;
1893       return ;
1894     }
1895   void *argp;
1896   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1897   if(SWIG_IsOK(status))
1898     {
1899       daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1900       if(!daIntTyypp)
1901         {
1902           std::ostringstream oss; oss << msg << " Instance in null !";
1903           throw INTERP_KERNEL::Exception(oss.str().c_str());
1904         }
1905       sw=4;
1906       return ;
1907     }
1908   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI_TUPLE,0|0);
1909   if(SWIG_IsOK(status))
1910     {
1911       typedef typename MEDCoupling::Traits< typename ARRAY::Type >::ArrayTuple ARRAYTUPLE;
1912       ARRAYTUPLE *tmp=reinterpret_cast< ARRAYTUPLE * >(argp);
1913       if(!tmp)
1914         {
1915           std::ostringstream oss; oss << msg << " Instance in null !";
1916           throw INTERP_KERNEL::Exception(oss.str().c_str());
1917         }
1918       stdvecTyypp.resize(tmp->getNumberOfCompo());
1919       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1920       sw=2;
1921       return ;
1922     }
1923   throw INTERP_KERNEL::Exception(msg);
1924 }
1925
1926 /*!
1927  * Idem than convertIntStarOrSliceLikePyObjToCpp
1928  */
1929 template<class T, class ARRAY>
1930 static void convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1931 {
1932   convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1933   if(sw==1)
1934     {
1935       iTyypp=(T)InterpreteNegativeInt(iTyypp,nbelem);
1936     }
1937 }
1938
1939 /*!
1940  * if python int -> cpp int sw=1
1941  * if python tuple[int] -> cpp vector<int> sw=2
1942  * if python list[int] -> cpp vector<int> sw=2
1943  * if python slice -> cpp pair sw=3
1944  * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4 . WARNING The returned pointer can be the null pointer !
1945  */
1946 template< class TUPLE_T >
1947 static void convertObjToPossibleCpp22(PyObject *value, mcIdType nbelem, mcIdType& sw, mcIdType& iTyypp, std::vector<mcIdType>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple *& daIntTyypp)
1948 {
1949   sw=-1;
1950   if(PyInt_Check(value))
1951     {
1952       iTyypp=ToIdType(PyInt_AS_LONG(value));
1953       sw=1;
1954       return;
1955     }
1956   if(PyTuple_Check(value))
1957     {
1958       std::size_t size=PyTuple_Size(value);
1959       stdvecTyypp.resize(size);
1960       for(std::size_t i=0;i<size;i++)
1961         {
1962           PyObject *o=PyTuple_GetItem(value,i);
1963           if(PyInt_Check(o))
1964             stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1965           else
1966             {
1967               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1968               throw INTERP_KERNEL::Exception(oss.str().c_str());
1969             }
1970         }
1971       sw=2;
1972       return;
1973     }
1974   if(PyList_Check(value))
1975     {
1976       std::size_t size=PyList_Size(value);
1977       stdvecTyypp.resize(size);
1978       for(std::size_t i=0;i<size;i++)
1979         {
1980           PyObject *o=PyList_GetItem(value,i);
1981           if(PyInt_Check(o))
1982             stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1983           else
1984             {
1985               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1986               throw INTERP_KERNEL::Exception(oss.str().c_str());
1987             }
1988         }
1989       sw=2;
1990       return;
1991     }
1992   if(PySlice_Check(value))
1993     {
1994       Py_ssize_t strt=2,stp=2,step=2;
1995       GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1996       p.first=ToIdType(strt);
1997       p.second.first=ToIdType(stp);
1998       p.second.second=ToIdType(step);
1999       sw=3;
2000       return ;
2001     }
2002   void *argp;
2003   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<TUPLE_T>::TI_TUPLE,0|0);
2004   if(!SWIG_IsOK(status))
2005     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdTypeTuple");
2006   daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple * >(argp);
2007   sw=4;
2008 }
2009
2010 /*!
2011  * if python string with size one -> cpp char sw=1
2012  * if python string with size different from one -> cpp string sw=2
2013  * if python tuple[string] or list[string] -> vector<string> sw=3
2014  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
2015  * switch between (int,string,vector<string>,DataArrayChar)
2016  */
2017 static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
2018 {
2019   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
2020   sw=-1;
2021   if(PyString_Check(value))
2022     {
2023       const char *pt=PyString_AsString(value);
2024       Py_ssize_t sz=PyString_Size(value);
2025       if(sz==1)
2026         {
2027           cTyp=pt[0];
2028           sw=1;
2029           return;
2030         }
2031       else
2032         {
2033           sType=pt;
2034           sw=2;
2035           return;
2036         }
2037     }
2038 #if PY_VERSION_HEX >= 0x03000000
2039   if(PyUnicode_Check(value))
2040     {
2041       Py_ssize_t sz;
2042       const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
2043       if(sz==1)
2044         {
2045           cTyp=pt[0];
2046           sw=1;
2047           return;
2048         }
2049       else
2050         {
2051           sType=pt;
2052           sw=2;
2053           return;
2054         }
2055     }
2056 #endif
2057   if(PyTuple_Check(value))
2058     {
2059       std::size_t size=PyTuple_Size(value);
2060       vsType.resize(size);
2061       for(std::size_t i=0;i<size;i++)
2062         {
2063           PyObject *o=PyTuple_GetItem(value,i);
2064           try
2065             {
2066               vsType[i]=convertPyObjectToStr(o);
2067             }
2068           catch(INTERP_KERNEL::Exception& )
2069             {
2070               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2071               throw INTERP_KERNEL::Exception(oss.str().c_str());
2072             }
2073         }
2074       sw=3;
2075       return;
2076     }
2077   if(PyList_Check(value))
2078     {
2079       std::size_t size=PyList_Size(value);
2080       vsType.resize(size);
2081       for(std::size_t i=0;i<size;i++)
2082         {
2083           PyObject *o=PyList_GetItem(value,i);
2084           try
2085             {
2086               vsType[i]=convertPyObjectToStr(o);
2087             }
2088           catch(INTERP_KERNEL::Exception& )
2089             {
2090               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2091               throw INTERP_KERNEL::Exception(oss.str().c_str());
2092             }
2093         }
2094       sw=3;
2095       return;
2096     }
2097   void *argp;
2098   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
2099   if(SWIG_IsOK(status))
2100     {
2101       dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
2102       if(!dacType)
2103         {
2104           std::ostringstream oss; oss << msg << " Instance in null !";
2105           throw INTERP_KERNEL::Exception(oss.str().c_str());
2106         }
2107       sw=4;
2108       return ;
2109     }
2110   throw INTERP_KERNEL::Exception(msg);
2111 }
2112
2113 /*!
2114  * if value int -> cpp it sw=1
2115  * if value list[int] -> vt sw=2
2116  * if value tuple[int] -> vt sw=2
2117  * if value slice -> pt sw=3
2118  * if value DataArrayIdType -> dt sw=4
2119  * if value tuple [int,int] -> cpp it,ip sw=5
2120  * if value tuple [list[int],int] -> cpp vt,ip sw=6
2121  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2122  * if value tuple [slice,int] -> cpp pt,ip sw=7
2123  * if value tuple [DaI,int] -> cpp dt,ip sw=8
2124  * if value tuple [int,list[int]] -> cpp it,vc sw=9
2125  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2126  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2127  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2128  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2129  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2130  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2131  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2132  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2133  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2134  * if value tuple [int,slice] -> cpp it,pc sw=13
2135  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2136  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2137  * if value tuple [slice,slice] -> cpp pt,pc sw=15
2138  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2139  *
2140  * switch between (int,vector<int>,DataArrayIdType)
2141  */
2142 template<class TC>
2143 static void convertObjToPossibleCpp3(PyObject *value, mcIdType nbTuple, int nbCompo, mcIdType& sw, mcIdType& it, TC& ic, std::vector<mcIdType>& vt, std::vector<TC>& vc,
2144                                      std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pt, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pc,
2145                                      MEDCoupling::DataArrayIdType *&dt, MEDCoupling::DataArrayIdType *&dc)
2146 {
2147   if(!PyTuple_Check(value))
2148     {
2149       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2150       return ;
2151     }
2152   else
2153     {
2154       std::size_t sz=PyTuple_Size(value);
2155       if(sz!=2)
2156         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2157       PyObject *ob0=PyTuple_GetItem(value,0);
2158       mcIdType sw1,sw2;
2159       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2160       PyObject *ob1=PyTuple_GetItem(value,1);
2161       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2162       sw=4*sw2+sw1;
2163     }
2164 }
2165
2166 /*!
2167  * if value int -> cpp val sw=1
2168  * if value double -> cpp val sw=1
2169  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2170  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2171  * if value list[int,double] -> cpp std::vector<double> sw=4
2172  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2173  */
2174 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2175                                                    const char *msg, mcIdType nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2176 {
2177   sw=-1;
2178   if(PyFloat_Check(value))
2179     {
2180       val=PyFloat_AS_DOUBLE(value);
2181       sw=1;
2182       if(nbTuplesExpected*nbCompExpected!=1)
2183         {
2184           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2185           throw INTERP_KERNEL::Exception(oss.str().c_str());
2186         }
2187       return &val;
2188     }
2189   if(PyInt_Check(value))
2190     {
2191       val=(double)PyInt_AS_LONG(value);
2192       sw=1;
2193       if(nbTuplesExpected*nbCompExpected!=1)
2194         {
2195           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2196           throw INTERP_KERNEL::Exception(oss.str().c_str());
2197         }
2198       return &val;
2199     }
2200   if(PyTuple_Check(value) || PyList_Check(value))
2201     {
2202       try
2203         {
2204           mcIdType tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2205           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2206           sw=4;
2207           f=ret;
2208           return &f[0];
2209         }
2210       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2211     }
2212   void *argp;
2213   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2214   if(SWIG_IsOK(status))
2215     {
2216       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2217       sw=2;
2218       if(d)
2219         {
2220           if(d->getNumberOfTuples()==nbTuplesExpected)
2221             {
2222               if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2223                 {
2224                   return d->getConstPointer();
2225                 }
2226               else
2227                 {
2228                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2229                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2230                 }
2231             }
2232           else
2233             {
2234               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2235               throw INTERP_KERNEL::Exception(oss.str().c_str());
2236             }
2237         }
2238       else
2239         {
2240           if(throwIfNullPt)
2241             {
2242               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2243               throw INTERP_KERNEL::Exception(oss.str().c_str());
2244             }
2245           else
2246             return 0;
2247         }
2248     }
2249   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2250   if(SWIG_IsOK(status))
2251     {
2252       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2253       sw=3;
2254       if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2255         {
2256           if(nbTuplesExpected==1)
2257             return e->getConstPointer();
2258           else
2259             {
2260               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by construction !";
2261               throw INTERP_KERNEL::Exception(oss.str().c_str());
2262             }
2263         }
2264       else
2265         {
2266           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2267           throw INTERP_KERNEL::Exception(oss.str().c_str());
2268         }
2269     }
2270   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2271 }
2272
2273 /*!
2274  * if value int -> cpp val sw=1
2275  * if value double -> cpp val sw=1
2276  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2277  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2278  * if value list[int,double] -> cpp std::vector<double> sw=4
2279  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2280  */
2281 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2282                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, mcIdType& nbTuples)
2283 {
2284   sw=-1;
2285   if(PyFloat_Check(value))
2286     {
2287       val=PyFloat_AS_DOUBLE(value);
2288       sw=1;
2289       if(nbCompExpected!=1)
2290         {
2291           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2292           throw INTERP_KERNEL::Exception(oss.str().c_str());
2293         }
2294       nbTuples=1;
2295       return &val;
2296     }
2297   if(PyInt_Check(value))
2298     {
2299       val=(double)PyInt_AS_LONG(value);
2300       sw=1;
2301       if(nbCompExpected!=1)
2302         {
2303           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2304           throw INTERP_KERNEL::Exception(oss.str().c_str());
2305         }
2306       nbTuples=1;
2307       return &val;
2308     }
2309   if(PyTuple_Check(value))
2310     {
2311       std::size_t size=PyTuple_Size(value);
2312       f.resize(size);
2313       for(std::size_t i=0;i<size;i++)
2314         {
2315           PyObject *o=PyTuple_GetItem(value,i);
2316           if(PyFloat_Check(o))
2317             f[i]=PyFloat_AS_DOUBLE(o);
2318           else if(PyInt_Check(o))
2319             f[i]=(double)PyInt_AS_LONG(o);
2320           else
2321             {
2322               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2323               throw INTERP_KERNEL::Exception(oss.str().c_str());
2324             }
2325         }
2326       sw=4;
2327       if(size%nbCompExpected!=0)
2328         {
2329           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2330           throw INTERP_KERNEL::Exception(oss.str().c_str());
2331         }
2332       nbTuples=ToIdType(size/nbCompExpected);
2333       return &f[0];
2334     }
2335   if(PyList_Check(value))
2336     {
2337       std::size_t size=PyList_Size(value);
2338       f.resize(size);
2339       for(std::size_t i=0;i<size;i++)
2340         {
2341           PyObject *o=PyList_GetItem(value,i);
2342           if(PyFloat_Check(o))
2343             f[i]=PyFloat_AS_DOUBLE(o);
2344           else if(PyInt_Check(o))
2345             f[i]=(double)PyInt_AS_LONG(o);
2346           else
2347             {
2348               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2349               throw INTERP_KERNEL::Exception(oss.str().c_str());
2350             }
2351         }
2352       sw=4;
2353       if(size%nbCompExpected!=0)
2354         {
2355           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2356           throw INTERP_KERNEL::Exception(oss.str().c_str());
2357         }
2358       nbTuples=ToIdType(size/nbCompExpected);
2359       return &f[0];
2360     }
2361   void *argp;
2362   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2363   if(SWIG_IsOK(status))
2364     {
2365       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2366       sw=2;
2367       if(d)
2368         {
2369           if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2370             {
2371               nbTuples=d->getNumberOfTuples();
2372               return d->getConstPointer();
2373             }
2374           else
2375             {
2376               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2377               throw INTERP_KERNEL::Exception(oss.str().c_str());
2378             }
2379         }
2380       else
2381         {
2382           if(throwIfNullPt)
2383             {
2384               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2385               throw INTERP_KERNEL::Exception(oss.str().c_str());
2386             }
2387           else
2388             { nbTuples=0; return 0; }
2389         }
2390     }
2391   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2392   if(SWIG_IsOK(status))
2393     {
2394       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2395       sw=3;
2396       if(e)
2397         {
2398           if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2399             {
2400               nbTuples=1;
2401               return e->getConstPointer();
2402             }
2403           else
2404             {
2405               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2406               throw INTERP_KERNEL::Exception(oss.str().c_str());
2407             }
2408         }
2409       else
2410         {
2411           if(throwIfNullPt)
2412             {
2413               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2414               throw INTERP_KERNEL::Exception(oss.str().c_str());
2415             }
2416           else
2417             { nbTuples=0; return 0; }
2418         }
2419     }
2420   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2421 }
2422
2423 /*!
2424  * if value int -> cpp val sw=1
2425  * if value double -> cpp val sw=1
2426  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2427  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2428  * if value list[int,double] -> cpp std::vector<double> sw=4
2429  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2430  */
2431 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, mcIdType& sw, double& val, std::vector<double>& f,
2432                                                           const char *msg, bool throwIfNullPt, mcIdType& nbTuples)
2433 {
2434   MEDCoupling::DataArrayDouble *d=0;
2435   MEDCoupling::DataArrayDoubleTuple *e=0;
2436   sw=-1;
2437   if(PyFloat_Check(value))
2438     {
2439       val=PyFloat_AS_DOUBLE(value);
2440       sw=1;
2441       nbTuples=1;
2442       return &val;
2443     }
2444   if(PyInt_Check(value))
2445     {
2446       val=(double)PyInt_AS_LONG(value);
2447       sw=1;
2448       nbTuples=1;
2449       return &val;
2450     }
2451   if(PyTuple_Check(value))
2452     {
2453       std::size_t size=PyTuple_Size(value);
2454       f.resize(size);
2455       for(std::size_t i=0;i<size;i++)
2456         {
2457           PyObject *o=PyTuple_GetItem(value,i);
2458           if(PyFloat_Check(o))
2459             f[i]=PyFloat_AS_DOUBLE(o);
2460           else if(PyInt_Check(o))
2461             f[i]=(double)PyInt_AS_LONG(o);
2462           else
2463             {
2464               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2465               throw INTERP_KERNEL::Exception(oss.str().c_str());
2466             }
2467         }
2468       sw=4;
2469       nbTuples=ToIdType(size);
2470       return &f[0];
2471     }
2472   if(PyList_Check(value))
2473     {
2474       std::size_t size=PyList_Size(value);
2475       f.resize(size);
2476       for(std::size_t i=0;i<size;i++)
2477         {
2478           PyObject *o=PyList_GetItem(value,i);
2479           if(PyFloat_Check(o))
2480             f[i]=PyFloat_AS_DOUBLE(o);
2481           else if(PyInt_Check(o))
2482             f[i]=(double)PyInt_AS_LONG(o);
2483           else
2484             {
2485               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2486               throw INTERP_KERNEL::Exception(oss.str().c_str());
2487             }
2488         }
2489       sw=4;
2490       nbTuples=ToIdType(size);
2491       return &f[0];
2492     }
2493   void *argp;
2494   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2495   if(SWIG_IsOK(status))
2496     {
2497       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2498       sw=2;
2499       if(d)
2500         {
2501           if(d->getNumberOfComponents()==1)
2502             {
2503               nbTuples=d->getNumberOfTuples();
2504               return d->getConstPointer();
2505             }
2506           else
2507             {
2508               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2509               throw INTERP_KERNEL::Exception(oss.str().c_str());
2510             }
2511         }
2512       else
2513         {
2514           if(throwIfNullPt)
2515             {
2516               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2517               throw INTERP_KERNEL::Exception(oss.str().c_str());
2518             }
2519           else
2520             { nbTuples=0; return 0; }
2521         }
2522     }
2523   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2524   if(SWIG_IsOK(status))
2525     {
2526       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2527       sw=3;
2528       if(e)
2529         {
2530           nbTuples=ToIdType(e->getNumberOfCompo());
2531           return e->getConstPointer();
2532         }
2533       else
2534         {
2535           if(throwIfNullPt)
2536             {
2537               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2538               throw INTERP_KERNEL::Exception(oss.str().c_str());
2539             }
2540           else
2541             { nbTuples=0; return 0; }
2542         }
2543     }
2544   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2545 }
2546
2547 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2548 {
2549   void *aBasePtrVS=0;
2550   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2551   if(!SWIG_IsOK(status))
2552     {
2553       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2554       if(!SWIG_IsOK(status))
2555         {
2556           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt32,0|0);
2557           if(!SWIG_IsOK(status))
2558             {
2559               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt64,0|0);
2560               if(!SWIG_IsOK(status))
2561                 {
2562                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2563                   if(!SWIG_IsOK(status))
2564                     {
2565                       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2566                       std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayIdType, DataArrayAsciiChar, DataArrayByte !";
2567                       throw INTERP_KERNEL::Exception(oss.str().c_str());
2568                     }
2569                 }
2570             }
2571         }
2572     }
2573   return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2574 }
2575
2576 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2577 {
2578   PyObject *ret=0;
2579   if(!pd)
2580     {
2581       Py_XINCREF(Py_None);
2582       return Py_None;
2583     }
2584   if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2585     ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2586   else
2587     ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2588   return ret;
2589 }
2590
2591 template<class T>
2592 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2593 {
2594   const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
2595   std::string msg(msgBase);
2596 #ifdef WITH_NUMPY
2597   msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2598 #endif
2599   msg+=" !";
2600   if(PyList_Check(elt0) || PyTuple_Check(elt0))
2601     {
2602       if(nbOfTuples)
2603         {
2604           if(PyInt_Check(nbOfTuples))
2605             {
2606               mcIdType nbOfTuples1=ToIdType(PyInt_AS_LONG(nbOfTuples));
2607               if(nbOfTuples1<0)
2608                 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2609               if(elt2)
2610                 {
2611                   if(PyInt_Check(elt2))
2612                     {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2613                       mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(elt2));
2614                       if(nbOfCompo<0)
2615                         throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2616                       MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2617                       std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2618                       ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2619                       return ret.retn();
2620                     }
2621                   else
2622                     throw INTERP_KERNEL::Exception(msg.c_str());
2623                 }
2624               else
2625                 {//DataArrayDouble.New([1.,3.,4.],3)
2626                   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2627                   mcIdType tmpp1(-1);
2628                   std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2629                   ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2630                   return ret.retn();
2631                 }
2632             }
2633           else
2634             throw INTERP_KERNEL::Exception(msg.c_str());
2635         }
2636       else
2637         {// DataArrayDouble.New([1.,3.,4.])
2638           MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2639           mcIdType tmpp1(-1),tmpp2(-1);
2640           std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2641           ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2642           return ret.retn();
2643         }
2644     }
2645   else if(PyInt_Check(elt0))
2646     {
2647       mcIdType nbOfTuples1(ToIdType(PyInt_AS_LONG(elt0)));
2648       if(nbOfTuples1<0)
2649         throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2650       if(nbOfTuples)
2651         {
2652           if(!elt2)
2653             {
2654               if(PyInt_Check(nbOfTuples))
2655                 {//DataArrayDouble.New(5,2)
2656                   mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(nbOfTuples));
2657                   if(nbOfCompo<0)
2658                     throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2659                   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2660                   ret->alloc(nbOfTuples1,nbOfCompo);
2661                   return ret.retn();
2662                 }
2663               else
2664                 throw INTERP_KERNEL::Exception(msg.c_str());
2665             }
2666           else
2667             throw INTERP_KERNEL::Exception(msg.c_str());
2668         }
2669       else
2670         {//DataArrayDouble.New(5)
2671           MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2672           ret->alloc(nbOfTuples1,1);
2673           return ret.retn();
2674         }
2675     }
2676 #ifdef WITH_NUMPY
2677   else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2678     {//DataArrayDouble.New(numpyArray)
2679       return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2680     }
2681 #endif
2682   else
2683     throw INTERP_KERNEL::Exception(msg.c_str());
2684   throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2685 }
2686
2687 template<class T>
2688 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2689 {
2690   self->checkAllocated();
2691   const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2692   mcIdType nbOfTuples(self->getNumberOfTuples());
2693   int nbOfComponents((int)(self->getNumberOfComponents()));
2694   mcIdType sw1,sw2;
2695   T i1;
2696   std::vector<T> v1;
2697   typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2698   considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2699   mcIdType it1,ic1;
2700   std::vector<mcIdType> vt1;
2701   std::vector<mcIdType> vc1;
2702   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
2703   MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
2704   convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2705   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2706   switch(sw2)
2707     {
2708     case 1:
2709       {
2710         switch(sw1)
2711           {
2712           case 1:
2713             self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2714             return self;
2715           case 2:
2716             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2717             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2718             self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2719             return self;
2720           case 3:
2721             self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2722             return self;
2723           default:
2724             throw INTERP_KERNEL::Exception(msg);
2725           }
2726         break;
2727       }
2728     case 2:
2729       {
2730         switch(sw1)
2731           {
2732           case 1:
2733             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2734             return self;
2735           case 2:
2736             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2737             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2738             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2739             return self;
2740           case 3:
2741             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2742             return self;
2743           default:
2744             throw INTERP_KERNEL::Exception(msg);
2745           }
2746         break;
2747       }
2748     case 3:
2749       {
2750         switch(sw1)
2751           {
2752           case 1:
2753             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2754             return self;
2755           case 2:
2756             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2757             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2758             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2759             return self;
2760           case 3:
2761             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2762             return self;
2763           default:
2764             throw INTERP_KERNEL::Exception(msg);
2765           }
2766         break;
2767       }
2768     case 4:
2769       {
2770         switch(sw1)
2771           {
2772           case 1:
2773             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2774             return self;
2775           case 2:
2776             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2777             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2778             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2779             return self;
2780           case 3:
2781             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2782             return self;
2783           default:
2784             throw INTERP_KERNEL::Exception(msg);
2785           }
2786         break;
2787       }
2788     case 5:
2789       {
2790         switch(sw1)
2791           {
2792           case 1:
2793             self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2794             return self;
2795           case 2:
2796             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2797             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2798             self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2799             return self;
2800           case 3:
2801             self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2802             return self;
2803           default:
2804             throw INTERP_KERNEL::Exception(msg);
2805           }
2806         break;
2807       }
2808     case 6:
2809       {
2810         switch(sw1)
2811           {
2812           case 1:
2813             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2814             return self;
2815           case 2:
2816             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2817             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2818             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2819             return self;
2820           case 3:
2821             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2822             return self;
2823           default:
2824             throw INTERP_KERNEL::Exception(msg);
2825           }
2826         break;
2827       }
2828     case 7:
2829       {
2830         switch(sw1)
2831           {
2832           case 1:
2833             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2834             return self;
2835           case 2:
2836             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2837             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2838             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2839             return self;
2840           case 3:
2841             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2842             return self;
2843           default:
2844             throw INTERP_KERNEL::Exception(msg);
2845           }
2846         break;
2847       }
2848     case 8:
2849       {
2850         switch(sw1)
2851           {
2852           case 1:
2853             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2854             return self;
2855           case 2:
2856             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2857             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2858             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2859             return self;
2860           case 3:
2861             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2862             return self;
2863           default:
2864             throw INTERP_KERNEL::Exception(msg);
2865           }
2866         break;
2867       }
2868     case 9:
2869       {
2870         switch(sw1)
2871           {
2872           case 1:
2873             self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2874             return self;
2875           case 2:
2876             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2877             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2878             self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2879             return self;
2880           case 3:
2881             self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2882             return self;
2883           default:
2884             throw INTERP_KERNEL::Exception(msg);
2885           }
2886         break;
2887       }
2888     case 10:
2889       {
2890         switch(sw1)
2891           {
2892           case 1:
2893             self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2894             return self;
2895           case 2:
2896             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2897             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2898             self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2899             return self;
2900           case 3:
2901             self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2902             return self;
2903           default:
2904             throw INTERP_KERNEL::Exception(msg);
2905           }
2906         break;
2907       }
2908     case 11:
2909       {
2910         switch(sw1)
2911           {
2912           case 1:
2913             self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2914             return self;
2915           case 2:
2916             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2917             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2918             self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2919             return self;
2920           case 3:
2921             self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2922             return self;
2923           default:
2924             throw INTERP_KERNEL::Exception(msg);
2925           }
2926         break;
2927       }
2928     case 12:
2929       {
2930         switch(sw1)
2931           {
2932           case 1:
2933             self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2934             return self;
2935           case 2:
2936             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2937             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2938             self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2939             return self;
2940           case 3:
2941             self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2942             return self;
2943           default:
2944             throw INTERP_KERNEL::Exception(msg);
2945           }
2946         break;
2947       }
2948     case 13:
2949       {
2950         switch(sw1)
2951           {
2952           case 1:
2953             self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2954             return self;
2955           case 2:
2956             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2957             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2958             self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2959             return self;
2960           case 3:
2961             self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2962             return self;
2963           default:
2964             throw INTERP_KERNEL::Exception(msg);
2965           }
2966         break;
2967       }
2968     case 14:
2969       {
2970         switch(sw1)
2971           {
2972           case 1:
2973             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2974             return self;
2975           case 2:
2976             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2977             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2978             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2979             return self;
2980           case 3:
2981             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2982             return self;
2983           default:
2984             throw INTERP_KERNEL::Exception(msg);
2985           }
2986         break;
2987       }
2988     case 15:
2989       {
2990         switch(sw1)
2991           {
2992           case 1:
2993             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2994             return self;
2995           case 2:
2996             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2997             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2998             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2999             return self;
3000           case 3:
3001             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
3002             return self;
3003           default:
3004             throw INTERP_KERNEL::Exception(msg);
3005           }
3006         break;
3007       }
3008     case 16:
3009       {
3010         switch(sw1)
3011           {
3012           case 1:
3013             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3014             return self;
3015           case 2:
3016             tmp=MEDCoupling::Traits<T>::ArrayType::New();
3017             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
3018             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
3019             return self;
3020           case 3:
3021             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3022             return self;
3023           default:
3024             throw INTERP_KERNEL::Exception(msg);
3025           }
3026         break;
3027       }
3028     default:
3029       throw INTERP_KERNEL::Exception(msg);
3030     }
3031   return self;
3032 }
3033
3034 template<class T>
3035 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3036 {
3037   const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3038   const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3039   self->checkAllocated();
3040   mcIdType nbOfTuples(self->getNumberOfTuples());
3041   int nbOfComponents((int)(self->getNumberOfComponents()));
3042   mcIdType it1;
3043   std::size_t ic1;
3044   std::vector<mcIdType> vt1;
3045   std::vector<std::size_t> vc1;
3046   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
3047   MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
3048   mcIdType sw;
3049   convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3050   MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3051   switch(sw)
3052     {
3053     case 1:
3054       if(nbOfComponents==1)
3055         return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3056       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3057     case 2:
3058       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3059     case 3:
3060       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3061     case 4:
3062       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3063     case 5:
3064       return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3065     case 6:
3066       {
3067         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3068         std::vector<std::size_t> v2(1,ic1);
3069         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3070       }
3071     case 7:
3072       {
3073         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3074         std::vector<std::size_t> v2(1,ic1);
3075         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3076       }
3077     case 8:
3078       {
3079         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3080         std::vector<std::size_t> v2(1,ic1);
3081         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3082       }
3083     case 9:
3084       {
3085         ret=self->selectByTupleIdSafe(&it1,&it1+1);
3086         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3087       }
3088     case 10:
3089       {
3090         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3091         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3092       }
3093     case 11:
3094       {
3095         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3096         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3097       }
3098     case 12:
3099       {
3100         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3101         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3102       }
3103     case 13:
3104       {
3105         ret=self->selectByTupleIdSafe(&it1,&it1+1);
3106         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3107         std::vector<std::size_t> v2(nbOfComp);
3108         for(mcIdType i=0;i<nbOfComp;i++)
3109           v2[i]=pc1.first+i*pc1.second.second;
3110         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3111       }
3112     case 14:
3113       {
3114         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3115         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3116         std::vector<std::size_t> v2(nbOfComp);
3117         for(int i=0;i<nbOfComp;i++)
3118           v2[i]=pc1.first+i*pc1.second.second;
3119         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3120       }
3121     case 15:
3122       {
3123         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3124         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3125         std::vector<std::size_t> v2(nbOfComp);
3126         for(int i=0;i<nbOfComp;i++)
3127           v2[i]=pc1.first+i*pc1.second.second;
3128         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3129       }
3130     case 16:
3131       {
3132         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3133         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3134         std::vector<std::size_t> v2(nbOfComp);
3135         for(int i=0;i<nbOfComp;i++)
3136           v2[i]=pc1.first+i*pc1.second.second;
3137         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3138       }
3139     default:
3140       throw INTERP_KERNEL::Exception(msg);
3141     }
3142 }
3143
3144 bool isCSRMatrix(PyObject *m)
3145 {
3146 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
3147   PyObject* pdict(PyDict_New());
3148   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
3149   PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
3150   if (!tmp)
3151   {
3152     PyErr_Clear(); // Otherwise exception propagation will fail.
3153     throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse! Is Scipy module available and present?");
3154   }
3155   PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
3156   if(!csrMatrixCls)
3157     throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
3158   bool ret(PyObject_IsInstance(m,csrMatrixCls));
3159   Py_DECREF(pdict); Py_XDECREF(tmp);
3160   return ret;
3161 #else
3162   return false;
3163 #endif
3164 }
3165
3166 void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
3167 {
3168   auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
3169   if(nbOfRows<0)
3170     throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !");
3171   mCpp.resize(nbOfRows);
3172   auto indPtrCPtr(indptrPtr->begin());
3173   auto indicesCPtr(indicesPtr->begin());
3174   auto dataCPtr(dataPtr->begin());
3175   for(auto i=0;i<nbOfRows;i++)
3176     {
3177       auto& line(mCpp[i]);
3178       for(auto j=indPtrCPtr[i];j<indPtrCPtr[i+1];j++)
3179         {
3180           line[indicesCPtr[j]]=dataCPtr[j];
3181         }
3182     }
3183 }
3184
3185 void convertToVectMapIntDouble(PyObject *pyobj, std::vector<std::map<mcIdType,double> >& mCpp)
3186 {
3187   if(!PyList_Check(pyobj))
3188     throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !");
3189   mCpp.clear();
3190   Py_ssize_t sz(PyList_Size(pyobj));
3191   mCpp.resize(sz);
3192   for(Py_ssize_t i=0;i<sz;i++)
3193     {
3194       PyObject *elt(PyList_GetItem(pyobj,i));
3195       if(!PyDict_Check(elt))
3196         {
3197           std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist a dict is exepect !";
3198           throw INTERP_KERNEL::Exception(oss.str());
3199         }
3200       PyObject *key, *value;
3201       Py_ssize_t pos(0);
3202       std::map<mcIdType,double>& mapCpp(mCpp[i]);
3203       while(PyDict_Next(elt,&pos,&key,&value))
3204         {
3205           if(!PyInt_Check(key))
3206             {
3207               std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !";
3208               throw INTERP_KERNEL::Exception(oss.str());
3209             }
3210           if(!PyFloat_Check(value))
3211             {
3212               std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !";
3213               throw INTERP_KERNEL::Exception(oss.str());
3214             }
3215           mapCpp[ToIdType(PyInt_AS_LONG(key))]=PyFloat_AS_DOUBLE(value);
3216         }
3217     }
3218 }
3219
3220 template<class T>
3221 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3222 {
3223   const char msg[]="Unexpected situation in __imul__ !";
3224   T val;
3225   typename MEDCoupling::Traits<T>::ArrayType *a;
3226   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3227   std::vector<T> bb;
3228   mcIdType sw;
3229   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3230   switch(sw)
3231     {
3232     case 1:
3233       {
3234         self->applyLin(val,0.);
3235         Py_XINCREF(trueSelf);
3236         return trueSelf;
3237       }
3238     case 2:
3239       {
3240         self->multiplyEqual(a);
3241         Py_XINCREF(trueSelf);
3242         return trueSelf;
3243       }
3244     case 3:
3245       {
3246         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3247         self->multiplyEqual(aaa);
3248         Py_XINCREF(trueSelf);
3249         return trueSelf;
3250       }
3251     case 4:
3252       {
3253         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3254         self->multiplyEqual(aaa);
3255         Py_XINCREF(trueSelf);
3256         return trueSelf;
3257       }
3258     default:
3259       throw INTERP_KERNEL::Exception(msg);
3260     }
3261 }
3262
3263 template<class T>
3264 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3265 {
3266   const char msg[]="Unexpected situation in __idiv__ !";
3267   T val;
3268   typename MEDCoupling::Traits<T>::ArrayType *a;
3269   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3270   std::vector<T> bb;
3271   mcIdType sw;
3272   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3273   switch(sw)
3274     {
3275     case 1:
3276       {
3277         if(val==0.)
3278           throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3279         self->applyLin((T)(1./val),(T)0.);
3280         Py_XINCREF(trueSelf);
3281         return trueSelf;
3282       }
3283     case 2:
3284       {
3285         self->divideEqual(a);
3286         Py_XINCREF(trueSelf);
3287         return trueSelf;
3288       }
3289     case 3:
3290       {
3291         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3292         self->divideEqual(aaa);
3293         Py_XINCREF(trueSelf);
3294         return trueSelf;
3295       }
3296     case 4:
3297       {
3298         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3299         self->divideEqual(aaa);
3300         Py_XINCREF(trueSelf);
3301         return trueSelf;
3302       }
3303     default:
3304       throw INTERP_KERNEL::Exception(msg);
3305     }
3306 }
3307
3308 template<class T>
3309 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3310 {
3311   const char msg[]="Unexpected situation in __iadd__ !";
3312   T val;
3313   typename MEDCoupling::Traits<T>::ArrayType *a;
3314   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3315   std::vector<T> bb;
3316   mcIdType sw;
3317   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3318   switch(sw)
3319     {
3320     case 1:
3321       {
3322         self->applyLin(1.,val);
3323         Py_XINCREF(trueSelf);
3324         return trueSelf;
3325       }
3326     case 2:
3327       {
3328         self->addEqual(a);
3329         Py_XINCREF(trueSelf);
3330         return trueSelf;
3331       }
3332     case 3:
3333       {
3334         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3335         self->addEqual(aaa);
3336         Py_XINCREF(trueSelf);
3337         return trueSelf;
3338       }
3339     case 4:
3340       {
3341         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3342         self->addEqual(aaa);
3343         Py_XINCREF(trueSelf);
3344         return trueSelf;
3345       }
3346     default:
3347       throw INTERP_KERNEL::Exception(msg);
3348     }
3349 }
3350
3351 template<class T>
3352 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3353 {
3354   const char msg[]="Unexpected situation in __isub__ !";
3355   T val;
3356   typename MEDCoupling::Traits<T>::ArrayType *a;
3357   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3358   std::vector<T> bb;
3359   mcIdType sw;
3360   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3361   switch(sw)
3362     {
3363     case 1:
3364       {
3365         self->applyLin(1.,-val);
3366         Py_XINCREF(trueSelf);
3367         return trueSelf;
3368       }
3369     case 2:
3370       {
3371         self->substractEqual(a);
3372         Py_XINCREF(trueSelf);
3373         return trueSelf;
3374       }
3375     case 3:
3376       {
3377         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3378         self->substractEqual(aaa);
3379         Py_XINCREF(trueSelf);
3380         return trueSelf;
3381       }
3382     case 4:
3383       {
3384         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3385         self->substractEqual(aaa);
3386         Py_XINCREF(trueSelf);
3387         return trueSelf;
3388       }
3389     default:
3390       throw INTERP_KERNEL::Exception(msg);
3391     }
3392 }
3393
3394 #ifdef WITH_NUMPY
3395 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3396
3397 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3398
3399 PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
3400
3401 PyTypeObject *NPYTraits<MEDCoupling::Int64>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
3402 #endif
3403
3404 template<class T>
3405 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3406 {
3407   return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3408 }
3409
3410 template<class T>
3411 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3412 {
3413   return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3414 }
3415
3416 template<class T>
3417 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3418 {
3419   return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3420 }
3421
3422 template<class T>
3423 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3424 {
3425   return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3426 }
3427
3428 template<class T>
3429 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3430 {
3431   return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3432 }
3433
3434 template<class T>
3435 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3436 {
3437   return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3438 }
3439
3440 template<class T>
3441 typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3442 {
3443   const char msg[]="Unexpected situation in __rmul__ !";
3444   T val;
3445   typename MEDCoupling::Traits<T>::ArrayType *a;
3446   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3447   std::vector<T> bb;
3448   mcIdType sw;
3449   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3450   switch(sw)
3451     {
3452     case 1:
3453       {
3454         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
3455         ret->applyLin(val,0.);
3456         return ret.retn();
3457       }
3458     case 3:
3459       {
3460         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
3461         return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3462       }
3463     case 4:
3464       {
3465         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3466         return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3467       }
3468     default:
3469       throw INTERP_KERNEL::Exception(msg);
3470     }
3471 }
3472
3473 #endif