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