Salome HOME
Fix of reference connectivity of faces of PENTA15 cell from Roberto Da Via
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
1 // Copyright (C) 2007-2021  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 convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
685 {
686   const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer 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         {
693           PyObject *o=PyList_GetItem(pyLi,i);
694           if(PyTuple_Check(o))
695             {
696               std::size_t sz2=PyTuple_Size(o);
697               if(sz2!=2)
698                 throw INTERP_KERNEL::Exception(msg);
699               PyObject *o_0=PyTuple_GetItem(o,0);
700               PyObject *o_1=PyTuple_GetItem(o,1);
701               arr[i].first=convertPyObjectToStr(o_0,msg);
702               if(!PyInt_Check(o_1))
703                 throw INTERP_KERNEL::Exception(msg);
704               arr[i].second=(int)PyInt_AS_LONG(o_1);
705             }
706           else
707             throw INTERP_KERNEL::Exception(msg);
708         }
709     }
710   else if(PyTuple_Check(pyLi))
711     {
712       std::size_t size=PyTuple_Size(pyLi);
713       arr.resize(size);
714       for(std::size_t i=0;i<size;i++)
715         {
716           PyObject *o=PyTuple_GetItem(pyLi,i);
717           if(PyTuple_Check(o))
718             {
719               std::size_t sz2=PyTuple_Size(o);
720               if(sz2!=2)
721                 throw INTERP_KERNEL::Exception(msg);
722               PyObject *o_0=PyTuple_GetItem(o,0);
723               PyObject *o_1=PyTuple_GetItem(o,1);
724               arr[i].first=convertPyObjectToStr(o_0,msg);
725               if(!PyInt_Check(o_1))
726                 throw INTERP_KERNEL::Exception(msg);
727               arr[i].second=(int)PyInt_AS_LONG(o_1);
728             }
729           else
730             throw INTERP_KERNEL::Exception(msg);
731         }
732     }
733   else
734     throw INTERP_KERNEL::Exception(msg);
735 }
736
737 template<class T>
738 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<T>& arr)
739 {
740   if(PyList_Check(pyLi))
741     {
742       std::size_t size=PyList_Size(pyLi);
743       arr.resize(size);
744       for(std::size_t i=0;i<size;i++)
745         {
746           PyObject *o=PyList_GetItem(pyLi,i);
747           if(PyInt_Check(o))
748             {
749               T val=(T)PyInt_AS_LONG(o);
750               arr[i]=val;
751             }
752           else
753             throw INTERP_KERNEL::Exception("list must contain integers only");
754         }
755     }
756   else if(PyTuple_Check(pyLi))
757     {
758       std::size_t size=PyTuple_Size(pyLi);
759       arr.resize(size);
760       for(std::size_t i=0;i<size;i++)
761         {
762           PyObject *o=PyTuple_GetItem(pyLi,i);
763           if(PyInt_Check(o))
764             {
765               T val=(T)PyInt_AS_LONG(o);
766               arr[i]=val;
767             }
768           else
769             throw INTERP_KERNEL::Exception("tuple must contain integers only");
770         }
771     }
772   else
773     {
774       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
775     }
776 }
777
778 static void convertPyToNewIntArr4(PyObject *pyLi, mcIdType recurseLev, mcIdType nbOfSubPart, std::vector<mcIdType>& arr)
779 {
780   if(recurseLev<0)
781     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
782   arr.clear();
783   if(PyList_Check(pyLi))
784     {
785       std::size_t size=PyList_Size(pyLi);
786       for(std::size_t i=0;i<size;i++)
787         {
788           PyObject *o=PyList_GetItem(pyLi,i);
789           if(PyInt_Check(o))
790             {
791               mcIdType val=(mcIdType)PyInt_AS_LONG(o);
792               arr.push_back(val);
793             }
794           else
795             {
796               std::vector<mcIdType> arr2;
797               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
798               if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
799                   {
800                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
801                     throw INTERP_KERNEL::Exception(oss.str().c_str());
802                   }
803               arr.insert(arr.end(),arr2.begin(),arr2.end());
804             }
805         }
806     }
807   else if(PyTuple_Check(pyLi))
808     {
809       std::size_t size=PyTuple_Size(pyLi);
810       for(std::size_t i=0;i<size;i++)
811         {
812           PyObject *o=PyTuple_GetItem(pyLi,i);
813           if(PyInt_Check(o))
814             {
815               mcIdType val=ToIdType(PyInt_AS_LONG(o));
816               arr.push_back(val);
817             }
818           else
819             {
820               std::vector<mcIdType> arr2;
821               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
822               if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
823                   {
824                     std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " <<  recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
825                     throw INTERP_KERNEL::Exception(oss.str().c_str());
826                   }
827               arr.insert(arr.end(),arr2.begin(),arr2.end());
828             }
829         }
830     }
831   else
832     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
833 }
834
835 static void checkFillArrayWithPyList(mcIdType size1, mcIdType size2, mcIdType& nbOfTuples, mcIdType& nbOfComp)
836 {
837   if(nbOfTuples==-1)
838     {
839       if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
840       else { if(nbOfComp==size2) { nbOfTuples=size1; } else
841           {
842             std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
843             oss << " whereas nb of components expected is " << nbOfComp << " !";
844             throw INTERP_KERNEL::Exception(oss.str().c_str());
845           } }
846     }
847   else
848     {
849       if(nbOfComp!=-1)
850         {
851           if((nbOfTuples!=size1 || nbOfComp!=size2))
852             {
853               if(size2!=1 || size1!=nbOfComp*nbOfTuples)
854                 {
855                   std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
856                   oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
857                   throw INTERP_KERNEL::Exception(oss.str().c_str());
858                 }
859             }
860         }
861       else
862         {
863           if(nbOfTuples==size1)
864             nbOfComp=size2;
865           else
866             {
867               std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
868               oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
869               throw INTERP_KERNEL::Exception(oss.str().c_str());
870             }
871         }
872     }
873 }
874
875 template< class T >
876 static void fillArrayWithPyListInt3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<T>& ret)
877 {
878   static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
879   if(PyInt_Check(pyLi))
880     {
881       T val=(T)PyInt_AS_LONG(pyLi);
882       if(nbOfElt==-1)
883         nbOfElt=1;
884       else
885         if(nbOfElt!=1)
886           throw INTERP_KERNEL::Exception(MSG);
887       ret.push_back(val);
888     }
889   else if(PyList_Check(pyLi))
890     {
891       std::size_t size=PyList_Size(pyLi);
892       mcIdType tmp=0;
893       for(std::size_t i=0;i<size;i++)
894         {
895           PyObject *o=PyList_GetItem(pyLi,i);
896           mcIdType tmp1=-1;
897           fillArrayWithPyListInt3(o,tmp1,ret);
898           tmp+=tmp1;
899         }
900       if(nbOfElt==-1)
901         nbOfElt=tmp;
902       else
903         {
904           if(nbOfElt!=tmp)
905             throw INTERP_KERNEL::Exception(MSG);
906         }
907     }
908   else if(PyTuple_Check(pyLi))
909     {
910       std::size_t size=PyTuple_Size(pyLi);
911       mcIdType tmp=0;
912       for(std::size_t i=0;i<size;i++)
913         {
914           PyObject *o=PyTuple_GetItem(pyLi,i);
915           mcIdType tmp1=-1;
916           fillArrayWithPyListInt3(o,tmp1,ret);
917           tmp+=tmp1;
918         }
919       if(nbOfElt==-1)
920         nbOfElt=tmp;
921       else
922         {
923           if(nbOfElt!=tmp)
924             throw INTERP_KERNEL::Exception(MSG);
925         }
926     }
927   else
928     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
929 }
930
931 template< class T = mcIdType >
932 static std::vector<T> fillArrayWithPyListInt2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
933 {
934   std::vector<T> ret;
935   mcIdType size1=-1,size2=-1;
936   if(PyList_Check(pyLi))
937     {
938       size1=ToIdType(PyList_Size(pyLi));
939       for(mcIdType i=0;i<size1;i++)
940         {
941           PyObject *o=PyList_GetItem(pyLi,i);
942           fillArrayWithPyListInt3(o,size2,ret);
943         }
944       if(size1==0)
945         size2=1;
946     }
947   else if(PyTuple_Check(pyLi))
948     {
949       size1=ToIdType(PyTuple_Size(pyLi));
950       for(mcIdType i=0;i<size1;i++)
951         {
952           PyObject *o=PyTuple_GetItem(pyLi,i);
953           fillArrayWithPyListInt3(o,size2,ret);
954         }
955       if(size1==0)
956         size2=1;
957     }
958   else
959     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
960   //
961   checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
962   return ret;
963 }
964
965 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
966 {
967   if(PyList_Check(pyLi))
968     {
969       Py_ssize_t sz=PyList_Size(pyLi);
970       vec.resize(sz);
971       for(mcIdType i=0;i<sz;i++)
972         {
973           PyObject *o=PyList_GetItem(pyLi,i);
974           if(!convertPyObjectToStrNT(o,vec[i]))
975             return false;
976         }
977       return true;
978     }
979   else if(PyTuple_Check(pyLi))
980     {
981       Py_ssize_t sz=PyTuple_Size(pyLi);
982       vec.resize(sz);
983       for(mcIdType i=0;i<sz;i++)
984         {
985           PyObject *o=PyTuple_GetItem(pyLi,i);
986           if(!convertPyObjectToStrNT(o,vec[i]))
987             return false;
988         }
989       return true;
990     }
991   else
992     return false;
993 }
994 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
995 {
996   const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
997   if(PyList_Check(pyLi))
998     {
999       Py_ssize_t sz=PyList_Size(pyLi);
1000       arr.resize(sz);
1001       for(mcIdType i=0;i<sz;i++)
1002         {
1003           PyObject *o=PyList_GetItem(pyLi,i);
1004           if(!fillStringVector(o,arr[i]))
1005             throw INTERP_KERNEL::Exception(msg);
1006         }
1007     }
1008   else if(PyTuple_Check(pyLi))
1009     {
1010       Py_ssize_t sz=PyTuple_Size(pyLi);
1011       arr.resize(sz);
1012       for(mcIdType i=0;i<sz;i++)
1013         {
1014           PyObject *o=PyTuple_GetItem(pyLi,i);
1015           if(!fillStringVector(o,arr[i]))
1016             throw INTERP_KERNEL::Exception(msg);
1017         }
1018     }
1019   else
1020     throw INTERP_KERNEL::Exception(msg);
1021 }
1022
1023 static bool fillIntVector(PyObject *pyLi, std::vector<mcIdType>& vec)
1024 {
1025   if(PyList_Check(pyLi))
1026     {
1027       Py_ssize_t sz=PyList_Size(pyLi);
1028       vec.resize(sz);
1029       for(mcIdType i=0;i<sz;i++)
1030         {
1031           PyObject *o=PyList_GetItem(pyLi,i);
1032           if(PyInt_Check(o))
1033             vec[i]=ToIdType(PyInt_AS_LONG(o));
1034           else
1035             return false;
1036         }
1037       return true;
1038     }
1039   else if(PyTuple_Check(pyLi))
1040     {
1041       Py_ssize_t sz=PyTuple_Size(pyLi);
1042       vec.resize(sz);
1043       for(mcIdType i=0;i<sz;i++)
1044         {
1045           PyObject *o=PyTuple_GetItem(pyLi,i);
1046           if(PyInt_Check(o))
1047             vec[i]=ToIdType(PyInt_AS_LONG(o));
1048           else
1049             return false;
1050         }
1051       return true;
1052     }
1053   else
1054     return false;
1055 }
1056
1057 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<mcIdType> >& arr)
1058 {
1059   const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1060   if(PyList_Check(pyLi))
1061     {
1062       Py_ssize_t sz=PyList_Size(pyLi);
1063       arr.resize(sz);
1064       for(mcIdType i=0;i<sz;i++)
1065         {
1066           PyObject *o=PyList_GetItem(pyLi,i);
1067           if(!fillIntVector(o,arr[i]))
1068             throw INTERP_KERNEL::Exception(msg);
1069         }
1070     }
1071   else if(PyTuple_Check(pyLi))
1072     {
1073       Py_ssize_t sz=PyTuple_Size(pyLi);
1074       arr.resize(sz);
1075       for(mcIdType i=0;i<sz;i++)
1076         {
1077           PyObject *o=PyTuple_GetItem(pyLi,i);
1078           if(!fillIntVector(o,arr[i]))
1079             throw INTERP_KERNEL::Exception(msg);
1080         }
1081     }
1082   else
1083     throw INTERP_KERNEL::Exception(msg);
1084 }
1085
1086 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
1087 {
1088   const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1089   if(PyList_Check(pyLi))
1090     {
1091       Py_ssize_t sz=PyList_Size(pyLi);
1092       arr.resize(sz);
1093       for(mcIdType i=0;i<sz;i++)
1094         {
1095           PyObject *o=PyList_GetItem(pyLi,i);
1096           if(PyTuple_Check(o))
1097             {
1098               std::size_t sz2=PyTuple_Size(o);
1099               if(sz2!=2)
1100                 throw INTERP_KERNEL::Exception(msg);
1101               std::pair<std::string, std::vector<std::string> > item;
1102               PyObject *o_0=PyTuple_GetItem(o,0);
1103               item.first=convertPyObjectToStr(o_0,msg);
1104               PyObject *o_1=PyTuple_GetItem(o,1);
1105               if(!fillStringVector(o_1,item.second))
1106                 throw INTERP_KERNEL::Exception(msg);
1107               arr[i]=item;
1108             }
1109           else
1110             throw INTERP_KERNEL::Exception(msg);
1111         }
1112     }
1113   else if(PyTuple_Check(pyLi))
1114     {
1115       Py_ssize_t sz=PyTuple_Size(pyLi);
1116       arr.resize(sz);
1117       for(Py_ssize_t i=0;i<sz;i++)
1118         {
1119           PyObject *o=PyTuple_GetItem(pyLi,i);
1120           if(PyTuple_Check(o))
1121             {
1122               std::size_t sz2=PyTuple_Size(o);
1123               if(sz2!=2)
1124                 throw INTERP_KERNEL::Exception(msg);
1125               std::pair<std::string, std::vector<std::string> > item;
1126               PyObject *o_0=PyTuple_GetItem(o,0);
1127               item.first=convertPyObjectToStr(o_0,msg);
1128               PyObject *o_1=PyTuple_GetItem(o,1);
1129               if(!fillStringVector(o_1,item.second))
1130                 throw INTERP_KERNEL::Exception(msg);
1131               arr[i]=item;
1132             }
1133           else
1134             throw INTERP_KERNEL::Exception(msg);
1135         }
1136     }
1137   else
1138     throw INTERP_KERNEL::Exception(msg);
1139 }
1140
1141 template<class T>
1142 PyObject *convertDblArrToPyList(const T *ptr, std::size_t size)
1143 {
1144   PyObject *ret(PyList_New(size));
1145   for(std::size_t i=0;i<size;i++)
1146     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1147   return ret;
1148 }
1149
1150 static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
1151 {
1152   std::size_t size(v.size());
1153   PyObject *ret(PyList_New(size));
1154   for(std::size_t i=0;i<size;i++)
1155     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1156   return ret;
1157 }
1158
1159 template<class T>
1160 PyObject *convertDblArrToPyListOfTuple(const T *vals, std::size_t nbOfComp, mcIdType nbOfTuples)
1161 {
1162   PyObject *ret(PyList_New(nbOfTuples));
1163   for(mcIdType i=0;i<nbOfTuples;i++)
1164     {
1165       PyObject *t=PyTuple_New(nbOfComp);
1166       for(std::size_t j=0;j<nbOfComp;j++)
1167         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1168       PyList_SetItem(ret,i,t);
1169     }
1170   return ret;
1171 }
1172
1173 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, mcIdType nbOfTuples)
1174 {
1175   PyObject *ret=PyList_New(nbOfTuples);
1176   INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1177   for(mcIdType i=0;i<nbOfTuples;i++)
1178     {
1179       std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1180       PyList_SetItem(ret,i,PyString_FromString(tmp));
1181     }
1182   return ret;
1183 }
1184
1185 static double *convertPyToNewDblArr2(PyObject *pyLi, mcIdType *size)
1186 {
1187   if(PyList_Check(pyLi))
1188     {
1189       *size=ToIdType(PyList_Size(pyLi));
1190       double *tmp=(double *)malloc((*size)*sizeof(double));
1191       for(mcIdType i=0;i<*size;i++)
1192         {
1193           PyObject *o=PyList_GetItem(pyLi,i);
1194           if(PyFloat_Check(o))
1195             {
1196               double val=PyFloat_AS_DOUBLE(o);
1197               tmp[i]=val;
1198             }
1199           else if(PyInt_Check(o))
1200             {
1201               long val0=PyInt_AS_LONG(o);
1202               double val=(double)val0;
1203               tmp[i]=val;
1204             }
1205           else
1206             {
1207               free(tmp);
1208               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1209             }
1210         }
1211       return tmp;
1212     }
1213   else if(PyTuple_Check(pyLi))
1214     {
1215       *size=ToIdType(PyTuple_Size(pyLi));
1216       double *tmp=(double *)malloc((*size)*sizeof(double));
1217       for(mcIdType i=0;i<*size;i++)
1218         {
1219           PyObject *o=PyTuple_GetItem(pyLi,i);
1220           if(PyFloat_Check(o))
1221             {
1222               double val=PyFloat_AS_DOUBLE(o);
1223               tmp[i]=val;
1224             }
1225           else if(PyInt_Check(o))
1226             {
1227               long val0=PyInt_AS_LONG(o);
1228               double val=(double)val0;
1229               tmp[i]=val;
1230             }
1231           else
1232             {
1233               free(tmp);
1234               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1235             }
1236         }
1237       return tmp;
1238     }
1239   else
1240     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1241 }
1242
1243 static void fillArrayWithPyListDbl3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<double>& ret)
1244 {
1245   static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1246   if(PyFloat_Check(pyLi))
1247     {
1248       if(nbOfElt==-1)
1249         nbOfElt=1;
1250       else
1251         if(nbOfElt!=1)
1252           throw INTERP_KERNEL::Exception(MSG);
1253       double val=PyFloat_AS_DOUBLE(pyLi);
1254       ret.push_back(val);
1255     }
1256   else if(PyInt_Check(pyLi))
1257     {
1258       mcIdType val0=ToIdType(PyInt_AS_LONG(pyLi));
1259       double val=(double)val0;
1260       if(nbOfElt==-1)
1261         nbOfElt=1;
1262       else
1263         if(nbOfElt!=1)
1264           throw INTERP_KERNEL::Exception(MSG);
1265       ret.push_back(val);
1266     }
1267   else if(PyList_Check(pyLi))
1268     {
1269       std::size_t size=PyList_Size(pyLi);
1270       mcIdType tmp=0;
1271       for(std::size_t i=0;i<size;i++)
1272         {
1273           PyObject *o=PyList_GetItem(pyLi,i);
1274           mcIdType tmp1=-1;
1275           fillArrayWithPyListDbl3(o,tmp1,ret);
1276           tmp+=tmp1;
1277         }
1278       if(nbOfElt==-1)
1279         nbOfElt=tmp;
1280       else
1281         {
1282           if(nbOfElt!=tmp)
1283             throw INTERP_KERNEL::Exception(MSG);
1284         }
1285     }
1286   else if(PyTuple_Check(pyLi))
1287     {
1288       std::size_t size=PyTuple_Size(pyLi);
1289       mcIdType tmp=0;
1290       for(std::size_t i=0;i<size;i++)
1291         {
1292           PyObject *o=PyTuple_GetItem(pyLi,i);
1293           mcIdType tmp1=-1;
1294           fillArrayWithPyListDbl3(o,tmp1,ret);
1295           tmp+=tmp1;
1296         }
1297       if(nbOfElt==-1)
1298         nbOfElt=tmp;
1299       else
1300         {
1301           if(nbOfElt!=tmp)
1302             throw INTERP_KERNEL::Exception(MSG);
1303         }
1304     }
1305   else
1306     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1307 }
1308
1309 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
1310 {
1311   std::vector<double> ret;
1312   std::size_t size1=-1;
1313   mcIdType size2=-1;
1314   if(PyList_Check(pyLi))
1315     {
1316       size1=PyList_Size(pyLi);
1317       for(std::size_t i=0;i<size1;i++)
1318         {
1319           PyObject *o=PyList_GetItem(pyLi,i);
1320           fillArrayWithPyListDbl3(o,size2,ret);
1321         }
1322       if(size1==0)
1323         size2=1;
1324     }
1325   else if(PyTuple_Check(pyLi))
1326     {
1327       size1=PyTuple_Size(pyLi);
1328       for(std::size_t i=0;i<size1;i++)
1329         {
1330           PyObject *o=PyTuple_GetItem(pyLi,i);
1331           fillArrayWithPyListDbl3(o,size2,ret);
1332         }
1333       if(size1==0)
1334         size2=1;
1335     }
1336   else
1337     throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1338   //
1339   checkFillArrayWithPyList(ToIdType(size1),ToIdType(size2),nbOfTuples,nbOfComp);
1340   return ret;
1341 }
1342
1343 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1344 template<class T>
1345 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1346 {
1347   void *argp=0;
1348   if(PyList_Check(pyLi))
1349     {
1350       std::size_t size=PyList_Size(pyLi);
1351       ret.resize(size);
1352       for(std::size_t i=0;i<size;i++)
1353         {
1354           PyObject *obj=PyList_GetItem(pyLi,i);
1355           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1356           if(!SWIG_IsOK(status))
1357             {
1358               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1359               throw INTERP_KERNEL::Exception(oss.str().c_str());
1360             }
1361           T arg=reinterpret_cast< T >(argp);
1362           ret[i]=arg;
1363         }
1364     }
1365   else if(PyTuple_Check(pyLi))
1366     {
1367       std::size_t size=PyTuple_Size(pyLi);
1368       ret.resize(size);
1369       for(std::size_t i=0;i<size;i++)
1370         {
1371           PyObject *obj=PyTuple_GetItem(pyLi,i);
1372           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1373           if(!SWIG_IsOK(status))
1374             {
1375               std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1376               throw INTERP_KERNEL::Exception(oss.str().c_str());
1377             }
1378           T arg=reinterpret_cast< T >(argp);
1379           ret[i]=arg;
1380         }
1381     }
1382   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1383     {
1384       ret.resize(1);
1385       T arg=reinterpret_cast< T >(argp);
1386       ret[0]=arg;
1387     }
1388   else
1389     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1390 }
1391
1392 //convertFromVectorAutoObjToPyObj<MEDCoupling::MEDCouplingUMesh>(inpv,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh)
1393 template<class T>
1394 static PyObject *convertFromVectorAutoObjToPyObj(std::vector< MCAuto<T> >& inpVector, swig_type_info *ty)
1395 {
1396   std::size_t sz(inpVector.size());
1397   PyObject *ret = PyList_New(sz);
1398   for(std::size_t i=0;i<sz;++i)
1399     PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(inpVector[i].retn()),ty, SWIG_POINTER_OWN | 0 ));
1400   return ret;
1401 }
1402
1403 /*!
1404  * if python int -> cpp int sw=1
1405  * if python list[int] -> cpp vector<int> sw=2
1406  * if python tuple[int] -> cpp vector<int> sw=2
1407  * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1408  * if python DataArrayIntTuple -> cpp DataArrayIdTypeTuple sw=4
1409  *
1410  * switch between (int,vector<int>,DataArrayIdType)
1411  */
1412 template< class T, class ARRAY >
1413 static void convertIntStarLikePyObjToCpp(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, ARRAY *& daIntTyypp, typename MEDCoupling::Traits< T >::ArrayTuple *&daIntTuple)
1414 {
1415   sw=-1;
1416   if(PyInt_Check(value))
1417     {
1418       iTyypp=(T)PyInt_AS_LONG(value);
1419       sw=1;
1420       return;
1421     }
1422   if(PyTuple_Check(value))
1423     {
1424       std::size_t size=PyTuple_Size(value);
1425       stdvecTyypp.resize(size);
1426       for(std::size_t i=0;i<size;i++)
1427         {
1428           PyObject *o=PyTuple_GetItem(value,i);
1429           if(PyInt_Check(o))
1430             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1431           else
1432             {
1433               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1434               throw INTERP_KERNEL::Exception(oss.str().c_str());
1435             }
1436         }
1437       sw=2;
1438       return;
1439     }
1440   if(PyList_Check(value))
1441     {
1442       std::size_t size=PyList_Size(value);
1443       stdvecTyypp.resize(size);
1444       for(std::size_t i=0;i<size;i++)
1445         {
1446           PyObject *o=PyList_GetItem(value,i);
1447           if(PyInt_Check(o))
1448             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1449           else
1450             {
1451               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1452               throw INTERP_KERNEL::Exception(oss.str().c_str());
1453             }
1454         }
1455       sw=2;
1456       return;
1457     }
1458   void *argp;
1459   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1460   if(SWIG_IsOK(status))
1461     {
1462       daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1463       sw=3;
1464       return;
1465     }
1466   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1467   if(SWIG_IsOK(status))
1468     {
1469       daIntTuple=reinterpret_cast< typename MEDCoupling::Traits< T >::ArrayTuple * >(argp);
1470       sw=4;
1471       return ;
1472     }
1473   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1474 }
1475
1476 /*!
1477  * if python int -> cpp int sw=1
1478  * if python list[int] -> cpp vector<int> sw=2
1479  * if python tuple[int] -> cpp vector<int> sw=2
1480  * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1481  * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4
1482  *
1483  * switch between (int,vector<int>,DataArrayIdType)
1484  */
1485 template< class T >
1486 static const T *convertIntStarLikePyObjToCppIntStar(PyObject *value, mcIdType& sw, mcIdType& sz, T& iTyypp, std::vector<T>& stdvecTyypp)
1487 {
1488   sw=-1;
1489   if(PyInt_Check(value))
1490     {
1491       iTyypp=(T)PyInt_AS_LONG(value);
1492       sw=1; sz=1;
1493       return &iTyypp;
1494     }
1495   if(PyTuple_Check(value))
1496     {
1497       std::size_t size=PyTuple_Size(value);
1498       stdvecTyypp.resize(size);
1499       for(std::size_t i=0;i<size;i++)
1500         {
1501           PyObject *o=PyTuple_GetItem(value,i);
1502           if(PyInt_Check(o))
1503             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1504           else
1505             {
1506               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1507               throw INTERP_KERNEL::Exception(oss.str().c_str());
1508             }
1509         }
1510       sw=2; sz=ToIdType(size);
1511       return &stdvecTyypp[0];
1512     }
1513   if(PyList_Check(value))
1514     {
1515       std::size_t size=PyList_Size(value);
1516       stdvecTyypp.resize(size);
1517       for(std::size_t i=0;i<size;i++)
1518         {
1519           PyObject *o=PyList_GetItem(value,i);
1520           if(PyInt_Check(o))
1521             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1522           else
1523             {
1524               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1525               throw INTERP_KERNEL::Exception(oss.str().c_str());
1526             }
1527         }
1528       sw=2; sz=ToIdType(size);
1529       return &stdvecTyypp[0];
1530     }
1531   void *argp;
1532   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI,0|0);
1533   if(SWIG_IsOK(status))
1534     {
1535       typedef typename MEDCoupling::Traits< T >::ArrayType ARRAY;
1536       ARRAY *daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1537       if(daIntTyypp)
1538         {
1539           sw=3; sz=daIntTyypp->getNbOfElems();
1540           return daIntTyypp->begin();
1541         }
1542       else
1543         {
1544           sz=0;
1545           return 0;
1546         }
1547     }
1548   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1549   if(SWIG_IsOK(status))
1550     {
1551       typedef typename MEDCoupling::Traits< T >::ArrayTuple ARRAYTUPLE;
1552       ARRAYTUPLE *daIntTuple=reinterpret_cast< ARRAYTUPLE * >(argp);
1553       sw=4; sz=ToIdType(daIntTuple->getNumberOfCompo());
1554       return daIntTuple->getConstPointer();
1555     }
1556   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1557 }
1558
1559 /*!
1560  * if python double -> cpp double sw=1
1561  * if python int -> cpp double sw=1
1562  * if python list[double] -> cpp vector<double> sw=2
1563  * if python list[int] -> cpp vector<double> sw=2
1564  * if python tuple[double] -> cpp vector<double> sw=2
1565  * if python tuple[int] -> cpp vector<double> sw=2
1566  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1567  *
1568  * switch between (int,vector<int>,DataArrayIdType)
1569  */
1570 template<class T>
1571 void considerPyObjAsATStarLikeObject(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1572 {
1573   sw=-1;
1574   if(PyFloat_Check(value))
1575     {
1576       iTyypp=(T)PyFloat_AS_DOUBLE(value);
1577       sw=1;
1578       return;
1579     }
1580   if(PyInt_Check(value))
1581     {
1582       iTyypp=(T)PyInt_AS_LONG(value);
1583       sw=1;
1584       return;
1585     }
1586   if(PyTuple_Check(value))
1587     {
1588       std::size_t size=PyTuple_Size(value);
1589       stdvecTyypp.resize(size);
1590       for(std::size_t i=0;i<size;i++)
1591         {
1592           PyObject *o=PyTuple_GetItem(value,i);
1593           if(PyFloat_Check(o))
1594             stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1595           else if(PyInt_Check(o))
1596             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1597           else
1598             {
1599               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1600               throw INTERP_KERNEL::Exception(oss.str().c_str());
1601             }
1602         }
1603       sw=2;
1604       return;
1605     }
1606   if(PyList_Check(value))
1607     {
1608       std::size_t size=PyList_Size(value);
1609       stdvecTyypp.resize(size);
1610       for(std::size_t i=0;i<size;i++)
1611         {
1612           PyObject *o=PyList_GetItem(value,i);
1613           if(PyFloat_Check(o))
1614             stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1615           else if(PyInt_Check(o))
1616             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1617           else
1618             {
1619               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1620               throw INTERP_KERNEL::Exception(oss.str().c_str());
1621             }
1622         }
1623       sw=2;
1624       return;
1625     }
1626   void *argp;
1627   int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1628   if(!SWIG_IsOK(status))
1629     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1630   daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1631   sw=3;
1632 }
1633
1634 /*!
1635  * if python double -> cpp double sw=1
1636  * if python int -> cpp double sw=1
1637  * if python list[double] -> cpp vector<double> sw=2
1638  * if python list[int] -> cpp vector<double> sw=2
1639  * if python tuple[double] -> cpp vector<double> sw=2
1640  * if python tuple[int] -> cpp vector<double> sw=2
1641  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1642  *
1643  * switch between (int,vector<int>,DataArrayIdType)
1644  */
1645 static void convertDoubleStarLikePyObjToCpp(PyObject *value, mcIdType& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1646 {
1647   sw=-1;
1648   if(PyFloat_Check(value))
1649     {
1650       iTyypp=PyFloat_AS_DOUBLE(value);
1651       sw=1;
1652       return;
1653     }
1654   if(PyInt_Check(value))
1655     {
1656       iTyypp=(double)PyInt_AS_LONG(value);
1657       sw=1;
1658       return;
1659     }
1660   if(PyTuple_Check(value))
1661     {
1662       std::size_t size=PyTuple_Size(value);
1663       stdvecTyypp.resize(size);
1664       for(std::size_t i=0;i<size;i++)
1665         {
1666           PyObject *o=PyTuple_GetItem(value,i);
1667           if(PyFloat_Check(o))
1668             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1669           else if(PyInt_Check(o))
1670             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1671           else
1672             {
1673               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1674               throw INTERP_KERNEL::Exception(oss.str().c_str());
1675             }
1676         }
1677       sw=2;
1678       return;
1679     }
1680   if(PyList_Check(value))
1681     {
1682       std::size_t size=PyList_Size(value);
1683       stdvecTyypp.resize(size);
1684       for(std::size_t i=0;i<size;i++)
1685         {
1686           PyObject *o=PyList_GetItem(value,i);
1687           if(PyFloat_Check(o))
1688             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1689           else if(PyInt_Check(o))
1690             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1691           else
1692             {
1693               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1694               throw INTERP_KERNEL::Exception(oss.str().c_str());
1695             }
1696         }
1697       sw=2;
1698       return;
1699     }
1700   void *argp;
1701   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1702   if(!SWIG_IsOK(status))
1703     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1704   daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1705   sw=3;
1706 }
1707
1708 template<class T>
1709 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)
1710 {
1711   sw=-1;
1712   if(PyFloat_Check(value))
1713     {
1714       val=(T)PyFloat_AS_DOUBLE(value);
1715       sw=1;
1716       return;
1717     }
1718   if(PyInt_Check(value))
1719     {
1720       val=(T)PyInt_AS_LONG(value);
1721       sw=1;
1722       return;
1723     }
1724   if(PyTuple_Check(value))
1725     {
1726       std::size_t size=PyTuple_Size(value);
1727       f.resize(size);
1728       for(std::size_t i=0;i<size;i++)
1729         {
1730           PyObject *o=PyTuple_GetItem(value,i);
1731           if(PyFloat_Check(o))
1732             f[i]=(T)PyFloat_AS_DOUBLE(o);
1733           else if(PyInt_Check(o))
1734             f[i]=(T)PyInt_AS_LONG(o);
1735           else
1736             {
1737               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1738               throw INTERP_KERNEL::Exception(oss.str().c_str());
1739             }
1740         }
1741       sw=4;
1742       return;
1743     }
1744   if(PyList_Check(value))
1745     {
1746       std::size_t size=PyList_Size(value);
1747       f.resize(size);
1748       for(std::size_t i=0;i<size;i++)
1749         {
1750           PyObject *o=PyList_GetItem(value,i);
1751           if(PyFloat_Check(o))
1752             f[i]=(T)PyFloat_AS_DOUBLE(o);
1753           else if(PyInt_Check(o))
1754             f[i]=(T)PyInt_AS_LONG(o);
1755           else
1756             {
1757               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1758               throw INTERP_KERNEL::Exception(oss.str().c_str());
1759             }
1760         }
1761       sw=4;
1762       return;
1763     }
1764   void *argp;
1765   int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1766   if(SWIG_IsOK(status))
1767     {
1768       d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1769       sw=2;
1770       return ;
1771     }
1772   status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1773   if(SWIG_IsOK(status))
1774     {
1775       e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1776       sw=3;
1777       return ;
1778     }
1779   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1780 }
1781
1782 /*!
1783  * if value int -> cpp val sw=1
1784  * if value double -> cpp val sw=1
1785  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1786  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1787  * if value list[int,double] -> cpp std::vector<double> sw=4
1788  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1789  */
1790 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1791 {
1792   convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1793 }
1794
1795 /*!
1796  * if value int -> cpp val sw=1
1797  * if value double -> cpp val sw=1
1798  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1799  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1800  * if value list[int,double] -> cpp std::vector<double> sw=4
1801  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1802  */
1803 static void convertFloatStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
1804 {
1805   convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
1806 }
1807
1808 /*!
1809  * if python int -> cpp int sw=1
1810  * if python list[int] -> cpp vector<int> sw=2
1811  * if python tuple[int] -> cpp vector<int> sw=2
1812  * if python slicp -> cpp pair sw=3 (begin,end,step)
1813  * if python DataArrayIdType -> cpp DataArrayIdType sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1814  *
1815  * switch between (int,vector<int>,DataArrayIdType)
1816  */
1817 template<class T, class ARRAY>
1818 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)
1819 {
1820   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdType, DataArrayIdTypeTuple";
1821   sw=-1;
1822   if(PyInt_Check(value))
1823     {
1824       iTyypp=(T)PyInt_AS_LONG(value);
1825       sw=1;
1826       return;
1827     }
1828   if(PyTuple_Check(value))
1829     {
1830       std::size_t size=PyTuple_Size(value);
1831       stdvecTyypp.resize(size);
1832       for(std::size_t i=0;i<size;i++)
1833         {
1834           PyObject *o=PyTuple_GetItem(value,i);
1835           if(PyInt_Check(o))
1836             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1837           else
1838             {
1839               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1840               throw INTERP_KERNEL::Exception(oss.str().c_str());
1841             }
1842         }
1843       sw=2;
1844       return;
1845     }
1846   if(PyList_Check(value))
1847     {
1848       std::size_t size=PyList_Size(value);
1849       stdvecTyypp.resize(size);
1850       for(std::size_t i=0;i<size;i++)
1851         {
1852           PyObject *o=PyList_GetItem(value,i);
1853           if(PyInt_Check(o))
1854             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1855           else
1856             {
1857               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1858               throw INTERP_KERNEL::Exception(oss.str().c_str());
1859             }
1860         }
1861       sw=2;
1862       return;
1863     }
1864   if(PySlice_Check(value))
1865     {
1866       Py_ssize_t strt=2,stp=2,step=2;
1867       GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1868       p.first=ToIdType(strt);
1869       p.second.first=ToIdType(stp);
1870       p.second.second=ToIdType(step);
1871       sw=3;
1872       return ;
1873     }
1874   void *argp;
1875   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1876   if(SWIG_IsOK(status))
1877     {
1878       daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1879       if(!daIntTyypp)
1880         {
1881           std::ostringstream oss; oss << msg << " Instance in null !";
1882           throw INTERP_KERNEL::Exception(oss.str().c_str());
1883         }
1884       sw=4;
1885       return ;
1886     }
1887   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI_TUPLE,0|0);
1888   if(SWIG_IsOK(status))
1889     {
1890       typedef typename MEDCoupling::Traits< typename ARRAY::Type >::ArrayTuple ARRAYTUPLE;
1891       ARRAYTUPLE *tmp=reinterpret_cast< ARRAYTUPLE * >(argp);
1892       if(!tmp)
1893         {
1894           std::ostringstream oss; oss << msg << " Instance in null !";
1895           throw INTERP_KERNEL::Exception(oss.str().c_str());
1896         }
1897       stdvecTyypp.resize(tmp->getNumberOfCompo());
1898       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1899       sw=2;
1900       return ;
1901     }
1902   throw INTERP_KERNEL::Exception(msg);
1903 }
1904
1905 /*!
1906  * Idem than convertIntStarOrSliceLikePyObjToCpp
1907  */
1908 template<class T, class ARRAY>
1909 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)
1910 {
1911   convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1912   if(sw==1)
1913     {
1914       iTyypp=(T)InterpreteNegativeInt(iTyypp,nbelem);
1915     }
1916 }
1917
1918 /*!
1919  * if python int -> cpp int sw=1
1920  * if python tuple[int] -> cpp vector<int> sw=2
1921  * if python list[int] -> cpp vector<int> sw=2
1922  * if python slice -> cpp pair sw=3
1923  * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4 . WARNING The returned pointer can be the null pointer !
1924  */
1925 template< class TUPLE_T >
1926 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)
1927 {
1928   sw=-1;
1929   if(PyInt_Check(value))
1930     {
1931       iTyypp=ToIdType(PyInt_AS_LONG(value));
1932       sw=1;
1933       return;
1934     }
1935   if(PyTuple_Check(value))
1936     {
1937       std::size_t size=PyTuple_Size(value);
1938       stdvecTyypp.resize(size);
1939       for(std::size_t i=0;i<size;i++)
1940         {
1941           PyObject *o=PyTuple_GetItem(value,i);
1942           if(PyInt_Check(o))
1943             stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1944           else
1945             {
1946               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1947               throw INTERP_KERNEL::Exception(oss.str().c_str());
1948             }
1949         }
1950       sw=2;
1951       return;
1952     }
1953   if(PyList_Check(value))
1954     {
1955       std::size_t size=PyList_Size(value);
1956       stdvecTyypp.resize(size);
1957       for(std::size_t i=0;i<size;i++)
1958         {
1959           PyObject *o=PyList_GetItem(value,i);
1960           if(PyInt_Check(o))
1961             stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1962           else
1963             {
1964               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1965               throw INTERP_KERNEL::Exception(oss.str().c_str());
1966             }
1967         }
1968       sw=2;
1969       return;
1970     }
1971   if(PySlice_Check(value))
1972     {
1973       Py_ssize_t strt=2,stp=2,step=2;
1974       GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1975       p.first=ToIdType(strt);
1976       p.second.first=ToIdType(stp);
1977       p.second.second=ToIdType(step);
1978       sw=3;
1979       return ;
1980     }
1981   void *argp;
1982   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<TUPLE_T>::TI_TUPLE,0|0);
1983   if(!SWIG_IsOK(status))
1984     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdTypeTuple");
1985   daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple * >(argp);
1986   sw=4;
1987 }
1988
1989 /*!
1990  * if python string with size one -> cpp char sw=1
1991  * if python string with size different from one -> cpp string sw=2
1992  * if python tuple[string] or list[string] -> vector<string> sw=3
1993  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1994  * switch between (int,string,vector<string>,DataArrayChar)
1995  */
1996 static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
1997 {
1998   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1999   sw=-1;
2000   if(PyString_Check(value))
2001     {
2002       const char *pt=PyString_AsString(value);
2003       Py_ssize_t sz=PyString_Size(value);
2004       if(sz==1)
2005         {
2006           cTyp=pt[0];
2007           sw=1;
2008           return;
2009         }
2010       else
2011         {
2012           sType=pt;
2013           sw=2;
2014           return;
2015         }
2016     }
2017 #if PY_VERSION_HEX >= 0x03000000
2018   if(PyUnicode_Check(value))
2019     {
2020       Py_ssize_t sz;
2021       const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
2022       if(sz==1)
2023         {
2024           cTyp=pt[0];
2025           sw=1;
2026           return;
2027         }
2028       else
2029         {
2030           sType=pt;
2031           sw=2;
2032           return;
2033         }
2034     }
2035 #endif
2036   if(PyTuple_Check(value))
2037     {
2038       std::size_t size=PyTuple_Size(value);
2039       vsType.resize(size);
2040       for(std::size_t i=0;i<size;i++)
2041         {
2042           PyObject *o=PyTuple_GetItem(value,i);
2043           try
2044             {
2045               vsType[i]=convertPyObjectToStr(o);
2046             }
2047           catch(INTERP_KERNEL::Exception& )
2048             {
2049               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2050               throw INTERP_KERNEL::Exception(oss.str().c_str());
2051             }
2052         }
2053       sw=3;
2054       return;
2055     }
2056   if(PyList_Check(value))
2057     {
2058       std::size_t size=PyList_Size(value);
2059       vsType.resize(size);
2060       for(std::size_t i=0;i<size;i++)
2061         {
2062           PyObject *o=PyList_GetItem(value,i);
2063           try
2064             {
2065               vsType[i]=convertPyObjectToStr(o);
2066             }
2067           catch(INTERP_KERNEL::Exception& )
2068             {
2069               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2070               throw INTERP_KERNEL::Exception(oss.str().c_str());
2071             }
2072         }
2073       sw=3;
2074       return;
2075     }
2076   void *argp;
2077   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
2078   if(SWIG_IsOK(status))
2079     {
2080       dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
2081       if(!dacType)
2082         {
2083           std::ostringstream oss; oss << msg << " Instance in null !";
2084           throw INTERP_KERNEL::Exception(oss.str().c_str());
2085         }
2086       sw=4;
2087       return ;
2088     }
2089   throw INTERP_KERNEL::Exception(msg);
2090 }
2091
2092 /*!
2093  * if value int -> cpp it sw=1
2094  * if value list[int] -> vt sw=2
2095  * if value tuple[int] -> vt sw=2
2096  * if value slice -> pt sw=3
2097  * if value DataArrayIdType -> dt sw=4
2098  * if value tuple [int,int] -> cpp it,ip sw=5
2099  * if value tuple [list[int],int] -> cpp vt,ip sw=6
2100  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2101  * if value tuple [slice,int] -> cpp pt,ip sw=7
2102  * if value tuple [DaI,int] -> cpp dt,ip sw=8
2103  * if value tuple [int,list[int]] -> cpp it,vc sw=9
2104  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2105  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2106  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2107  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2108  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2109  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2110  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2111  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2112  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2113  * if value tuple [int,slice] -> cpp it,pc sw=13
2114  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2115  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2116  * if value tuple [slice,slice] -> cpp pt,pc sw=15
2117  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2118  *
2119  * switch between (int,vector<int>,DataArrayIdType)
2120  */
2121 template<class TC>
2122 static void convertObjToPossibleCpp3(PyObject *value, mcIdType nbTuple, int nbCompo, mcIdType& sw, mcIdType& it, TC& ic, std::vector<mcIdType>& vt, std::vector<TC>& vc,
2123                                      std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pt, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pc,
2124                                      MEDCoupling::DataArrayIdType *&dt, MEDCoupling::DataArrayIdType *&dc)
2125 {
2126   if(!PyTuple_Check(value))
2127     {
2128       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2129       return ;
2130     }
2131   else
2132     {
2133       std::size_t sz=PyTuple_Size(value);
2134       if(sz!=2)
2135         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2136       PyObject *ob0=PyTuple_GetItem(value,0);
2137       mcIdType sw1,sw2;
2138       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2139       PyObject *ob1=PyTuple_GetItem(value,1);
2140       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2141       sw=4*sw2+sw1;
2142     }
2143 }
2144
2145 /*!
2146  * if value int -> cpp val sw=1
2147  * if value double -> cpp val sw=1
2148  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2149  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2150  * if value list[int,double] -> cpp std::vector<double> sw=4
2151  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2152  */
2153 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2154                                                    const char *msg, mcIdType nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2155 {
2156   sw=-1;
2157   if(PyFloat_Check(value))
2158     {
2159       val=PyFloat_AS_DOUBLE(value);
2160       sw=1;
2161       if(nbTuplesExpected*nbCompExpected!=1)
2162         {
2163           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2164           throw INTERP_KERNEL::Exception(oss.str().c_str());
2165         }
2166       return &val;
2167     }
2168   if(PyInt_Check(value))
2169     {
2170       val=(double)PyInt_AS_LONG(value);
2171       sw=1;
2172       if(nbTuplesExpected*nbCompExpected!=1)
2173         {
2174           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2175           throw INTERP_KERNEL::Exception(oss.str().c_str());
2176         }
2177       return &val;
2178     }
2179   if(PyTuple_Check(value) || PyList_Check(value))
2180     {
2181       try
2182         {
2183           mcIdType tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2184           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2185           sw=4;
2186           f=ret;
2187           return &f[0];
2188         }
2189       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2190     }
2191   void *argp;
2192   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2193   if(SWIG_IsOK(status))
2194     {
2195       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2196       sw=2;
2197       if(d)
2198         {
2199           if(d->getNumberOfTuples()==nbTuplesExpected)
2200             {
2201               if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2202                 {
2203                   return d->getConstPointer();
2204                 }
2205               else
2206                 {
2207                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2208                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2209                 }
2210             }
2211           else
2212             {
2213               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2214               throw INTERP_KERNEL::Exception(oss.str().c_str());
2215             }
2216         }
2217       else
2218         {
2219           if(throwIfNullPt)
2220             {
2221               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2222               throw INTERP_KERNEL::Exception(oss.str().c_str());
2223             }
2224           else
2225             return 0;
2226         }
2227     }
2228   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2229   if(SWIG_IsOK(status))
2230     {
2231       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2232       sw=3;
2233       if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2234         {
2235           if(nbTuplesExpected==1)
2236             return e->getConstPointer();
2237           else
2238             {
2239               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by construction !";
2240               throw INTERP_KERNEL::Exception(oss.str().c_str());
2241             }
2242         }
2243       else
2244         {
2245           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2246           throw INTERP_KERNEL::Exception(oss.str().c_str());
2247         }
2248     }
2249   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2250 }
2251
2252 /*!
2253  * if value int -> cpp val sw=1
2254  * if value double -> cpp val sw=1
2255  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2256  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2257  * if value list[int,double] -> cpp std::vector<double> sw=4
2258  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2259  */
2260 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2261                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, mcIdType& nbTuples)
2262 {
2263   sw=-1;
2264   if(PyFloat_Check(value))
2265     {
2266       val=PyFloat_AS_DOUBLE(value);
2267       sw=1;
2268       if(nbCompExpected!=1)
2269         {
2270           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2271           throw INTERP_KERNEL::Exception(oss.str().c_str());
2272         }
2273       nbTuples=1;
2274       return &val;
2275     }
2276   if(PyInt_Check(value))
2277     {
2278       val=(double)PyInt_AS_LONG(value);
2279       sw=1;
2280       if(nbCompExpected!=1)
2281         {
2282           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2283           throw INTERP_KERNEL::Exception(oss.str().c_str());
2284         }
2285       nbTuples=1;
2286       return &val;
2287     }
2288   if(PyTuple_Check(value))
2289     {
2290       std::size_t size=PyTuple_Size(value);
2291       f.resize(size);
2292       for(std::size_t i=0;i<size;i++)
2293         {
2294           PyObject *o=PyTuple_GetItem(value,i);
2295           if(PyFloat_Check(o))
2296             f[i]=PyFloat_AS_DOUBLE(o);
2297           else if(PyInt_Check(o))
2298             f[i]=(double)PyInt_AS_LONG(o);
2299           else
2300             {
2301               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2302               throw INTERP_KERNEL::Exception(oss.str().c_str());
2303             }
2304         }
2305       sw=4;
2306       if(size%nbCompExpected!=0)
2307         {
2308           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2309           throw INTERP_KERNEL::Exception(oss.str().c_str());
2310         }
2311       nbTuples=ToIdType(size/nbCompExpected);
2312       return &f[0];
2313     }
2314   if(PyList_Check(value))
2315     {
2316       std::size_t size=PyList_Size(value);
2317       f.resize(size);
2318       for(std::size_t i=0;i<size;i++)
2319         {
2320           PyObject *o=PyList_GetItem(value,i);
2321           if(PyFloat_Check(o))
2322             f[i]=PyFloat_AS_DOUBLE(o);
2323           else if(PyInt_Check(o))
2324             f[i]=(double)PyInt_AS_LONG(o);
2325           else
2326             {
2327               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2328               throw INTERP_KERNEL::Exception(oss.str().c_str());
2329             }
2330         }
2331       sw=4;
2332       if(size%nbCompExpected!=0)
2333         {
2334           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2335           throw INTERP_KERNEL::Exception(oss.str().c_str());
2336         }
2337       nbTuples=ToIdType(size/nbCompExpected);
2338       return &f[0];
2339     }
2340   void *argp;
2341   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2342   if(SWIG_IsOK(status))
2343     {
2344       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2345       sw=2;
2346       if(d)
2347         {
2348           if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2349             {
2350               nbTuples=d->getNumberOfTuples();
2351               return d->getConstPointer();
2352             }
2353           else
2354             {
2355               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2356               throw INTERP_KERNEL::Exception(oss.str().c_str());
2357             }
2358         }
2359       else
2360         {
2361           if(throwIfNullPt)
2362             {
2363               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2364               throw INTERP_KERNEL::Exception(oss.str().c_str());
2365             }
2366           else
2367             { nbTuples=0; return 0; }
2368         }
2369     }
2370   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2371   if(SWIG_IsOK(status))
2372     {
2373       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2374       sw=3;
2375       if(e)
2376         {
2377           if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2378             {
2379               nbTuples=1;
2380               return e->getConstPointer();
2381             }
2382           else
2383             {
2384               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2385               throw INTERP_KERNEL::Exception(oss.str().c_str());
2386             }
2387         }
2388       else
2389         {
2390           if(throwIfNullPt)
2391             {
2392               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2393               throw INTERP_KERNEL::Exception(oss.str().c_str());
2394             }
2395           else
2396             { nbTuples=0; return 0; }
2397         }
2398     }
2399   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2400 }
2401
2402 /*!
2403  * if value int -> cpp val sw=1
2404  * if value double -> cpp val sw=1
2405  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2406  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2407  * if value list[int,double] -> cpp std::vector<double> sw=4
2408  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2409  */
2410 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, mcIdType& sw, double& val, std::vector<double>& f,
2411                                                           const char *msg, bool throwIfNullPt, mcIdType& nbTuples)
2412 {
2413   MEDCoupling::DataArrayDouble *d=0;
2414   MEDCoupling::DataArrayDoubleTuple *e=0;
2415   sw=-1;
2416   if(PyFloat_Check(value))
2417     {
2418       val=PyFloat_AS_DOUBLE(value);
2419       sw=1;
2420       nbTuples=1;
2421       return &val;
2422     }
2423   if(PyInt_Check(value))
2424     {
2425       val=(double)PyInt_AS_LONG(value);
2426       sw=1;
2427       nbTuples=1;
2428       return &val;
2429     }
2430   if(PyTuple_Check(value))
2431     {
2432       std::size_t size=PyTuple_Size(value);
2433       f.resize(size);
2434       for(std::size_t i=0;i<size;i++)
2435         {
2436           PyObject *o=PyTuple_GetItem(value,i);
2437           if(PyFloat_Check(o))
2438             f[i]=PyFloat_AS_DOUBLE(o);
2439           else if(PyInt_Check(o))
2440             f[i]=(double)PyInt_AS_LONG(o);
2441           else
2442             {
2443               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2444               throw INTERP_KERNEL::Exception(oss.str().c_str());
2445             }
2446         }
2447       sw=4;
2448       nbTuples=ToIdType(size);
2449       return &f[0];
2450     }
2451   if(PyList_Check(value))
2452     {
2453       std::size_t size=PyList_Size(value);
2454       f.resize(size);
2455       for(std::size_t i=0;i<size;i++)
2456         {
2457           PyObject *o=PyList_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 << "List as been detected but element #" << i << " is not double ! only lists 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   void *argp;
2473   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2474   if(SWIG_IsOK(status))
2475     {
2476       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2477       sw=2;
2478       if(d)
2479         {
2480           if(d->getNumberOfComponents()==1)
2481             {
2482               nbTuples=d->getNumberOfTuples();
2483               return d->getConstPointer();
2484             }
2485           else
2486             {
2487               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2488               throw INTERP_KERNEL::Exception(oss.str().c_str());
2489             }
2490         }
2491       else
2492         {
2493           if(throwIfNullPt)
2494             {
2495               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2496               throw INTERP_KERNEL::Exception(oss.str().c_str());
2497             }
2498           else
2499             { nbTuples=0; return 0; }
2500         }
2501     }
2502   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2503   if(SWIG_IsOK(status))
2504     {
2505       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2506       sw=3;
2507       if(e)
2508         {
2509           nbTuples=ToIdType(e->getNumberOfCompo());
2510           return e->getConstPointer();
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   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2524 }
2525
2526 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2527 {
2528   void *aBasePtrVS=0;
2529   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2530   if(!SWIG_IsOK(status))
2531     {
2532       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2533       if(!SWIG_IsOK(status))
2534         {
2535           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt32,0|0);
2536           if(!SWIG_IsOK(status))
2537             {
2538               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt64,0|0);
2539               if(!SWIG_IsOK(status))
2540                 {
2541                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2542                   if(!SWIG_IsOK(status))
2543                     {
2544                       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2545                       std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayIdType, DataArrayAsciiChar, DataArrayByte !";
2546                       throw INTERP_KERNEL::Exception(oss.str().c_str());
2547                     }
2548                 }
2549             }
2550         }
2551     }
2552   return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2553 }
2554
2555 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2556 {
2557   PyObject *ret=0;
2558   if(!pd)
2559     {
2560       Py_XINCREF(Py_None);
2561       return Py_None;
2562     }
2563   if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2564     ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2565   else
2566     ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2567   return ret;
2568 }
2569
2570 template<class T>
2571 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2572 {
2573   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)";
2574   std::string msg(msgBase);
2575 #ifdef WITH_NUMPY
2576   msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2577 #endif
2578   msg+=" !";
2579   if(PyList_Check(elt0) || PyTuple_Check(elt0))
2580     {
2581       if(nbOfTuples)
2582         {
2583           if(PyInt_Check(nbOfTuples))
2584             {
2585               mcIdType nbOfTuples1=ToIdType(PyInt_AS_LONG(nbOfTuples));
2586               if(nbOfTuples1<0)
2587                 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2588               if(elt2)
2589                 {
2590                   if(PyInt_Check(elt2))
2591                     {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2592                       mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(elt2));
2593                       if(nbOfCompo<0)
2594                         throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2595                       MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2596                       std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2597                       ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2598                       return ret.retn();
2599                     }
2600                   else
2601                     throw INTERP_KERNEL::Exception(msg.c_str());
2602                 }
2603               else
2604                 {//DataArrayDouble.New([1.,3.,4.],3)
2605                   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2606                   mcIdType tmpp1(-1);
2607                   std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2608                   ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2609                   return ret.retn();
2610                 }
2611             }
2612           else
2613             throw INTERP_KERNEL::Exception(msg.c_str());
2614         }
2615       else
2616         {// DataArrayDouble.New([1.,3.,4.])
2617           MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2618           mcIdType tmpp1(-1),tmpp2(-1);
2619           std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2620           ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2621           return ret.retn();
2622         }
2623     }
2624   else if(PyInt_Check(elt0))
2625     {
2626       mcIdType nbOfTuples1(ToIdType(PyInt_AS_LONG(elt0)));
2627       if(nbOfTuples1<0)
2628         throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2629       if(nbOfTuples)
2630         {
2631           if(!elt2)
2632             {
2633               if(PyInt_Check(nbOfTuples))
2634                 {//DataArrayDouble.New(5,2)
2635                   mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(nbOfTuples));
2636                   if(nbOfCompo<0)
2637                     throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2638                   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2639                   ret->alloc(nbOfTuples1,nbOfCompo);
2640                   return ret.retn();
2641                 }
2642               else
2643                 throw INTERP_KERNEL::Exception(msg.c_str());
2644             }
2645           else
2646             throw INTERP_KERNEL::Exception(msg.c_str());
2647         }
2648       else
2649         {//DataArrayDouble.New(5)
2650           MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2651           ret->alloc(nbOfTuples1,1);
2652           return ret.retn();
2653         }
2654     }
2655 #ifdef WITH_NUMPY
2656   else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2657     {//DataArrayDouble.New(numpyArray)
2658       return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2659     }
2660 #endif
2661   else
2662     throw INTERP_KERNEL::Exception(msg.c_str());
2663   throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2664 }
2665
2666 template<class T>
2667 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2668 {
2669   self->checkAllocated();
2670   const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2671   mcIdType nbOfTuples(self->getNumberOfTuples());
2672   int nbOfComponents((int)(self->getNumberOfComponents()));
2673   mcIdType sw1,sw2;
2674   T i1;
2675   std::vector<T> v1;
2676   typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2677   considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2678   mcIdType it1,ic1;
2679   std::vector<mcIdType> vt1;
2680   std::vector<mcIdType> vc1;
2681   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
2682   MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
2683   convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2684   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2685   switch(sw2)
2686     {
2687     case 1:
2688       {
2689         switch(sw1)
2690           {
2691           case 1:
2692             self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2693             return self;
2694           case 2:
2695             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2696             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2697             self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2698             return self;
2699           case 3:
2700             self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2701             return self;
2702           default:
2703             throw INTERP_KERNEL::Exception(msg);
2704           }
2705         break;
2706       }
2707     case 2:
2708       {
2709         switch(sw1)
2710           {
2711           case 1:
2712             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2713             return self;
2714           case 2:
2715             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2716             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2717             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2718             return self;
2719           case 3:
2720             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2721             return self;
2722           default:
2723             throw INTERP_KERNEL::Exception(msg);
2724           }
2725         break;
2726       }
2727     case 3:
2728       {
2729         switch(sw1)
2730           {
2731           case 1:
2732             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2733             return self;
2734           case 2:
2735             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2736             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2737             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2738             return self;
2739           case 3:
2740             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2741             return self;
2742           default:
2743             throw INTERP_KERNEL::Exception(msg);
2744           }
2745         break;
2746       }
2747     case 4:
2748       {
2749         switch(sw1)
2750           {
2751           case 1:
2752             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2753             return self;
2754           case 2:
2755             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2756             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2757             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2758             return self;
2759           case 3:
2760             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2761             return self;
2762           default:
2763             throw INTERP_KERNEL::Exception(msg);
2764           }
2765         break;
2766       }
2767     case 5:
2768       {
2769         switch(sw1)
2770           {
2771           case 1:
2772             self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2773             return self;
2774           case 2:
2775             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2776             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2777             self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2778             return self;
2779           case 3:
2780             self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2781             return self;
2782           default:
2783             throw INTERP_KERNEL::Exception(msg);
2784           }
2785         break;
2786       }
2787     case 6:
2788       {
2789         switch(sw1)
2790           {
2791           case 1:
2792             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2793             return self;
2794           case 2:
2795             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2796             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2797             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2798             return self;
2799           case 3:
2800             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2801             return self;
2802           default:
2803             throw INTERP_KERNEL::Exception(msg);
2804           }
2805         break;
2806       }
2807     case 7:
2808       {
2809         switch(sw1)
2810           {
2811           case 1:
2812             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2813             return self;
2814           case 2:
2815             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2816             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2817             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2818             return self;
2819           case 3:
2820             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2821             return self;
2822           default:
2823             throw INTERP_KERNEL::Exception(msg);
2824           }
2825         break;
2826       }
2827     case 8:
2828       {
2829         switch(sw1)
2830           {
2831           case 1:
2832             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2833             return self;
2834           case 2:
2835             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2836             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2837             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2838             return self;
2839           case 3:
2840             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2841             return self;
2842           default:
2843             throw INTERP_KERNEL::Exception(msg);
2844           }
2845         break;
2846       }
2847     case 9:
2848       {
2849         switch(sw1)
2850           {
2851           case 1:
2852             self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2853             return self;
2854           case 2:
2855             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2856             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2857             self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2858             return self;
2859           case 3:
2860             self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2861             return self;
2862           default:
2863             throw INTERP_KERNEL::Exception(msg);
2864           }
2865         break;
2866       }
2867     case 10:
2868       {
2869         switch(sw1)
2870           {
2871           case 1:
2872             self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2873             return self;
2874           case 2:
2875             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2876             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2877             self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2878             return self;
2879           case 3:
2880             self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2881             return self;
2882           default:
2883             throw INTERP_KERNEL::Exception(msg);
2884           }
2885         break;
2886       }
2887     case 11:
2888       {
2889         switch(sw1)
2890           {
2891           case 1:
2892             self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2893             return self;
2894           case 2:
2895             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2896             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2897             self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2898             return self;
2899           case 3:
2900             self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2901             return self;
2902           default:
2903             throw INTERP_KERNEL::Exception(msg);
2904           }
2905         break;
2906       }
2907     case 12:
2908       {
2909         switch(sw1)
2910           {
2911           case 1:
2912             self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2913             return self;
2914           case 2:
2915             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2916             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2917             self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2918             return self;
2919           case 3:
2920             self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2921             return self;
2922           default:
2923             throw INTERP_KERNEL::Exception(msg);
2924           }
2925         break;
2926       }
2927     case 13:
2928       {
2929         switch(sw1)
2930           {
2931           case 1:
2932             self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2933             return self;
2934           case 2:
2935             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2936             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2937             self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2938             return self;
2939           case 3:
2940             self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2941             return self;
2942           default:
2943             throw INTERP_KERNEL::Exception(msg);
2944           }
2945         break;
2946       }
2947     case 14:
2948       {
2949         switch(sw1)
2950           {
2951           case 1:
2952             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2953             return self;
2954           case 2:
2955             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2956             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2957             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2958             return self;
2959           case 3:
2960             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2961             return self;
2962           default:
2963             throw INTERP_KERNEL::Exception(msg);
2964           }
2965         break;
2966       }
2967     case 15:
2968       {
2969         switch(sw1)
2970           {
2971           case 1:
2972             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2973             return self;
2974           case 2:
2975             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2976             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2977             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2978             return self;
2979           case 3:
2980             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2981             return self;
2982           default:
2983             throw INTERP_KERNEL::Exception(msg);
2984           }
2985         break;
2986       }
2987     case 16:
2988       {
2989         switch(sw1)
2990           {
2991           case 1:
2992             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2993             return self;
2994           case 2:
2995             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2996             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2997             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
2998             return self;
2999           case 3:
3000             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3001             return self;
3002           default:
3003             throw INTERP_KERNEL::Exception(msg);
3004           }
3005         break;
3006       }
3007     default:
3008       throw INTERP_KERNEL::Exception(msg);
3009     }
3010   return self;
3011 }
3012
3013 template<class T>
3014 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3015 {
3016   const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3017   const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3018   self->checkAllocated();
3019   mcIdType nbOfTuples(self->getNumberOfTuples());
3020   int nbOfComponents((int)(self->getNumberOfComponents()));
3021   mcIdType it1;
3022   std::size_t ic1;
3023   std::vector<mcIdType> vt1;
3024   std::vector<std::size_t> vc1;
3025   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
3026   MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
3027   mcIdType sw;
3028   convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3029   MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3030   switch(sw)
3031     {
3032     case 1:
3033       if(nbOfComponents==1)
3034         return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3035       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3036     case 2:
3037       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3038     case 3:
3039       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3040     case 4:
3041       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3042     case 5:
3043       return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3044     case 6:
3045       {
3046         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3047         std::vector<std::size_t> v2(1,ic1);
3048         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3049       }
3050     case 7:
3051       {
3052         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3053         std::vector<std::size_t> v2(1,ic1);
3054         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3055       }
3056     case 8:
3057       {
3058         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3059         std::vector<std::size_t> v2(1,ic1);
3060         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3061       }
3062     case 9:
3063       {
3064         ret=self->selectByTupleIdSafe(&it1,&it1+1);
3065         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3066       }
3067     case 10:
3068       {
3069         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3070         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3071       }
3072     case 11:
3073       {
3074         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3075         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3076       }
3077     case 12:
3078       {
3079         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3080         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3081       }
3082     case 13:
3083       {
3084         ret=self->selectByTupleIdSafe(&it1,&it1+1);
3085         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3086         std::vector<std::size_t> v2(nbOfComp);
3087         for(mcIdType i=0;i<nbOfComp;i++)
3088           v2[i]=pc1.first+i*pc1.second.second;
3089         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3090       }
3091     case 14:
3092       {
3093         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3094         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3095         std::vector<std::size_t> v2(nbOfComp);
3096         for(int i=0;i<nbOfComp;i++)
3097           v2[i]=pc1.first+i*pc1.second.second;
3098         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3099       }
3100     case 15:
3101       {
3102         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3103         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3104         std::vector<std::size_t> v2(nbOfComp);
3105         for(int i=0;i<nbOfComp;i++)
3106           v2[i]=pc1.first+i*pc1.second.second;
3107         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3108       }
3109     case 16:
3110       {
3111         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3112         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3113         std::vector<std::size_t> v2(nbOfComp);
3114         for(int i=0;i<nbOfComp;i++)
3115           v2[i]=pc1.first+i*pc1.second.second;
3116         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3117       }
3118     default:
3119       throw INTERP_KERNEL::Exception(msg);
3120     }
3121 }
3122
3123 bool isCSRMatrix(PyObject *m)
3124 {
3125 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
3126   PyObject* pdict(PyDict_New());
3127   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
3128   PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
3129   if(!tmp)
3130     throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
3131   PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
3132   if(!csrMatrixCls)
3133     throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
3134   bool ret(PyObject_IsInstance(m,csrMatrixCls));
3135   Py_DECREF(pdict); Py_XDECREF(tmp);
3136   return ret;
3137 #else
3138   return false;
3139 #endif
3140 }
3141
3142 void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
3143 {
3144   auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
3145   if(nbOfRows<0)
3146     throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !");
3147   mCpp.resize(nbOfRows);
3148   auto indPtrCPtr(indptrPtr->begin());
3149   auto indicesCPtr(indicesPtr->begin());
3150   auto dataCPtr(dataPtr->begin());
3151   for(auto i=0;i<nbOfRows;i++)
3152     {
3153       auto& line(mCpp[i]);
3154       for(auto j=indPtrCPtr[i];j<indPtrCPtr[i+1];j++)
3155         {
3156           line[indicesCPtr[j]]=dataCPtr[j];
3157         }
3158     }
3159 }
3160
3161 void convertToVectMapIntDouble(PyObject *pyobj, std::vector<std::map<mcIdType,double> >& mCpp)
3162 {
3163   if(!PyList_Check(pyobj))
3164     throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !");
3165   mCpp.clear();
3166   Py_ssize_t sz(PyList_Size(pyobj));
3167   mCpp.resize(sz);
3168   for(Py_ssize_t i=0;i<sz;i++)
3169     {
3170       PyObject *elt(PyList_GetItem(pyobj,i));
3171       if(!PyDict_Check(elt))
3172         {
3173           std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist a dict is exepect !";
3174           throw INTERP_KERNEL::Exception(oss.str());
3175         }
3176       PyObject *key, *value;
3177       Py_ssize_t pos(0);
3178       std::map<mcIdType,double>& mapCpp(mCpp[i]);
3179       while(PyDict_Next(elt,&pos,&key,&value))
3180         {
3181           if(!PyInt_Check(key))
3182             {
3183               std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !";
3184               throw INTERP_KERNEL::Exception(oss.str());
3185             }
3186           if(!PyFloat_Check(value))
3187             {
3188               std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !";
3189               throw INTERP_KERNEL::Exception(oss.str());
3190             }
3191           mapCpp[ToIdType(PyInt_AS_LONG(key))]=PyFloat_AS_DOUBLE(value);
3192         }
3193     }
3194 }
3195
3196 template<class T>
3197 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3198 {
3199   const char msg[]="Unexpected situation in __imul__ !";
3200   T val;
3201   typename MEDCoupling::Traits<T>::ArrayType *a;
3202   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3203   std::vector<T> bb;
3204   mcIdType sw;
3205   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3206   switch(sw)
3207     {
3208     case 1:
3209       {
3210         self->applyLin(val,0.);
3211         Py_XINCREF(trueSelf);
3212         return trueSelf;
3213       }
3214     case 2:
3215       {
3216         self->multiplyEqual(a);
3217         Py_XINCREF(trueSelf);
3218         return trueSelf;
3219       }
3220     case 3:
3221       {
3222         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3223         self->multiplyEqual(aaa);
3224         Py_XINCREF(trueSelf);
3225         return trueSelf;
3226       }
3227     case 4:
3228       {
3229         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());
3230         self->multiplyEqual(aaa);
3231         Py_XINCREF(trueSelf);
3232         return trueSelf;
3233       }
3234     default:
3235       throw INTERP_KERNEL::Exception(msg);
3236     }
3237 }
3238
3239 template<class T>
3240 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3241 {
3242   const char msg[]="Unexpected situation in __idiv__ !";
3243   T val;
3244   typename MEDCoupling::Traits<T>::ArrayType *a;
3245   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3246   std::vector<T> bb;
3247   mcIdType sw;
3248   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3249   switch(sw)
3250     {
3251     case 1:
3252       {
3253         if(val==0.)
3254           throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3255         self->applyLin((T)(1./val),(T)0.);
3256         Py_XINCREF(trueSelf);
3257         return trueSelf;
3258       }
3259     case 2:
3260       {
3261         self->divideEqual(a);
3262         Py_XINCREF(trueSelf);
3263         return trueSelf;
3264       }
3265     case 3:
3266       {
3267         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3268         self->divideEqual(aaa);
3269         Py_XINCREF(trueSelf);
3270         return trueSelf;
3271       }
3272     case 4:
3273       {
3274         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());
3275         self->divideEqual(aaa);
3276         Py_XINCREF(trueSelf);
3277         return trueSelf;
3278       }
3279     default:
3280       throw INTERP_KERNEL::Exception(msg);
3281     }
3282 }
3283
3284 template<class T>
3285 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3286 {
3287   const char msg[]="Unexpected situation in __iadd__ !";
3288   T val;
3289   typename MEDCoupling::Traits<T>::ArrayType *a;
3290   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3291   std::vector<T> bb;
3292   mcIdType sw;
3293   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3294   switch(sw)
3295     {
3296     case 1:
3297       {
3298         self->applyLin(1.,val);
3299         Py_XINCREF(trueSelf);
3300         return trueSelf;
3301       }
3302     case 2:
3303       {
3304         self->addEqual(a);
3305         Py_XINCREF(trueSelf);
3306         return trueSelf;
3307       }
3308     case 3:
3309       {
3310         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3311         self->addEqual(aaa);
3312         Py_XINCREF(trueSelf);
3313         return trueSelf;
3314       }
3315     case 4:
3316       {
3317         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());
3318         self->addEqual(aaa);
3319         Py_XINCREF(trueSelf);
3320         return trueSelf;
3321       }
3322     default:
3323       throw INTERP_KERNEL::Exception(msg);
3324     }
3325 }
3326
3327 template<class T>
3328 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3329 {
3330   const char msg[]="Unexpected situation in __isub__ !";
3331   T val;
3332   typename MEDCoupling::Traits<T>::ArrayType *a;
3333   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3334   std::vector<T> bb;
3335   mcIdType sw;
3336   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3337   switch(sw)
3338     {
3339     case 1:
3340       {
3341         self->applyLin(1.,-val);
3342         Py_XINCREF(trueSelf);
3343         return trueSelf;
3344       }
3345     case 2:
3346       {
3347         self->substractEqual(a);
3348         Py_XINCREF(trueSelf);
3349         return trueSelf;
3350       }
3351     case 3:
3352       {
3353         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3354         self->substractEqual(aaa);
3355         Py_XINCREF(trueSelf);
3356         return trueSelf;
3357       }
3358     case 4:
3359       {
3360         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());
3361         self->substractEqual(aaa);
3362         Py_XINCREF(trueSelf);
3363         return trueSelf;
3364       }
3365     default:
3366       throw INTERP_KERNEL::Exception(msg);
3367     }
3368 }
3369
3370 #ifdef WITH_NUMPY
3371 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3372
3373 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3374
3375 PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
3376
3377 PyTypeObject *NPYTraits<MEDCoupling::Int64>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
3378 #endif
3379
3380 template<class T>
3381 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3382 {
3383   return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3384 }
3385
3386 template<class T>
3387 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3388 {
3389   return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3390 }
3391
3392 template<class T>
3393 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3394 {
3395   return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3396 }
3397
3398 template<class T>
3399 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3400 {
3401   return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3402 }
3403
3404 template<class T>
3405 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3406 {
3407   return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3408 }
3409
3410 template<class T>
3411 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3412 {
3413   return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3414 }
3415
3416 template<class T>
3417 typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3418 {
3419   const char msg[]="Unexpected situation in __rmul__ !";
3420   T val;
3421   typename MEDCoupling::Traits<T>::ArrayType *a;
3422   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3423   std::vector<T> bb;
3424   mcIdType sw;
3425   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3426   switch(sw)
3427     {
3428     case 1:
3429       {
3430         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
3431         ret->applyLin(val,0.);
3432         return ret.retn();
3433       }
3434     case 3:
3435       {
3436         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
3437         return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3438       }
3439     case 4:
3440       {
3441         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());
3442         return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3443       }
3444     default:
3445       throw INTERP_KERNEL::Exception(msg);
3446     }
3447 }
3448
3449 #endif