1 // Copyright (C) 2007-2020 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 convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
686 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
687 if(PyList_Check(pyLi))
689 std::size_t size=PyList_Size(pyLi);
691 for(std::size_t i=0;i<size;i++)
693 PyObject *o=PyList_GetItem(pyLi,i);
696 std::size_t sz2=PyTuple_Size(o);
698 throw INTERP_KERNEL::Exception(msg);
699 PyObject *o_0=PyTuple_GetItem(o,0);
700 PyObject *o_1=PyTuple_GetItem(o,1);
701 arr[i].first=convertPyObjectToStr(o_0,msg);
702 if(!PyInt_Check(o_1))
703 throw INTERP_KERNEL::Exception(msg);
704 arr[i].second=(int)PyInt_AS_LONG(o_1);
707 throw INTERP_KERNEL::Exception(msg);
710 else if(PyTuple_Check(pyLi))
712 std::size_t size=PyTuple_Size(pyLi);
714 for(std::size_t i=0;i<size;i++)
716 PyObject *o=PyTuple_GetItem(pyLi,i);
719 std::size_t sz2=PyTuple_Size(o);
721 throw INTERP_KERNEL::Exception(msg);
722 PyObject *o_0=PyTuple_GetItem(o,0);
723 PyObject *o_1=PyTuple_GetItem(o,1);
724 arr[i].first=convertPyObjectToStr(o_0,msg);
725 if(!PyInt_Check(o_1))
726 throw INTERP_KERNEL::Exception(msg);
727 arr[i].second=(int)PyInt_AS_LONG(o_1);
730 throw INTERP_KERNEL::Exception(msg);
734 throw INTERP_KERNEL::Exception(msg);
738 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<T>& arr)
740 if(PyList_Check(pyLi))
742 std::size_t size=PyList_Size(pyLi);
744 for(std::size_t i=0;i<size;i++)
746 PyObject *o=PyList_GetItem(pyLi,i);
749 T val=(T)PyInt_AS_LONG(o);
753 throw INTERP_KERNEL::Exception("list must contain integers only");
756 else if(PyTuple_Check(pyLi))
758 std::size_t size=PyTuple_Size(pyLi);
760 for(std::size_t i=0;i<size;i++)
762 PyObject *o=PyTuple_GetItem(pyLi,i);
765 T val=(T)PyInt_AS_LONG(o);
769 throw INTERP_KERNEL::Exception("tuple must contain integers only");
774 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
778 static void convertPyToNewIntArr4(PyObject *pyLi, mcIdType recurseLev, mcIdType nbOfSubPart, std::vector<mcIdType>& arr)
781 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
783 if(PyList_Check(pyLi))
785 std::size_t size=PyList_Size(pyLi);
786 for(std::size_t i=0;i<size;i++)
788 PyObject *o=PyList_GetItem(pyLi,i);
791 mcIdType val=(mcIdType)PyInt_AS_LONG(o);
796 std::vector<mcIdType> arr2;
797 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
798 if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
800 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
801 throw INTERP_KERNEL::Exception(oss.str().c_str());
803 arr.insert(arr.end(),arr2.begin(),arr2.end());
807 else if(PyTuple_Check(pyLi))
809 std::size_t size=PyTuple_Size(pyLi);
810 for(std::size_t i=0;i<size;i++)
812 PyObject *o=PyTuple_GetItem(pyLi,i);
815 mcIdType val=ToIdType(PyInt_AS_LONG(o));
820 std::vector<mcIdType> arr2;
821 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
822 if(nbOfSubPart>=1 && nbOfSubPart!=(mcIdType)arr2.size())
824 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
825 throw INTERP_KERNEL::Exception(oss.str().c_str());
827 arr.insert(arr.end(),arr2.begin(),arr2.end());
832 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
835 static void checkFillArrayWithPyList(mcIdType size1, mcIdType size2, mcIdType& nbOfTuples, mcIdType& nbOfComp)
839 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
840 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
842 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
843 oss << " whereas nb of components expected is " << nbOfComp << " !";
844 throw INTERP_KERNEL::Exception(oss.str().c_str());
851 if((nbOfTuples!=size1 || nbOfComp!=size2))
853 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
855 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
856 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
857 throw INTERP_KERNEL::Exception(oss.str().c_str());
863 if(nbOfTuples==size1)
867 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
868 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
869 throw INTERP_KERNEL::Exception(oss.str().c_str());
876 static void fillArrayWithPyListInt3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<T>& ret)
878 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
879 if(PyInt_Check(pyLi))
881 T val=(T)PyInt_AS_LONG(pyLi);
886 throw INTERP_KERNEL::Exception(MSG);
889 else if(PyList_Check(pyLi))
891 std::size_t size=PyList_Size(pyLi);
893 for(std::size_t i=0;i<size;i++)
895 PyObject *o=PyList_GetItem(pyLi,i);
897 fillArrayWithPyListInt3(o,tmp1,ret);
905 throw INTERP_KERNEL::Exception(MSG);
908 else if(PyTuple_Check(pyLi))
910 std::size_t size=PyTuple_Size(pyLi);
912 for(std::size_t i=0;i<size;i++)
914 PyObject *o=PyTuple_GetItem(pyLi,i);
916 fillArrayWithPyListInt3(o,tmp1,ret);
924 throw INTERP_KERNEL::Exception(MSG);
928 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
931 template< class T = mcIdType >
932 static std::vector<T> fillArrayWithPyListInt2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
935 mcIdType size1=-1,size2=-1;
936 if(PyList_Check(pyLi))
938 size1=ToIdType(PyList_Size(pyLi));
939 for(mcIdType i=0;i<size1;i++)
941 PyObject *o=PyList_GetItem(pyLi,i);
942 fillArrayWithPyListInt3(o,size2,ret);
947 else if(PyTuple_Check(pyLi))
949 size1=ToIdType(PyTuple_Size(pyLi));
950 for(mcIdType i=0;i<size1;i++)
952 PyObject *o=PyTuple_GetItem(pyLi,i);
953 fillArrayWithPyListInt3(o,size2,ret);
959 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
961 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
965 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
967 if(PyList_Check(pyLi))
969 Py_ssize_t sz=PyList_Size(pyLi);
971 for(mcIdType i=0;i<sz;i++)
973 PyObject *o=PyList_GetItem(pyLi,i);
974 if(!convertPyObjectToStrNT(o,vec[i]))
979 else if(PyTuple_Check(pyLi))
981 Py_ssize_t sz=PyTuple_Size(pyLi);
983 for(mcIdType i=0;i<sz;i++)
985 PyObject *o=PyTuple_GetItem(pyLi,i);
986 if(!convertPyObjectToStrNT(o,vec[i]))
994 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
996 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
997 if(PyList_Check(pyLi))
999 Py_ssize_t sz=PyList_Size(pyLi);
1001 for(mcIdType i=0;i<sz;i++)
1003 PyObject *o=PyList_GetItem(pyLi,i);
1004 if(!fillStringVector(o,arr[i]))
1005 throw INTERP_KERNEL::Exception(msg);
1008 else if(PyTuple_Check(pyLi))
1010 Py_ssize_t sz=PyTuple_Size(pyLi);
1012 for(mcIdType i=0;i<sz;i++)
1014 PyObject *o=PyTuple_GetItem(pyLi,i);
1015 if(!fillStringVector(o,arr[i]))
1016 throw INTERP_KERNEL::Exception(msg);
1020 throw INTERP_KERNEL::Exception(msg);
1023 static bool fillIntVector(PyObject *pyLi, std::vector<mcIdType>& vec)
1025 if(PyList_Check(pyLi))
1027 Py_ssize_t sz=PyList_Size(pyLi);
1029 for(mcIdType i=0;i<sz;i++)
1031 PyObject *o=PyList_GetItem(pyLi,i);
1033 vec[i]=ToIdType(PyInt_AS_LONG(o));
1039 else if(PyTuple_Check(pyLi))
1041 Py_ssize_t sz=PyTuple_Size(pyLi);
1043 for(mcIdType i=0;i<sz;i++)
1045 PyObject *o=PyTuple_GetItem(pyLi,i);
1047 vec[i]=ToIdType(PyInt_AS_LONG(o));
1057 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<mcIdType> >& arr)
1059 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1060 if(PyList_Check(pyLi))
1062 Py_ssize_t sz=PyList_Size(pyLi);
1064 for(mcIdType i=0;i<sz;i++)
1066 PyObject *o=PyList_GetItem(pyLi,i);
1067 if(!fillIntVector(o,arr[i]))
1068 throw INTERP_KERNEL::Exception(msg);
1071 else if(PyTuple_Check(pyLi))
1073 Py_ssize_t sz=PyTuple_Size(pyLi);
1075 for(mcIdType i=0;i<sz;i++)
1077 PyObject *o=PyTuple_GetItem(pyLi,i);
1078 if(!fillIntVector(o,arr[i]))
1079 throw INTERP_KERNEL::Exception(msg);
1083 throw INTERP_KERNEL::Exception(msg);
1086 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
1088 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1089 if(PyList_Check(pyLi))
1091 Py_ssize_t sz=PyList_Size(pyLi);
1093 for(mcIdType i=0;i<sz;i++)
1095 PyObject *o=PyList_GetItem(pyLi,i);
1096 if(PyTuple_Check(o))
1098 std::size_t sz2=PyTuple_Size(o);
1100 throw INTERP_KERNEL::Exception(msg);
1101 std::pair<std::string, std::vector<std::string> > item;
1102 PyObject *o_0=PyTuple_GetItem(o,0);
1103 item.first=convertPyObjectToStr(o_0,msg);
1104 PyObject *o_1=PyTuple_GetItem(o,1);
1105 if(!fillStringVector(o_1,item.second))
1106 throw INTERP_KERNEL::Exception(msg);
1110 throw INTERP_KERNEL::Exception(msg);
1113 else if(PyTuple_Check(pyLi))
1115 Py_ssize_t sz=PyTuple_Size(pyLi);
1117 for(Py_ssize_t i=0;i<sz;i++)
1119 PyObject *o=PyTuple_GetItem(pyLi,i);
1120 if(PyTuple_Check(o))
1122 std::size_t sz2=PyTuple_Size(o);
1124 throw INTERP_KERNEL::Exception(msg);
1125 std::pair<std::string, std::vector<std::string> > item;
1126 PyObject *o_0=PyTuple_GetItem(o,0);
1127 item.first=convertPyObjectToStr(o_0,msg);
1128 PyObject *o_1=PyTuple_GetItem(o,1);
1129 if(!fillStringVector(o_1,item.second))
1130 throw INTERP_KERNEL::Exception(msg);
1134 throw INTERP_KERNEL::Exception(msg);
1138 throw INTERP_KERNEL::Exception(msg);
1142 PyObject *convertDblArrToPyList(const T *ptr, std::size_t size)
1144 PyObject *ret(PyList_New(size));
1145 for(std::size_t i=0;i<size;i++)
1146 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1150 static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
1152 std::size_t size(v.size());
1153 PyObject *ret(PyList_New(size));
1154 for(std::size_t i=0;i<size;i++)
1155 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1160 PyObject *convertDblArrToPyListOfTuple(const T *vals, std::size_t nbOfComp, mcIdType nbOfTuples)
1162 PyObject *ret(PyList_New(nbOfTuples));
1163 for(mcIdType i=0;i<nbOfTuples;i++)
1165 PyObject *t=PyTuple_New(nbOfComp);
1166 for(std::size_t j=0;j<nbOfComp;j++)
1167 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1168 PyList_SetItem(ret,i,t);
1173 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, mcIdType nbOfTuples)
1175 PyObject *ret=PyList_New(nbOfTuples);
1176 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1177 for(mcIdType i=0;i<nbOfTuples;i++)
1179 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1180 PyList_SetItem(ret,i,PyString_FromString(tmp));
1185 static double *convertPyToNewDblArr2(PyObject *pyLi, mcIdType *size)
1187 if(PyList_Check(pyLi))
1189 *size=ToIdType(PyList_Size(pyLi));
1190 double *tmp=(double *)malloc((*size)*sizeof(double));
1191 for(mcIdType i=0;i<*size;i++)
1193 PyObject *o=PyList_GetItem(pyLi,i);
1194 if(PyFloat_Check(o))
1196 double val=PyFloat_AS_DOUBLE(o);
1199 else if(PyInt_Check(o))
1201 long val0=PyInt_AS_LONG(o);
1202 double val=(double)val0;
1208 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1213 else if(PyTuple_Check(pyLi))
1215 *size=ToIdType(PyTuple_Size(pyLi));
1216 double *tmp=(double *)malloc((*size)*sizeof(double));
1217 for(mcIdType i=0;i<*size;i++)
1219 PyObject *o=PyTuple_GetItem(pyLi,i);
1220 if(PyFloat_Check(o))
1222 double val=PyFloat_AS_DOUBLE(o);
1225 else if(PyInt_Check(o))
1227 long val0=PyInt_AS_LONG(o);
1228 double val=(double)val0;
1234 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1240 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1243 static void fillArrayWithPyListDbl3(PyObject *pyLi, mcIdType& nbOfElt, std::vector<double>& ret)
1245 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1246 if(PyFloat_Check(pyLi))
1252 throw INTERP_KERNEL::Exception(MSG);
1253 double val=PyFloat_AS_DOUBLE(pyLi);
1256 else if(PyInt_Check(pyLi))
1258 mcIdType val0=ToIdType(PyInt_AS_LONG(pyLi));
1259 double val=(double)val0;
1264 throw INTERP_KERNEL::Exception(MSG);
1267 else if(PyList_Check(pyLi))
1269 std::size_t size=PyList_Size(pyLi);
1271 for(std::size_t i=0;i<size;i++)
1273 PyObject *o=PyList_GetItem(pyLi,i);
1275 fillArrayWithPyListDbl3(o,tmp1,ret);
1283 throw INTERP_KERNEL::Exception(MSG);
1286 else if(PyTuple_Check(pyLi))
1288 std::size_t size=PyTuple_Size(pyLi);
1290 for(std::size_t i=0;i<size;i++)
1292 PyObject *o=PyTuple_GetItem(pyLi,i);
1294 fillArrayWithPyListDbl3(o,tmp1,ret);
1302 throw INTERP_KERNEL::Exception(MSG);
1306 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1309 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, mcIdType& nbOfTuples, mcIdType& nbOfComp)
1311 std::vector<double> ret;
1312 std::size_t size1=-1;
1314 if(PyList_Check(pyLi))
1316 size1=PyList_Size(pyLi);
1317 for(std::size_t i=0;i<size1;i++)
1319 PyObject *o=PyList_GetItem(pyLi,i);
1320 fillArrayWithPyListDbl3(o,size2,ret);
1325 else if(PyTuple_Check(pyLi))
1327 size1=PyTuple_Size(pyLi);
1328 for(std::size_t i=0;i<size1;i++)
1330 PyObject *o=PyTuple_GetItem(pyLi,i);
1331 fillArrayWithPyListDbl3(o,size2,ret);
1337 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1339 checkFillArrayWithPyList(ToIdType(size1),ToIdType(size2),nbOfTuples,nbOfComp);
1343 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1345 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1348 if(PyList_Check(pyLi))
1350 std::size_t size=PyList_Size(pyLi);
1352 for(std::size_t i=0;i<size;i++)
1354 PyObject *obj=PyList_GetItem(pyLi,i);
1355 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1356 if(!SWIG_IsOK(status))
1358 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1359 throw INTERP_KERNEL::Exception(oss.str().c_str());
1361 T arg=reinterpret_cast< T >(argp);
1365 else if(PyTuple_Check(pyLi))
1367 std::size_t size=PyTuple_Size(pyLi);
1369 for(std::size_t i=0;i<size;i++)
1371 PyObject *obj=PyTuple_GetItem(pyLi,i);
1372 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1373 if(!SWIG_IsOK(status))
1375 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1376 throw INTERP_KERNEL::Exception(oss.str().c_str());
1378 T arg=reinterpret_cast< T >(argp);
1382 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1385 T arg=reinterpret_cast< T >(argp);
1389 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1392 //convertFromVectorAutoObjToPyObj<MEDCoupling::MEDCouplingUMesh>(inpv,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh)
1394 static PyObject *convertFromVectorAutoObjToPyObj(std::vector< MCAuto<T> >& inpVector, swig_type_info *ty)
1396 std::size_t sz(inpVector.size());
1397 PyObject *ret = PyList_New(sz);
1398 for(std::size_t i=0;i<sz;++i)
1399 PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(inpVector[i].retn()),ty, SWIG_POINTER_OWN | 0 ));
1404 * if python int -> cpp int sw=1
1405 * if python list[int] -> cpp vector<int> sw=2
1406 * if python tuple[int] -> cpp vector<int> sw=2
1407 * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1408 * if python DataArrayIntTuple -> cpp DataArrayIdTypeTuple sw=4
1410 * switch between (int,vector<int>,DataArrayIdType)
1412 template< class T, class ARRAY >
1413 static void convertIntStarLikePyObjToCpp(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, ARRAY *& daIntTyypp, typename MEDCoupling::Traits< T >::ArrayTuple *&daIntTuple)
1416 if(PyInt_Check(value))
1418 iTyypp=(T)PyInt_AS_LONG(value);
1422 if(PyTuple_Check(value))
1424 std::size_t size=PyTuple_Size(value);
1425 stdvecTyypp.resize(size);
1426 for(std::size_t i=0;i<size;i++)
1428 PyObject *o=PyTuple_GetItem(value,i);
1430 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1433 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1434 throw INTERP_KERNEL::Exception(oss.str().c_str());
1440 if(PyList_Check(value))
1442 std::size_t size=PyList_Size(value);
1443 stdvecTyypp.resize(size);
1444 for(std::size_t i=0;i<size;i++)
1446 PyObject *o=PyList_GetItem(value,i);
1448 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1451 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1452 throw INTERP_KERNEL::Exception(oss.str().c_str());
1459 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1460 if(SWIG_IsOK(status))
1462 daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1466 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1467 if(SWIG_IsOK(status))
1469 daIntTuple=reinterpret_cast< typename MEDCoupling::Traits< T >::ArrayTuple * >(argp);
1473 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1477 * if python int -> cpp int sw=1
1478 * if python list[int] -> cpp vector<int> sw=2
1479 * if python tuple[int] -> cpp vector<int> sw=2
1480 * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1481 * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4
1483 * switch between (int,vector<int>,DataArrayIdType)
1486 static const T *convertIntStarLikePyObjToCppIntStar(PyObject *value, mcIdType& sw, mcIdType& sz, T& iTyypp, std::vector<T>& stdvecTyypp)
1489 if(PyInt_Check(value))
1491 iTyypp=(T)PyInt_AS_LONG(value);
1495 if(PyTuple_Check(value))
1497 std::size_t size=PyTuple_Size(value);
1498 stdvecTyypp.resize(size);
1499 for(std::size_t i=0;i<size;i++)
1501 PyObject *o=PyTuple_GetItem(value,i);
1503 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1506 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1507 throw INTERP_KERNEL::Exception(oss.str().c_str());
1510 sw=2; sz=ToIdType(size);
1511 return &stdvecTyypp[0];
1513 if(PyList_Check(value))
1515 std::size_t size=PyList_Size(value);
1516 stdvecTyypp.resize(size);
1517 for(std::size_t i=0;i<size;i++)
1519 PyObject *o=PyList_GetItem(value,i);
1521 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1524 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1525 throw INTERP_KERNEL::Exception(oss.str().c_str());
1528 sw=2; sz=ToIdType(size);
1529 return &stdvecTyypp[0];
1532 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI,0|0);
1533 if(SWIG_IsOK(status))
1535 typedef typename MEDCoupling::Traits< T >::ArrayType ARRAY;
1536 ARRAY *daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1539 sw=3; sz=daIntTyypp->getNbOfElems();
1540 return daIntTyypp->begin();
1548 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1549 if(SWIG_IsOK(status))
1551 typedef typename MEDCoupling::Traits< T >::ArrayTuple ARRAYTUPLE;
1552 ARRAYTUPLE *daIntTuple=reinterpret_cast< ARRAYTUPLE * >(argp);
1553 sw=4; sz=ToIdType(daIntTuple->getNumberOfCompo());
1554 return daIntTuple->getConstPointer();
1556 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1560 * if python double -> cpp double sw=1
1561 * if python int -> cpp double sw=1
1562 * if python list[double] -> cpp vector<double> sw=2
1563 * if python list[int] -> cpp vector<double> sw=2
1564 * if python tuple[double] -> cpp vector<double> sw=2
1565 * if python tuple[int] -> cpp vector<double> sw=2
1566 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1568 * switch between (int,vector<int>,DataArrayIdType)
1571 void considerPyObjAsATStarLikeObject(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1574 if(PyFloat_Check(value))
1576 iTyypp=(T)PyFloat_AS_DOUBLE(value);
1580 if(PyInt_Check(value))
1582 iTyypp=(T)PyInt_AS_LONG(value);
1586 if(PyTuple_Check(value))
1588 std::size_t size=PyTuple_Size(value);
1589 stdvecTyypp.resize(size);
1590 for(std::size_t i=0;i<size;i++)
1592 PyObject *o=PyTuple_GetItem(value,i);
1593 if(PyFloat_Check(o))
1594 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1595 else if(PyInt_Check(o))
1596 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1599 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1600 throw INTERP_KERNEL::Exception(oss.str().c_str());
1606 if(PyList_Check(value))
1608 std::size_t size=PyList_Size(value);
1609 stdvecTyypp.resize(size);
1610 for(std::size_t i=0;i<size;i++)
1612 PyObject *o=PyList_GetItem(value,i);
1613 if(PyFloat_Check(o))
1614 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1615 else if(PyInt_Check(o))
1616 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1619 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1620 throw INTERP_KERNEL::Exception(oss.str().c_str());
1627 int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1628 if(!SWIG_IsOK(status))
1629 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1630 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1635 * if python double -> cpp double sw=1
1636 * if python int -> cpp double sw=1
1637 * if python list[double] -> cpp vector<double> sw=2
1638 * if python list[int] -> cpp vector<double> sw=2
1639 * if python tuple[double] -> cpp vector<double> sw=2
1640 * if python tuple[int] -> cpp vector<double> sw=2
1641 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1643 * switch between (int,vector<int>,DataArrayIdType)
1645 static void convertDoubleStarLikePyObjToCpp(PyObject *value, mcIdType& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1648 if(PyFloat_Check(value))
1650 iTyypp=PyFloat_AS_DOUBLE(value);
1654 if(PyInt_Check(value))
1656 iTyypp=(double)PyInt_AS_LONG(value);
1660 if(PyTuple_Check(value))
1662 std::size_t size=PyTuple_Size(value);
1663 stdvecTyypp.resize(size);
1664 for(std::size_t i=0;i<size;i++)
1666 PyObject *o=PyTuple_GetItem(value,i);
1667 if(PyFloat_Check(o))
1668 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1669 else if(PyInt_Check(o))
1670 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1673 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1674 throw INTERP_KERNEL::Exception(oss.str().c_str());
1680 if(PyList_Check(value))
1682 std::size_t size=PyList_Size(value);
1683 stdvecTyypp.resize(size);
1684 for(std::size_t i=0;i<size;i++)
1686 PyObject *o=PyList_GetItem(value,i);
1687 if(PyFloat_Check(o))
1688 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1689 else if(PyInt_Check(o))
1690 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1693 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1694 throw INTERP_KERNEL::Exception(oss.str().c_str());
1701 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1702 if(!SWIG_IsOK(status))
1703 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1704 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1709 void convertFPStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
1712 if(PyFloat_Check(value))
1714 val=(T)PyFloat_AS_DOUBLE(value);
1718 if(PyInt_Check(value))
1720 val=(T)PyInt_AS_LONG(value);
1724 if(PyTuple_Check(value))
1726 std::size_t size=PyTuple_Size(value);
1728 for(std::size_t i=0;i<size;i++)
1730 PyObject *o=PyTuple_GetItem(value,i);
1731 if(PyFloat_Check(o))
1732 f[i]=(T)PyFloat_AS_DOUBLE(o);
1733 else if(PyInt_Check(o))
1734 f[i]=(T)PyInt_AS_LONG(o);
1737 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1738 throw INTERP_KERNEL::Exception(oss.str().c_str());
1744 if(PyList_Check(value))
1746 std::size_t size=PyList_Size(value);
1748 for(std::size_t i=0;i<size;i++)
1750 PyObject *o=PyList_GetItem(value,i);
1751 if(PyFloat_Check(o))
1752 f[i]=(T)PyFloat_AS_DOUBLE(o);
1753 else if(PyInt_Check(o))
1754 f[i]=(T)PyInt_AS_LONG(o);
1757 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1758 throw INTERP_KERNEL::Exception(oss.str().c_str());
1765 int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1766 if(SWIG_IsOK(status))
1768 d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1772 status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1773 if(SWIG_IsOK(status))
1775 e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1779 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1783 * if value int -> cpp val sw=1
1784 * if value double -> cpp val sw=1
1785 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1786 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1787 * if value list[int,double] -> cpp std::vector<double> sw=4
1788 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1790 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1792 convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1796 * if value int -> cpp val sw=1
1797 * if value double -> cpp val sw=1
1798 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1799 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1800 * if value list[int,double] -> cpp std::vector<double> sw=4
1801 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1803 static void convertFloatStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
1805 convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
1809 * if python int -> cpp int sw=1
1810 * if python list[int] -> cpp vector<int> sw=2
1811 * if python tuple[int] -> cpp vector<int> sw=2
1812 * if python slicp -> cpp pair sw=3 (begin,end,step)
1813 * if python DataArrayIdType -> cpp DataArrayIdType sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1815 * switch between (int,vector<int>,DataArrayIdType)
1817 template<class T, class ARRAY>
1818 static void convertIntStarOrSliceLikePyObjToCpp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1820 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdType, DataArrayIdTypeTuple";
1822 if(PyInt_Check(value))
1824 iTyypp=(T)PyInt_AS_LONG(value);
1828 if(PyTuple_Check(value))
1830 std::size_t size=PyTuple_Size(value);
1831 stdvecTyypp.resize(size);
1832 for(std::size_t i=0;i<size;i++)
1834 PyObject *o=PyTuple_GetItem(value,i);
1836 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1839 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1840 throw INTERP_KERNEL::Exception(oss.str().c_str());
1846 if(PyList_Check(value))
1848 std::size_t size=PyList_Size(value);
1849 stdvecTyypp.resize(size);
1850 for(std::size_t i=0;i<size;i++)
1852 PyObject *o=PyList_GetItem(value,i);
1854 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1857 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1858 throw INTERP_KERNEL::Exception(oss.str().c_str());
1864 if(PySlice_Check(value))
1866 Py_ssize_t strt=2,stp=2,step=2;
1867 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1868 p.first=ToIdType(strt);
1869 p.second.first=ToIdType(stp);
1870 p.second.second=ToIdType(step);
1875 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1876 if(SWIG_IsOK(status))
1878 daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1881 std::ostringstream oss; oss << msg << " Instance in null !";
1882 throw INTERP_KERNEL::Exception(oss.str().c_str());
1887 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI_TUPLE,0|0);
1888 if(SWIG_IsOK(status))
1890 typedef typename MEDCoupling::Traits< typename ARRAY::Type >::ArrayTuple ARRAYTUPLE;
1891 ARRAYTUPLE *tmp=reinterpret_cast< ARRAYTUPLE * >(argp);
1894 std::ostringstream oss; oss << msg << " Instance in null !";
1895 throw INTERP_KERNEL::Exception(oss.str().c_str());
1897 stdvecTyypp.resize(tmp->getNumberOfCompo());
1898 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1902 throw INTERP_KERNEL::Exception(msg);
1906 * Idem than convertIntStarOrSliceLikePyObjToCpp
1908 template<class T, class ARRAY>
1909 static void convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1911 convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1914 iTyypp=(T)InterpreteNegativeInt(iTyypp,nbelem);
1919 * if python int -> cpp int sw=1
1920 * if python tuple[int] -> cpp vector<int> sw=2
1921 * if python list[int] -> cpp vector<int> sw=2
1922 * if python slice -> cpp pair sw=3
1923 * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4 . WARNING The returned pointer can be the null pointer !
1925 template< class TUPLE_T >
1926 static void convertObjToPossibleCpp22(PyObject *value, mcIdType nbelem, mcIdType& sw, mcIdType& iTyypp, std::vector<mcIdType>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple *& daIntTyypp)
1929 if(PyInt_Check(value))
1931 iTyypp=ToIdType(PyInt_AS_LONG(value));
1935 if(PyTuple_Check(value))
1937 std::size_t size=PyTuple_Size(value);
1938 stdvecTyypp.resize(size);
1939 for(std::size_t i=0;i<size;i++)
1941 PyObject *o=PyTuple_GetItem(value,i);
1943 stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1946 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1947 throw INTERP_KERNEL::Exception(oss.str().c_str());
1953 if(PyList_Check(value))
1955 std::size_t size=PyList_Size(value);
1956 stdvecTyypp.resize(size);
1957 for(std::size_t i=0;i<size;i++)
1959 PyObject *o=PyList_GetItem(value,i);
1961 stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1964 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1965 throw INTERP_KERNEL::Exception(oss.str().c_str());
1971 if(PySlice_Check(value))
1973 Py_ssize_t strt=2,stp=2,step=2;
1974 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1975 p.first=ToIdType(strt);
1976 p.second.first=ToIdType(stp);
1977 p.second.second=ToIdType(step);
1982 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<TUPLE_T>::TI_TUPLE,0|0);
1983 if(!SWIG_IsOK(status))
1984 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdTypeTuple");
1985 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple * >(argp);
1990 * if python string with size one -> cpp char sw=1
1991 * if python string with size different from one -> cpp string sw=2
1992 * if python tuple[string] or list[string] -> vector<string> sw=3
1993 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1994 * switch between (int,string,vector<string>,DataArrayChar)
1996 static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
1998 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
2000 if(PyString_Check(value))
2002 const char *pt=PyString_AsString(value);
2003 Py_ssize_t sz=PyString_Size(value);
2017 #if PY_VERSION_HEX >= 0x03000000
2018 if(PyUnicode_Check(value))
2021 const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
2036 if(PyTuple_Check(value))
2038 std::size_t size=PyTuple_Size(value);
2039 vsType.resize(size);
2040 for(std::size_t i=0;i<size;i++)
2042 PyObject *o=PyTuple_GetItem(value,i);
2045 vsType[i]=convertPyObjectToStr(o);
2047 catch(INTERP_KERNEL::Exception& )
2049 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2050 throw INTERP_KERNEL::Exception(oss.str().c_str());
2056 if(PyList_Check(value))
2058 std::size_t size=PyList_Size(value);
2059 vsType.resize(size);
2060 for(std::size_t i=0;i<size;i++)
2062 PyObject *o=PyList_GetItem(value,i);
2065 vsType[i]=convertPyObjectToStr(o);
2067 catch(INTERP_KERNEL::Exception& )
2069 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2070 throw INTERP_KERNEL::Exception(oss.str().c_str());
2077 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
2078 if(SWIG_IsOK(status))
2080 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
2083 std::ostringstream oss; oss << msg << " Instance in null !";
2084 throw INTERP_KERNEL::Exception(oss.str().c_str());
2089 throw INTERP_KERNEL::Exception(msg);
2093 * if value int -> cpp it sw=1
2094 * if value list[int] -> vt sw=2
2095 * if value tuple[int] -> vt sw=2
2096 * if value slice -> pt sw=3
2097 * if value DataArrayIdType -> dt sw=4
2098 * if value tuple [int,int] -> cpp it,ip sw=5
2099 * if value tuple [list[int],int] -> cpp vt,ip sw=6
2100 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2101 * if value tuple [slice,int] -> cpp pt,ip sw=7
2102 * if value tuple [DaI,int] -> cpp dt,ip sw=8
2103 * if value tuple [int,list[int]] -> cpp it,vc sw=9
2104 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2105 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2106 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2107 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2108 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2109 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2110 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2111 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2112 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2113 * if value tuple [int,slice] -> cpp it,pc sw=13
2114 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2115 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2116 * if value tuple [slice,slice] -> cpp pt,pc sw=15
2117 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2119 * switch between (int,vector<int>,DataArrayIdType)
2122 static void convertObjToPossibleCpp3(PyObject *value, mcIdType nbTuple, int nbCompo, mcIdType& sw, mcIdType& it, TC& ic, std::vector<mcIdType>& vt, std::vector<TC>& vc,
2123 std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pt, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pc,
2124 MEDCoupling::DataArrayIdType *&dt, MEDCoupling::DataArrayIdType *&dc)
2126 if(!PyTuple_Check(value))
2128 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2133 std::size_t sz=PyTuple_Size(value);
2135 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2136 PyObject *ob0=PyTuple_GetItem(value,0);
2138 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2139 PyObject *ob1=PyTuple_GetItem(value,1);
2140 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2146 * if value int -> cpp val sw=1
2147 * if value double -> cpp val sw=1
2148 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2149 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2150 * if value list[int,double] -> cpp std::vector<double> sw=4
2151 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2153 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2154 const char *msg, mcIdType nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2157 if(PyFloat_Check(value))
2159 val=PyFloat_AS_DOUBLE(value);
2161 if(nbTuplesExpected*nbCompExpected!=1)
2163 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2164 throw INTERP_KERNEL::Exception(oss.str().c_str());
2168 if(PyInt_Check(value))
2170 val=(double)PyInt_AS_LONG(value);
2172 if(nbTuplesExpected*nbCompExpected!=1)
2174 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2175 throw INTERP_KERNEL::Exception(oss.str().c_str());
2179 if(PyTuple_Check(value) || PyList_Check(value))
2183 mcIdType tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2184 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2189 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2192 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2193 if(SWIG_IsOK(status))
2195 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2199 if(d->getNumberOfTuples()==nbTuplesExpected)
2201 if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2203 return d->getConstPointer();
2207 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2208 throw INTERP_KERNEL::Exception(oss.str().c_str());
2213 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2214 throw INTERP_KERNEL::Exception(oss.str().c_str());
2221 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2222 throw INTERP_KERNEL::Exception(oss.str().c_str());
2228 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2229 if(SWIG_IsOK(status))
2231 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2233 if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2235 if(nbTuplesExpected==1)
2236 return e->getConstPointer();
2239 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by construction !";
2240 throw INTERP_KERNEL::Exception(oss.str().c_str());
2245 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2246 throw INTERP_KERNEL::Exception(oss.str().c_str());
2249 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2253 * if value int -> cpp val sw=1
2254 * if value double -> cpp val sw=1
2255 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2256 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2257 * if value list[int,double] -> cpp std::vector<double> sw=4
2258 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2260 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2261 const char *msg, int nbCompExpected, bool throwIfNullPt, mcIdType& nbTuples)
2264 if(PyFloat_Check(value))
2266 val=PyFloat_AS_DOUBLE(value);
2268 if(nbCompExpected!=1)
2270 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2271 throw INTERP_KERNEL::Exception(oss.str().c_str());
2276 if(PyInt_Check(value))
2278 val=(double)PyInt_AS_LONG(value);
2280 if(nbCompExpected!=1)
2282 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2283 throw INTERP_KERNEL::Exception(oss.str().c_str());
2288 if(PyTuple_Check(value))
2290 std::size_t size=PyTuple_Size(value);
2292 for(std::size_t i=0;i<size;i++)
2294 PyObject *o=PyTuple_GetItem(value,i);
2295 if(PyFloat_Check(o))
2296 f[i]=PyFloat_AS_DOUBLE(o);
2297 else if(PyInt_Check(o))
2298 f[i]=(double)PyInt_AS_LONG(o);
2301 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2302 throw INTERP_KERNEL::Exception(oss.str().c_str());
2306 if(size%nbCompExpected!=0)
2308 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2309 throw INTERP_KERNEL::Exception(oss.str().c_str());
2311 nbTuples=ToIdType(size/nbCompExpected);
2314 if(PyList_Check(value))
2316 std::size_t size=PyList_Size(value);
2318 for(std::size_t i=0;i<size;i++)
2320 PyObject *o=PyList_GetItem(value,i);
2321 if(PyFloat_Check(o))
2322 f[i]=PyFloat_AS_DOUBLE(o);
2323 else if(PyInt_Check(o))
2324 f[i]=(double)PyInt_AS_LONG(o);
2327 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2328 throw INTERP_KERNEL::Exception(oss.str().c_str());
2332 if(size%nbCompExpected!=0)
2334 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2335 throw INTERP_KERNEL::Exception(oss.str().c_str());
2337 nbTuples=ToIdType(size/nbCompExpected);
2341 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2342 if(SWIG_IsOK(status))
2344 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2348 if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2350 nbTuples=d->getNumberOfTuples();
2351 return d->getConstPointer();
2355 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2356 throw INTERP_KERNEL::Exception(oss.str().c_str());
2363 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2364 throw INTERP_KERNEL::Exception(oss.str().c_str());
2367 { nbTuples=0; return 0; }
2370 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2371 if(SWIG_IsOK(status))
2373 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2377 if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2380 return e->getConstPointer();
2384 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2385 throw INTERP_KERNEL::Exception(oss.str().c_str());
2392 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2393 throw INTERP_KERNEL::Exception(oss.str().c_str());
2396 { nbTuples=0; return 0; }
2399 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2403 * if value int -> cpp val sw=1
2404 * if value double -> cpp val sw=1
2405 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2406 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2407 * if value list[int,double] -> cpp std::vector<double> sw=4
2408 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2410 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, mcIdType& sw, double& val, std::vector<double>& f,
2411 const char *msg, bool throwIfNullPt, mcIdType& nbTuples)
2413 MEDCoupling::DataArrayDouble *d=0;
2414 MEDCoupling::DataArrayDoubleTuple *e=0;
2416 if(PyFloat_Check(value))
2418 val=PyFloat_AS_DOUBLE(value);
2423 if(PyInt_Check(value))
2425 val=(double)PyInt_AS_LONG(value);
2430 if(PyTuple_Check(value))
2432 std::size_t size=PyTuple_Size(value);
2434 for(std::size_t i=0;i<size;i++)
2436 PyObject *o=PyTuple_GetItem(value,i);
2437 if(PyFloat_Check(o))
2438 f[i]=PyFloat_AS_DOUBLE(o);
2439 else if(PyInt_Check(o))
2440 f[i]=(double)PyInt_AS_LONG(o);
2443 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2444 throw INTERP_KERNEL::Exception(oss.str().c_str());
2448 nbTuples=ToIdType(size);
2451 if(PyList_Check(value))
2453 std::size_t size=PyList_Size(value);
2455 for(std::size_t i=0;i<size;i++)
2457 PyObject *o=PyList_GetItem(value,i);
2458 if(PyFloat_Check(o))
2459 f[i]=PyFloat_AS_DOUBLE(o);
2460 else if(PyInt_Check(o))
2461 f[i]=(double)PyInt_AS_LONG(o);
2464 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2465 throw INTERP_KERNEL::Exception(oss.str().c_str());
2469 nbTuples=ToIdType(size);
2473 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2474 if(SWIG_IsOK(status))
2476 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2480 if(d->getNumberOfComponents()==1)
2482 nbTuples=d->getNumberOfTuples();
2483 return d->getConstPointer();
2487 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2488 throw INTERP_KERNEL::Exception(oss.str().c_str());
2495 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2496 throw INTERP_KERNEL::Exception(oss.str().c_str());
2499 { nbTuples=0; return 0; }
2502 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2503 if(SWIG_IsOK(status))
2505 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2509 nbTuples=ToIdType(e->getNumberOfCompo());
2510 return e->getConstPointer();
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 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2526 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2529 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2530 if(!SWIG_IsOK(status))
2532 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2533 if(!SWIG_IsOK(status))
2535 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt32,0|0);
2536 if(!SWIG_IsOK(status))
2538 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt64,0|0);
2539 if(!SWIG_IsOK(status))
2541 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2542 if(!SWIG_IsOK(status))
2544 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2545 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayIdType, DataArrayAsciiChar, DataArrayByte !";
2546 throw INTERP_KERNEL::Exception(oss.str().c_str());
2552 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2555 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2560 Py_XINCREF(Py_None);
2563 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2564 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2566 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2571 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2573 const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
2574 std::string msg(msgBase);
2576 msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2579 if(PyList_Check(elt0) || PyTuple_Check(elt0))
2583 if(PyInt_Check(nbOfTuples))
2585 mcIdType nbOfTuples1=ToIdType(PyInt_AS_LONG(nbOfTuples));
2587 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2590 if(PyInt_Check(elt2))
2591 {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2592 mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(elt2));
2594 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2595 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2596 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2597 ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2601 throw INTERP_KERNEL::Exception(msg.c_str());
2604 {//DataArrayDouble.New([1.,3.,4.],3)
2605 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2607 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2608 ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2613 throw INTERP_KERNEL::Exception(msg.c_str());
2616 {// DataArrayDouble.New([1.,3.,4.])
2617 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2618 mcIdType tmpp1(-1),tmpp2(-1);
2619 std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2620 ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2624 else if(PyInt_Check(elt0))
2626 mcIdType nbOfTuples1(ToIdType(PyInt_AS_LONG(elt0)));
2628 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2633 if(PyInt_Check(nbOfTuples))
2634 {//DataArrayDouble.New(5,2)
2635 mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(nbOfTuples));
2637 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2638 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2639 ret->alloc(nbOfTuples1,nbOfCompo);
2643 throw INTERP_KERNEL::Exception(msg.c_str());
2646 throw INTERP_KERNEL::Exception(msg.c_str());
2649 {//DataArrayDouble.New(5)
2650 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2651 ret->alloc(nbOfTuples1,1);
2656 else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2657 {//DataArrayDouble.New(numpyArray)
2658 return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2662 throw INTERP_KERNEL::Exception(msg.c_str());
2663 throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2667 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2669 self->checkAllocated();
2670 const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2671 mcIdType nbOfTuples(self->getNumberOfTuples());
2672 int nbOfComponents((int)(self->getNumberOfComponents()));
2676 typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2677 considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2679 std::vector<mcIdType> vt1;
2680 std::vector<mcIdType> vc1;
2681 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
2682 MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
2683 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2684 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2692 self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2695 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2696 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2697 self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2700 self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2703 throw INTERP_KERNEL::Exception(msg);
2712 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2715 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2716 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2717 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2720 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2723 throw INTERP_KERNEL::Exception(msg);
2732 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2735 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2736 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2737 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2740 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2743 throw INTERP_KERNEL::Exception(msg);
2752 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2755 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2756 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2757 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2760 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2763 throw INTERP_KERNEL::Exception(msg);
2772 self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2775 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2776 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2777 self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2780 self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2783 throw INTERP_KERNEL::Exception(msg);
2792 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2795 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2796 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2797 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2800 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2803 throw INTERP_KERNEL::Exception(msg);
2812 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2815 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2816 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2817 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2820 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2823 throw INTERP_KERNEL::Exception(msg);
2832 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2835 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2836 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2837 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2840 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2843 throw INTERP_KERNEL::Exception(msg);
2852 self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2855 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2856 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2857 self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2860 self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2863 throw INTERP_KERNEL::Exception(msg);
2872 self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2875 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2876 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2877 self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2880 self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2883 throw INTERP_KERNEL::Exception(msg);
2892 self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2895 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2896 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2897 self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2900 self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2903 throw INTERP_KERNEL::Exception(msg);
2912 self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2915 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2916 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2917 self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2920 self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2923 throw INTERP_KERNEL::Exception(msg);
2932 self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2935 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2936 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2937 self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2940 self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2943 throw INTERP_KERNEL::Exception(msg);
2952 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2955 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2956 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2957 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2960 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2963 throw INTERP_KERNEL::Exception(msg);
2972 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2975 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2976 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2977 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2980 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2983 throw INTERP_KERNEL::Exception(msg);
2992 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2995 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2996 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2997 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
3000 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3003 throw INTERP_KERNEL::Exception(msg);
3008 throw INTERP_KERNEL::Exception(msg);
3014 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3016 const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3017 const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3018 self->checkAllocated();
3019 mcIdType nbOfTuples(self->getNumberOfTuples());
3020 int nbOfComponents((int)(self->getNumberOfComponents()));
3023 std::vector<mcIdType> vt1;
3024 std::vector<std::size_t> vc1;
3025 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
3026 MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
3028 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3029 MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3033 if(nbOfComponents==1)
3034 return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3035 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3037 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3039 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3041 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3043 return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3046 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3047 std::vector<std::size_t> v2(1,ic1);
3048 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3052 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3053 std::vector<std::size_t> v2(1,ic1);
3054 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3058 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3059 std::vector<std::size_t> v2(1,ic1);
3060 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3064 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3065 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3069 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3070 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3074 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3075 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3079 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3080 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3084 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3085 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3086 std::vector<std::size_t> v2(nbOfComp);
3087 for(mcIdType i=0;i<nbOfComp;i++)
3088 v2[i]=pc1.first+i*pc1.second.second;
3089 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3093 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3094 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3095 std::vector<std::size_t> v2(nbOfComp);
3096 for(int i=0;i<nbOfComp;i++)
3097 v2[i]=pc1.first+i*pc1.second.second;
3098 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3102 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3103 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3104 std::vector<std::size_t> v2(nbOfComp);
3105 for(int i=0;i<nbOfComp;i++)
3106 v2[i]=pc1.first+i*pc1.second.second;
3107 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3111 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3112 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3113 std::vector<std::size_t> v2(nbOfComp);
3114 for(int i=0;i<nbOfComp;i++)
3115 v2[i]=pc1.first+i*pc1.second.second;
3116 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3119 throw INTERP_KERNEL::Exception(msg);
3123 bool isCSRMatrix(PyObject *m)
3125 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
3126 PyObject* pdict(PyDict_New());
3127 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
3128 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
3130 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
3131 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
3133 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
3134 bool ret(PyObject_IsInstance(m,csrMatrixCls));
3135 Py_DECREF(pdict); Py_XDECREF(tmp);
3142 void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
3144 auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
3146 throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !");
3147 mCpp.resize(nbOfRows);
3148 auto indPtrCPtr(indptrPtr->begin());
3149 auto indicesCPtr(indicesPtr->begin());
3150 auto dataCPtr(dataPtr->begin());
3151 for(auto i=0;i<nbOfRows;i++)
3153 auto& line(mCpp[i]);
3154 for(auto j=indPtrCPtr[i];j<indPtrCPtr[i+1];j++)
3156 line[indicesCPtr[j]]=dataCPtr[j];
3161 void convertToVectMapIntDouble(PyObject *pyobj, std::vector<std::map<mcIdType,double> >& mCpp)
3163 if(!PyList_Check(pyobj))
3164 throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !");
3166 Py_ssize_t sz(PyList_Size(pyobj));
3168 for(Py_ssize_t i=0;i<sz;i++)
3170 PyObject *elt(PyList_GetItem(pyobj,i));
3171 if(!PyDict_Check(elt))
3173 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist a dict is exepect !";
3174 throw INTERP_KERNEL::Exception(oss.str());
3176 PyObject *key, *value;
3178 std::map<mcIdType,double>& mapCpp(mCpp[i]);
3179 while(PyDict_Next(elt,&pos,&key,&value))
3181 if(!PyInt_Check(key))
3183 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !";
3184 throw INTERP_KERNEL::Exception(oss.str());
3186 if(!PyFloat_Check(value))
3188 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !";
3189 throw INTERP_KERNEL::Exception(oss.str());
3191 mapCpp[ToIdType(PyInt_AS_LONG(key))]=PyFloat_AS_DOUBLE(value);
3197 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3199 const char msg[]="Unexpected situation in __imul__ !";
3201 typename MEDCoupling::Traits<T>::ArrayType *a;
3202 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3205 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3210 self->applyLin(val,0.);
3211 Py_XINCREF(trueSelf);
3216 self->multiplyEqual(a);
3217 Py_XINCREF(trueSelf);
3222 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3223 self->multiplyEqual(aaa);
3224 Py_XINCREF(trueSelf);
3229 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3230 self->multiplyEqual(aaa);
3231 Py_XINCREF(trueSelf);
3235 throw INTERP_KERNEL::Exception(msg);
3240 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3242 const char msg[]="Unexpected situation in __idiv__ !";
3244 typename MEDCoupling::Traits<T>::ArrayType *a;
3245 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3248 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3254 throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3255 self->applyLin((T)(1./val),(T)0.);
3256 Py_XINCREF(trueSelf);
3261 self->divideEqual(a);
3262 Py_XINCREF(trueSelf);
3267 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3268 self->divideEqual(aaa);
3269 Py_XINCREF(trueSelf);
3274 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3275 self->divideEqual(aaa);
3276 Py_XINCREF(trueSelf);
3280 throw INTERP_KERNEL::Exception(msg);
3285 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3287 const char msg[]="Unexpected situation in __iadd__ !";
3289 typename MEDCoupling::Traits<T>::ArrayType *a;
3290 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3293 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3298 self->applyLin(1.,val);
3299 Py_XINCREF(trueSelf);
3305 Py_XINCREF(trueSelf);
3310 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3311 self->addEqual(aaa);
3312 Py_XINCREF(trueSelf);
3317 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3318 self->addEqual(aaa);
3319 Py_XINCREF(trueSelf);
3323 throw INTERP_KERNEL::Exception(msg);
3328 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3330 const char msg[]="Unexpected situation in __isub__ !";
3332 typename MEDCoupling::Traits<T>::ArrayType *a;
3333 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3336 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3341 self->applyLin(1.,-val);
3342 Py_XINCREF(trueSelf);
3347 self->substractEqual(a);
3348 Py_XINCREF(trueSelf);
3353 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3354 self->substractEqual(aaa);
3355 Py_XINCREF(trueSelf);
3360 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3361 self->substractEqual(aaa);
3362 Py_XINCREF(trueSelf);
3366 throw INTERP_KERNEL::Exception(msg);
3371 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3373 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3375 PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
3377 PyTypeObject *NPYTraits<MEDCoupling::Int64>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
3381 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3383 return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3387 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3389 return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3393 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3395 return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3399 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3401 return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3405 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3407 return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3411 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3413 return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3417 typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3419 const char msg[]="Unexpected situation in __rmul__ !";
3421 typename MEDCoupling::Traits<T>::ArrayType *a;
3422 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3425 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3430 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
3431 ret->applyLin(val,0.);
3436 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
3437 return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3441 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3442 return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3445 throw INTERP_KERNEL::Exception(msg);