1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
22 #define __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
24 #if PY_VERSION_HEX >= 0x03000000
25 #define PyInt_AS_LONG PyLong_AS_LONG
28 #include "InterpKernelAutoPtr.hxx"
29 #include "MEDCouplingDataArrayTraits.hxx"
34 using namespace MEDCoupling;
41 struct SWIGTITraits<double>
42 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
45 struct SWIGTITraits<float>
46 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
49 struct SWIGTITraits<Int32>
50 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
53 struct SWIGTITraits<Int64>
54 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
56 swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
57 swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
58 swig_type_info *SWIGTITraits<Int32>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt32 is null when called here ! Postpone initialization at inlined initializeMe()
59 swig_type_info *SWIGTITraits<Int64>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt64 is null when called here ! Postpone initialization at inlined initializeMe()
60 swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
61 swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
62 swig_type_info *SWIGTITraits<Int32>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt32 is null when called here ! Postpone initialization at inlined initializeMe()
63 swig_type_info *SWIGTITraits<Int64>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayInt64 is null when called here ! Postpone initialization at inlined initializeMe()
65 static PyObject *convertArray(MEDCoupling::DataArray *array, int owner)
73 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(array))
74 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
75 if(dynamic_cast<MEDCoupling::DataArrayInt32 *>(array))
76 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt32,owner);
77 if(dynamic_cast<MEDCoupling::DataArrayInt64 *>(array))
78 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt64,owner);
79 if(dynamic_cast<MEDCoupling::DataArrayFloat *>(array))
80 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
82 throw INTERP_KERNEL::Exception("Not recognized type of array on downcast !");
87 * This method is an extension of PySlice_GetIndices but less
88 * open than PySlice_GetIndicesEx that accepts too many situations.
90 void GetIndicesOfSlice(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
92 int ret(PySlice_GetIndices(
93 #if PY_VERSION_HEX >= 0x03000000
96 reinterpret_cast<PySliceObject *>(slice),
98 length,start,stop,step));
101 if(*step>0 && *start==*stop && length==*start)
103 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
107 * This method allows to retrieve slice info from \a slice.
109 void GetIndicesOfSliceExplicitely(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
111 int ret(PySlice_GetIndices(
112 #if PY_VERSION_HEX >= 0x03000000
115 reinterpret_cast<PySliceObject *>(slice),
117 std::numeric_limits<int>::max(),start,stop,step));
120 if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
122 std::ostringstream oss;
123 oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
124 throw INTERP_KERNEL::Exception(oss.str().c_str());
126 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
129 int InterpreteNegativeInt(long val, mcIdType nbelem)
133 int newVal((int)(nbelem+val));
136 std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
137 throw INTERP_KERNEL::Exception(oss.str().c_str());
146 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
147 // in input when an another DataArray is already client of this.
148 template<class MCData>
149 void numarrdeal2(void *pt, void *obj)
151 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
152 void **obj1=(void **)obj;
153 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
154 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
156 Py_XDECREF(weakRefOnOwner);
161 template<class MCData, class T>
162 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
164 int ndim=PyArray_NDIM(elt0);
165 if(ndim!=1 && ndim!=2)
166 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
167 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
169 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
171 oss << " type_num == " << PyArray_DESCR(elt0)->type_num;
173 throw INTERP_KERNEL::Exception(oss.str().c_str());
175 npy_intp sz0=PyArray_DIM(elt0,0);
176 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
178 int itemSize=PyArray_ITEMSIZE(elt0);
179 if(itemSize!=sizeof(T))
181 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
182 throw INTERP_KERNEL::Exception(oss.str().c_str());
184 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
185 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
187 if(itemSize!=PyArray_STRIDE(elt0,1))
188 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays for component #1 !");
189 const char *data=PyArray_BYTES(elt0);
190 typename MEDCoupling::MCAuto<MCData> ret=MCData::New();
191 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
193 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
194 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
195 int mask=MED_NUMPY_OWNDATA; mask=~mask;
197 PyObject *deepestObj=elt0;
198 PyObject *base=elt0C->base;
199 if(base) deepestObj=base;
200 bool isSpetialCase(false);
203 if(PyArray_Check(base))
205 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
206 eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
209 if(base) deepestObj=base;
218 {// this case is present for numpy arrayint coming from load of pickelized string. The owner of elt0 is not an array -> A copy is requested.
219 std::size_t nbOfElems(sz0*sz1);
220 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
221 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
222 ret->useArray(dataCpy,true,MEDCoupling::DeallocType::C_DEALLOC,sz0,sz1);
225 typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
228 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
230 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::DeallocType::C_DEALLOC,sz0,sz1);
231 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
232 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
233 mma.setParameterForDeallocator(objs);
234 mma.setSpecificDeallocator(numarrdeal2<MCData>);
235 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayIdType instance) ! Release it, or perform a copy on the input array !");
239 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::DeallocType::C_DEALLOC_WITH_OFFSET,sz0,sz1);
240 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
241 typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::COffsetDeallocator);
242 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
243 const char *dataEltOwning(PyArray_BYTES(eltOwning));//In case of input array is a sub array of a 2D,3D... array there is an offset
245 if(data!=dataEltOwning)
247 offset=data>dataEltOwning?-((int64_t)(std::distance(dataEltOwning,data))):(int64_t)std::distance(data,dataEltOwning);
249 void **objs=new void *[3]; objs[0]=ref; objs[1]=*tmp2; objs[2]=new int64_t(offset);
250 mma.setParameterForDeallocator(objs);
251 mma.setSpecificDeallocator(numarrdeal);
254 else if(PyArray_ISBEHAVED_RO(elt0))
255 ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::DeallocType::CPP_DEALLOC,sz0,sz1);
260 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
263 PyErr_SetString(PyExc_ValueError,
264 "Cannot set the NumPy array 'base' "
265 "dependency to NULL after initialization");
269 * Allow the base to be set only once. Once the object which
270 * owns the data is set, it doesn't make sense to change it.
272 if (PyArray_BASE(arr) != NULL) {
274 PyErr_SetString(PyExc_ValueError,
275 "Cannot set the NumPy array 'base' "
276 "dependency more than once");
281 * Don't allow infinite chains of views, always set the base
282 * to the first owner of the data.
283 * That is, either the first object which isn't an array,
284 * or the first object which owns its own data.
287 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
288 PyArrayObject *obj_arr = (PyArrayObject *)obj;
292 /* If this array owns its own data, stop collapsing */
293 if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
297 tmp = PyArray_BASE(obj_arr);
298 /* If there's no base, stop collapsing */
302 /* Stop the collapse new base when the would not be of the same
303 * type (i.e. different subclass).
305 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
315 /* Disallow circular references */
316 if ((PyObject *)arr == obj) {
318 PyErr_SetString(PyExc_ValueError,
319 "Cannot create a circular NumPy array 'base' dependency");
328 template<class MCData, class T>
329 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, mcIdType nbTuples, std::size_t nbComp)
331 if(!self->isAllocated())
333 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
334 throw INTERP_KERNEL::Exception(oss.str().c_str());
336 MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
339 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
340 throw INTERP_KERNEL::Exception(oss.str().c_str());
342 int nbDims=nbComp==1?1:2;
344 dim[0]=(npy_intp)nbTuples; dim[1]=(npy_intp)nbComp;
345 const T *bg=self->getConstPointer();
346 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
347 if(mem.isDeallocatorCalled())
349 if(mem.getDeallocator()!=numarrdeal)
350 {// case for the first call of toNumPyArray
351 PyObject *ref(PyWeakref_NewRef(ret,NULL));
352 typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
353 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
354 void **objs=new void *[3]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2; objs[2]=new int64_t(0);
355 mem.setParameterForDeallocator(objs);
356 mem.setSpecificDeallocator(numarrdeal);
360 {// case for the second and other call of toNumPyArray
361 void **objs=(void **)mem.getParameterForDeallocator();
362 PyObject *weakRefOnOwner=(PyObject *)objs[0];
363 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
365 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
367 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
370 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
371 Py_XDECREF(weakRefOnOwner);
372 PyObject *ref=PyWeakref_NewRef(ret,NULL);
380 template<class MCData, class T>
381 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
383 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
386 SWIGINTERN PyObject *MEDCoupling_DataArrayInt32_toNumPyArray(MEDCoupling::DataArrayInt32 *self);
387 SWIGINTERN PyObject *MEDCoupling_DataArrayInt64_toNumPyArray(MEDCoupling::DataArrayInt64 *self);
388 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
393 PyObject *ToCSRMatrix(const std::vector<std::map<mcIdType,double> >& m, mcIdType nbCols)
395 mcIdType nbRows((mcIdType)m.size());
396 MEDCoupling::MCAuto<MEDCoupling::DataArrayIdType> indPtr(MEDCoupling::DataArrayIdType::New()),indices(MEDCoupling::DataArrayIdType::New());
397 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
398 indPtr->alloc(nbRows+1,1);
399 mcIdType *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
401 for(std::vector<std::map<mcIdType,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
403 sz2+=(mcIdType)(*it0).size();
406 indices->alloc(sz2,1); data->alloc(sz2,1);
407 mcIdType *indices_ptr(indices->getPointer());
408 double *data_ptr(data->getPointer());
409 for(std::vector<std::map<mcIdType,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
410 for(std::map<mcIdType,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
412 *indices_ptr=(*it1).first;
413 *data_ptr=(*it1).second;
415 #ifndef MEDCOUPLING_USE_64BIT_IDS
416 PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt32_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt32_toNumPyArray(indPtr));
418 PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt64_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt64_toNumPyArray(indPtr));
421 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
422 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
423 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
424 PyObject *tmp1(PyString_FromString("shape"));
425 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
426 PyObject* pdict=PyDict_New();
427 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
428 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
430 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
431 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
433 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
434 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
435 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
441 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner)
449 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
450 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
451 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
452 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
454 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
458 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner)
466 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
467 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
468 if(dynamic_cast<MEDCoupling::DataArrayInt32 *>(dac))
469 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt32,owner);
470 if(dynamic_cast<MEDCoupling::DataArrayInt64 *>(dac))
471 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt64,owner);
472 if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
473 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
474 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
475 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
476 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
477 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
479 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
484 static PyObject *convertIntArrToPyList(const T *ptr, mcIdType size)
486 PyObject *ret=PyList_New(size);
487 for(T i=0;i<size;i++)
488 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
493 static PyObject *convertIntArrToPyList2(const std::vector<T>& v)
495 std::size_t size=v.size();
496 PyObject *ret=PyList_New(size);
497 for(std::size_t i=0;i<size;i++)
498 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
503 static PyObject *convertIntArrToPyList3(const std::set<T>& v)
505 std::size_t size=v.size();
506 PyObject *ret=PyList_New(size);
507 typename std::set<T>::const_iterator it=v.begin();
508 for(std::size_t i=0;i<size;i++,it++)
509 PyList_SetItem(ret,i,PyInt_FromLong(*it));
513 static bool convertPyObjectToStrNT(PyObject *obj, std::string& ret)
515 if(PyString_Check(obj))
517 ret=PyString_AsString(obj);
520 #if PY_VERSION_HEX >= 0x03000000
521 else if(PyUnicode_Check(obj))
523 ret=PyUnicode_AsUTF8(obj);
530 static std::string convertPyObjectToStr(PyObject *obj, const char *msg=NULL)
533 if(PyString_Check(obj))
534 ret=PyString_AsString(obj);
535 #if PY_VERSION_HEX >= 0x03000000
536 else if(PyUnicode_Check(obj))
537 ret=PyUnicode_AsUTF8(obj);
541 std::ostringstream oss;
545 oss << "PyWrap convertPyObjectToStr : expect a string like py object !";
546 throw INTERP_KERNEL::Exception(oss.str());
552 static PyObject *convertIntArrToPyListOfTuple(const T *vals, mcIdType nbOfComp, mcIdType nbOfTuples)
554 PyObject *ret=PyList_New(nbOfTuples);
555 for(T i=0;i<nbOfTuples;i++)
557 PyObject *t=PyTuple_New(nbOfComp);
558 for(T j=0;j<nbOfComp;j++)
559 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
560 PyList_SetItem(ret,i,t);
565 template< class T = mcIdType >
566 static T *convertPyToNewIntArr2(PyObject *pyLi, mcIdType *size)
568 if(PyList_Check(pyLi))
570 *size=ToIdType(PyList_Size(pyLi));
572 for(mcIdType i=0;i<*size;i++)
574 PyObject *o=PyList_GetItem(pyLi,i);
577 T val=(T)PyInt_AS_LONG(o);
583 throw INTERP_KERNEL::Exception("list must contain integers only");
588 else if(PyTuple_Check(pyLi))
590 *size=ToIdType(PyTuple_Size(pyLi));
592 for(mcIdType i=0;i<*size;i++)
594 PyObject *o=PyTuple_GetItem(pyLi,i);
597 T val=(T)PyInt_AS_LONG(o);
603 throw INTERP_KERNEL::Exception("tuple must contain integers only");
610 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
614 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<mcIdType,mcIdType> >& arr)
616 PyObject *ret=PyList_New(arr.size());
617 for(std::size_t i=0;i<arr.size();i++)
619 PyObject *t=PyTuple_New(2);
620 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
621 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
622 PyList_SetItem(ret,i,t);
627 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<mcIdType,mcIdType> >& arr)
629 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
630 if(PyList_Check(pyLi))
632 std::size_t size=PyList_Size(pyLi);
634 for(std::size_t i=0;i<size;i++)
636 PyObject *o=PyList_GetItem(pyLi,i);
639 std::size_t sz2=PyTuple_Size(o);
641 throw INTERP_KERNEL::Exception(msg);
642 PyObject *o_0=PyTuple_GetItem(o,0);
643 if(!PyInt_Check(o_0))
644 throw INTERP_KERNEL::Exception(msg);
645 PyObject *o_1=PyTuple_GetItem(o,1);
646 if(!PyInt_Check(o_1))
647 throw INTERP_KERNEL::Exception(msg);
648 arr[i].first=(mcIdType)PyInt_AS_LONG(o_0);
649 arr[i].second=(mcIdType)PyInt_AS_LONG(o_1);
652 throw INTERP_KERNEL::Exception(msg);
655 else if(PyTuple_Check(pyLi))
657 std::size_t size=PyTuple_Size(pyLi);
659 for(std::size_t i=0;i<size;i++)
661 PyObject *o=PyTuple_GetItem(pyLi,i);
664 std::size_t sz2=PyTuple_Size(o);
666 throw INTERP_KERNEL::Exception(msg);
667 PyObject *o_0=PyTuple_GetItem(o,0);
668 if(!PyInt_Check(o_0))
669 throw INTERP_KERNEL::Exception(msg);
670 PyObject *o_1=PyTuple_GetItem(o,1);
671 if(!PyInt_Check(o_1))
672 throw INTERP_KERNEL::Exception(msg);
673 arr[i].first=(mcIdType)PyInt_AS_LONG(o_0);
674 arr[i].second=(mcIdType)PyInt_AS_LONG(o_1);
677 throw INTERP_KERNEL::Exception(msg);
681 throw INTERP_KERNEL::Exception(msg);
684 static void convertPyToVectorVectorPairInt(PyObject *pyLi, std::vector< std::vector< std::pair<mcIdType,mcIdType> > >& arr)
686 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
687 if(PyList_Check(pyLi))
689 std::size_t size=PyList_Size(pyLi);
691 for(std::size_t i = 0 ; i < size ; ++i)
692 convertPyToVectorPairInt(PyList_GetItem(pyLi,i),arr[i]);
694 else if(PyTuple_Check(pyLi))
696 std::size_t size=PyTuple_Size(pyLi);
698 for(std::size_t i = 0 ; i < size ; ++i)
699 convertPyToVectorPairInt(PyTuple_GetItem(pyLi,i),arr[i]);
702 throw INTERP_KERNEL::Exception(msg);
705 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
707 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
708 if(PyList_Check(pyLi))
710 std::size_t size=PyList_Size(pyLi);
712 for(std::size_t i=0;i<size;i++)
714 PyObject *o=PyList_GetItem(pyLi,i);
717 std::size_t sz2=PyTuple_Size(o);
719 throw INTERP_KERNEL::Exception(msg);
720 PyObject *o_0=PyTuple_GetItem(o,0);
721 PyObject *o_1=PyTuple_GetItem(o,1);
722 arr[i].first=convertPyObjectToStr(o_0,msg);
723 if(!PyInt_Check(o_1))
724 throw INTERP_KERNEL::Exception(msg);
725 arr[i].second=(int)PyInt_AS_LONG(o_1);
728 throw INTERP_KERNEL::Exception(msg);
731 else if(PyTuple_Check(pyLi))
733 std::size_t size=PyTuple_Size(pyLi);
735 for(std::size_t i=0;i<size;i++)
737 PyObject *o=PyTuple_GetItem(pyLi,i);
740 std::size_t sz2=PyTuple_Size(o);
742 throw INTERP_KERNEL::Exception(msg);
743 PyObject *o_0=PyTuple_GetItem(o,0);
744 PyObject *o_1=PyTuple_GetItem(o,1);
745 arr[i].first=convertPyObjectToStr(o_0,msg);
746 if(!PyInt_Check(o_1))
747 throw INTERP_KERNEL::Exception(msg);
748 arr[i].second=(int)PyInt_AS_LONG(o_1);
751 throw INTERP_KERNEL::Exception(msg);
755 throw INTERP_KERNEL::Exception(msg);
759 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<T>& arr)
761 if(PyList_Check(pyLi))
763 std::size_t size=PyList_Size(pyLi);
765 for(std::size_t i=0;i<size;i++)
767 PyObject *o=PyList_GetItem(pyLi,i);
770 T val=(T)PyInt_AS_LONG(o);
774 throw INTERP_KERNEL::Exception("list must contain integers only");
777 else if(PyTuple_Check(pyLi))
779 std::size_t size=PyTuple_Size(pyLi);
781 for(std::size_t i=0;i<size;i++)
783 PyObject *o=PyTuple_GetItem(pyLi,i);
786 T val=(T)PyInt_AS_LONG(o);
790 throw INTERP_KERNEL::Exception("tuple must contain integers only");
795 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
799 static void convertPyToNewIntArr4(PyObject *pyLi, mcIdType recurseLev, mcIdType nbOfSubPart, std::vector<mcIdType>& arr)
802 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
804 if(PyList_Check(pyLi))
806 std::size_t size=PyList_Size(pyLi);
807 for(std::size_t i=0;i<size;i++)
809 PyObject *o=PyList_GetItem(pyLi,i);
812 mcIdType val=(mcIdType)PyInt_AS_LONG(o);
817 std::vector<mcIdType> arr2;
818 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
819 if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
821 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
822 throw INTERP_KERNEL::Exception(oss.str().c_str());
824 arr.insert(arr.end(),arr2.begin(),arr2.end());
828 else if(PyTuple_Check(pyLi))
830 std::size_t size=PyTuple_Size(pyLi);
831 for(std::size_t i=0;i<size;i++)
833 PyObject *o=PyTuple_GetItem(pyLi,i);
836 mcIdType val=ToIdType(PyInt_AS_LONG(o));
841 std::vector<mcIdType> arr2;
842 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
843 if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
845 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
846 throw INTERP_KERNEL::Exception(oss.str().c_str());
848 arr.insert(arr.end(),arr2.begin(),arr2.end());
853 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
856 static void checkFillArrayWithPyList(mcIdType size1, mcIdType size2, mcIdType& nbOfTuples, mcIdType& nbOfComp)
860 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
861 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
863 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
864 oss << " whereas nb of components expected is " << nbOfComp << " !";
865 throw INTERP_KERNEL::Exception(oss.str().c_str());
872 if((nbOfTuples!=size1 || nbOfComp!=size2))
874 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
876 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
877 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
878 throw INTERP_KERNEL::Exception(oss.str().c_str());
884 if(nbOfTuples==size1)
888 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
889 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
890 throw INTERP_KERNEL::Exception(oss.str().c_str());
897 static void fillArrayWithPyListInt3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<T>& ret)
899 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
900 if(PyInt_Check(pyLi))
902 T val=(T)PyInt_AS_LONG(pyLi);
907 throw INTERP_KERNEL::Exception(MSG);
910 else if(PyList_Check(pyLi))
912 std::size_t size=PyList_Size(pyLi);
914 for(std::size_t i=0;i<size;i++)
916 PyObject *o=PyList_GetItem(pyLi,i);
918 fillArrayWithPyListInt3(o,tmp1,ret);
926 throw INTERP_KERNEL::Exception(MSG);
929 else if(PyTuple_Check(pyLi))
931 std::size_t size=PyTuple_Size(pyLi);
933 for(std::size_t i=0;i<size;i++)
935 PyObject *o=PyTuple_GetItem(pyLi,i);
937 fillArrayWithPyListInt3(o,tmp1,ret);
945 throw INTERP_KERNEL::Exception(MSG);
949 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
952 template< class T = mcIdType >
953 static std::vector<T> fillArrayWithPyListInt2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
956 mcIdType size1=-1,size2=-1;
957 if(PyList_Check(pyLi))
959 size1=ToIdType(PyList_Size(pyLi));
960 for(mcIdType i=0;i<size1;i++)
962 PyObject *o=PyList_GetItem(pyLi,i);
963 fillArrayWithPyListInt3(o,size2,ret);
968 else if(PyTuple_Check(pyLi))
970 size1=ToIdType(PyTuple_Size(pyLi));
971 for(mcIdType i=0;i<size1;i++)
973 PyObject *o=PyTuple_GetItem(pyLi,i);
974 fillArrayWithPyListInt3(o,size2,ret);
980 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
982 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
986 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
988 if(PyList_Check(pyLi))
990 Py_ssize_t sz=PyList_Size(pyLi);
992 for(mcIdType i=0;i<sz;i++)
994 PyObject *o=PyList_GetItem(pyLi,i);
995 if(!convertPyObjectToStrNT(o,vec[i]))
1000 else if(PyTuple_Check(pyLi))
1002 Py_ssize_t sz=PyTuple_Size(pyLi);
1004 for(mcIdType i=0;i<sz;i++)
1006 PyObject *o=PyTuple_GetItem(pyLi,i);
1007 if(!convertPyObjectToStrNT(o,vec[i]))
1015 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
1017 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1018 if(PyList_Check(pyLi))
1020 Py_ssize_t sz=PyList_Size(pyLi);
1022 for(mcIdType i=0;i<sz;i++)
1024 PyObject *o=PyList_GetItem(pyLi,i);
1025 if(!fillStringVector(o,arr[i]))
1026 throw INTERP_KERNEL::Exception(msg);
1029 else if(PyTuple_Check(pyLi))
1031 Py_ssize_t sz=PyTuple_Size(pyLi);
1033 for(mcIdType i=0;i<sz;i++)
1035 PyObject *o=PyTuple_GetItem(pyLi,i);
1036 if(!fillStringVector(o,arr[i]))
1037 throw INTERP_KERNEL::Exception(msg);
1041 throw INTERP_KERNEL::Exception(msg);
1044 static bool fillIntVector(PyObject *pyLi, std::vector<mcIdType>& vec)
1046 if(PyList_Check(pyLi))
1048 Py_ssize_t sz=PyList_Size(pyLi);
1050 for(mcIdType i=0;i<sz;i++)
1052 PyObject *o=PyList_GetItem(pyLi,i);
1054 vec[i]=ToIdType(PyInt_AS_LONG(o));
1060 else if(PyTuple_Check(pyLi))
1062 Py_ssize_t sz=PyTuple_Size(pyLi);
1064 for(mcIdType i=0;i<sz;i++)
1066 PyObject *o=PyTuple_GetItem(pyLi,i);
1068 vec[i]=ToIdType(PyInt_AS_LONG(o));
1078 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<mcIdType> >& arr)
1080 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1081 if(PyList_Check(pyLi))
1083 Py_ssize_t sz=PyList_Size(pyLi);
1085 for(mcIdType i=0;i<sz;i++)
1087 PyObject *o=PyList_GetItem(pyLi,i);
1088 if(!fillIntVector(o,arr[i]))
1089 throw INTERP_KERNEL::Exception(msg);
1092 else if(PyTuple_Check(pyLi))
1094 Py_ssize_t sz=PyTuple_Size(pyLi);
1096 for(mcIdType i=0;i<sz;i++)
1098 PyObject *o=PyTuple_GetItem(pyLi,i);
1099 if(!fillIntVector(o,arr[i]))
1100 throw INTERP_KERNEL::Exception(msg);
1104 throw INTERP_KERNEL::Exception(msg);
1107 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
1109 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1110 if(PyList_Check(pyLi))
1112 Py_ssize_t sz=PyList_Size(pyLi);
1114 for(mcIdType i=0;i<sz;i++)
1116 PyObject *o=PyList_GetItem(pyLi,i);
1117 if(PyTuple_Check(o))
1119 std::size_t sz2=PyTuple_Size(o);
1121 throw INTERP_KERNEL::Exception(msg);
1122 std::pair<std::string, std::vector<std::string> > item;
1123 PyObject *o_0=PyTuple_GetItem(o,0);
1124 item.first=convertPyObjectToStr(o_0,msg);
1125 PyObject *o_1=PyTuple_GetItem(o,1);
1126 if(!fillStringVector(o_1,item.second))
1127 throw INTERP_KERNEL::Exception(msg);
1131 throw INTERP_KERNEL::Exception(msg);
1134 else if(PyTuple_Check(pyLi))
1136 Py_ssize_t sz=PyTuple_Size(pyLi);
1138 for(Py_ssize_t i=0;i<sz;i++)
1140 PyObject *o=PyTuple_GetItem(pyLi,i);
1141 if(PyTuple_Check(o))
1143 std::size_t sz2=PyTuple_Size(o);
1145 throw INTERP_KERNEL::Exception(msg);
1146 std::pair<std::string, std::vector<std::string> > item;
1147 PyObject *o_0=PyTuple_GetItem(o,0);
1148 item.first=convertPyObjectToStr(o_0,msg);
1149 PyObject *o_1=PyTuple_GetItem(o,1);
1150 if(!fillStringVector(o_1,item.second))
1151 throw INTERP_KERNEL::Exception(msg);
1155 throw INTERP_KERNEL::Exception(msg);
1159 throw INTERP_KERNEL::Exception(msg);
1163 PyObject *convertDblArrToPyList(const T *ptr, std::size_t size)
1165 PyObject *ret(PyList_New(size));
1166 for(std::size_t i=0;i<size;i++)
1167 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1171 static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
1173 std::size_t size(v.size());
1174 PyObject *ret(PyList_New(size));
1175 for(std::size_t i=0;i<size;i++)
1176 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1181 PyObject *convertDblArrToPyListOfTuple(const T *vals, std::size_t nbOfComp, mcIdType nbOfTuples)
1183 PyObject *ret(PyList_New(nbOfTuples));
1184 for(mcIdType i=0;i<nbOfTuples;i++)
1186 PyObject *t=PyTuple_New(nbOfComp);
1187 for(std::size_t j=0;j<nbOfComp;j++)
1188 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1189 PyList_SetItem(ret,i,t);
1194 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, mcIdType nbOfTuples)
1196 PyObject *ret=PyList_New(nbOfTuples);
1197 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1198 for(mcIdType i=0;i<nbOfTuples;i++)
1200 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1201 PyList_SetItem(ret,i,PyString_FromString(tmp));
1206 static double *convertPyToNewDblArr2(PyObject *pyLi, mcIdType *size)
1208 if(PyList_Check(pyLi))
1210 *size=ToIdType(PyList_Size(pyLi));
1211 double *tmp=(double *)malloc((*size)*sizeof(double));
1212 for(mcIdType i=0;i<*size;i++)
1214 PyObject *o=PyList_GetItem(pyLi,i);
1215 if(PyFloat_Check(o))
1217 double val=PyFloat_AS_DOUBLE(o);
1220 else if(PyInt_Check(o))
1222 long val0=PyInt_AS_LONG(o);
1223 double val=(double)val0;
1229 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1234 else if(PyTuple_Check(pyLi))
1236 *size=ToIdType(PyTuple_Size(pyLi));
1237 double *tmp=(double *)malloc((*size)*sizeof(double));
1238 for(mcIdType i=0;i<*size;i++)
1240 PyObject *o=PyTuple_GetItem(pyLi,i);
1241 if(PyFloat_Check(o))
1243 double val=PyFloat_AS_DOUBLE(o);
1246 else if(PyInt_Check(o))
1248 long val0=PyInt_AS_LONG(o);
1249 double val=(double)val0;
1255 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1261 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1264 static void fillArrayWithPyListDbl3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<double>& ret)
1266 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1267 if(PyFloat_Check(pyLi))
1273 throw INTERP_KERNEL::Exception(MSG);
1274 double val=PyFloat_AS_DOUBLE(pyLi);
1277 else if(PyInt_Check(pyLi))
1279 mcIdType val0=ToIdType(PyInt_AS_LONG(pyLi));
1280 double val=(double)val0;
1285 throw INTERP_KERNEL::Exception(MSG);
1288 else if(PyList_Check(pyLi))
1290 std::size_t size=PyList_Size(pyLi);
1292 for(std::size_t i=0;i<size;i++)
1294 PyObject *o=PyList_GetItem(pyLi,i);
1296 fillArrayWithPyListDbl3(o,tmp1,ret);
1304 throw INTERP_KERNEL::Exception(MSG);
1307 else if(PyTuple_Check(pyLi))
1309 std::size_t size=PyTuple_Size(pyLi);
1311 for(std::size_t i=0;i<size;i++)
1313 PyObject *o=PyTuple_GetItem(pyLi,i);
1315 fillArrayWithPyListDbl3(o,tmp1,ret);
1323 throw INTERP_KERNEL::Exception(MSG);
1327 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1330 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
1332 std::vector<double> ret;
1333 std::size_t size1=-1;
1335 if(PyList_Check(pyLi))
1337 size1=PyList_Size(pyLi);
1338 for(std::size_t i=0;i<size1;i++)
1340 PyObject *o=PyList_GetItem(pyLi,i);
1341 fillArrayWithPyListDbl3(o,size2,ret);
1346 else if(PyTuple_Check(pyLi))
1348 size1=PyTuple_Size(pyLi);
1349 for(std::size_t i=0;i<size1;i++)
1351 PyObject *o=PyTuple_GetItem(pyLi,i);
1352 fillArrayWithPyListDbl3(o,size2,ret);
1358 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1360 checkFillArrayWithPyList(ToIdType(size1),ToIdType(size2),nbOfTuples,nbOfComp);
1364 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1366 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1369 if(PyList_Check(pyLi))
1371 std::size_t size=PyList_Size(pyLi);
1373 for(std::size_t i=0;i<size;i++)
1375 PyObject *obj=PyList_GetItem(pyLi,i);
1376 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1377 if(!SWIG_IsOK(status))
1379 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1380 throw INTERP_KERNEL::Exception(oss.str().c_str());
1382 T arg=reinterpret_cast< T >(argp);
1386 else if(PyTuple_Check(pyLi))
1388 std::size_t size=PyTuple_Size(pyLi);
1390 for(std::size_t i=0;i<size;i++)
1392 PyObject *obj=PyTuple_GetItem(pyLi,i);
1393 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1394 if(!SWIG_IsOK(status))
1396 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1397 throw INTERP_KERNEL::Exception(oss.str().c_str());
1399 T arg=reinterpret_cast< T >(argp);
1403 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1406 T arg=reinterpret_cast< T >(argp);
1410 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1413 //convertFromVectorAutoObjToPyObj<MEDCoupling::MEDCouplingUMesh>(inpv,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh)
1415 static PyObject *convertFromVectorAutoObjToPyObj(std::vector< MCAuto<T> >& inpVector, swig_type_info *ty)
1417 std::size_t sz(inpVector.size());
1418 PyObject *ret = PyList_New(sz);
1419 for(std::size_t i=0;i<sz;++i)
1420 PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(inpVector[i].retn()),ty, SWIG_POINTER_OWN | 0 ));
1425 * if python int -> cpp int sw=1
1426 * if python list[int] -> cpp vector<int> sw=2
1427 * if python tuple[int] -> cpp vector<int> sw=2
1428 * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1429 * if python DataArrayIntTuple -> cpp DataArrayIdTypeTuple sw=4
1431 * switch between (int,vector<int>,DataArrayIdType)
1433 template< class T, class ARRAY >
1434 static void convertIntStarLikePyObjToCpp(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, ARRAY *& daIntTyypp, typename MEDCoupling::Traits< T >::ArrayTuple *&daIntTuple)
1437 if(PyInt_Check(value))
1439 iTyypp=(T)PyInt_AS_LONG(value);
1443 if(PyTuple_Check(value))
1445 std::size_t size=PyTuple_Size(value);
1446 stdvecTyypp.resize(size);
1447 for(std::size_t i=0;i<size;i++)
1449 PyObject *o=PyTuple_GetItem(value,i);
1451 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1454 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1455 throw INTERP_KERNEL::Exception(oss.str().c_str());
1461 if(PyList_Check(value))
1463 std::size_t size=PyList_Size(value);
1464 stdvecTyypp.resize(size);
1465 for(std::size_t i=0;i<size;i++)
1467 PyObject *o=PyList_GetItem(value,i);
1469 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1472 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1473 throw INTERP_KERNEL::Exception(oss.str().c_str());
1480 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1481 if(SWIG_IsOK(status))
1483 daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1487 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1488 if(SWIG_IsOK(status))
1490 daIntTuple=reinterpret_cast< typename MEDCoupling::Traits< T >::ArrayTuple * >(argp);
1494 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1498 * if python int -> cpp int sw=1
1499 * if python list[int] -> cpp vector<int> sw=2
1500 * if python tuple[int] -> cpp vector<int> sw=2
1501 * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1502 * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4
1504 * switch between (int,vector<int>,DataArrayIdType)
1507 static const T *convertIntStarLikePyObjToCppIntStar(PyObject *value, mcIdType& sw, mcIdType& sz, T& iTyypp, std::vector<T>& stdvecTyypp)
1510 if(PyInt_Check(value))
1512 iTyypp=(T)PyInt_AS_LONG(value);
1516 if(PyTuple_Check(value))
1518 std::size_t size=PyTuple_Size(value);
1519 stdvecTyypp.resize(size);
1520 for(std::size_t i=0;i<size;i++)
1522 PyObject *o=PyTuple_GetItem(value,i);
1524 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1527 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1528 throw INTERP_KERNEL::Exception(oss.str().c_str());
1531 sw=2; sz=ToIdType(size);
1532 return &stdvecTyypp[0];
1534 if(PyList_Check(value))
1536 std::size_t size=PyList_Size(value);
1537 stdvecTyypp.resize(size);
1538 for(std::size_t i=0;i<size;i++)
1540 PyObject *o=PyList_GetItem(value,i);
1542 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1545 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1546 throw INTERP_KERNEL::Exception(oss.str().c_str());
1549 sw=2; sz=ToIdType(size);
1550 return &stdvecTyypp[0];
1553 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI,0|0);
1554 if(SWIG_IsOK(status))
1556 typedef typename MEDCoupling::Traits< T >::ArrayType ARRAY;
1557 ARRAY *daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1560 sw=3; sz=daIntTyypp->getNbOfElems();
1561 return daIntTyypp->begin();
1569 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1570 if(SWIG_IsOK(status))
1572 typedef typename MEDCoupling::Traits< T >::ArrayTuple ARRAYTUPLE;
1573 ARRAYTUPLE *daIntTuple=reinterpret_cast< ARRAYTUPLE * >(argp);
1574 sw=4; sz=ToIdType(daIntTuple->getNumberOfCompo());
1575 return daIntTuple->getConstPointer();
1577 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1581 * if python double -> cpp double sw=1
1582 * if python int -> cpp double sw=1
1583 * if python list[double] -> cpp vector<double> sw=2
1584 * if python list[int] -> cpp vector<double> sw=2
1585 * if python tuple[double] -> cpp vector<double> sw=2
1586 * if python tuple[int] -> cpp vector<double> sw=2
1587 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1589 * switch between (int,vector<int>,DataArrayIdType)
1592 void considerPyObjAsATStarLikeObject(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1595 if(PyFloat_Check(value))
1597 iTyypp=(T)PyFloat_AS_DOUBLE(value);
1601 if(PyInt_Check(value))
1603 iTyypp=(T)PyInt_AS_LONG(value);
1607 if(PyTuple_Check(value))
1609 std::size_t size=PyTuple_Size(value);
1610 stdvecTyypp.resize(size);
1611 for(std::size_t i=0;i<size;i++)
1613 PyObject *o=PyTuple_GetItem(value,i);
1614 if(PyFloat_Check(o))
1615 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1616 else if(PyInt_Check(o))
1617 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1620 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1621 throw INTERP_KERNEL::Exception(oss.str().c_str());
1627 if(PyList_Check(value))
1629 std::size_t size=PyList_Size(value);
1630 stdvecTyypp.resize(size);
1631 for(std::size_t i=0;i<size;i++)
1633 PyObject *o=PyList_GetItem(value,i);
1634 if(PyFloat_Check(o))
1635 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1636 else if(PyInt_Check(o))
1637 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1640 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1641 throw INTERP_KERNEL::Exception(oss.str().c_str());
1648 int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1649 if(!SWIG_IsOK(status))
1650 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1651 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1656 * if python double -> cpp double sw=1
1657 * if python int -> cpp double sw=1
1658 * if python list[double] -> cpp vector<double> sw=2
1659 * if python list[int] -> cpp vector<double> sw=2
1660 * if python tuple[double] -> cpp vector<double> sw=2
1661 * if python tuple[int] -> cpp vector<double> sw=2
1662 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1664 * switch between (int,vector<int>,DataArrayIdType)
1666 static void convertDoubleStarLikePyObjToCpp(PyObject *value, mcIdType& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1669 if(PyFloat_Check(value))
1671 iTyypp=PyFloat_AS_DOUBLE(value);
1675 if(PyInt_Check(value))
1677 iTyypp=(double)PyInt_AS_LONG(value);
1681 if(PyTuple_Check(value))
1683 std::size_t size=PyTuple_Size(value);
1684 stdvecTyypp.resize(size);
1685 for(std::size_t i=0;i<size;i++)
1687 PyObject *o=PyTuple_GetItem(value,i);
1688 if(PyFloat_Check(o))
1689 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1690 else if(PyInt_Check(o))
1691 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1694 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1695 throw INTERP_KERNEL::Exception(oss.str().c_str());
1701 if(PyList_Check(value))
1703 std::size_t size=PyList_Size(value);
1704 stdvecTyypp.resize(size);
1705 for(std::size_t i=0;i<size;i++)
1707 PyObject *o=PyList_GetItem(value,i);
1708 if(PyFloat_Check(o))
1709 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1710 else if(PyInt_Check(o))
1711 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1714 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1715 throw INTERP_KERNEL::Exception(oss.str().c_str());
1722 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1723 if(!SWIG_IsOK(status))
1724 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1725 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1730 void convertFPStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
1733 if(PyFloat_Check(value))
1735 val=(T)PyFloat_AS_DOUBLE(value);
1739 if(PyInt_Check(value))
1741 val=(T)PyInt_AS_LONG(value);
1745 if(PyTuple_Check(value))
1747 std::size_t size=PyTuple_Size(value);
1749 for(std::size_t i=0;i<size;i++)
1751 PyObject *o=PyTuple_GetItem(value,i);
1752 if(PyFloat_Check(o))
1753 f[i]=(T)PyFloat_AS_DOUBLE(o);
1754 else if(PyInt_Check(o))
1755 f[i]=(T)PyInt_AS_LONG(o);
1758 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1759 throw INTERP_KERNEL::Exception(oss.str().c_str());
1765 if(PyList_Check(value))
1767 std::size_t size=PyList_Size(value);
1769 for(std::size_t i=0;i<size;i++)
1771 PyObject *o=PyList_GetItem(value,i);
1772 if(PyFloat_Check(o))
1773 f[i]=(T)PyFloat_AS_DOUBLE(o);
1774 else if(PyInt_Check(o))
1775 f[i]=(T)PyInt_AS_LONG(o);
1778 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1779 throw INTERP_KERNEL::Exception(oss.str().c_str());
1786 int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1787 if(SWIG_IsOK(status))
1789 d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1793 status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1794 if(SWIG_IsOK(status))
1796 e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1800 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1804 * if value int -> cpp val sw=1
1805 * if value double -> cpp val sw=1
1806 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1807 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1808 * if value list[int,double] -> cpp std::vector<double> sw=4
1809 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1811 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1813 convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1817 * if value int -> cpp val sw=1
1818 * if value double -> cpp val sw=1
1819 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1820 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1821 * if value list[int,double] -> cpp std::vector<double> sw=4
1822 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1824 static void convertFloatStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
1826 convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
1830 * if python int -> cpp int sw=1
1831 * if python list[int] -> cpp vector<int> sw=2
1832 * if python tuple[int] -> cpp vector<int> sw=2
1833 * if python slicp -> cpp pair sw=3 (begin,end,step)
1834 * if python DataArrayIdType -> cpp DataArrayIdType sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1836 * switch between (int,vector<int>,DataArrayIdType)
1838 template<class T, class ARRAY>
1839 static void convertIntStarOrSliceLikePyObjToCpp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1841 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdType, DataArrayIdTypeTuple";
1843 if(PyInt_Check(value))
1845 iTyypp=(T)PyInt_AS_LONG(value);
1849 if(PyTuple_Check(value))
1851 std::size_t size=PyTuple_Size(value);
1852 stdvecTyypp.resize(size);
1853 for(std::size_t i=0;i<size;i++)
1855 PyObject *o=PyTuple_GetItem(value,i);
1857 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1860 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1861 throw INTERP_KERNEL::Exception(oss.str().c_str());
1867 if(PyList_Check(value))
1869 std::size_t size=PyList_Size(value);
1870 stdvecTyypp.resize(size);
1871 for(std::size_t i=0;i<size;i++)
1873 PyObject *o=PyList_GetItem(value,i);
1875 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1878 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1879 throw INTERP_KERNEL::Exception(oss.str().c_str());
1885 if(PySlice_Check(value))
1887 Py_ssize_t strt=2,stp=2,step=2;
1888 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1889 p.first=ToIdType(strt);
1890 p.second.first=ToIdType(stp);
1891 p.second.second=ToIdType(step);
1896 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1897 if(SWIG_IsOK(status))
1899 daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1902 std::ostringstream oss; oss << msg << " Instance in null !";
1903 throw INTERP_KERNEL::Exception(oss.str().c_str());
1908 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI_TUPLE,0|0);
1909 if(SWIG_IsOK(status))
1911 typedef typename MEDCoupling::Traits< typename ARRAY::Type >::ArrayTuple ARRAYTUPLE;
1912 ARRAYTUPLE *tmp=reinterpret_cast< ARRAYTUPLE * >(argp);
1915 std::ostringstream oss; oss << msg << " Instance in null !";
1916 throw INTERP_KERNEL::Exception(oss.str().c_str());
1918 stdvecTyypp.resize(tmp->getNumberOfCompo());
1919 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1923 throw INTERP_KERNEL::Exception(msg);
1927 * Idem than convertIntStarOrSliceLikePyObjToCpp
1929 template<class T, class ARRAY>
1930 static void convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1932 convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1935 iTyypp=(T)InterpreteNegativeInt(iTyypp,nbelem);
1940 * if python int -> cpp int sw=1
1941 * if python tuple[int] -> cpp vector<int> sw=2
1942 * if python list[int] -> cpp vector<int> sw=2
1943 * if python slice -> cpp pair sw=3
1944 * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4 . WARNING The returned pointer can be the null pointer !
1946 template< class TUPLE_T >
1947 static void convertObjToPossibleCpp22(PyObject *value, mcIdType nbelem, mcIdType& sw, mcIdType& iTyypp, std::vector<mcIdType>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple *& daIntTyypp)
1950 if(PyInt_Check(value))
1952 iTyypp=ToIdType(PyInt_AS_LONG(value));
1956 if(PyTuple_Check(value))
1958 std::size_t size=PyTuple_Size(value);
1959 stdvecTyypp.resize(size);
1960 for(std::size_t i=0;i<size;i++)
1962 PyObject *o=PyTuple_GetItem(value,i);
1964 stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1967 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1968 throw INTERP_KERNEL::Exception(oss.str().c_str());
1974 if(PyList_Check(value))
1976 std::size_t size=PyList_Size(value);
1977 stdvecTyypp.resize(size);
1978 for(std::size_t i=0;i<size;i++)
1980 PyObject *o=PyList_GetItem(value,i);
1982 stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1985 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1986 throw INTERP_KERNEL::Exception(oss.str().c_str());
1992 if(PySlice_Check(value))
1994 Py_ssize_t strt=2,stp=2,step=2;
1995 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1996 p.first=ToIdType(strt);
1997 p.second.first=ToIdType(stp);
1998 p.second.second=ToIdType(step);
2003 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<TUPLE_T>::TI_TUPLE,0|0);
2004 if(!SWIG_IsOK(status))
2005 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdTypeTuple");
2006 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple * >(argp);
2011 * if python string with size one -> cpp char sw=1
2012 * if python string with size different from one -> cpp string sw=2
2013 * if python tuple[string] or list[string] -> vector<string> sw=3
2014 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
2015 * switch between (int,string,vector<string>,DataArrayChar)
2017 static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
2019 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
2021 if(PyString_Check(value))
2023 const char *pt=PyString_AsString(value);
2024 Py_ssize_t sz=PyString_Size(value);
2038 #if PY_VERSION_HEX >= 0x03000000
2039 if(PyUnicode_Check(value))
2042 const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
2057 if(PyTuple_Check(value))
2059 std::size_t size=PyTuple_Size(value);
2060 vsType.resize(size);
2061 for(std::size_t i=0;i<size;i++)
2063 PyObject *o=PyTuple_GetItem(value,i);
2066 vsType[i]=convertPyObjectToStr(o);
2068 catch(INTERP_KERNEL::Exception& )
2070 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2071 throw INTERP_KERNEL::Exception(oss.str().c_str());
2077 if(PyList_Check(value))
2079 std::size_t size=PyList_Size(value);
2080 vsType.resize(size);
2081 for(std::size_t i=0;i<size;i++)
2083 PyObject *o=PyList_GetItem(value,i);
2086 vsType[i]=convertPyObjectToStr(o);
2088 catch(INTERP_KERNEL::Exception& )
2090 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2091 throw INTERP_KERNEL::Exception(oss.str().c_str());
2098 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
2099 if(SWIG_IsOK(status))
2101 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
2104 std::ostringstream oss; oss << msg << " Instance in null !";
2105 throw INTERP_KERNEL::Exception(oss.str().c_str());
2110 throw INTERP_KERNEL::Exception(msg);
2114 * if value int -> cpp it sw=1
2115 * if value list[int] -> vt sw=2
2116 * if value tuple[int] -> vt sw=2
2117 * if value slice -> pt sw=3
2118 * if value DataArrayIdType -> dt sw=4
2119 * if value tuple [int,int] -> cpp it,ip sw=5
2120 * if value tuple [list[int],int] -> cpp vt,ip sw=6
2121 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2122 * if value tuple [slice,int] -> cpp pt,ip sw=7
2123 * if value tuple [DaI,int] -> cpp dt,ip sw=8
2124 * if value tuple [int,list[int]] -> cpp it,vc sw=9
2125 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2126 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2127 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2128 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2129 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2130 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2131 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2132 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2133 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2134 * if value tuple [int,slice] -> cpp it,pc sw=13
2135 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2136 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2137 * if value tuple [slice,slice] -> cpp pt,pc sw=15
2138 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2140 * switch between (int,vector<int>,DataArrayIdType)
2143 static void convertObjToPossibleCpp3(PyObject *value, mcIdType nbTuple, int nbCompo, mcIdType& sw, mcIdType& it, TC& ic, std::vector<mcIdType>& vt, std::vector<TC>& vc,
2144 std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pt, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pc,
2145 MEDCoupling::DataArrayIdType *&dt, MEDCoupling::DataArrayIdType *&dc)
2147 if(!PyTuple_Check(value))
2149 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2154 std::size_t sz=PyTuple_Size(value);
2156 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2157 PyObject *ob0=PyTuple_GetItem(value,0);
2159 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2160 PyObject *ob1=PyTuple_GetItem(value,1);
2161 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2167 * if value int -> cpp val sw=1
2168 * if value double -> cpp val sw=1
2169 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2170 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2171 * if value list[int,double] -> cpp std::vector<double> sw=4
2172 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2174 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2175 const char *msg, mcIdType nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2178 if(PyFloat_Check(value))
2180 val=PyFloat_AS_DOUBLE(value);
2182 if(nbTuplesExpected*nbCompExpected!=1)
2184 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2185 throw INTERP_KERNEL::Exception(oss.str().c_str());
2189 if(PyInt_Check(value))
2191 val=(double)PyInt_AS_LONG(value);
2193 if(nbTuplesExpected*nbCompExpected!=1)
2195 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2196 throw INTERP_KERNEL::Exception(oss.str().c_str());
2200 if(PyTuple_Check(value) || PyList_Check(value))
2204 mcIdType tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2205 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2210 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2213 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2214 if(SWIG_IsOK(status))
2216 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2220 if(d->getNumberOfTuples()==nbTuplesExpected)
2222 if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2224 return d->getConstPointer();
2228 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2229 throw INTERP_KERNEL::Exception(oss.str().c_str());
2234 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2235 throw INTERP_KERNEL::Exception(oss.str().c_str());
2242 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2243 throw INTERP_KERNEL::Exception(oss.str().c_str());
2249 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2250 if(SWIG_IsOK(status))
2252 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2254 if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2256 if(nbTuplesExpected==1)
2257 return e->getConstPointer();
2260 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by construction !";
2261 throw INTERP_KERNEL::Exception(oss.str().c_str());
2266 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2267 throw INTERP_KERNEL::Exception(oss.str().c_str());
2270 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2274 * if value int -> cpp val sw=1
2275 * if value double -> cpp val sw=1
2276 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2277 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2278 * if value list[int,double] -> cpp std::vector<double> sw=4
2279 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2281 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2282 const char *msg, int nbCompExpected, bool throwIfNullPt, mcIdType& nbTuples)
2285 if(PyFloat_Check(value))
2287 val=PyFloat_AS_DOUBLE(value);
2289 if(nbCompExpected!=1)
2291 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2292 throw INTERP_KERNEL::Exception(oss.str().c_str());
2297 if(PyInt_Check(value))
2299 val=(double)PyInt_AS_LONG(value);
2301 if(nbCompExpected!=1)
2303 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2304 throw INTERP_KERNEL::Exception(oss.str().c_str());
2309 if(PyTuple_Check(value))
2311 std::size_t size=PyTuple_Size(value);
2313 for(std::size_t i=0;i<size;i++)
2315 PyObject *o=PyTuple_GetItem(value,i);
2316 if(PyFloat_Check(o))
2317 f[i]=PyFloat_AS_DOUBLE(o);
2318 else if(PyInt_Check(o))
2319 f[i]=(double)PyInt_AS_LONG(o);
2322 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2323 throw INTERP_KERNEL::Exception(oss.str().c_str());
2327 if(size%nbCompExpected!=0)
2329 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2330 throw INTERP_KERNEL::Exception(oss.str().c_str());
2332 nbTuples=ToIdType(size/nbCompExpected);
2335 if(PyList_Check(value))
2337 std::size_t size=PyList_Size(value);
2339 for(std::size_t i=0;i<size;i++)
2341 PyObject *o=PyList_GetItem(value,i);
2342 if(PyFloat_Check(o))
2343 f[i]=PyFloat_AS_DOUBLE(o);
2344 else if(PyInt_Check(o))
2345 f[i]=(double)PyInt_AS_LONG(o);
2348 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2349 throw INTERP_KERNEL::Exception(oss.str().c_str());
2353 if(size%nbCompExpected!=0)
2355 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2356 throw INTERP_KERNEL::Exception(oss.str().c_str());
2358 nbTuples=ToIdType(size/nbCompExpected);
2362 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2363 if(SWIG_IsOK(status))
2365 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2369 if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2371 nbTuples=d->getNumberOfTuples();
2372 return d->getConstPointer();
2376 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2377 throw INTERP_KERNEL::Exception(oss.str().c_str());
2384 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2385 throw INTERP_KERNEL::Exception(oss.str().c_str());
2388 { nbTuples=0; return 0; }
2391 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2392 if(SWIG_IsOK(status))
2394 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2398 if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2401 return e->getConstPointer();
2405 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2406 throw INTERP_KERNEL::Exception(oss.str().c_str());
2413 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2414 throw INTERP_KERNEL::Exception(oss.str().c_str());
2417 { nbTuples=0; return 0; }
2420 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2424 * if value int -> cpp val sw=1
2425 * if value double -> cpp val sw=1
2426 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2427 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2428 * if value list[int,double] -> cpp std::vector<double> sw=4
2429 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2431 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, mcIdType& sw, double& val, std::vector<double>& f,
2432 const char *msg, bool throwIfNullPt, mcIdType& nbTuples)
2434 MEDCoupling::DataArrayDouble *d=0;
2435 MEDCoupling::DataArrayDoubleTuple *e=0;
2437 if(PyFloat_Check(value))
2439 val=PyFloat_AS_DOUBLE(value);
2444 if(PyInt_Check(value))
2446 val=(double)PyInt_AS_LONG(value);
2451 if(PyTuple_Check(value))
2453 std::size_t size=PyTuple_Size(value);
2455 for(std::size_t i=0;i<size;i++)
2457 PyObject *o=PyTuple_GetItem(value,i);
2458 if(PyFloat_Check(o))
2459 f[i]=PyFloat_AS_DOUBLE(o);
2460 else if(PyInt_Check(o))
2461 f[i]=(double)PyInt_AS_LONG(o);
2464 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2465 throw INTERP_KERNEL::Exception(oss.str().c_str());
2469 nbTuples=ToIdType(size);
2472 if(PyList_Check(value))
2474 std::size_t size=PyList_Size(value);
2476 for(std::size_t i=0;i<size;i++)
2478 PyObject *o=PyList_GetItem(value,i);
2479 if(PyFloat_Check(o))
2480 f[i]=PyFloat_AS_DOUBLE(o);
2481 else if(PyInt_Check(o))
2482 f[i]=(double)PyInt_AS_LONG(o);
2485 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2486 throw INTERP_KERNEL::Exception(oss.str().c_str());
2490 nbTuples=ToIdType(size);
2494 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2495 if(SWIG_IsOK(status))
2497 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2501 if(d->getNumberOfComponents()==1)
2503 nbTuples=d->getNumberOfTuples();
2504 return d->getConstPointer();
2508 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2509 throw INTERP_KERNEL::Exception(oss.str().c_str());
2516 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2517 throw INTERP_KERNEL::Exception(oss.str().c_str());
2520 { nbTuples=0; return 0; }
2523 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2524 if(SWIG_IsOK(status))
2526 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2530 nbTuples=ToIdType(e->getNumberOfCompo());
2531 return e->getConstPointer();
2537 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2538 throw INTERP_KERNEL::Exception(oss.str().c_str());
2541 { nbTuples=0; return 0; }
2544 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2547 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2550 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2551 if(!SWIG_IsOK(status))
2553 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2554 if(!SWIG_IsOK(status))
2556 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt32,0|0);
2557 if(!SWIG_IsOK(status))
2559 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt64,0|0);
2560 if(!SWIG_IsOK(status))
2562 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2563 if(!SWIG_IsOK(status))
2565 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2566 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayIdType, DataArrayAsciiChar, DataArrayByte !";
2567 throw INTERP_KERNEL::Exception(oss.str().c_str());
2573 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2576 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2581 Py_XINCREF(Py_None);
2584 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2585 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2587 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2592 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2594 const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
2595 std::string msg(msgBase);
2597 msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2600 if(PyList_Check(elt0) || PyTuple_Check(elt0))
2604 if(PyInt_Check(nbOfTuples))
2606 mcIdType nbOfTuples1=ToIdType(PyInt_AS_LONG(nbOfTuples));
2608 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2611 if(PyInt_Check(elt2))
2612 {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2613 mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(elt2));
2615 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2616 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2617 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2618 ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2622 throw INTERP_KERNEL::Exception(msg.c_str());
2625 {//DataArrayDouble.New([1.,3.,4.],3)
2626 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2628 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2629 ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2634 throw INTERP_KERNEL::Exception(msg.c_str());
2637 {// DataArrayDouble.New([1.,3.,4.])
2638 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2639 mcIdType tmpp1(-1),tmpp2(-1);
2640 std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2641 ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2645 else if(PyInt_Check(elt0))
2647 mcIdType nbOfTuples1(ToIdType(PyInt_AS_LONG(elt0)));
2649 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2654 if(PyInt_Check(nbOfTuples))
2655 {//DataArrayDouble.New(5,2)
2656 mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(nbOfTuples));
2658 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2659 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2660 ret->alloc(nbOfTuples1,nbOfCompo);
2664 throw INTERP_KERNEL::Exception(msg.c_str());
2667 throw INTERP_KERNEL::Exception(msg.c_str());
2670 {//DataArrayDouble.New(5)
2671 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2672 ret->alloc(nbOfTuples1,1);
2677 else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2678 {//DataArrayDouble.New(numpyArray)
2679 return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2683 throw INTERP_KERNEL::Exception(msg.c_str());
2684 throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2688 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2690 self->checkAllocated();
2691 const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2692 mcIdType nbOfTuples(self->getNumberOfTuples());
2693 int nbOfComponents((int)(self->getNumberOfComponents()));
2697 typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2698 considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2700 std::vector<mcIdType> vt1;
2701 std::vector<mcIdType> vc1;
2702 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
2703 MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
2704 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2705 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2713 self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2716 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2717 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2718 self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2721 self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2724 throw INTERP_KERNEL::Exception(msg);
2733 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2736 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2737 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2738 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2741 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2744 throw INTERP_KERNEL::Exception(msg);
2753 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2756 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2757 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2758 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2761 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2764 throw INTERP_KERNEL::Exception(msg);
2773 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2776 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2777 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2778 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2781 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2784 throw INTERP_KERNEL::Exception(msg);
2793 self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2796 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2797 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2798 self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2801 self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2804 throw INTERP_KERNEL::Exception(msg);
2813 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2816 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2817 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2818 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2821 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2824 throw INTERP_KERNEL::Exception(msg);
2833 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2836 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2837 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2838 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2841 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2844 throw INTERP_KERNEL::Exception(msg);
2853 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2856 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2857 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2858 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2861 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2864 throw INTERP_KERNEL::Exception(msg);
2873 self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2876 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2877 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2878 self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2881 self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2884 throw INTERP_KERNEL::Exception(msg);
2893 self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2896 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2897 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2898 self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2901 self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2904 throw INTERP_KERNEL::Exception(msg);
2913 self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2916 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2917 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2918 self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2921 self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2924 throw INTERP_KERNEL::Exception(msg);
2933 self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2936 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2937 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2938 self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2941 self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2944 throw INTERP_KERNEL::Exception(msg);
2953 self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2956 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2957 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2958 self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2961 self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2964 throw INTERP_KERNEL::Exception(msg);
2973 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2976 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2977 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2978 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2981 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2984 throw INTERP_KERNEL::Exception(msg);
2993 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2996 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2997 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2998 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
3001 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
3004 throw INTERP_KERNEL::Exception(msg);
3013 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3016 tmp=MEDCoupling::Traits<T>::ArrayType::New();
3017 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
3018 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
3021 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3024 throw INTERP_KERNEL::Exception(msg);
3029 throw INTERP_KERNEL::Exception(msg);
3035 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3037 const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3038 const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3039 self->checkAllocated();
3040 mcIdType nbOfTuples(self->getNumberOfTuples());
3041 int nbOfComponents((int)(self->getNumberOfComponents()));
3044 std::vector<mcIdType> vt1;
3045 std::vector<std::size_t> vc1;
3046 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
3047 MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
3049 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3050 MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3054 if(nbOfComponents==1)
3055 return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3056 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3058 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3060 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3062 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3064 return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3067 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3068 std::vector<std::size_t> v2(1,ic1);
3069 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3073 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3074 std::vector<std::size_t> v2(1,ic1);
3075 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3079 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3080 std::vector<std::size_t> v2(1,ic1);
3081 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3085 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3086 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3090 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3091 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3095 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3096 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3100 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3101 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3105 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3106 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3107 std::vector<std::size_t> v2(nbOfComp);
3108 for(mcIdType i=0;i<nbOfComp;i++)
3109 v2[i]=pc1.first+i*pc1.second.second;
3110 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3114 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3115 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3116 std::vector<std::size_t> v2(nbOfComp);
3117 for(int i=0;i<nbOfComp;i++)
3118 v2[i]=pc1.first+i*pc1.second.second;
3119 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3123 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3124 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3125 std::vector<std::size_t> v2(nbOfComp);
3126 for(int i=0;i<nbOfComp;i++)
3127 v2[i]=pc1.first+i*pc1.second.second;
3128 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3132 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3133 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3134 std::vector<std::size_t> v2(nbOfComp);
3135 for(int i=0;i<nbOfComp;i++)
3136 v2[i]=pc1.first+i*pc1.second.second;
3137 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3140 throw INTERP_KERNEL::Exception(msg);
3144 bool isCSRMatrix(PyObject *m)
3146 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
3147 PyObject* pdict(PyDict_New());
3148 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
3149 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
3151 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
3152 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
3154 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
3155 bool ret(PyObject_IsInstance(m,csrMatrixCls));
3156 Py_DECREF(pdict); Py_XDECREF(tmp);
3163 void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
3165 auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
3167 throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !");
3168 mCpp.resize(nbOfRows);
3169 auto indPtrCPtr(indptrPtr->begin());
3170 auto indicesCPtr(indicesPtr->begin());
3171 auto dataCPtr(dataPtr->begin());
3172 for(auto i=0;i<nbOfRows;i++)
3174 auto& line(mCpp[i]);
3175 for(auto j=indPtrCPtr[i];j<indPtrCPtr[i+1];j++)
3177 line[indicesCPtr[j]]=dataCPtr[j];
3182 void convertToVectMapIntDouble(PyObject *pyobj, std::vector<std::map<mcIdType,double> >& mCpp)
3184 if(!PyList_Check(pyobj))
3185 throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !");
3187 Py_ssize_t sz(PyList_Size(pyobj));
3189 for(Py_ssize_t i=0;i<sz;i++)
3191 PyObject *elt(PyList_GetItem(pyobj,i));
3192 if(!PyDict_Check(elt))
3194 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist a dict is exepect !";
3195 throw INTERP_KERNEL::Exception(oss.str());
3197 PyObject *key, *value;
3199 std::map<mcIdType,double>& mapCpp(mCpp[i]);
3200 while(PyDict_Next(elt,&pos,&key,&value))
3202 if(!PyInt_Check(key))
3204 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !";
3205 throw INTERP_KERNEL::Exception(oss.str());
3207 if(!PyFloat_Check(value))
3209 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !";
3210 throw INTERP_KERNEL::Exception(oss.str());
3212 mapCpp[ToIdType(PyInt_AS_LONG(key))]=PyFloat_AS_DOUBLE(value);
3218 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3220 const char msg[]="Unexpected situation in __imul__ !";
3222 typename MEDCoupling::Traits<T>::ArrayType *a;
3223 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3226 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3231 self->applyLin(val,0.);
3232 Py_XINCREF(trueSelf);
3237 self->multiplyEqual(a);
3238 Py_XINCREF(trueSelf);
3243 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3244 self->multiplyEqual(aaa);
3245 Py_XINCREF(trueSelf);
3250 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3251 self->multiplyEqual(aaa);
3252 Py_XINCREF(trueSelf);
3256 throw INTERP_KERNEL::Exception(msg);
3261 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3263 const char msg[]="Unexpected situation in __idiv__ !";
3265 typename MEDCoupling::Traits<T>::ArrayType *a;
3266 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3269 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3275 throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3276 self->applyLin((T)(1./val),(T)0.);
3277 Py_XINCREF(trueSelf);
3282 self->divideEqual(a);
3283 Py_XINCREF(trueSelf);
3288 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3289 self->divideEqual(aaa);
3290 Py_XINCREF(trueSelf);
3295 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3296 self->divideEqual(aaa);
3297 Py_XINCREF(trueSelf);
3301 throw INTERP_KERNEL::Exception(msg);
3306 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3308 const char msg[]="Unexpected situation in __iadd__ !";
3310 typename MEDCoupling::Traits<T>::ArrayType *a;
3311 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3314 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3319 self->applyLin(1.,val);
3320 Py_XINCREF(trueSelf);
3326 Py_XINCREF(trueSelf);
3331 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3332 self->addEqual(aaa);
3333 Py_XINCREF(trueSelf);
3338 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3339 self->addEqual(aaa);
3340 Py_XINCREF(trueSelf);
3344 throw INTERP_KERNEL::Exception(msg);
3349 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3351 const char msg[]="Unexpected situation in __isub__ !";
3353 typename MEDCoupling::Traits<T>::ArrayType *a;
3354 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3357 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3362 self->applyLin(1.,-val);
3363 Py_XINCREF(trueSelf);
3368 self->substractEqual(a);
3369 Py_XINCREF(trueSelf);
3374 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3375 self->substractEqual(aaa);
3376 Py_XINCREF(trueSelf);
3381 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3382 self->substractEqual(aaa);
3383 Py_XINCREF(trueSelf);
3387 throw INTERP_KERNEL::Exception(msg);
3392 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3394 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3396 PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
3398 PyTypeObject *NPYTraits<MEDCoupling::Int64>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
3402 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3404 return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3408 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3410 return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3414 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3416 return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3420 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3422 return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3426 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3428 return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3432 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3434 return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3438 typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3440 const char msg[]="Unexpected situation in __rmul__ !";
3442 typename MEDCoupling::Traits<T>::ArrayType *a;
3443 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3446 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3451 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
3452 ret->applyLin(val,0.);
3457 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
3458 return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3462 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3463 return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3466 throw INTERP_KERNEL::Exception(msg);