Salome HOME
cc99dc9bbd7c50f5a96e099b2df78ac9d4571cd6
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
1 // Copyright (C) 2007-2019  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 /*!
1393  * if python int -> cpp int sw=1
1394  * if python list[int] -> cpp vector<int> sw=2
1395  * if python tuple[int] -> cpp vector<int> sw=2
1396  * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1397  * if python DataArrayIntTuple -> cpp DataArrayIdTypeTuple sw=4
1398  *
1399  * switch between (int,vector<int>,DataArrayIdType)
1400  */
1401 template< class T, class ARRAY >
1402 static void convertIntStarLikePyObjToCpp(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, ARRAY *& daIntTyypp, typename MEDCoupling::Traits< T >::ArrayTuple *&daIntTuple)
1403 {
1404   sw=-1;
1405   if(PyInt_Check(value))
1406     {
1407       iTyypp=(T)PyInt_AS_LONG(value);
1408       sw=1;
1409       return;
1410     }
1411   if(PyTuple_Check(value))
1412     {
1413       std::size_t size=PyTuple_Size(value);
1414       stdvecTyypp.resize(size);
1415       for(std::size_t i=0;i<size;i++)
1416         {
1417           PyObject *o=PyTuple_GetItem(value,i);
1418           if(PyInt_Check(o))
1419             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1420           else
1421             {
1422               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1423               throw INTERP_KERNEL::Exception(oss.str().c_str());
1424             }
1425         }
1426       sw=2;
1427       return;
1428     }
1429   if(PyList_Check(value))
1430     {
1431       std::size_t size=PyList_Size(value);
1432       stdvecTyypp.resize(size);
1433       for(std::size_t i=0;i<size;i++)
1434         {
1435           PyObject *o=PyList_GetItem(value,i);
1436           if(PyInt_Check(o))
1437             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1438           else
1439             {
1440               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1441               throw INTERP_KERNEL::Exception(oss.str().c_str());
1442             }
1443         }
1444       sw=2;
1445       return;
1446     }
1447   void *argp;
1448   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1449   if(SWIG_IsOK(status))
1450     {
1451       daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1452       sw=3;
1453       return;
1454     }
1455   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1456   if(SWIG_IsOK(status))
1457     {
1458       daIntTuple=reinterpret_cast< typename MEDCoupling::Traits< T >::ArrayTuple * >(argp);
1459       sw=4;
1460       return ;
1461     }
1462   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1463 }
1464
1465 /*!
1466  * if python int -> cpp int sw=1
1467  * if python list[int] -> cpp vector<int> sw=2
1468  * if python tuple[int] -> cpp vector<int> sw=2
1469  * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1470  * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4
1471  *
1472  * switch between (int,vector<int>,DataArrayIdType)
1473  */
1474 template< class T >
1475 static const T *convertIntStarLikePyObjToCppIntStar(PyObject *value, mcIdType& sw, mcIdType& sz, T& iTyypp, std::vector<T>& stdvecTyypp)
1476 {
1477   sw=-1;
1478   if(PyInt_Check(value))
1479     {
1480       iTyypp=(T)PyInt_AS_LONG(value);
1481       sw=1; sz=1;
1482       return &iTyypp;
1483     }
1484   if(PyTuple_Check(value))
1485     {
1486       std::size_t size=PyTuple_Size(value);
1487       stdvecTyypp.resize(size);
1488       for(std::size_t i=0;i<size;i++)
1489         {
1490           PyObject *o=PyTuple_GetItem(value,i);
1491           if(PyInt_Check(o))
1492             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1493           else
1494             {
1495               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1496               throw INTERP_KERNEL::Exception(oss.str().c_str());
1497             }
1498         }
1499       sw=2; sz=ToIdType(size);
1500       return &stdvecTyypp[0];
1501     }
1502   if(PyList_Check(value))
1503     {
1504       std::size_t size=PyList_Size(value);
1505       stdvecTyypp.resize(size);
1506       for(std::size_t i=0;i<size;i++)
1507         {
1508           PyObject *o=PyList_GetItem(value,i);
1509           if(PyInt_Check(o))
1510             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1511           else
1512             {
1513               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1514               throw INTERP_KERNEL::Exception(oss.str().c_str());
1515             }
1516         }
1517       sw=2; sz=ToIdType(size);
1518       return &stdvecTyypp[0];
1519     }
1520   void *argp;
1521   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI,0|0);
1522   if(SWIG_IsOK(status))
1523     {
1524       typedef typename MEDCoupling::Traits< T >::ArrayType ARRAY;
1525       ARRAY *daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1526       if(daIntTyypp)
1527         {
1528           sw=3; sz=daIntTyypp->getNbOfElems();
1529           return daIntTyypp->begin();
1530         }
1531       else
1532         {
1533           sz=0;
1534           return 0;
1535         }
1536     }
1537   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1538   if(SWIG_IsOK(status))
1539     {
1540       typedef typename MEDCoupling::Traits< T >::ArrayTuple ARRAYTUPLE;
1541       ARRAYTUPLE *daIntTuple=reinterpret_cast< ARRAYTUPLE * >(argp);
1542       sw=4; sz=ToIdType(daIntTuple->getNumberOfCompo());
1543       return daIntTuple->getConstPointer();
1544     }
1545   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1546 }
1547
1548 /*!
1549  * if python double -> cpp double sw=1
1550  * if python int -> cpp double sw=1
1551  * if python list[double] -> cpp vector<double> sw=2
1552  * if python list[int] -> cpp vector<double> sw=2
1553  * if python tuple[double] -> cpp vector<double> sw=2
1554  * if python tuple[int] -> cpp vector<double> sw=2
1555  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1556  *
1557  * switch between (int,vector<int>,DataArrayIdType)
1558  */
1559 template<class T>
1560 void considerPyObjAsATStarLikeObject(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1561 {
1562   sw=-1;
1563   if(PyFloat_Check(value))
1564     {
1565       iTyypp=(T)PyFloat_AS_DOUBLE(value);
1566       sw=1;
1567       return;
1568     }
1569   if(PyInt_Check(value))
1570     {
1571       iTyypp=(T)PyInt_AS_LONG(value);
1572       sw=1;
1573       return;
1574     }
1575   if(PyTuple_Check(value))
1576     {
1577       std::size_t size=PyTuple_Size(value);
1578       stdvecTyypp.resize(size);
1579       for(std::size_t i=0;i<size;i++)
1580         {
1581           PyObject *o=PyTuple_GetItem(value,i);
1582           if(PyFloat_Check(o))
1583             stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1584           else if(PyInt_Check(o))
1585             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1586           else
1587             {
1588               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1589               throw INTERP_KERNEL::Exception(oss.str().c_str());
1590             }
1591         }
1592       sw=2;
1593       return;
1594     }
1595   if(PyList_Check(value))
1596     {
1597       std::size_t size=PyList_Size(value);
1598       stdvecTyypp.resize(size);
1599       for(std::size_t i=0;i<size;i++)
1600         {
1601           PyObject *o=PyList_GetItem(value,i);
1602           if(PyFloat_Check(o))
1603             stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1604           else if(PyInt_Check(o))
1605             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1606           else
1607             {
1608               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1609               throw INTERP_KERNEL::Exception(oss.str().c_str());
1610             }
1611         }
1612       sw=2;
1613       return;
1614     }
1615   void *argp;
1616   int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1617   if(!SWIG_IsOK(status))
1618     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1619   daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1620   sw=3;
1621 }
1622
1623 /*!
1624  * if python double -> cpp double sw=1
1625  * if python int -> cpp double sw=1
1626  * if python list[double] -> cpp vector<double> sw=2
1627  * if python list[int] -> cpp vector<double> sw=2
1628  * if python tuple[double] -> cpp vector<double> sw=2
1629  * if python tuple[int] -> cpp vector<double> sw=2
1630  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1631  *
1632  * switch between (int,vector<int>,DataArrayIdType)
1633  */
1634 static void convertDoubleStarLikePyObjToCpp(PyObject *value, mcIdType& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1635 {
1636   sw=-1;
1637   if(PyFloat_Check(value))
1638     {
1639       iTyypp=PyFloat_AS_DOUBLE(value);
1640       sw=1;
1641       return;
1642     }
1643   if(PyInt_Check(value))
1644     {
1645       iTyypp=(double)PyInt_AS_LONG(value);
1646       sw=1;
1647       return;
1648     }
1649   if(PyTuple_Check(value))
1650     {
1651       std::size_t size=PyTuple_Size(value);
1652       stdvecTyypp.resize(size);
1653       for(std::size_t i=0;i<size;i++)
1654         {
1655           PyObject *o=PyTuple_GetItem(value,i);
1656           if(PyFloat_Check(o))
1657             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1658           else if(PyInt_Check(o))
1659             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1660           else
1661             {
1662               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1663               throw INTERP_KERNEL::Exception(oss.str().c_str());
1664             }
1665         }
1666       sw=2;
1667       return;
1668     }
1669   if(PyList_Check(value))
1670     {
1671       std::size_t size=PyList_Size(value);
1672       stdvecTyypp.resize(size);
1673       for(std::size_t i=0;i<size;i++)
1674         {
1675           PyObject *o=PyList_GetItem(value,i);
1676           if(PyFloat_Check(o))
1677             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1678           else if(PyInt_Check(o))
1679             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1680           else
1681             {
1682               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1683               throw INTERP_KERNEL::Exception(oss.str().c_str());
1684             }
1685         }
1686       sw=2;
1687       return;
1688     }
1689   void *argp;
1690   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1691   if(!SWIG_IsOK(status))
1692     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1693   daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1694   sw=3;
1695 }
1696
1697 template<class T>
1698 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)
1699 {
1700   sw=-1;
1701   if(PyFloat_Check(value))
1702     {
1703       val=(T)PyFloat_AS_DOUBLE(value);
1704       sw=1;
1705       return;
1706     }
1707   if(PyInt_Check(value))
1708     {
1709       val=(T)PyInt_AS_LONG(value);
1710       sw=1;
1711       return;
1712     }
1713   if(PyTuple_Check(value))
1714     {
1715       std::size_t size=PyTuple_Size(value);
1716       f.resize(size);
1717       for(std::size_t i=0;i<size;i++)
1718         {
1719           PyObject *o=PyTuple_GetItem(value,i);
1720           if(PyFloat_Check(o))
1721             f[i]=(T)PyFloat_AS_DOUBLE(o);
1722           else if(PyInt_Check(o))
1723             f[i]=(T)PyInt_AS_LONG(o);
1724           else
1725             {
1726               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1727               throw INTERP_KERNEL::Exception(oss.str().c_str());
1728             }
1729         }
1730       sw=4;
1731       return;
1732     }
1733   if(PyList_Check(value))
1734     {
1735       std::size_t size=PyList_Size(value);
1736       f.resize(size);
1737       for(std::size_t i=0;i<size;i++)
1738         {
1739           PyObject *o=PyList_GetItem(value,i);
1740           if(PyFloat_Check(o))
1741             f[i]=(T)PyFloat_AS_DOUBLE(o);
1742           else if(PyInt_Check(o))
1743             f[i]=(T)PyInt_AS_LONG(o);
1744           else
1745             {
1746               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1747               throw INTERP_KERNEL::Exception(oss.str().c_str());
1748             }
1749         }
1750       sw=4;
1751       return;
1752     }
1753   void *argp;
1754   int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1755   if(SWIG_IsOK(status))
1756     {
1757       d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1758       sw=2;
1759       return ;
1760     }
1761   status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1762   if(SWIG_IsOK(status))
1763     {
1764       e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1765       sw=3;
1766       return ;
1767     }
1768   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1769 }
1770
1771 /*!
1772  * if value int -> cpp val sw=1
1773  * if value double -> cpp val sw=1
1774  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1775  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1776  * if value list[int,double] -> cpp std::vector<double> sw=4
1777  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1778  */
1779 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1780 {
1781   convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1782 }
1783
1784 /*!
1785  * if value int -> cpp val sw=1
1786  * if value double -> cpp val sw=1
1787  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1788  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1789  * if value list[int,double] -> cpp std::vector<double> sw=4
1790  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1791  */
1792 static void convertFloatStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
1793 {
1794   convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
1795 }
1796
1797 /*!
1798  * if python int -> cpp int sw=1
1799  * if python list[int] -> cpp vector<int> sw=2
1800  * if python tuple[int] -> cpp vector<int> sw=2
1801  * if python slicp -> cpp pair sw=3 (begin,end,step)
1802  * if python DataArrayIdType -> cpp DataArrayIdType sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1803  *
1804  * switch between (int,vector<int>,DataArrayIdType)
1805  */
1806 template<class T, class ARRAY>
1807 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)
1808 {
1809   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdType, DataArrayIdTypeTuple";
1810   sw=-1;
1811   if(PyInt_Check(value))
1812     {
1813       iTyypp=(T)PyInt_AS_LONG(value);
1814       sw=1;
1815       return;
1816     }
1817   if(PyTuple_Check(value))
1818     {
1819       std::size_t size=PyTuple_Size(value);
1820       stdvecTyypp.resize(size);
1821       for(std::size_t i=0;i<size;i++)
1822         {
1823           PyObject *o=PyTuple_GetItem(value,i);
1824           if(PyInt_Check(o))
1825             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1826           else
1827             {
1828               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1829               throw INTERP_KERNEL::Exception(oss.str().c_str());
1830             }
1831         }
1832       sw=2;
1833       return;
1834     }
1835   if(PyList_Check(value))
1836     {
1837       std::size_t size=PyList_Size(value);
1838       stdvecTyypp.resize(size);
1839       for(std::size_t i=0;i<size;i++)
1840         {
1841           PyObject *o=PyList_GetItem(value,i);
1842           if(PyInt_Check(o))
1843             stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1844           else
1845             {
1846               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1847               throw INTERP_KERNEL::Exception(oss.str().c_str());
1848             }
1849         }
1850       sw=2;
1851       return;
1852     }
1853   if(PySlice_Check(value))
1854     {
1855       Py_ssize_t strt=2,stp=2,step=2;
1856       GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1857       p.first=ToIdType(strt);
1858       p.second.first=ToIdType(stp);
1859       p.second.second=ToIdType(step);
1860       sw=3;
1861       return ;
1862     }
1863   void *argp;
1864   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1865   if(SWIG_IsOK(status))
1866     {
1867       daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1868       if(!daIntTyypp)
1869         {
1870           std::ostringstream oss; oss << msg << " Instance in null !";
1871           throw INTERP_KERNEL::Exception(oss.str().c_str());
1872         }
1873       sw=4;
1874       return ;
1875     }
1876   status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI_TUPLE,0|0);
1877   if(SWIG_IsOK(status))
1878     {
1879       typedef typename MEDCoupling::Traits< typename ARRAY::Type >::ArrayTuple ARRAYTUPLE;
1880       ARRAYTUPLE *tmp=reinterpret_cast< ARRAYTUPLE * >(argp);
1881       if(!tmp)
1882         {
1883           std::ostringstream oss; oss << msg << " Instance in null !";
1884           throw INTERP_KERNEL::Exception(oss.str().c_str());
1885         }
1886       stdvecTyypp.resize(tmp->getNumberOfCompo());
1887       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1888       sw=2;
1889       return ;
1890     }
1891   throw INTERP_KERNEL::Exception(msg);
1892 }
1893
1894 /*!
1895  * Idem than convertIntStarOrSliceLikePyObjToCpp
1896  */
1897 template<class T, class ARRAY>
1898 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)
1899 {
1900   convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1901   if(sw==1)
1902     {
1903       iTyypp=(T)InterpreteNegativeInt(iTyypp,nbelem);
1904     }
1905 }
1906
1907 /*!
1908  * if python int -> cpp int sw=1
1909  * if python tuple[int] -> cpp vector<int> sw=2
1910  * if python list[int] -> cpp vector<int> sw=2
1911  * if python slice -> cpp pair sw=3
1912  * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4 . WARNING The returned pointer can be the null pointer !
1913  */
1914 template< class TUPLE_T >
1915 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)
1916 {
1917   sw=-1;
1918   if(PyInt_Check(value))
1919     {
1920       iTyypp=ToIdType(PyInt_AS_LONG(value));
1921       sw=1;
1922       return;
1923     }
1924   if(PyTuple_Check(value))
1925     {
1926       std::size_t size=PyTuple_Size(value);
1927       stdvecTyypp.resize(size);
1928       for(std::size_t i=0;i<size;i++)
1929         {
1930           PyObject *o=PyTuple_GetItem(value,i);
1931           if(PyInt_Check(o))
1932             stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1933           else
1934             {
1935               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1936               throw INTERP_KERNEL::Exception(oss.str().c_str());
1937             }
1938         }
1939       sw=2;
1940       return;
1941     }
1942   if(PyList_Check(value))
1943     {
1944       std::size_t size=PyList_Size(value);
1945       stdvecTyypp.resize(size);
1946       for(std::size_t i=0;i<size;i++)
1947         {
1948           PyObject *o=PyList_GetItem(value,i);
1949           if(PyInt_Check(o))
1950             stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1951           else
1952             {
1953               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1954               throw INTERP_KERNEL::Exception(oss.str().c_str());
1955             }
1956         }
1957       sw=2;
1958       return;
1959     }
1960   if(PySlice_Check(value))
1961     {
1962       Py_ssize_t strt=2,stp=2,step=2;
1963       GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1964       p.first=ToIdType(strt);
1965       p.second.first=ToIdType(stp);
1966       p.second.second=ToIdType(step);
1967       sw=3;
1968       return ;
1969     }
1970   void *argp;
1971   int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<TUPLE_T>::TI_TUPLE,0|0);
1972   if(!SWIG_IsOK(status))
1973     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdTypeTuple");
1974   daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple * >(argp);
1975   sw=4;
1976 }
1977
1978 /*!
1979  * if python string with size one -> cpp char sw=1
1980  * if python string with size different from one -> cpp string sw=2
1981  * if python tuple[string] or list[string] -> vector<string> sw=3
1982  * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1983  * switch between (int,string,vector<string>,DataArrayChar)
1984  */
1985 static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
1986 {
1987   const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1988   sw=-1;
1989   if(PyString_Check(value))
1990     {
1991       const char *pt=PyString_AsString(value);
1992       Py_ssize_t sz=PyString_Size(value);
1993       if(sz==1)
1994         {
1995           cTyp=pt[0];
1996           sw=1;
1997           return;
1998         }
1999       else
2000         {
2001           sType=pt;
2002           sw=2;
2003           return;
2004         }
2005     }
2006 #if PY_VERSION_HEX >= 0x03000000
2007   if(PyUnicode_Check(value))
2008     {
2009       Py_ssize_t sz;
2010       const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
2011       if(sz==1)
2012         {
2013           cTyp=pt[0];
2014           sw=1;
2015           return;
2016         }
2017       else
2018         {
2019           sType=pt;
2020           sw=2;
2021           return;
2022         }
2023     }
2024 #endif
2025   if(PyTuple_Check(value))
2026     {
2027       std::size_t size=PyTuple_Size(value);
2028       vsType.resize(size);
2029       for(std::size_t i=0;i<size;i++)
2030         {
2031           PyObject *o=PyTuple_GetItem(value,i);
2032           try
2033             {
2034               vsType[i]=convertPyObjectToStr(o);
2035             }
2036           catch(INTERP_KERNEL::Exception& e)
2037             {
2038               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2039               throw INTERP_KERNEL::Exception(oss.str().c_str());
2040             }
2041         }
2042       sw=3;
2043       return;
2044     }
2045   if(PyList_Check(value))
2046     {
2047       std::size_t size=PyList_Size(value);
2048       vsType.resize(size);
2049       for(std::size_t i=0;i<size;i++)
2050         {
2051           PyObject *o=PyList_GetItem(value,i);
2052           try
2053             {
2054               vsType[i]=convertPyObjectToStr(o);
2055             }
2056           catch(INTERP_KERNEL::Exception& e)
2057             {
2058               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2059               throw INTERP_KERNEL::Exception(oss.str().c_str());
2060             }
2061         }
2062       sw=3;
2063       return;
2064     }
2065   void *argp;
2066   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
2067   if(SWIG_IsOK(status))
2068     {
2069       dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
2070       if(!dacType)
2071         {
2072           std::ostringstream oss; oss << msg << " Instance in null !";
2073           throw INTERP_KERNEL::Exception(oss.str().c_str());
2074         }
2075       sw=4;
2076       return ;
2077     }
2078   throw INTERP_KERNEL::Exception(msg);
2079 }
2080
2081 /*!
2082  * if value int -> cpp it sw=1
2083  * if value list[int] -> vt sw=2
2084  * if value tuple[int] -> vt sw=2
2085  * if value slice -> pt sw=3
2086  * if value DataArrayIdType -> dt sw=4
2087  * if value tuple [int,int] -> cpp it,ip sw=5
2088  * if value tuple [list[int],int] -> cpp vt,ip sw=6
2089  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2090  * if value tuple [slice,int] -> cpp pt,ip sw=7
2091  * if value tuple [DaI,int] -> cpp dt,ip sw=8
2092  * if value tuple [int,list[int]] -> cpp it,vc sw=9
2093  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2094  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2095  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2096  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2097  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2098  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2099  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2100  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2101  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2102  * if value tuple [int,slice] -> cpp it,pc sw=13
2103  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2104  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2105  * if value tuple [slice,slice] -> cpp pt,pc sw=15
2106  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2107  *
2108  * switch between (int,vector<int>,DataArrayIdType)
2109  */
2110 template<class TC>
2111 static void convertObjToPossibleCpp3(PyObject *value, mcIdType nbTuple, int nbCompo, mcIdType& sw, mcIdType& it, TC& ic, std::vector<mcIdType>& vt, std::vector<TC>& vc,
2112                                      std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pt, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pc,
2113                                      MEDCoupling::DataArrayIdType *&dt, MEDCoupling::DataArrayIdType *&dc)
2114 {
2115   if(!PyTuple_Check(value))
2116     {
2117       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2118       return ;
2119     }
2120   else
2121     {
2122       std::size_t sz=PyTuple_Size(value);
2123       if(sz!=2)
2124         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2125       PyObject *ob0=PyTuple_GetItem(value,0);
2126       mcIdType sw1,sw2;
2127       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2128       PyObject *ob1=PyTuple_GetItem(value,1);
2129       convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2130       sw=4*sw2+sw1;
2131     }
2132 }
2133
2134 /*!
2135  * if value int -> cpp val sw=1
2136  * if value double -> cpp val sw=1
2137  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2138  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2139  * if value list[int,double] -> cpp std::vector<double> sw=4
2140  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2141  */
2142 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2143                                                    const char *msg, mcIdType nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2144 {
2145   sw=-1;
2146   if(PyFloat_Check(value))
2147     {
2148       val=PyFloat_AS_DOUBLE(value);
2149       sw=1;
2150       if(nbTuplesExpected*nbCompExpected!=1)
2151         {
2152           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2153           throw INTERP_KERNEL::Exception(oss.str().c_str());
2154         }
2155       return &val;
2156     }
2157   if(PyInt_Check(value))
2158     {
2159       val=(double)PyInt_AS_LONG(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 PyInt) !";
2164           throw INTERP_KERNEL::Exception(oss.str().c_str());
2165         }
2166       return &val;
2167     }
2168   if(PyTuple_Check(value) || PyList_Check(value))
2169     {
2170       try
2171         {
2172           mcIdType tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2173           std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2174           sw=4;
2175           f=ret;
2176           return &f[0];
2177         }
2178       catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2179     }
2180   void *argp;
2181   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2182   if(SWIG_IsOK(status))
2183     {
2184       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2185       sw=2;
2186       if(d)
2187         {
2188           if(d->getNumberOfTuples()==nbTuplesExpected)
2189             {
2190               if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2191                 {
2192                   return d->getConstPointer();
2193                 }
2194               else
2195                 {
2196                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2197                   throw INTERP_KERNEL::Exception(oss.str().c_str());
2198                 }
2199             }
2200           else
2201             {
2202               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2203               throw INTERP_KERNEL::Exception(oss.str().c_str());
2204             }
2205         }
2206       else
2207         {
2208           if(throwIfNullPt)
2209             {
2210               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2211               throw INTERP_KERNEL::Exception(oss.str().c_str());
2212             }
2213           else
2214             return 0;
2215         }
2216     }
2217   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2218   if(SWIG_IsOK(status))
2219     {
2220       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2221       sw=3;
2222       if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2223         {
2224           if(nbTuplesExpected==1)
2225             return e->getConstPointer();
2226           else
2227             {
2228               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by construction !";
2229               throw INTERP_KERNEL::Exception(oss.str().c_str());
2230             }
2231         }
2232       else
2233         {
2234           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2235           throw INTERP_KERNEL::Exception(oss.str().c_str());
2236         }
2237     }
2238   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2239 }
2240
2241 /*!
2242  * if value int -> cpp val sw=1
2243  * if value double -> cpp val sw=1
2244  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2245  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2246  * if value list[int,double] -> cpp std::vector<double> sw=4
2247  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2248  */
2249 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2250                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, mcIdType& nbTuples)
2251 {
2252   sw=-1;
2253   if(PyFloat_Check(value))
2254     {
2255       val=PyFloat_AS_DOUBLE(value);
2256       sw=1;
2257       if(nbCompExpected!=1)
2258         {
2259           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2260           throw INTERP_KERNEL::Exception(oss.str().c_str());
2261         }
2262       nbTuples=1;
2263       return &val;
2264     }
2265   if(PyInt_Check(value))
2266     {
2267       val=(double)PyInt_AS_LONG(value);
2268       sw=1;
2269       if(nbCompExpected!=1)
2270         {
2271           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2272           throw INTERP_KERNEL::Exception(oss.str().c_str());
2273         }
2274       nbTuples=1;
2275       return &val;
2276     }
2277   if(PyTuple_Check(value))
2278     {
2279       std::size_t size=PyTuple_Size(value);
2280       f.resize(size);
2281       for(std::size_t i=0;i<size;i++)
2282         {
2283           PyObject *o=PyTuple_GetItem(value,i);
2284           if(PyFloat_Check(o))
2285             f[i]=PyFloat_AS_DOUBLE(o);
2286           else if(PyInt_Check(o))
2287             f[i]=(double)PyInt_AS_LONG(o);
2288           else
2289             {
2290               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2291               throw INTERP_KERNEL::Exception(oss.str().c_str());
2292             }
2293         }
2294       sw=4;
2295       if(size%nbCompExpected!=0)
2296         {
2297           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2298           throw INTERP_KERNEL::Exception(oss.str().c_str());
2299         }
2300       nbTuples=ToIdType(size/nbCompExpected);
2301       return &f[0];
2302     }
2303   if(PyList_Check(value))
2304     {
2305       std::size_t size=PyList_Size(value);
2306       f.resize(size);
2307       for(std::size_t i=0;i<size;i++)
2308         {
2309           PyObject *o=PyList_GetItem(value,i);
2310           if(PyFloat_Check(o))
2311             f[i]=PyFloat_AS_DOUBLE(o);
2312           else if(PyInt_Check(o))
2313             f[i]=(double)PyInt_AS_LONG(o);
2314           else
2315             {
2316               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2317               throw INTERP_KERNEL::Exception(oss.str().c_str());
2318             }
2319         }
2320       sw=4;
2321       if(size%nbCompExpected!=0)
2322         {
2323           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2324           throw INTERP_KERNEL::Exception(oss.str().c_str());
2325         }
2326       nbTuples=ToIdType(size/nbCompExpected);
2327       return &f[0];
2328     }
2329   void *argp;
2330   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2331   if(SWIG_IsOK(status))
2332     {
2333       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2334       sw=2;
2335       if(d)
2336         {
2337           if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2338             {
2339               nbTuples=d->getNumberOfTuples();
2340               return d->getConstPointer();
2341             }
2342           else
2343             {
2344               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2345               throw INTERP_KERNEL::Exception(oss.str().c_str());
2346             }
2347         }
2348       else
2349         {
2350           if(throwIfNullPt)
2351             {
2352               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2353               throw INTERP_KERNEL::Exception(oss.str().c_str());
2354             }
2355           else
2356             { nbTuples=0; return 0; }
2357         }
2358     }
2359   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2360   if(SWIG_IsOK(status))
2361     {
2362       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2363       sw=3;
2364       if(e)
2365         {
2366           if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2367             {
2368               nbTuples=1;
2369               return e->getConstPointer();
2370             }
2371           else
2372             {
2373               std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2374               throw INTERP_KERNEL::Exception(oss.str().c_str());
2375             }
2376         }
2377       else
2378         {
2379           if(throwIfNullPt)
2380             {
2381               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2382               throw INTERP_KERNEL::Exception(oss.str().c_str());
2383             }
2384           else
2385             { nbTuples=0; return 0; }
2386         }
2387     }
2388   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2389 }
2390
2391 /*!
2392  * if value int -> cpp val sw=1
2393  * if value double -> cpp val sw=1
2394  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2395  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2396  * if value list[int,double] -> cpp std::vector<double> sw=4
2397  * if value tuple[int,double] -> cpp std::vector<double> sw=4
2398  */
2399 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, mcIdType& sw, double& val, std::vector<double>& f,
2400                                                           const char *msg, bool throwIfNullPt, mcIdType& nbTuples)
2401 {
2402   MEDCoupling::DataArrayDouble *d=0;
2403   MEDCoupling::DataArrayDoubleTuple *e=0;
2404   sw=-1;
2405   if(PyFloat_Check(value))
2406     {
2407       val=PyFloat_AS_DOUBLE(value);
2408       sw=1;
2409       nbTuples=1;
2410       return &val;
2411     }
2412   if(PyInt_Check(value))
2413     {
2414       val=(double)PyInt_AS_LONG(value);
2415       sw=1;
2416       nbTuples=1;
2417       return &val;
2418     }
2419   if(PyTuple_Check(value))
2420     {
2421       std::size_t size=PyTuple_Size(value);
2422       f.resize(size);
2423       for(std::size_t i=0;i<size;i++)
2424         {
2425           PyObject *o=PyTuple_GetItem(value,i);
2426           if(PyFloat_Check(o))
2427             f[i]=PyFloat_AS_DOUBLE(o);
2428           else if(PyInt_Check(o))
2429             f[i]=(double)PyInt_AS_LONG(o);
2430           else
2431             {
2432               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2433               throw INTERP_KERNEL::Exception(oss.str().c_str());
2434             }
2435         }
2436       sw=4;
2437       nbTuples=ToIdType(size);
2438       return &f[0];
2439     }
2440   if(PyList_Check(value))
2441     {
2442       std::size_t size=PyList_Size(value);
2443       f.resize(size);
2444       for(std::size_t i=0;i<size;i++)
2445         {
2446           PyObject *o=PyList_GetItem(value,i);
2447           if(PyFloat_Check(o))
2448             f[i]=PyFloat_AS_DOUBLE(o);
2449           else if(PyInt_Check(o))
2450             f[i]=(double)PyInt_AS_LONG(o);
2451           else
2452             {
2453               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2454               throw INTERP_KERNEL::Exception(oss.str().c_str());
2455             }
2456         }
2457       sw=4;
2458       nbTuples=ToIdType(size);
2459       return &f[0];
2460     }
2461   void *argp;
2462   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2463   if(SWIG_IsOK(status))
2464     {
2465       d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2466       sw=2;
2467       if(d)
2468         {
2469           if(d->getNumberOfComponents()==1)
2470             {
2471               nbTuples=d->getNumberOfTuples();
2472               return d->getConstPointer();
2473             }
2474           else
2475             {
2476               std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2477               throw INTERP_KERNEL::Exception(oss.str().c_str());
2478             }
2479         }
2480       else
2481         {
2482           if(throwIfNullPt)
2483             {
2484               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2485               throw INTERP_KERNEL::Exception(oss.str().c_str());
2486             }
2487           else
2488             { nbTuples=0; return 0; }
2489         }
2490     }
2491   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2492   if(SWIG_IsOK(status))
2493     {
2494       e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2495       sw=3;
2496       if(e)
2497         {
2498           nbTuples=ToIdType(e->getNumberOfCompo());
2499           return e->getConstPointer();
2500         }
2501       else
2502         {
2503           if(throwIfNullPt)
2504             {
2505               std::ostringstream oss; oss << msg << " null pointer not accepted!";
2506               throw INTERP_KERNEL::Exception(oss.str().c_str());
2507             }
2508           else
2509             { nbTuples=0; return 0; }
2510         }
2511     }
2512   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2513 }
2514
2515 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2516 {
2517   void *aBasePtrVS=0;
2518   int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2519   if(!SWIG_IsOK(status))
2520     {
2521       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2522       if(!SWIG_IsOK(status))
2523         {
2524           status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt32,0|0);
2525           if(!SWIG_IsOK(status))
2526             {
2527               status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt64,0|0);
2528               if(!SWIG_IsOK(status))
2529                 {
2530                   status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2531                   if(!SWIG_IsOK(status))
2532                     {
2533                       status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2534                       std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayIdType, DataArrayAsciiChar, DataArrayByte !";
2535                       throw INTERP_KERNEL::Exception(oss.str().c_str());
2536                     }
2537                 }
2538             }
2539         }
2540     }
2541   return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2542 }
2543
2544 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2545 {
2546   PyObject *ret=0;
2547   if(!pd)
2548     {
2549       Py_XINCREF(Py_None);
2550       return Py_None;
2551     }
2552   if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2553     ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2554   else
2555     ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2556   return ret;
2557 }
2558
2559 template<class T>
2560 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2561 {
2562   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)";
2563   std::string msg(msgBase);
2564 #ifdef WITH_NUMPY
2565   msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2566 #endif
2567   msg+=" !";
2568   if(PyList_Check(elt0) || PyTuple_Check(elt0))
2569     {
2570       if(nbOfTuples)
2571         {
2572           if(PyInt_Check(nbOfTuples))
2573             {
2574               mcIdType nbOfTuples1=ToIdType(PyInt_AS_LONG(nbOfTuples));
2575               if(nbOfTuples1<0)
2576                 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2577               if(elt2)
2578                 {
2579                   if(PyInt_Check(elt2))
2580                     {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2581                       mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(elt2));
2582                       if(nbOfCompo<0)
2583                         throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2584                       MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2585                       std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2586                       ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2587                       return ret.retn();
2588                     }
2589                   else
2590                     throw INTERP_KERNEL::Exception(msg.c_str());
2591                 }
2592               else
2593                 {//DataArrayDouble.New([1.,3.,4.],3)
2594                   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2595                   mcIdType tmpp1(-1);
2596                   std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2597                   ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2598                   return ret.retn();
2599                 }
2600             }
2601           else
2602             throw INTERP_KERNEL::Exception(msg.c_str());
2603         }
2604       else
2605         {// DataArrayDouble.New([1.,3.,4.])
2606           MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2607           mcIdType tmpp1(-1),tmpp2(-1);
2608           std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2609           ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2610           return ret.retn();
2611         }
2612     }
2613   else if(PyInt_Check(elt0))
2614     {
2615       mcIdType nbOfTuples1(ToIdType(PyInt_AS_LONG(elt0)));
2616       if(nbOfTuples1<0)
2617         throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2618       if(nbOfTuples)
2619         {
2620           if(!elt2)
2621             {
2622               if(PyInt_Check(nbOfTuples))
2623                 {//DataArrayDouble.New(5,2)
2624                   mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(nbOfTuples));
2625                   if(nbOfCompo<0)
2626                     throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2627                   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2628                   ret->alloc(nbOfTuples1,nbOfCompo);
2629                   return ret.retn();
2630                 }
2631               else
2632                 throw INTERP_KERNEL::Exception(msg.c_str());
2633             }
2634           else
2635             throw INTERP_KERNEL::Exception(msg.c_str());
2636         }
2637       else
2638         {//DataArrayDouble.New(5)
2639           MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2640           ret->alloc(nbOfTuples1,1);
2641           return ret.retn();
2642         }
2643     }
2644 #ifdef WITH_NUMPY
2645   else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2646     {//DataArrayDouble.New(numpyArray)
2647       return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2648     }
2649 #endif
2650   else
2651     throw INTERP_KERNEL::Exception(msg.c_str());
2652   throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2653 }
2654
2655 template<class T>
2656 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2657 {
2658   self->checkAllocated();
2659   const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2660   mcIdType nbOfTuples(self->getNumberOfTuples());
2661   int nbOfComponents((int)(self->getNumberOfComponents()));
2662   mcIdType sw1,sw2;
2663   T i1;
2664   std::vector<T> v1;
2665   typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2666   considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2667   mcIdType it1,ic1;
2668   std::vector<mcIdType> vt1;
2669   std::vector<mcIdType> vc1;
2670   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
2671   MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
2672   convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2673   MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2674   switch(sw2)
2675     {
2676     case 1:
2677       {
2678         switch(sw1)
2679           {
2680           case 1:
2681             self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2682             return self;
2683           case 2:
2684             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2685             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2686             self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2687             return self;
2688           case 3:
2689             self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2690             return self;
2691           default:
2692             throw INTERP_KERNEL::Exception(msg);
2693           }
2694         break;
2695       }
2696     case 2:
2697       {
2698         switch(sw1)
2699           {
2700           case 1:
2701             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2702             return self;
2703           case 2:
2704             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2705             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2706             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2707             return self;
2708           case 3:
2709             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2710             return self;
2711           default:
2712             throw INTERP_KERNEL::Exception(msg);
2713           }
2714         break;
2715       }
2716     case 3:
2717       {
2718         switch(sw1)
2719           {
2720           case 1:
2721             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2722             return self;
2723           case 2:
2724             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2725             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2726             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2727             return self;
2728           case 3:
2729             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2730             return self;
2731           default:
2732             throw INTERP_KERNEL::Exception(msg);
2733           }
2734         break;
2735       }
2736     case 4:
2737       {
2738         switch(sw1)
2739           {
2740           case 1:
2741             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2742             return self;
2743           case 2:
2744             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2745             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2746             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2747             return self;
2748           case 3:
2749             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2750             return self;
2751           default:
2752             throw INTERP_KERNEL::Exception(msg);
2753           }
2754         break;
2755       }
2756     case 5:
2757       {
2758         switch(sw1)
2759           {
2760           case 1:
2761             self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2762             return self;
2763           case 2:
2764             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2765             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2766             self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2767             return self;
2768           case 3:
2769             self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2770             return self;
2771           default:
2772             throw INTERP_KERNEL::Exception(msg);
2773           }
2774         break;
2775       }
2776     case 6:
2777       {
2778         switch(sw1)
2779           {
2780           case 1:
2781             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2782             return self;
2783           case 2:
2784             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2785             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2786             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2787             return self;
2788           case 3:
2789             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2790             return self;
2791           default:
2792             throw INTERP_KERNEL::Exception(msg);
2793           }
2794         break;
2795       }
2796     case 7:
2797       {
2798         switch(sw1)
2799           {
2800           case 1:
2801             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2802             return self;
2803           case 2:
2804             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2805             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2806             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2807             return self;
2808           case 3:
2809             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2810             return self;
2811           default:
2812             throw INTERP_KERNEL::Exception(msg);
2813           }
2814         break;
2815       }
2816     case 8:
2817       {
2818         switch(sw1)
2819           {
2820           case 1:
2821             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2822             return self;
2823           case 2:
2824             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2825             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2826             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2827             return self;
2828           case 3:
2829             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2830             return self;
2831           default:
2832             throw INTERP_KERNEL::Exception(msg);
2833           }
2834         break;
2835       }
2836     case 9:
2837       {
2838         switch(sw1)
2839           {
2840           case 1:
2841             self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2842             return self;
2843           case 2:
2844             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2845             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2846             self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2847             return self;
2848           case 3:
2849             self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2850             return self;
2851           default:
2852             throw INTERP_KERNEL::Exception(msg);
2853           }
2854         break;
2855       }
2856     case 10:
2857       {
2858         switch(sw1)
2859           {
2860           case 1:
2861             self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2862             return self;
2863           case 2:
2864             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2865             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2866             self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2867             return self;
2868           case 3:
2869             self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2870             return self;
2871           default:
2872             throw INTERP_KERNEL::Exception(msg);
2873           }
2874         break;
2875       }
2876     case 11:
2877       {
2878         switch(sw1)
2879           {
2880           case 1:
2881             self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2882             return self;
2883           case 2:
2884             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2885             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2886             self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2887             return self;
2888           case 3:
2889             self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2890             return self;
2891           default:
2892             throw INTERP_KERNEL::Exception(msg);
2893           }
2894         break;
2895       }
2896     case 12:
2897       {
2898         switch(sw1)
2899           {
2900           case 1:
2901             self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2902             return self;
2903           case 2:
2904             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2905             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2906             self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2907             return self;
2908           case 3:
2909             self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2910             return self;
2911           default:
2912             throw INTERP_KERNEL::Exception(msg);
2913           }
2914         break;
2915       }
2916     case 13:
2917       {
2918         switch(sw1)
2919           {
2920           case 1:
2921             self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2922             return self;
2923           case 2:
2924             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2925             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2926             self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2927             return self;
2928           case 3:
2929             self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2930             return self;
2931           default:
2932             throw INTERP_KERNEL::Exception(msg);
2933           }
2934         break;
2935       }
2936     case 14:
2937       {
2938         switch(sw1)
2939           {
2940           case 1:
2941             self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2942             return self;
2943           case 2:
2944             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2945             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2946             self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2947             return self;
2948           case 3:
2949             self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2950             return self;
2951           default:
2952             throw INTERP_KERNEL::Exception(msg);
2953           }
2954         break;
2955       }
2956     case 15:
2957       {
2958         switch(sw1)
2959           {
2960           case 1:
2961             self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2962             return self;
2963           case 2:
2964             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2965             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2966             self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2967             return self;
2968           case 3:
2969             self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2970             return self;
2971           default:
2972             throw INTERP_KERNEL::Exception(msg);
2973           }
2974         break;
2975       }
2976     case 16:
2977       {
2978         switch(sw1)
2979           {
2980           case 1:
2981             self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2982             return self;
2983           case 2:
2984             tmp=MEDCoupling::Traits<T>::ArrayType::New();
2985             tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2986             self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
2987             return self;
2988           case 3:
2989             self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2990             return self;
2991           default:
2992             throw INTERP_KERNEL::Exception(msg);
2993           }
2994         break;
2995       }
2996     default:
2997       throw INTERP_KERNEL::Exception(msg);
2998     }
2999   return self;
3000 }
3001
3002 template<class T>
3003 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3004 {
3005   const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3006   const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3007   self->checkAllocated();
3008   mcIdType nbOfTuples(self->getNumberOfTuples());
3009   int nbOfComponents((int)(self->getNumberOfComponents()));
3010   mcIdType it1;
3011   std::size_t ic1;
3012   std::vector<mcIdType> vt1;
3013   std::vector<std::size_t> vc1;
3014   std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
3015   MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
3016   mcIdType sw;
3017   convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3018   MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3019   switch(sw)
3020     {
3021     case 1:
3022       if(nbOfComponents==1)
3023         return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3024       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3025     case 2:
3026       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3027     case 3:
3028       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3029     case 4:
3030       return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3031     case 5:
3032       return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3033     case 6:
3034       {
3035         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3036         std::vector<std::size_t> v2(1,ic1);
3037         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3038       }
3039     case 7:
3040       {
3041         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3042         std::vector<std::size_t> v2(1,ic1);
3043         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3044       }
3045     case 8:
3046       {
3047         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3048         std::vector<std::size_t> v2(1,ic1);
3049         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3050       }
3051     case 9:
3052       {
3053         ret=self->selectByTupleIdSafe(&it1,&it1+1);
3054         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3055       }
3056     case 10:
3057       {
3058         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3059         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3060       }
3061     case 11:
3062       {
3063         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3064         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3065       }
3066     case 12:
3067       {
3068         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3069         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3070       }
3071     case 13:
3072       {
3073         ret=self->selectByTupleIdSafe(&it1,&it1+1);
3074         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3075         std::vector<std::size_t> v2(nbOfComp);
3076         for(mcIdType i=0;i<nbOfComp;i++)
3077           v2[i]=pc1.first+i*pc1.second.second;
3078         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3079       }
3080     case 14:
3081       {
3082         ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3083         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3084         std::vector<std::size_t> v2(nbOfComp);
3085         for(int i=0;i<nbOfComp;i++)
3086           v2[i]=pc1.first+i*pc1.second.second;
3087         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3088       }
3089     case 15:
3090       {
3091         ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3092         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3093         std::vector<std::size_t> v2(nbOfComp);
3094         for(int i=0;i<nbOfComp;i++)
3095           v2[i]=pc1.first+i*pc1.second.second;
3096         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3097       }
3098     case 16:
3099       {
3100         ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3101         mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3102         std::vector<std::size_t> v2(nbOfComp);
3103         for(int i=0;i<nbOfComp;i++)
3104           v2[i]=pc1.first+i*pc1.second.second;
3105         return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3106       }
3107     default:
3108       throw INTERP_KERNEL::Exception(msg);
3109     }
3110 }
3111
3112 bool isCSRMatrix(PyObject *m)
3113 {
3114 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
3115   PyObject* pdict(PyDict_New());
3116   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
3117   PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
3118   if(!tmp)
3119     throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
3120   PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
3121   if(!csrMatrixCls)
3122     throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
3123   bool ret(PyObject_IsInstance(m,csrMatrixCls));
3124   Py_DECREF(pdict); Py_XDECREF(tmp);
3125   return ret;
3126 #else
3127   return false;
3128 #endif
3129 }
3130
3131 void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
3132 {
3133   auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
3134   if(nbOfRows<0)
3135     throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !");
3136   mCpp.resize(nbOfRows);
3137   auto indPtrCPtr(indptrPtr->begin());
3138   auto indicesCPtr(indicesPtr->begin());
3139   auto dataCPtr(dataPtr->begin());
3140   for(auto i=0;i<nbOfRows;i++)
3141     {
3142       auto& line(mCpp[i]);
3143       for(auto j=indPtrCPtr[i];j<indPtrCPtr[i+1];j++)
3144         {
3145           line[indicesCPtr[j]]=dataCPtr[j];
3146         }
3147     }
3148 }
3149
3150 void convertToVectMapIntDouble(PyObject *pyobj, std::vector<std::map<mcIdType,double> >& mCpp)
3151 {
3152   if(!PyList_Check(pyobj))
3153     throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !");
3154   mCpp.clear();
3155   Py_ssize_t sz(PyList_Size(pyobj));
3156   mCpp.resize(sz);
3157   for(Py_ssize_t i=0;i<sz;i++)
3158     {
3159       PyObject *elt(PyList_GetItem(pyobj,i));
3160       if(!PyDict_Check(elt))
3161         {
3162           std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist a dict is exepect !";
3163           throw INTERP_KERNEL::Exception(oss.str());
3164         }
3165       PyObject *key, *value;
3166       Py_ssize_t pos(0);
3167       std::map<mcIdType,double>& mapCpp(mCpp[i]);
3168       while(PyDict_Next(elt,&pos,&key,&value))
3169         {
3170           if(!PyInt_Check(key))
3171             {
3172               std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !";
3173               throw INTERP_KERNEL::Exception(oss.str());
3174             }
3175           if(!PyFloat_Check(value))
3176             {
3177               std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !";
3178               throw INTERP_KERNEL::Exception(oss.str());
3179             }
3180           mapCpp[ToIdType(PyInt_AS_LONG(key))]=PyFloat_AS_DOUBLE(value);
3181         }
3182     }
3183 }
3184
3185 template<class T>
3186 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3187 {
3188   const char msg[]="Unexpected situation in __imul__ !";
3189   T val;
3190   typename MEDCoupling::Traits<T>::ArrayType *a;
3191   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3192   std::vector<T> bb;
3193   mcIdType sw;
3194   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3195   switch(sw)
3196     {
3197     case 1:
3198       {
3199         self->applyLin(val,0.);
3200         Py_XINCREF(trueSelf);
3201         return trueSelf;
3202       }
3203     case 2:
3204       {
3205         self->multiplyEqual(a);
3206         Py_XINCREF(trueSelf);
3207         return trueSelf;
3208       }
3209     case 3:
3210       {
3211         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3212         self->multiplyEqual(aaa);
3213         Py_XINCREF(trueSelf);
3214         return trueSelf;
3215       }
3216     case 4:
3217       {
3218         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());
3219         self->multiplyEqual(aaa);
3220         Py_XINCREF(trueSelf);
3221         return trueSelf;
3222       }
3223     default:
3224       throw INTERP_KERNEL::Exception(msg);
3225     }
3226 }
3227
3228 template<class T>
3229 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3230 {
3231   const char msg[]="Unexpected situation in __idiv__ !";
3232   T val;
3233   typename MEDCoupling::Traits<T>::ArrayType *a;
3234   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3235   std::vector<T> bb;
3236   mcIdType sw;
3237   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3238   switch(sw)
3239     {
3240     case 1:
3241       {
3242         if(val==0.)
3243           throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3244         self->applyLin((T)(1./val),(T)0.);
3245         Py_XINCREF(trueSelf);
3246         return trueSelf;
3247       }
3248     case 2:
3249       {
3250         self->divideEqual(a);
3251         Py_XINCREF(trueSelf);
3252         return trueSelf;
3253       }
3254     case 3:
3255       {
3256         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3257         self->divideEqual(aaa);
3258         Py_XINCREF(trueSelf);
3259         return trueSelf;
3260       }
3261     case 4:
3262       {
3263         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());
3264         self->divideEqual(aaa);
3265         Py_XINCREF(trueSelf);
3266         return trueSelf;
3267       }
3268     default:
3269       throw INTERP_KERNEL::Exception(msg);
3270     }
3271 }
3272
3273 template<class T>
3274 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3275 {
3276   const char msg[]="Unexpected situation in __iadd__ !";
3277   T val;
3278   typename MEDCoupling::Traits<T>::ArrayType *a;
3279   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3280   std::vector<T> bb;
3281   mcIdType sw;
3282   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3283   switch(sw)
3284     {
3285     case 1:
3286       {
3287         self->applyLin(1.,val);
3288         Py_XINCREF(trueSelf);
3289         return trueSelf;
3290       }
3291     case 2:
3292       {
3293         self->addEqual(a);
3294         Py_XINCREF(trueSelf);
3295         return trueSelf;
3296       }
3297     case 3:
3298       {
3299         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3300         self->addEqual(aaa);
3301         Py_XINCREF(trueSelf);
3302         return trueSelf;
3303       }
3304     case 4:
3305       {
3306         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());
3307         self->addEqual(aaa);
3308         Py_XINCREF(trueSelf);
3309         return trueSelf;
3310       }
3311     default:
3312       throw INTERP_KERNEL::Exception(msg);
3313     }
3314 }
3315
3316 template<class T>
3317 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3318 {
3319   const char msg[]="Unexpected situation in __isub__ !";
3320   T val;
3321   typename MEDCoupling::Traits<T>::ArrayType *a;
3322   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3323   std::vector<T> bb;
3324   mcIdType sw;
3325   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3326   switch(sw)
3327     {
3328     case 1:
3329       {
3330         self->applyLin(1.,-val);
3331         Py_XINCREF(trueSelf);
3332         return trueSelf;
3333       }
3334     case 2:
3335       {
3336         self->substractEqual(a);
3337         Py_XINCREF(trueSelf);
3338         return trueSelf;
3339       }
3340     case 3:
3341       {
3342         MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3343         self->substractEqual(aaa);
3344         Py_XINCREF(trueSelf);
3345         return trueSelf;
3346       }
3347     case 4:
3348       {
3349         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());
3350         self->substractEqual(aaa);
3351         Py_XINCREF(trueSelf);
3352         return trueSelf;
3353       }
3354     default:
3355       throw INTERP_KERNEL::Exception(msg);
3356     }
3357 }
3358
3359 #ifdef WITH_NUMPY
3360 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3361
3362 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3363
3364 PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
3365
3366 PyTypeObject *NPYTraits<long>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
3367 #endif
3368
3369 template<class T>
3370 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3371 {
3372   return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3373 }
3374
3375 template<class T>
3376 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3377 {
3378   return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3379 }
3380
3381 template<class T>
3382 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3383 {
3384   return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3385 }
3386
3387 template<class T>
3388 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3389 {
3390   return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3391 }
3392
3393 template<class T>
3394 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3395 {
3396   return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3397 }
3398
3399 template<class T>
3400 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3401 {
3402   return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3403 }
3404
3405 template<class T>
3406 typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3407 {
3408   const char msg[]="Unexpected situation in __rmul__ !";
3409   T val;
3410   typename MEDCoupling::Traits<T>::ArrayType *a;
3411   typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3412   std::vector<T> bb;
3413   mcIdType sw;
3414   convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3415   switch(sw)
3416     {
3417     case 1:
3418       {
3419         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
3420         ret->applyLin(val,0.);
3421         return ret.retn();
3422       }
3423     case 3:
3424       {
3425         typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
3426         return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3427       }
3428     case 4:
3429       {
3430         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());
3431         return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3432       }
3433     default:
3434       throw INTERP_KERNEL::Exception(msg);
3435     }
3436 }
3437
3438 #endif