1 // Copyright (C) 2007-2019 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");
1393 * if python int -> cpp int sw=1
1394 * if python list[int] -> cpp vector<int> sw=2
1395 * if python tuple[int] -> cpp vector<int> sw=2
1396 * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1397 * if python DataArrayIntTuple -> cpp DataArrayIdTypeTuple sw=4
1399 * switch between (int,vector<int>,DataArrayIdType)
1401 template< class T, class ARRAY >
1402 static void convertIntStarLikePyObjToCpp(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, ARRAY *& daIntTyypp, typename MEDCoupling::Traits< T >::ArrayTuple *&daIntTuple)
1405 if(PyInt_Check(value))
1407 iTyypp=(T)PyInt_AS_LONG(value);
1411 if(PyTuple_Check(value))
1413 std::size_t size=PyTuple_Size(value);
1414 stdvecTyypp.resize(size);
1415 for(std::size_t i=0;i<size;i++)
1417 PyObject *o=PyTuple_GetItem(value,i);
1419 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1422 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1423 throw INTERP_KERNEL::Exception(oss.str().c_str());
1429 if(PyList_Check(value))
1431 std::size_t size=PyList_Size(value);
1432 stdvecTyypp.resize(size);
1433 for(std::size_t i=0;i<size;i++)
1435 PyObject *o=PyList_GetItem(value,i);
1437 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1440 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1441 throw INTERP_KERNEL::Exception(oss.str().c_str());
1448 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1449 if(SWIG_IsOK(status))
1451 daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1455 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1456 if(SWIG_IsOK(status))
1458 daIntTuple=reinterpret_cast< typename MEDCoupling::Traits< T >::ArrayTuple * >(argp);
1462 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1466 * if python int -> cpp int sw=1
1467 * if python list[int] -> cpp vector<int> sw=2
1468 * if python tuple[int] -> cpp vector<int> sw=2
1469 * if python DataArrayIdType -> cpp DataArrayIdType sw=3
1470 * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4
1472 * switch between (int,vector<int>,DataArrayIdType)
1475 static const T *convertIntStarLikePyObjToCppIntStar(PyObject *value, mcIdType& sw, mcIdType& sz, T& iTyypp, std::vector<T>& stdvecTyypp)
1478 if(PyInt_Check(value))
1480 iTyypp=(T)PyInt_AS_LONG(value);
1484 if(PyTuple_Check(value))
1486 std::size_t size=PyTuple_Size(value);
1487 stdvecTyypp.resize(size);
1488 for(std::size_t i=0;i<size;i++)
1490 PyObject *o=PyTuple_GetItem(value,i);
1492 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1495 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1496 throw INTERP_KERNEL::Exception(oss.str().c_str());
1499 sw=2; sz=ToIdType(size);
1500 return &stdvecTyypp[0];
1502 if(PyList_Check(value))
1504 std::size_t size=PyList_Size(value);
1505 stdvecTyypp.resize(size);
1506 for(std::size_t i=0;i<size;i++)
1508 PyObject *o=PyList_GetItem(value,i);
1510 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1513 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1514 throw INTERP_KERNEL::Exception(oss.str().c_str());
1517 sw=2; sz=ToIdType(size);
1518 return &stdvecTyypp[0];
1521 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI,0|0);
1522 if(SWIG_IsOK(status))
1524 typedef typename MEDCoupling::Traits< T >::ArrayType ARRAY;
1525 ARRAY *daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1528 sw=3; sz=daIntTyypp->getNbOfElems();
1529 return daIntTyypp->begin();
1537 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<T>::TI_TUPLE,0|0);
1538 if(SWIG_IsOK(status))
1540 typedef typename MEDCoupling::Traits< T >::ArrayTuple ARRAYTUPLE;
1541 ARRAYTUPLE *daIntTuple=reinterpret_cast< ARRAYTUPLE * >(argp);
1542 sw=4; sz=ToIdType(daIntTuple->getNumberOfCompo());
1543 return daIntTuple->getConstPointer();
1545 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayIdType, DataArrayIdTypeTuple");
1549 * if python double -> cpp double sw=1
1550 * if python int -> cpp double sw=1
1551 * if python list[double] -> cpp vector<double> sw=2
1552 * if python list[int] -> cpp vector<double> sw=2
1553 * if python tuple[double] -> cpp vector<double> sw=2
1554 * if python tuple[int] -> cpp vector<double> sw=2
1555 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1557 * switch between (int,vector<int>,DataArrayIdType)
1560 void considerPyObjAsATStarLikeObject(PyObject *value, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1563 if(PyFloat_Check(value))
1565 iTyypp=(T)PyFloat_AS_DOUBLE(value);
1569 if(PyInt_Check(value))
1571 iTyypp=(T)PyInt_AS_LONG(value);
1575 if(PyTuple_Check(value))
1577 std::size_t size=PyTuple_Size(value);
1578 stdvecTyypp.resize(size);
1579 for(std::size_t i=0;i<size;i++)
1581 PyObject *o=PyTuple_GetItem(value,i);
1582 if(PyFloat_Check(o))
1583 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1584 else if(PyInt_Check(o))
1585 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1588 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1589 throw INTERP_KERNEL::Exception(oss.str().c_str());
1595 if(PyList_Check(value))
1597 std::size_t size=PyList_Size(value);
1598 stdvecTyypp.resize(size);
1599 for(std::size_t i=0;i<size;i++)
1601 PyObject *o=PyList_GetItem(value,i);
1602 if(PyFloat_Check(o))
1603 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1604 else if(PyInt_Check(o))
1605 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1608 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1609 throw INTERP_KERNEL::Exception(oss.str().c_str());
1616 int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1617 if(!SWIG_IsOK(status))
1618 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1619 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1624 * if python double -> cpp double sw=1
1625 * if python int -> cpp double sw=1
1626 * if python list[double] -> cpp vector<double> sw=2
1627 * if python list[int] -> cpp vector<double> sw=2
1628 * if python tuple[double] -> cpp vector<double> sw=2
1629 * if python tuple[int] -> cpp vector<double> sw=2
1630 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1632 * switch between (int,vector<int>,DataArrayIdType)
1634 static void convertDoubleStarLikePyObjToCpp(PyObject *value, mcIdType& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1637 if(PyFloat_Check(value))
1639 iTyypp=PyFloat_AS_DOUBLE(value);
1643 if(PyInt_Check(value))
1645 iTyypp=(double)PyInt_AS_LONG(value);
1649 if(PyTuple_Check(value))
1651 std::size_t size=PyTuple_Size(value);
1652 stdvecTyypp.resize(size);
1653 for(std::size_t i=0;i<size;i++)
1655 PyObject *o=PyTuple_GetItem(value,i);
1656 if(PyFloat_Check(o))
1657 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1658 else if(PyInt_Check(o))
1659 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1662 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1663 throw INTERP_KERNEL::Exception(oss.str().c_str());
1669 if(PyList_Check(value))
1671 std::size_t size=PyList_Size(value);
1672 stdvecTyypp.resize(size);
1673 for(std::size_t i=0;i<size;i++)
1675 PyObject *o=PyList_GetItem(value,i);
1676 if(PyFloat_Check(o))
1677 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1678 else if(PyInt_Check(o))
1679 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1682 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1683 throw INTERP_KERNEL::Exception(oss.str().c_str());
1690 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1691 if(!SWIG_IsOK(status))
1692 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1693 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1698 void convertFPStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
1701 if(PyFloat_Check(value))
1703 val=(T)PyFloat_AS_DOUBLE(value);
1707 if(PyInt_Check(value))
1709 val=(T)PyInt_AS_LONG(value);
1713 if(PyTuple_Check(value))
1715 std::size_t size=PyTuple_Size(value);
1717 for(std::size_t i=0;i<size;i++)
1719 PyObject *o=PyTuple_GetItem(value,i);
1720 if(PyFloat_Check(o))
1721 f[i]=(T)PyFloat_AS_DOUBLE(o);
1722 else if(PyInt_Check(o))
1723 f[i]=(T)PyInt_AS_LONG(o);
1726 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1727 throw INTERP_KERNEL::Exception(oss.str().c_str());
1733 if(PyList_Check(value))
1735 std::size_t size=PyList_Size(value);
1737 for(std::size_t i=0;i<size;i++)
1739 PyObject *o=PyList_GetItem(value,i);
1740 if(PyFloat_Check(o))
1741 f[i]=(T)PyFloat_AS_DOUBLE(o);
1742 else if(PyInt_Check(o))
1743 f[i]=(T)PyInt_AS_LONG(o);
1746 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1747 throw INTERP_KERNEL::Exception(oss.str().c_str());
1754 int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1755 if(SWIG_IsOK(status))
1757 d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1761 status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1762 if(SWIG_IsOK(status))
1764 e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1768 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1772 * if value int -> cpp val sw=1
1773 * if value double -> cpp val sw=1
1774 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1775 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1776 * if value list[int,double] -> cpp std::vector<double> sw=4
1777 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1779 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1781 convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1785 * if value int -> cpp val sw=1
1786 * if value double -> cpp val sw=1
1787 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1788 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1789 * if value list[int,double] -> cpp std::vector<double> sw=4
1790 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1792 static void convertFloatStarLikePyObjToCpp_2(PyObject *value, mcIdType& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
1794 convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
1798 * if python int -> cpp int sw=1
1799 * if python list[int] -> cpp vector<int> sw=2
1800 * if python tuple[int] -> cpp vector<int> sw=2
1801 * if python slicp -> cpp pair sw=3 (begin,end,step)
1802 * if python DataArrayIdType -> cpp DataArrayIdType sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1804 * switch between (int,vector<int>,DataArrayIdType)
1806 template<class T, class ARRAY>
1807 static void convertIntStarOrSliceLikePyObjToCpp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1809 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdType, DataArrayIdTypeTuple";
1811 if(PyInt_Check(value))
1813 iTyypp=(T)PyInt_AS_LONG(value);
1817 if(PyTuple_Check(value))
1819 std::size_t size=PyTuple_Size(value);
1820 stdvecTyypp.resize(size);
1821 for(std::size_t i=0;i<size;i++)
1823 PyObject *o=PyTuple_GetItem(value,i);
1825 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1828 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1829 throw INTERP_KERNEL::Exception(oss.str().c_str());
1835 if(PyList_Check(value))
1837 std::size_t size=PyList_Size(value);
1838 stdvecTyypp.resize(size);
1839 for(std::size_t i=0;i<size;i++)
1841 PyObject *o=PyList_GetItem(value,i);
1843 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1846 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1847 throw INTERP_KERNEL::Exception(oss.str().c_str());
1853 if(PySlice_Check(value))
1855 Py_ssize_t strt=2,stp=2,step=2;
1856 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1857 p.first=ToIdType(strt);
1858 p.second.first=ToIdType(stp);
1859 p.second.second=ToIdType(step);
1864 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI,0|0);
1865 if(SWIG_IsOK(status))
1867 daIntTyypp=reinterpret_cast< ARRAY * >(argp);
1870 std::ostringstream oss; oss << msg << " Instance in null !";
1871 throw INTERP_KERNEL::Exception(oss.str().c_str());
1876 status=SWIG_ConvertPtr(value,&argp,SWIGTITraits< typename ARRAY::Type >::TI_TUPLE,0|0);
1877 if(SWIG_IsOK(status))
1879 typedef typename MEDCoupling::Traits< typename ARRAY::Type >::ArrayTuple ARRAYTUPLE;
1880 ARRAYTUPLE *tmp=reinterpret_cast< ARRAYTUPLE * >(argp);
1883 std::ostringstream oss; oss << msg << " Instance in null !";
1884 throw INTERP_KERNEL::Exception(oss.str().c_str());
1886 stdvecTyypp.resize(tmp->getNumberOfCompo());
1887 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1891 throw INTERP_KERNEL::Exception(msg);
1895 * Idem than convertIntStarOrSliceLikePyObjToCpp
1897 template<class T, class ARRAY>
1898 static void convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(PyObject *value, mcIdType nbelem, mcIdType& sw, T& iTyypp, std::vector<T>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, ARRAY *& daIntTyypp)
1900 convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1903 iTyypp=(T)InterpreteNegativeInt(iTyypp,nbelem);
1908 * if python int -> cpp int sw=1
1909 * if python tuple[int] -> cpp vector<int> sw=2
1910 * if python list[int] -> cpp vector<int> sw=2
1911 * if python slice -> cpp pair sw=3
1912 * if python DataArrayIdTypeTuple -> cpp DataArrayIdTypeTuple sw=4 . WARNING The returned pointer can be the null pointer !
1914 template< class TUPLE_T >
1915 static void convertObjToPossibleCpp22(PyObject *value, mcIdType nbelem, mcIdType& sw, mcIdType& iTyypp, std::vector<mcIdType>& stdvecTyypp, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& p, typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple *& daIntTyypp)
1918 if(PyInt_Check(value))
1920 iTyypp=ToIdType(PyInt_AS_LONG(value));
1924 if(PyTuple_Check(value))
1926 std::size_t size=PyTuple_Size(value);
1927 stdvecTyypp.resize(size);
1928 for(std::size_t i=0;i<size;i++)
1930 PyObject *o=PyTuple_GetItem(value,i);
1932 stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1935 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1936 throw INTERP_KERNEL::Exception(oss.str().c_str());
1942 if(PyList_Check(value))
1944 std::size_t size=PyList_Size(value);
1945 stdvecTyypp.resize(size);
1946 for(std::size_t i=0;i<size;i++)
1948 PyObject *o=PyList_GetItem(value,i);
1950 stdvecTyypp[i]=(mcIdType)PyInt_AS_LONG(o);
1953 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1954 throw INTERP_KERNEL::Exception(oss.str().c_str());
1960 if(PySlice_Check(value))
1962 Py_ssize_t strt=2,stp=2,step=2;
1963 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1964 p.first=ToIdType(strt);
1965 p.second.first=ToIdType(stp);
1966 p.second.second=ToIdType(step);
1971 int status=SWIG_ConvertPtr(value,&argp,SWIGTITraits<TUPLE_T>::TI_TUPLE,0|0);
1972 if(!SWIG_IsOK(status))
1973 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIdTypeTuple");
1974 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits< TUPLE_T >::ArrayTuple * >(argp);
1979 * if python string with size one -> cpp char sw=1
1980 * if python string with size different from one -> cpp string sw=2
1981 * if python tuple[string] or list[string] -> vector<string> sw=3
1982 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1983 * switch between (int,string,vector<string>,DataArrayChar)
1985 static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
1987 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1989 if(PyString_Check(value))
1991 const char *pt=PyString_AsString(value);
1992 Py_ssize_t sz=PyString_Size(value);
2006 #if PY_VERSION_HEX >= 0x03000000
2007 if(PyUnicode_Check(value))
2010 const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
2025 if(PyTuple_Check(value))
2027 std::size_t size=PyTuple_Size(value);
2028 vsType.resize(size);
2029 for(std::size_t i=0;i<size;i++)
2031 PyObject *o=PyTuple_GetItem(value,i);
2034 vsType[i]=convertPyObjectToStr(o);
2036 catch(INTERP_KERNEL::Exception& e)
2038 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2039 throw INTERP_KERNEL::Exception(oss.str().c_str());
2045 if(PyList_Check(value))
2047 std::size_t size=PyList_Size(value);
2048 vsType.resize(size);
2049 for(std::size_t i=0;i<size;i++)
2051 PyObject *o=PyList_GetItem(value,i);
2054 vsType[i]=convertPyObjectToStr(o);
2056 catch(INTERP_KERNEL::Exception& e)
2058 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
2059 throw INTERP_KERNEL::Exception(oss.str().c_str());
2066 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
2067 if(SWIG_IsOK(status))
2069 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
2072 std::ostringstream oss; oss << msg << " Instance in null !";
2073 throw INTERP_KERNEL::Exception(oss.str().c_str());
2078 throw INTERP_KERNEL::Exception(msg);
2082 * if value int -> cpp it sw=1
2083 * if value list[int] -> vt sw=2
2084 * if value tuple[int] -> vt sw=2
2085 * if value slice -> pt sw=3
2086 * if value DataArrayIdType -> dt sw=4
2087 * if value tuple [int,int] -> cpp it,ip sw=5
2088 * if value tuple [list[int],int] -> cpp vt,ip sw=6
2089 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2090 * if value tuple [slice,int] -> cpp pt,ip sw=7
2091 * if value tuple [DaI,int] -> cpp dt,ip sw=8
2092 * if value tuple [int,list[int]] -> cpp it,vc sw=9
2093 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2094 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2095 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2096 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2097 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2098 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2099 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2100 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2101 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2102 * if value tuple [int,slice] -> cpp it,pc sw=13
2103 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2104 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2105 * if value tuple [slice,slice] -> cpp pt,pc sw=15
2106 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2108 * switch between (int,vector<int>,DataArrayIdType)
2111 static void convertObjToPossibleCpp3(PyObject *value, mcIdType nbTuple, int nbCompo, mcIdType& sw, mcIdType& it, TC& ic, std::vector<mcIdType>& vt, std::vector<TC>& vc,
2112 std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pt, std::pair<mcIdType, std::pair<mcIdType,mcIdType> >& pc,
2113 MEDCoupling::DataArrayIdType *&dt, MEDCoupling::DataArrayIdType *&dc)
2115 if(!PyTuple_Check(value))
2117 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2122 std::size_t sz=PyTuple_Size(value);
2124 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2125 PyObject *ob0=PyTuple_GetItem(value,0);
2127 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2128 PyObject *ob1=PyTuple_GetItem(value,1);
2129 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2135 * if value int -> cpp val sw=1
2136 * if value double -> cpp val sw=1
2137 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2138 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2139 * if value list[int,double] -> cpp std::vector<double> sw=4
2140 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2142 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2143 const char *msg, mcIdType nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2146 if(PyFloat_Check(value))
2148 val=PyFloat_AS_DOUBLE(value);
2150 if(nbTuplesExpected*nbCompExpected!=1)
2152 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2153 throw INTERP_KERNEL::Exception(oss.str().c_str());
2157 if(PyInt_Check(value))
2159 val=(double)PyInt_AS_LONG(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 PyInt) !";
2164 throw INTERP_KERNEL::Exception(oss.str().c_str());
2168 if(PyTuple_Check(value) || PyList_Check(value))
2172 mcIdType tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2173 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2178 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2181 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2182 if(SWIG_IsOK(status))
2184 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2188 if(d->getNumberOfTuples()==nbTuplesExpected)
2190 if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2192 return d->getConstPointer();
2196 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2197 throw INTERP_KERNEL::Exception(oss.str().c_str());
2202 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2203 throw INTERP_KERNEL::Exception(oss.str().c_str());
2210 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2211 throw INTERP_KERNEL::Exception(oss.str().c_str());
2217 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2218 if(SWIG_IsOK(status))
2220 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2222 if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2224 if(nbTuplesExpected==1)
2225 return e->getConstPointer();
2228 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by construction !";
2229 throw INTERP_KERNEL::Exception(oss.str().c_str());
2234 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2235 throw INTERP_KERNEL::Exception(oss.str().c_str());
2238 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2242 * if value int -> cpp val sw=1
2243 * if value double -> cpp val sw=1
2244 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2245 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2246 * if value list[int,double] -> cpp std::vector<double> sw=4
2247 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2249 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, mcIdType& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2250 const char *msg, int nbCompExpected, bool throwIfNullPt, mcIdType& nbTuples)
2253 if(PyFloat_Check(value))
2255 val=PyFloat_AS_DOUBLE(value);
2257 if(nbCompExpected!=1)
2259 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2260 throw INTERP_KERNEL::Exception(oss.str().c_str());
2265 if(PyInt_Check(value))
2267 val=(double)PyInt_AS_LONG(value);
2269 if(nbCompExpected!=1)
2271 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2272 throw INTERP_KERNEL::Exception(oss.str().c_str());
2277 if(PyTuple_Check(value))
2279 std::size_t size=PyTuple_Size(value);
2281 for(std::size_t i=0;i<size;i++)
2283 PyObject *o=PyTuple_GetItem(value,i);
2284 if(PyFloat_Check(o))
2285 f[i]=PyFloat_AS_DOUBLE(o);
2286 else if(PyInt_Check(o))
2287 f[i]=(double)PyInt_AS_LONG(o);
2290 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2291 throw INTERP_KERNEL::Exception(oss.str().c_str());
2295 if(size%nbCompExpected!=0)
2297 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2298 throw INTERP_KERNEL::Exception(oss.str().c_str());
2300 nbTuples=ToIdType(size/nbCompExpected);
2303 if(PyList_Check(value))
2305 std::size_t size=PyList_Size(value);
2307 for(std::size_t i=0;i<size;i++)
2309 PyObject *o=PyList_GetItem(value,i);
2310 if(PyFloat_Check(o))
2311 f[i]=PyFloat_AS_DOUBLE(o);
2312 else if(PyInt_Check(o))
2313 f[i]=(double)PyInt_AS_LONG(o);
2316 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2317 throw INTERP_KERNEL::Exception(oss.str().c_str());
2321 if(size%nbCompExpected!=0)
2323 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2324 throw INTERP_KERNEL::Exception(oss.str().c_str());
2326 nbTuples=ToIdType(size/nbCompExpected);
2330 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2331 if(SWIG_IsOK(status))
2333 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2337 if(ToIdType(d->getNumberOfComponents())==nbCompExpected)
2339 nbTuples=d->getNumberOfTuples();
2340 return d->getConstPointer();
2344 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2345 throw INTERP_KERNEL::Exception(oss.str().c_str());
2352 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2353 throw INTERP_KERNEL::Exception(oss.str().c_str());
2356 { nbTuples=0; return 0; }
2359 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2360 if(SWIG_IsOK(status))
2362 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2366 if(ToIdType(e->getNumberOfCompo())==nbCompExpected)
2369 return e->getConstPointer();
2373 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2374 throw INTERP_KERNEL::Exception(oss.str().c_str());
2381 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2382 throw INTERP_KERNEL::Exception(oss.str().c_str());
2385 { nbTuples=0; return 0; }
2388 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2392 * if value int -> cpp val sw=1
2393 * if value double -> cpp val sw=1
2394 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2395 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2396 * if value list[int,double] -> cpp std::vector<double> sw=4
2397 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2399 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, mcIdType& sw, double& val, std::vector<double>& f,
2400 const char *msg, bool throwIfNullPt, mcIdType& nbTuples)
2402 MEDCoupling::DataArrayDouble *d=0;
2403 MEDCoupling::DataArrayDoubleTuple *e=0;
2405 if(PyFloat_Check(value))
2407 val=PyFloat_AS_DOUBLE(value);
2412 if(PyInt_Check(value))
2414 val=(double)PyInt_AS_LONG(value);
2419 if(PyTuple_Check(value))
2421 std::size_t size=PyTuple_Size(value);
2423 for(std::size_t i=0;i<size;i++)
2425 PyObject *o=PyTuple_GetItem(value,i);
2426 if(PyFloat_Check(o))
2427 f[i]=PyFloat_AS_DOUBLE(o);
2428 else if(PyInt_Check(o))
2429 f[i]=(double)PyInt_AS_LONG(o);
2432 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2433 throw INTERP_KERNEL::Exception(oss.str().c_str());
2437 nbTuples=ToIdType(size);
2440 if(PyList_Check(value))
2442 std::size_t size=PyList_Size(value);
2444 for(std::size_t i=0;i<size;i++)
2446 PyObject *o=PyList_GetItem(value,i);
2447 if(PyFloat_Check(o))
2448 f[i]=PyFloat_AS_DOUBLE(o);
2449 else if(PyInt_Check(o))
2450 f[i]=(double)PyInt_AS_LONG(o);
2453 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2454 throw INTERP_KERNEL::Exception(oss.str().c_str());
2458 nbTuples=ToIdType(size);
2462 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2463 if(SWIG_IsOK(status))
2465 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2469 if(d->getNumberOfComponents()==1)
2471 nbTuples=d->getNumberOfTuples();
2472 return d->getConstPointer();
2476 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2477 throw INTERP_KERNEL::Exception(oss.str().c_str());
2484 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2485 throw INTERP_KERNEL::Exception(oss.str().c_str());
2488 { nbTuples=0; return 0; }
2491 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2492 if(SWIG_IsOK(status))
2494 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2498 nbTuples=ToIdType(e->getNumberOfCompo());
2499 return e->getConstPointer();
2505 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2506 throw INTERP_KERNEL::Exception(oss.str().c_str());
2509 { nbTuples=0; return 0; }
2512 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2515 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2518 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2519 if(!SWIG_IsOK(status))
2521 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2522 if(!SWIG_IsOK(status))
2524 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt32,0|0);
2525 if(!SWIG_IsOK(status))
2527 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt64,0|0);
2528 if(!SWIG_IsOK(status))
2530 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2531 if(!SWIG_IsOK(status))
2533 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2534 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayIdType, DataArrayAsciiChar, DataArrayByte !";
2535 throw INTERP_KERNEL::Exception(oss.str().c_str());
2541 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2544 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2549 Py_XINCREF(Py_None);
2552 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2553 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2555 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2560 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2562 const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
2563 std::string msg(msgBase);
2565 msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2568 if(PyList_Check(elt0) || PyTuple_Check(elt0))
2572 if(PyInt_Check(nbOfTuples))
2574 mcIdType nbOfTuples1=ToIdType(PyInt_AS_LONG(nbOfTuples));
2576 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2579 if(PyInt_Check(elt2))
2580 {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2581 mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(elt2));
2583 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2584 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2585 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2586 ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2590 throw INTERP_KERNEL::Exception(msg.c_str());
2593 {//DataArrayDouble.New([1.,3.,4.],3)
2594 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2596 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2597 ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2602 throw INTERP_KERNEL::Exception(msg.c_str());
2605 {// DataArrayDouble.New([1.,3.,4.])
2606 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2607 mcIdType tmpp1(-1),tmpp2(-1);
2608 std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2609 ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2613 else if(PyInt_Check(elt0))
2615 mcIdType nbOfTuples1(ToIdType(PyInt_AS_LONG(elt0)));
2617 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2622 if(PyInt_Check(nbOfTuples))
2623 {//DataArrayDouble.New(5,2)
2624 mcIdType nbOfCompo=ToIdType(PyInt_AS_LONG(nbOfTuples));
2626 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2627 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2628 ret->alloc(nbOfTuples1,nbOfCompo);
2632 throw INTERP_KERNEL::Exception(msg.c_str());
2635 throw INTERP_KERNEL::Exception(msg.c_str());
2638 {//DataArrayDouble.New(5)
2639 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2640 ret->alloc(nbOfTuples1,1);
2645 else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2646 {//DataArrayDouble.New(numpyArray)
2647 return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2651 throw INTERP_KERNEL::Exception(msg.c_str());
2652 throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2656 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2658 self->checkAllocated();
2659 const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2660 mcIdType nbOfTuples(self->getNumberOfTuples());
2661 int nbOfComponents((int)(self->getNumberOfComponents()));
2665 typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2666 considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2668 std::vector<mcIdType> vt1;
2669 std::vector<mcIdType> vc1;
2670 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
2671 MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
2672 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2673 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2681 self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2684 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2685 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2686 self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2689 self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2692 throw INTERP_KERNEL::Exception(msg);
2701 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2704 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2705 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2706 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2709 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2712 throw INTERP_KERNEL::Exception(msg);
2721 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2724 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2725 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2726 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2729 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2732 throw INTERP_KERNEL::Exception(msg);
2741 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2744 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2745 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2746 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2749 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2752 throw INTERP_KERNEL::Exception(msg);
2761 self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2764 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2765 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2766 self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2769 self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2772 throw INTERP_KERNEL::Exception(msg);
2781 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2784 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2785 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2786 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2789 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2792 throw INTERP_KERNEL::Exception(msg);
2801 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2804 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2805 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2806 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2809 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2812 throw INTERP_KERNEL::Exception(msg);
2821 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2824 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2825 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2826 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2829 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2832 throw INTERP_KERNEL::Exception(msg);
2841 self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2844 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2845 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2846 self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2849 self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2852 throw INTERP_KERNEL::Exception(msg);
2861 self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2864 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2865 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2866 self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2869 self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2872 throw INTERP_KERNEL::Exception(msg);
2881 self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2884 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2885 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2886 self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2889 self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2892 throw INTERP_KERNEL::Exception(msg);
2901 self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2904 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2905 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2906 self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2909 self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2912 throw INTERP_KERNEL::Exception(msg);
2921 self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2924 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2925 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2926 self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2929 self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2932 throw INTERP_KERNEL::Exception(msg);
2941 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2944 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2945 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2946 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2949 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2952 throw INTERP_KERNEL::Exception(msg);
2961 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2964 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2965 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2966 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2969 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2972 throw INTERP_KERNEL::Exception(msg);
2981 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2984 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2985 tmp->useArray(&v1[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,v1.size());
2986 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
2989 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2992 throw INTERP_KERNEL::Exception(msg);
2997 throw INTERP_KERNEL::Exception(msg);
3003 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3005 const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3006 const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3007 self->checkAllocated();
3008 mcIdType nbOfTuples(self->getNumberOfTuples());
3009 int nbOfComponents((int)(self->getNumberOfComponents()));
3012 std::vector<mcIdType> vt1;
3013 std::vector<std::size_t> vc1;
3014 std::pair<mcIdType, std::pair<mcIdType,mcIdType> > pt1,pc1;
3015 MEDCoupling::DataArrayIdType *dt1=0,*dc1=0;
3017 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3018 MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3022 if(nbOfComponents==1)
3023 return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3024 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3026 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3028 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3030 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3032 return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3035 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3036 std::vector<std::size_t> v2(1,ic1);
3037 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3041 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3042 std::vector<std::size_t> v2(1,ic1);
3043 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3047 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3048 std::vector<std::size_t> v2(1,ic1);
3049 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3053 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3054 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3058 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3059 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3063 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3064 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3068 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3069 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3073 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3074 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3075 std::vector<std::size_t> v2(nbOfComp);
3076 for(mcIdType i=0;i<nbOfComp;i++)
3077 v2[i]=pc1.first+i*pc1.second.second;
3078 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3082 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3083 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3084 std::vector<std::size_t> v2(nbOfComp);
3085 for(int i=0;i<nbOfComp;i++)
3086 v2[i]=pc1.first+i*pc1.second.second;
3087 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3091 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3092 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3093 std::vector<std::size_t> v2(nbOfComp);
3094 for(int i=0;i<nbOfComp;i++)
3095 v2[i]=pc1.first+i*pc1.second.second;
3096 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3100 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3101 mcIdType nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3102 std::vector<std::size_t> v2(nbOfComp);
3103 for(int i=0;i<nbOfComp;i++)
3104 v2[i]=pc1.first+i*pc1.second.second;
3105 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3108 throw INTERP_KERNEL::Exception(msg);
3112 bool isCSRMatrix(PyObject *m)
3114 #if defined(WITH_NUMPY) && defined(WITH_SCIPY)
3115 PyObject* pdict(PyDict_New());
3116 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
3117 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
3119 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
3120 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
3122 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
3123 bool ret(PyObject_IsInstance(m,csrMatrixCls));
3124 Py_DECREF(pdict); Py_XDECREF(tmp);
3131 void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
3133 auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
3135 throw INTERP_KERNEL::Exception("pywrap of MEDCouplingRemapper::setMatrix : input CSR matrix looks bad regarding indptr array !");
3136 mCpp.resize(nbOfRows);
3137 auto indPtrCPtr(indptrPtr->begin());
3138 auto indicesCPtr(indicesPtr->begin());
3139 auto dataCPtr(dataPtr->begin());
3140 for(auto i=0;i<nbOfRows;i++)
3142 auto& line(mCpp[i]);
3143 for(auto j=indPtrCPtr[i];j<indPtrCPtr[i+1];j++)
3145 line[indicesCPtr[j]]=dataCPtr[j];
3150 void convertToVectMapIntDouble(PyObject *pyobj, std::vector<std::map<mcIdType,double> >& mCpp)
3152 if(!PyList_Check(pyobj))
3153 throw INTERP_KERNEL::Exception("convertToVectMapIntDouble : input is not a python list !");
3155 Py_ssize_t sz(PyList_Size(pyobj));
3157 for(Py_ssize_t i=0;i<sz;i++)
3159 PyObject *elt(PyList_GetItem(pyobj,i));
3160 if(!PyDict_Check(elt))
3162 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist a dict is exepect !";
3163 throw INTERP_KERNEL::Exception(oss.str());
3165 PyObject *key, *value;
3167 std::map<mcIdType,double>& mapCpp(mCpp[i]);
3168 while(PyDict_Next(elt,&pos,&key,&value))
3170 if(!PyInt_Check(key))
3172 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " a key not mappable to pyint !";
3173 throw INTERP_KERNEL::Exception(oss.str());
3175 if(!PyFloat_Check(value))
3177 std::ostringstream oss; oss << "convertToVectMapIntDouble : at pos # " << i << " of pylist the dict contains at pos " << pos << " the value not mappable to pyfloat !";
3178 throw INTERP_KERNEL::Exception(oss.str());
3180 mapCpp[ToIdType(PyInt_AS_LONG(key))]=PyFloat_AS_DOUBLE(value);
3186 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3188 const char msg[]="Unexpected situation in __imul__ !";
3190 typename MEDCoupling::Traits<T>::ArrayType *a;
3191 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3194 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3199 self->applyLin(val,0.);
3200 Py_XINCREF(trueSelf);
3205 self->multiplyEqual(a);
3206 Py_XINCREF(trueSelf);
3211 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3212 self->multiplyEqual(aaa);
3213 Py_XINCREF(trueSelf);
3218 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3219 self->multiplyEqual(aaa);
3220 Py_XINCREF(trueSelf);
3224 throw INTERP_KERNEL::Exception(msg);
3229 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3231 const char msg[]="Unexpected situation in __idiv__ !";
3233 typename MEDCoupling::Traits<T>::ArrayType *a;
3234 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3237 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3243 throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3244 self->applyLin((T)(1./val),(T)0.);
3245 Py_XINCREF(trueSelf);
3250 self->divideEqual(a);
3251 Py_XINCREF(trueSelf);
3256 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3257 self->divideEqual(aaa);
3258 Py_XINCREF(trueSelf);
3263 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3264 self->divideEqual(aaa);
3265 Py_XINCREF(trueSelf);
3269 throw INTERP_KERNEL::Exception(msg);
3274 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3276 const char msg[]="Unexpected situation in __iadd__ !";
3278 typename MEDCoupling::Traits<T>::ArrayType *a;
3279 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3282 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3287 self->applyLin(1.,val);
3288 Py_XINCREF(trueSelf);
3294 Py_XINCREF(trueSelf);
3299 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3300 self->addEqual(aaa);
3301 Py_XINCREF(trueSelf);
3306 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3307 self->addEqual(aaa);
3308 Py_XINCREF(trueSelf);
3312 throw INTERP_KERNEL::Exception(msg);
3317 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3319 const char msg[]="Unexpected situation in __isub__ !";
3321 typename MEDCoupling::Traits<T>::ArrayType *a;
3322 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3325 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3330 self->applyLin(1.,-val);
3331 Py_XINCREF(trueSelf);
3336 self->substractEqual(a);
3337 Py_XINCREF(trueSelf);
3342 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3343 self->substractEqual(aaa);
3344 Py_XINCREF(trueSelf);
3349 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3350 self->substractEqual(aaa);
3351 Py_XINCREF(trueSelf);
3355 throw INTERP_KERNEL::Exception(msg);
3360 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3362 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3364 PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
3366 PyTypeObject *NPYTraits<long>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
3370 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3372 return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3376 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3378 return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3382 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3384 return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3388 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3390 return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3394 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3396 return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3400 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3402 return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3406 typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3408 const char msg[]="Unexpected situation in __rmul__ !";
3410 typename MEDCoupling::Traits<T>::ArrayType *a;
3411 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3414 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3419 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
3420 ret->applyLin(val,0.);
3425 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
3426 return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3430 typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::DeallocType::CPP_DEALLOC,1,bb.size());
3431 return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
3434 throw INTERP_KERNEL::Exception(msg);