1 // Copyright (C) 2007-2016 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"
33 static PyObject *convertArray(MEDCoupling::DataArray *array, int owner)
41 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(array))
42 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
43 if(dynamic_cast<MEDCoupling::DataArrayInt *>(array))
44 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
45 if(dynamic_cast<MEDCoupling::DataArrayFloat *>(array))
46 ret=SWIG_NewPointerObj((void*)array,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
48 throw INTERP_KERNEL::Exception("Not recognized type of array on downcast !");
53 * This method is an extention of PySlice_GetIndices but less
54 * open than PySlice_GetIndicesEx that accepts too many situations.
56 void GetIndicesOfSlice(PyObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
58 int ret(PySlice_GetIndices(
59 #if PY_VERSION_HEX >= 0x03000000
62 reinterpret_cast<PySliceObject *>(slice),
64 length,start,stop,step));
67 if(*step>0 && *start==*stop && length==*start)
69 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
73 * This method allows to retrieve slice info from \a slice.
75 void GetIndicesOfSliceExplicitely(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
77 int ret(PySlice_GetIndices(
78 #if PY_VERSION_HEX >= 0x03000000
81 reinterpret_cast<PySliceObject *>(slice),
83 std::numeric_limits<int>::max(),start,stop,step));
86 if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
88 std::ostringstream oss;
89 oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
90 throw INTERP_KERNEL::Exception(oss.str().c_str());
92 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
95 int InterpreteNegativeInt(int val, int nbelem)
99 int newVal(nbelem+val);
102 std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
103 throw INTERP_KERNEL::Exception(oss.str().c_str());
111 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
112 // in input when an another DataArray is already client of this.
113 template<class MCData>
114 void numarrdeal2(void *pt, void *obj)
116 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
117 void **obj1=(void **)obj;
118 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
119 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
121 Py_XDECREF(weakRefOnOwner);
126 template<class MCData, class T>
127 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
129 int ndim=PyArray_NDIM(elt0);
130 if(ndim!=1 && ndim!=2)
131 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
132 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
134 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
135 throw INTERP_KERNEL::Exception(oss.str().c_str());
137 npy_intp sz0=PyArray_DIM(elt0,0);
138 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
140 int itemSize=PyArray_ITEMSIZE(elt0);
141 if(itemSize!=sizeof(T))
143 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
144 throw INTERP_KERNEL::Exception(oss.str().c_str());
146 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
147 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
149 if(itemSize!=PyArray_STRIDE(elt0,1))
150 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 !");
151 const char *data=PyArray_BYTES(elt0);
152 typename MEDCoupling::MCAuto<MCData> ret=MCData::New();
153 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
155 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
156 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
157 int mask=MED_NUMPY_OWNDATA; mask=~mask;
159 PyObject *deepestObj=elt0;
160 PyObject *base=elt0C->base;
161 if(base) deepestObj=base;
162 bool isSpetialCase(false);
165 if(PyArray_Check(base))
167 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
168 eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
171 if(base) deepestObj=base;
180 {// 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.
181 std::size_t nbOfElems(sz0*sz1);
182 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
183 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
184 ret->useArray(dataCpy,true,MEDCoupling::C_DEALLOC,sz0,sz1);
187 typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
190 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
192 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
193 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
194 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
195 mma.setParameterForDeallocator(objs);
196 mma.setSpecificDeallocator(numarrdeal2<MCData>);
197 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
201 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
202 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
203 typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::CDeallocator);
204 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
205 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
206 mma.setParameterForDeallocator(objs);
207 mma.setSpecificDeallocator(numarrdeal);
210 else if(PyArray_ISBEHAVED_RO(elt0))
211 ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::CPP_DEALLOC,sz0,sz1);
216 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
219 PyErr_SetString(PyExc_ValueError,
220 "Cannot set the NumPy array 'base' "
221 "dependency to NULL after initialization");
225 * Allow the base to be set only once. Once the object which
226 * owns the data is set, it doesn't make sense to change it.
228 if (PyArray_BASE(arr) != NULL) {
230 PyErr_SetString(PyExc_ValueError,
231 "Cannot set the NumPy array 'base' "
232 "dependency more than once");
237 * Don't allow infinite chains of views, always set the base
238 * to the first owner of the data.
239 * That is, either the first object which isn't an array,
240 * or the first object which owns its own data.
243 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
244 PyArrayObject *obj_arr = (PyArrayObject *)obj;
248 /* If this array owns its own data, stop collapsing */
249 if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
253 tmp = PyArray_BASE(obj_arr);
254 /* If there's no base, stop collapsing */
258 /* Stop the collapse new base when the would not be of the same
259 * type (i.e. different subclass).
261 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
271 /* Disallow circular references */
272 if ((PyObject *)arr == obj) {
274 PyErr_SetString(PyExc_ValueError,
275 "Cannot create a circular NumPy array 'base' dependency");
284 template<class MCData, class T>
285 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
287 if(!self->isAllocated())
289 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
290 throw INTERP_KERNEL::Exception(oss.str().c_str());
292 MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
295 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
296 throw INTERP_KERNEL::Exception(oss.str().c_str());
298 int nbDims=nbComp==1?1:2;
300 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
301 const T *bg=self->getConstPointer();
302 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
303 if(mem.isDeallocatorCalled())
305 if(mem.getDeallocator()!=numarrdeal)
306 {// case for the first call of toNumPyArray
307 PyObject *ref(PyWeakref_NewRef(ret,NULL));
308 typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
309 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
310 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
311 mem.setParameterForDeallocator(objs);
312 mem.setSpecificDeallocator(numarrdeal);
316 {// case for the second and other call of toNumPyArray
317 void **objs=(void **)mem.getParameterForDeallocator();
318 PyObject *weakRefOnOwner=(PyObject *)objs[0];
319 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
321 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
323 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
326 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
327 Py_XDECREF(weakRefOnOwner);
328 PyObject *ref=PyWeakref_NewRef(ret,NULL);
336 template<class MCData, class T>
337 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
339 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
342 SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
343 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
345 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols)
347 int nbRows((int)m.size());
348 MEDCoupling::MCAuto<MEDCoupling::DataArrayInt> indPtr(MEDCoupling::DataArrayInt::New()),indices(MEDCoupling::DataArrayInt::New());
349 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
350 indPtr->alloc(nbRows+1,1);
351 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
353 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
355 sz2+=(int)(*it0).size();
358 indices->alloc(sz2,1); data->alloc(sz2,1);
359 int *indices_ptr(indices->getPointer());
360 double *data_ptr(data->getPointer());
361 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
362 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
364 *indices_ptr=(*it1).first;
365 *data_ptr=(*it1).second;
367 PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt_toNumPyArray(indPtr));
369 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
370 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
371 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
372 PyObject *tmp1(PyString_FromString("shape"));
373 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
374 PyObject* pdict=PyDict_New();
375 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
376 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
378 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
379 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
381 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
382 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
383 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
387 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner)
395 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
396 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
397 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
398 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
400 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
404 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner)
412 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
413 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
414 if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
415 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
416 if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
417 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
418 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
419 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
420 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
421 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
423 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
427 static PyObject *convertIntArrToPyList(const int *ptr, int size)
429 PyObject *ret=PyList_New(size);
430 for(int i=0;i<size;i++)
431 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
435 static PyObject *convertIntArrToPyList2(const std::vector<int>& v)
438 PyObject *ret=PyList_New(size);
439 for(int i=0;i<size;i++)
440 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
444 static PyObject *convertIntArrToPyList3(const std::set<int>& v)
447 PyObject *ret=PyList_New(size);
448 std::set<int>::const_iterator it=v.begin();
449 for(int i=0;i<size;i++,it++)
450 PyList_SetItem(ret,i,PyInt_FromLong(*it));
454 static bool convertPyObjectToStrNT(PyObject *obj, std::string& ret)
456 if(PyString_Check(obj))
458 ret=PyString_AsString(obj);
461 #if PY_VERSION_HEX >= 0x03000000
462 else if(PyUnicode_Check(obj))
464 ret=PyUnicode_AsUTF8(obj);
471 static std::string convertPyObjectToStr(PyObject *obj, const char *msg=NULL)
474 if(PyString_Check(obj))
475 ret=PyString_AsString(obj);
476 #if PY_VERSION_HEX >= 0x03000000
477 else if(PyUnicode_Check(obj))
478 ret=PyUnicode_AsUTF8(obj);
482 std::ostringstream oss;
486 oss << "PyWrap convertPyObjectToStr : expect a sting like py object !";
487 throw INTERP_KERNEL::Exception(oss.str());
492 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples)
494 PyObject *ret=PyList_New(nbOfTuples);
495 for(int i=0;i<nbOfTuples;i++)
497 PyObject *t=PyTuple_New(nbOfComp);
498 for(int j=0;j<nbOfComp;j++)
499 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
500 PyList_SetItem(ret,i,t);
505 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size)
507 if(PyList_Check(pyLi))
509 *size=PyList_Size(pyLi);
510 int *tmp=new int[*size];
511 for(int i=0;i<*size;i++)
513 PyObject *o=PyList_GetItem(pyLi,i);
516 int val=(int)PyInt_AS_LONG(o);
522 throw INTERP_KERNEL::Exception("list must contain integers only");
527 else if(PyTuple_Check(pyLi))
529 *size=PyTuple_Size(pyLi);
530 int *tmp=new int[*size];
531 for(int i=0;i<*size;i++)
533 PyObject *o=PyTuple_GetItem(pyLi,i);
536 int val=(int)PyInt_AS_LONG(o);
542 throw INTERP_KERNEL::Exception("tuple must contain integers only");
549 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
553 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr)
555 PyObject *ret=PyList_New(arr.size());
556 for(std::size_t i=0;i<arr.size();i++)
558 PyObject *t=PyTuple_New(2);
559 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
560 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
561 PyList_SetItem(ret,i,t);
566 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr)
568 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
569 if(PyList_Check(pyLi))
571 int size=PyList_Size(pyLi);
573 for(int i=0;i<size;i++)
575 PyObject *o=PyList_GetItem(pyLi,i);
578 int sz2=PyTuple_Size(o);
580 throw INTERP_KERNEL::Exception(msg);
581 PyObject *o_0=PyTuple_GetItem(o,0);
582 if(!PyInt_Check(o_0))
583 throw INTERP_KERNEL::Exception(msg);
584 PyObject *o_1=PyTuple_GetItem(o,1);
585 if(!PyInt_Check(o_1))
586 throw INTERP_KERNEL::Exception(msg);
587 arr[i].first=(int)PyInt_AS_LONG(o_0);
588 arr[i].second=(int)PyInt_AS_LONG(o_1);
591 throw INTERP_KERNEL::Exception(msg);
594 else if(PyTuple_Check(pyLi))
596 int size=PyTuple_Size(pyLi);
598 for(int i=0;i<size;i++)
600 PyObject *o=PyTuple_GetItem(pyLi,i);
603 int sz2=PyTuple_Size(o);
605 throw INTERP_KERNEL::Exception(msg);
606 PyObject *o_0=PyTuple_GetItem(o,0);
607 if(!PyInt_Check(o_0))
608 throw INTERP_KERNEL::Exception(msg);
609 PyObject *o_1=PyTuple_GetItem(o,1);
610 if(!PyInt_Check(o_1))
611 throw INTERP_KERNEL::Exception(msg);
612 arr[i].first=(int)PyInt_AS_LONG(o_0);
613 arr[i].second=(int)PyInt_AS_LONG(o_1);
616 throw INTERP_KERNEL::Exception(msg);
620 throw INTERP_KERNEL::Exception(msg);
623 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
625 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
626 if(PyList_Check(pyLi))
628 int size=PyList_Size(pyLi);
630 for(int i=0;i<size;i++)
632 PyObject *o=PyList_GetItem(pyLi,i);
635 int sz2=PyTuple_Size(o);
637 throw INTERP_KERNEL::Exception(msg);
638 PyObject *o_0=PyTuple_GetItem(o,0);
639 PyObject *o_1=PyTuple_GetItem(o,1);
640 arr[i].first=convertPyObjectToStr(o_0,msg);
641 if(!PyInt_Check(o_1))
642 throw INTERP_KERNEL::Exception(msg);
643 arr[i].second=(int)PyInt_AS_LONG(o_1);
646 throw INTERP_KERNEL::Exception(msg);
649 else if(PyTuple_Check(pyLi))
651 int size=PyTuple_Size(pyLi);
653 for(int i=0;i<size;i++)
655 PyObject *o=PyTuple_GetItem(pyLi,i);
658 int sz2=PyTuple_Size(o);
660 throw INTERP_KERNEL::Exception(msg);
661 PyObject *o_0=PyTuple_GetItem(o,0);
662 PyObject *o_1=PyTuple_GetItem(o,1);
663 arr[i].first=convertPyObjectToStr(o_0,msg);
664 if(!PyInt_Check(o_1))
665 throw INTERP_KERNEL::Exception(msg);
666 arr[i].second=(int)PyInt_AS_LONG(o_1);
669 throw INTERP_KERNEL::Exception(msg);
673 throw INTERP_KERNEL::Exception(msg);
676 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr)
678 if(PyList_Check(pyLi))
680 int size=PyList_Size(pyLi);
682 for(int i=0;i<size;i++)
684 PyObject *o=PyList_GetItem(pyLi,i);
687 int val=(int)PyInt_AS_LONG(o);
691 throw INTERP_KERNEL::Exception("list must contain integers only");
694 else if(PyTuple_Check(pyLi))
696 int size=PyTuple_Size(pyLi);
698 for(int i=0;i<size;i++)
700 PyObject *o=PyTuple_GetItem(pyLi,i);
703 int val=(int)PyInt_AS_LONG(o);
707 throw INTERP_KERNEL::Exception("tuple must contain integers only");
712 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
716 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr)
719 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
721 if(PyList_Check(pyLi))
723 int size=PyList_Size(pyLi);
724 for(int i=0;i<size;i++)
726 PyObject *o=PyList_GetItem(pyLi,i);
729 int val=(int)PyInt_AS_LONG(o);
734 std::vector<int> arr2;
735 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
736 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
738 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
739 throw INTERP_KERNEL::Exception(oss.str().c_str());
741 arr.insert(arr.end(),arr2.begin(),arr2.end());
745 else if(PyTuple_Check(pyLi))
747 int size=PyTuple_Size(pyLi);
748 for(int i=0;i<size;i++)
750 PyObject *o=PyTuple_GetItem(pyLi,i);
753 int val=(int)PyInt_AS_LONG(o);
758 std::vector<int> arr2;
759 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
760 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
762 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
763 throw INTERP_KERNEL::Exception(oss.str().c_str());
765 arr.insert(arr.end(),arr2.begin(),arr2.end());
770 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
773 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp)
777 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
778 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
780 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
781 oss << " whereas nb of components expected is " << nbOfComp << " !";
782 throw INTERP_KERNEL::Exception(oss.str().c_str());
789 if((nbOfTuples!=size1 || nbOfComp!=size2))
791 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
793 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
794 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
795 throw INTERP_KERNEL::Exception(oss.str().c_str());
801 if(nbOfTuples==size1)
805 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
806 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
807 throw INTERP_KERNEL::Exception(oss.str().c_str());
813 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
815 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
816 if(PyInt_Check(pyLi))
818 long val=PyInt_AS_LONG(pyLi);
823 throw INTERP_KERNEL::Exception(MSG);
826 else if(PyList_Check(pyLi))
828 int size=PyList_Size(pyLi);
830 for(int i=0;i<size;i++)
832 PyObject *o=PyList_GetItem(pyLi,i);
834 fillArrayWithPyListInt3(o,tmp1,ret);
842 throw INTERP_KERNEL::Exception(MSG);
845 else if(PyTuple_Check(pyLi))
847 int size=PyTuple_Size(pyLi);
849 for(int i=0;i<size;i++)
851 PyObject *o=PyTuple_GetItem(pyLi,i);
853 fillArrayWithPyListInt3(o,tmp1,ret);
861 throw INTERP_KERNEL::Exception(MSG);
865 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
868 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp)
870 std::vector<int> ret;
871 int size1=-1,size2=-1;
872 if(PyList_Check(pyLi))
874 size1=PyList_Size(pyLi);
875 for(int i=0;i<size1;i++)
877 PyObject *o=PyList_GetItem(pyLi,i);
878 fillArrayWithPyListInt3(o,size2,ret);
883 else if(PyTuple_Check(pyLi))
885 size1=PyTuple_Size(pyLi);
886 for(int i=0;i<size1;i++)
888 PyObject *o=PyTuple_GetItem(pyLi,i);
889 fillArrayWithPyListInt3(o,size2,ret);
895 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
897 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
901 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
903 if(PyList_Check(pyLi))
905 Py_ssize_t sz=PyList_Size(pyLi);
907 for(int i=0;i<sz;i++)
909 PyObject *o=PyList_GetItem(pyLi,i);
910 if(!convertPyObjectToStrNT(o,vec[i]))
915 else if(PyTuple_Check(pyLi))
917 Py_ssize_t sz=PyTuple_Size(pyLi);
919 for(int i=0;i<sz;i++)
921 PyObject *o=PyTuple_GetItem(pyLi,i);
922 if(!convertPyObjectToStrNT(o,vec[i]))
930 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
932 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
933 if(PyList_Check(pyLi))
935 Py_ssize_t sz=PyList_Size(pyLi);
937 for(int i=0;i<sz;i++)
939 PyObject *o=PyList_GetItem(pyLi,i);
940 if(!fillStringVector(o,arr[i]))
941 throw INTERP_KERNEL::Exception(msg);
944 else if(PyTuple_Check(pyLi))
946 Py_ssize_t sz=PyTuple_Size(pyLi);
948 for(int i=0;i<sz;i++)
950 PyObject *o=PyTuple_GetItem(pyLi,i);
951 if(!fillStringVector(o,arr[i]))
952 throw INTERP_KERNEL::Exception(msg);
956 throw INTERP_KERNEL::Exception(msg);
959 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec)
961 if(PyList_Check(pyLi))
963 Py_ssize_t sz=PyList_Size(pyLi);
965 for(int i=0;i<sz;i++)
967 PyObject *o=PyList_GetItem(pyLi,i);
969 vec[i]=PyInt_AS_LONG(o);
975 else if(PyTuple_Check(pyLi))
977 Py_ssize_t sz=PyTuple_Size(pyLi);
979 for(int i=0;i<sz;i++)
981 PyObject *o=PyTuple_GetItem(pyLi,i);
983 vec[i]=PyInt_AS_LONG(o);
993 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr)
995 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
996 if(PyList_Check(pyLi))
998 Py_ssize_t sz=PyList_Size(pyLi);
1000 for(int i=0;i<sz;i++)
1002 PyObject *o=PyList_GetItem(pyLi,i);
1003 if(!fillIntVector(o,arr[i]))
1004 throw INTERP_KERNEL::Exception(msg);
1007 else if(PyTuple_Check(pyLi))
1009 Py_ssize_t sz=PyTuple_Size(pyLi);
1011 for(int i=0;i<sz;i++)
1013 PyObject *o=PyTuple_GetItem(pyLi,i);
1014 if(!fillIntVector(o,arr[i]))
1015 throw INTERP_KERNEL::Exception(msg);
1019 throw INTERP_KERNEL::Exception(msg);
1022 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
1024 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1025 if(PyList_Check(pyLi))
1027 Py_ssize_t sz=PyList_Size(pyLi);
1029 for(int i=0;i<sz;i++)
1031 PyObject *o=PyList_GetItem(pyLi,i);
1032 if(PyTuple_Check(o))
1034 int sz2=PyTuple_Size(o);
1036 throw INTERP_KERNEL::Exception(msg);
1037 std::pair<std::string, std::vector<std::string> > item;
1038 PyObject *o_0=PyTuple_GetItem(o,0);
1039 item.first=convertPyObjectToStr(o_0,msg);
1040 PyObject *o_1=PyTuple_GetItem(o,1);
1041 if(!fillStringVector(o_1,item.second))
1042 throw INTERP_KERNEL::Exception(msg);
1046 throw INTERP_KERNEL::Exception(msg);
1049 else if(PyTuple_Check(pyLi))
1051 Py_ssize_t sz=PyTuple_Size(pyLi);
1053 for(int i=0;i<sz;i++)
1055 PyObject *o=PyTuple_GetItem(pyLi,i);
1056 if(PyTuple_Check(o))
1058 int sz2=PyTuple_Size(o);
1060 throw INTERP_KERNEL::Exception(msg);
1061 std::pair<std::string, std::vector<std::string> > item;
1062 PyObject *o_0=PyTuple_GetItem(o,0);
1063 item.first=convertPyObjectToStr(o_0,msg);
1064 PyObject *o_1=PyTuple_GetItem(o,1);
1065 if(!fillStringVector(o_1,item.second))
1066 throw INTERP_KERNEL::Exception(msg);
1070 throw INTERP_KERNEL::Exception(msg);
1074 throw INTERP_KERNEL::Exception(msg);
1078 PyObject *convertDblArrToPyList(const T *ptr, int size)
1080 PyObject *ret(PyList_New(size));
1081 for(int i=0;i<size;i++)
1082 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1086 static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
1089 PyObject *ret(PyList_New(size));
1090 for(int i=0;i<size;i++)
1091 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1096 PyObject *convertDblArrToPyListOfTuple(const T *vals, int nbOfComp, int nbOfTuples)
1098 PyObject *ret(PyList_New(nbOfTuples));
1099 for(int i=0;i<nbOfTuples;i++)
1101 PyObject *t=PyTuple_New(nbOfComp);
1102 for(int j=0;j<nbOfComp;j++)
1103 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1104 PyList_SetItem(ret,i,t);
1109 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples)
1111 PyObject *ret=PyList_New(nbOfTuples);
1112 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1113 for(int i=0;i<nbOfTuples;i++)
1115 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1116 PyList_SetItem(ret,i,PyString_FromString(tmp));
1121 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size)
1123 if(PyList_Check(pyLi))
1125 *size=PyList_Size(pyLi);
1126 double *tmp=(double *)malloc((*size)*sizeof(double));
1127 for(int i=0;i<*size;i++)
1129 PyObject *o=PyList_GetItem(pyLi,i);
1130 if(PyFloat_Check(o))
1132 double val=PyFloat_AS_DOUBLE(o);
1135 else if(PyInt_Check(o))
1137 long val0=PyInt_AS_LONG(o);
1144 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1149 else if(PyTuple_Check(pyLi))
1151 *size=PyTuple_Size(pyLi);
1152 double *tmp=(double *)malloc((*size)*sizeof(double));
1153 for(int i=0;i<*size;i++)
1155 PyObject *o=PyTuple_GetItem(pyLi,i);
1156 if(PyFloat_Check(o))
1158 double val=PyFloat_AS_DOUBLE(o);
1161 else if(PyInt_Check(o))
1163 long val0=PyInt_AS_LONG(o);
1170 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1176 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1179 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1181 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1182 if(PyFloat_Check(pyLi))
1188 throw INTERP_KERNEL::Exception(MSG);
1189 double val=PyFloat_AS_DOUBLE(pyLi);
1192 else if(PyInt_Check(pyLi))
1194 long val0=PyInt_AS_LONG(pyLi);
1200 throw INTERP_KERNEL::Exception(MSG);
1203 else if(PyList_Check(pyLi))
1205 int size=PyList_Size(pyLi);
1207 for(int i=0;i<size;i++)
1209 PyObject *o=PyList_GetItem(pyLi,i);
1211 fillArrayWithPyListDbl3(o,tmp1,ret);
1219 throw INTERP_KERNEL::Exception(MSG);
1222 else if(PyTuple_Check(pyLi))
1224 int size=PyTuple_Size(pyLi);
1226 for(int i=0;i<size;i++)
1228 PyObject *o=PyTuple_GetItem(pyLi,i);
1230 fillArrayWithPyListDbl3(o,tmp1,ret);
1238 throw INTERP_KERNEL::Exception(MSG);
1242 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1245 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp)
1247 std::vector<double> ret;
1248 int size1=-1,size2=-1;
1249 if(PyList_Check(pyLi))
1251 size1=PyList_Size(pyLi);
1252 for(int i=0;i<size1;i++)
1254 PyObject *o=PyList_GetItem(pyLi,i);
1255 fillArrayWithPyListDbl3(o,size2,ret);
1260 else if(PyTuple_Check(pyLi))
1262 size1=PyTuple_Size(pyLi);
1263 for(int i=0;i<size1;i++)
1265 PyObject *o=PyTuple_GetItem(pyLi,i);
1266 fillArrayWithPyListDbl3(o,size2,ret);
1272 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1274 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1278 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1280 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1283 if(PyList_Check(pyLi))
1285 int size=PyList_Size(pyLi);
1287 for(int i=0;i<size;i++)
1289 PyObject *obj=PyList_GetItem(pyLi,i);
1290 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1291 if(!SWIG_IsOK(status))
1293 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1294 throw INTERP_KERNEL::Exception(oss.str().c_str());
1296 T arg=reinterpret_cast< T >(argp);
1300 else if(PyTuple_Check(pyLi))
1302 int size=PyTuple_Size(pyLi);
1304 for(int i=0;i<size;i++)
1306 PyObject *obj=PyTuple_GetItem(pyLi,i);
1307 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1308 if(!SWIG_IsOK(status))
1310 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1311 throw INTERP_KERNEL::Exception(oss.str().c_str());
1313 T arg=reinterpret_cast< T >(argp);
1317 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1320 T arg=reinterpret_cast< T >(argp);
1324 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1328 * if python int -> cpp int sw=1
1329 * if python list[int] -> cpp vector<int> sw=2
1330 * if python tuple[int] -> cpp vector<int> sw=2
1331 * if python DataArrayInt -> cpp DataArrayInt sw=3
1332 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1334 * switch between (int,vector<int>,DataArrayInt)
1336 static void convertIntStarLikePyObjToCpp(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple)
1339 if(PyInt_Check(value))
1341 iTyypp=(int)PyInt_AS_LONG(value);
1345 if(PyTuple_Check(value))
1347 int size=PyTuple_Size(value);
1348 stdvecTyypp.resize(size);
1349 for(int i=0;i<size;i++)
1351 PyObject *o=PyTuple_GetItem(value,i);
1353 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1356 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1357 throw INTERP_KERNEL::Exception(oss.str().c_str());
1363 if(PyList_Check(value))
1365 int size=PyList_Size(value);
1366 stdvecTyypp.resize(size);
1367 for(int i=0;i<size;i++)
1369 PyObject *o=PyList_GetItem(value,i);
1371 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1374 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1375 throw INTERP_KERNEL::Exception(oss.str().c_str());
1382 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1383 if(SWIG_IsOK(status))
1385 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1389 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1390 if(SWIG_IsOK(status))
1392 daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1396 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1400 * if python int -> cpp int sw=1
1401 * if python list[int] -> cpp vector<int> sw=2
1402 * if python tuple[int] -> cpp vector<int> sw=2
1403 * if python DataArrayInt -> cpp DataArrayInt sw=3
1404 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1406 * switch between (int,vector<int>,DataArrayInt)
1408 static const int *convertIntStarLikePyObjToCppIntStar(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp)
1411 if(PyInt_Check(value))
1413 iTyypp=(int)PyInt_AS_LONG(value);
1417 if(PyTuple_Check(value))
1419 int size=PyTuple_Size(value);
1420 stdvecTyypp.resize(size);
1421 for(int i=0;i<size;i++)
1423 PyObject *o=PyTuple_GetItem(value,i);
1425 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1428 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1429 throw INTERP_KERNEL::Exception(oss.str().c_str());
1433 return &stdvecTyypp[0];
1435 if(PyList_Check(value))
1437 int size=PyList_Size(value);
1438 stdvecTyypp.resize(size);
1439 for(int i=0;i<size;i++)
1441 PyObject *o=PyList_GetItem(value,i);
1443 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1446 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1447 throw INTERP_KERNEL::Exception(oss.str().c_str());
1451 return &stdvecTyypp[0];
1454 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1455 if(SWIG_IsOK(status))
1457 MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1460 sw=3; sz=daIntTyypp->getNbOfElems();
1461 return daIntTyypp->begin();
1469 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1470 if(SWIG_IsOK(status))
1472 MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1473 sw=4; sz=daIntTuple->getNumberOfCompo();
1474 return daIntTuple->getConstPointer();
1476 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1480 * if python double -> cpp double sw=1
1481 * if python int -> cpp double sw=1
1482 * if python list[double] -> cpp vector<double> sw=2
1483 * if python list[int] -> cpp vector<double> sw=2
1484 * if python tuple[double] -> cpp vector<double> sw=2
1485 * if python tuple[int] -> cpp vector<double> sw=2
1486 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1488 * switch between (int,vector<int>,DataArrayInt)
1491 void considerPyObjAsATStarLikeObject(PyObject *value, int& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1494 if(PyFloat_Check(value))
1496 iTyypp=(T)PyFloat_AS_DOUBLE(value);
1500 if(PyInt_Check(value))
1502 iTyypp=(T)PyInt_AS_LONG(value);
1506 if(PyTuple_Check(value))
1508 int size=PyTuple_Size(value);
1509 stdvecTyypp.resize(size);
1510 for(int i=0;i<size;i++)
1512 PyObject *o=PyTuple_GetItem(value,i);
1513 if(PyFloat_Check(o))
1514 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1515 else if(PyInt_Check(o))
1516 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1519 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1520 throw INTERP_KERNEL::Exception(oss.str().c_str());
1526 if(PyList_Check(value))
1528 int size=PyList_Size(value);
1529 stdvecTyypp.resize(size);
1530 for(int i=0;i<size;i++)
1532 PyObject *o=PyList_GetItem(value,i);
1533 if(PyFloat_Check(o))
1534 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1535 else if(PyInt_Check(o))
1536 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1539 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1540 throw INTERP_KERNEL::Exception(oss.str().c_str());
1547 int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1548 if(!SWIG_IsOK(status))
1549 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1550 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1555 * if python double -> cpp double sw=1
1556 * if python int -> cpp double sw=1
1557 * if python list[double] -> cpp vector<double> sw=2
1558 * if python list[int] -> cpp vector<double> sw=2
1559 * if python tuple[double] -> cpp vector<double> sw=2
1560 * if python tuple[int] -> cpp vector<double> sw=2
1561 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1563 * switch between (int,vector<int>,DataArrayInt)
1565 static void convertDoubleStarLikePyObjToCpp(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1568 if(PyFloat_Check(value))
1570 iTyypp=PyFloat_AS_DOUBLE(value);
1574 if(PyInt_Check(value))
1576 iTyypp=(double)PyInt_AS_LONG(value);
1580 if(PyTuple_Check(value))
1582 int size=PyTuple_Size(value);
1583 stdvecTyypp.resize(size);
1584 for(int i=0;i<size;i++)
1586 PyObject *o=PyTuple_GetItem(value,i);
1587 if(PyFloat_Check(o))
1588 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1589 else if(PyInt_Check(o))
1590 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1593 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1594 throw INTERP_KERNEL::Exception(oss.str().c_str());
1600 if(PyList_Check(value))
1602 int size=PyList_Size(value);
1603 stdvecTyypp.resize(size);
1604 for(int i=0;i<size;i++)
1606 PyObject *o=PyList_GetItem(value,i);
1607 if(PyFloat_Check(o))
1608 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1609 else if(PyInt_Check(o))
1610 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1613 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1614 throw INTERP_KERNEL::Exception(oss.str().c_str());
1621 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1622 if(!SWIG_IsOK(status))
1623 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1624 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1629 void convertFPStarLikePyObjToCpp_2(PyObject *value, int& sw, T& val, typename MEDCoupling::Traits<T>::ArrayType *&d, typename MEDCoupling::Traits<T>::ArrayTuple *&e, std::vector<T>& f, swig_type_info *ti_da, swig_type_info *ti_tuple)
1632 if(PyFloat_Check(value))
1634 val=PyFloat_AS_DOUBLE(value);
1638 if(PyInt_Check(value))
1640 val=(T)PyInt_AS_LONG(value);
1644 if(PyTuple_Check(value))
1646 int size=PyTuple_Size(value);
1648 for(int i=0;i<size;i++)
1650 PyObject *o=PyTuple_GetItem(value,i);
1651 if(PyFloat_Check(o))
1652 f[i]=PyFloat_AS_DOUBLE(o);
1653 else if(PyInt_Check(o))
1654 f[i]=(T)PyInt_AS_LONG(o);
1657 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1658 throw INTERP_KERNEL::Exception(oss.str().c_str());
1664 if(PyList_Check(value))
1666 int size=PyList_Size(value);
1668 for(int i=0;i<size;i++)
1670 PyObject *o=PyList_GetItem(value,i);
1671 if(PyFloat_Check(o))
1672 f[i]=PyFloat_AS_DOUBLE(o);
1673 else if(PyInt_Check(o))
1674 f[i]=(T)PyInt_AS_LONG(o);
1677 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1678 throw INTERP_KERNEL::Exception(oss.str().c_str());
1685 int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1686 if(SWIG_IsOK(status))
1688 d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1692 status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1693 if(SWIG_IsOK(status))
1695 e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1699 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1703 * if value int -> cpp val sw=1
1704 * if value double -> cpp val sw=1
1705 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1706 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1707 * if value list[int,double] -> cpp std::vector<double> sw=4
1708 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1710 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1712 convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1716 * if python int -> cpp int sw=1
1717 * if python list[int] -> cpp vector<int> sw=2
1718 * if python tuple[int] -> cpp vector<int> sw=2
1719 * if python slicp -> cpp pair sw=3 (begin,end,step)
1720 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1722 * switch between (int,vector<int>,DataArrayInt)
1724 static void convertIntStarOrSliceLikePyObjToCpp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp)
1726 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1728 if(PyInt_Check(value))
1730 iTyypp=(int)PyInt_AS_LONG(value);
1734 if(PyTuple_Check(value))
1736 int size=PyTuple_Size(value);
1737 stdvecTyypp.resize(size);
1738 for(int i=0;i<size;i++)
1740 PyObject *o=PyTuple_GetItem(value,i);
1742 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1745 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1746 throw INTERP_KERNEL::Exception(oss.str().c_str());
1752 if(PyList_Check(value))
1754 int size=PyList_Size(value);
1755 stdvecTyypp.resize(size);
1756 for(int i=0;i<size;i++)
1758 PyObject *o=PyList_GetItem(value,i);
1760 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1763 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1764 throw INTERP_KERNEL::Exception(oss.str().c_str());
1770 if(PySlice_Check(value))
1772 Py_ssize_t strt=2,stp=2,step=2;
1773 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1776 p.second.second=step;
1781 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1782 if(SWIG_IsOK(status))
1784 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1787 std::ostringstream oss; oss << msg << " Instance in null !";
1788 throw INTERP_KERNEL::Exception(oss.str().c_str());
1793 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1794 if(SWIG_IsOK(status))
1796 MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1799 std::ostringstream oss; oss << msg << " Instance in null !";
1800 throw INTERP_KERNEL::Exception(oss.str().c_str());
1802 stdvecTyypp.resize(tmp->getNumberOfCompo());
1803 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1807 throw INTERP_KERNEL::Exception(msg);
1811 * Idem than convertIntStarOrSliceLikePyObjToCpp
1813 static void convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayInt *& daIntTyypp)
1815 convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1818 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1823 * if python int -> cpp int sw=1
1824 * if python tuple[int] -> cpp vector<int> sw=2
1825 * if python list[int] -> cpp vector<int> sw=2
1826 * if python slice -> cpp pair sw=3
1827 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1829 static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, MEDCoupling::DataArrayIntTuple *& daIntTyypp)
1832 if(PyInt_Check(value))
1834 iTyypp=(int)PyInt_AS_LONG(value);
1838 if(PyTuple_Check(value))
1840 int size=PyTuple_Size(value);
1841 stdvecTyypp.resize(size);
1842 for(int i=0;i<size;i++)
1844 PyObject *o=PyTuple_GetItem(value,i);
1846 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1849 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1850 throw INTERP_KERNEL::Exception(oss.str().c_str());
1856 if(PyList_Check(value))
1858 int size=PyList_Size(value);
1859 stdvecTyypp.resize(size);
1860 for(int i=0;i<size;i++)
1862 PyObject *o=PyList_GetItem(value,i);
1864 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1867 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1868 throw INTERP_KERNEL::Exception(oss.str().c_str());
1874 if(PySlice_Check(value))
1876 Py_ssize_t strt=2,stp=2,step=2;
1877 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1880 p.second.second=step;
1885 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1886 if(!SWIG_IsOK(status))
1887 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1888 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1893 * if python string with size one -> cpp char sw=1
1894 * if python string with size different from one -> cpp string sw=2
1895 * if python tuple[string] or list[string] -> vector<string> sw=3
1896 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1897 * switch between (int,string,vector<string>,DataArrayChar)
1899 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
1901 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1903 if(PyString_Check(value))
1905 const char *pt=PyString_AsString(value);
1906 Py_ssize_t sz=PyString_Size(value);
1920 #if PY_VERSION_HEX >= 0x03000000
1921 if(PyUnicode_Check(value))
1924 const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
1939 if(PyTuple_Check(value))
1941 int size=PyTuple_Size(value);
1942 vsType.resize(size);
1943 for(int i=0;i<size;i++)
1945 PyObject *o=PyTuple_GetItem(value,i);
1948 vsType[i]=convertPyObjectToStr(o);
1950 catch(INTERP_KERNEL::Exception& e)
1952 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1953 throw INTERP_KERNEL::Exception(oss.str().c_str());
1959 if(PyList_Check(value))
1961 int size=PyList_Size(value);
1962 vsType.resize(size);
1963 for(int i=0;i<size;i++)
1965 PyObject *o=PyList_GetItem(value,i);
1968 vsType[i]=convertPyObjectToStr(o);
1970 catch(INTERP_KERNEL::Exception& e)
1972 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1973 throw INTERP_KERNEL::Exception(oss.str().c_str());
1980 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
1981 if(SWIG_IsOK(status))
1983 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
1986 std::ostringstream oss; oss << msg << " Instance in null !";
1987 throw INTERP_KERNEL::Exception(oss.str().c_str());
1992 throw INTERP_KERNEL::Exception(msg);
1996 * if value int -> cpp it sw=1
1997 * if value list[int] -> vt sw=2
1998 * if value tuple[int] -> vt sw=2
1999 * if value slice -> pt sw=3
2000 * if value DataArrayInt -> dt sw=4
2001 * if value tuple [int,int] -> cpp it,ip sw=5
2002 * if value tuple [list[int],int] -> cpp vt,ip sw=6
2003 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2004 * if value tuple [slice,int] -> cpp pt,ip sw=7
2005 * if value tuple [DaI,int] -> cpp dt,ip sw=8
2006 * if value tuple [int,list[int]] -> cpp it,vc sw=9
2007 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2008 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2009 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2010 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2011 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2012 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2013 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2014 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2015 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2016 * if value tuple [int,slice] -> cpp it,pc sw=13
2017 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2018 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2019 * if value tuple [slice,slice] -> cpp pt,pc sw=15
2020 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2022 * switch between (int,vector<int>,DataArrayInt)
2024 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
2025 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
2026 MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc)
2028 if(!PyTuple_Check(value))
2030 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2035 int sz=PyTuple_Size(value);
2037 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2038 PyObject *ob0=PyTuple_GetItem(value,0);
2040 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2041 PyObject *ob1=PyTuple_GetItem(value,1);
2042 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2048 * if value int -> cpp val sw=1
2049 * if value double -> cpp val sw=1
2050 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2051 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2052 * if value list[int,double] -> cpp std::vector<double> sw=4
2053 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2055 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2056 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2059 if(PyFloat_Check(value))
2061 val=PyFloat_AS_DOUBLE(value);
2063 if(nbTuplesExpected*nbCompExpected!=1)
2065 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2066 throw INTERP_KERNEL::Exception(oss.str().c_str());
2070 if(PyInt_Check(value))
2072 val=(double)PyInt_AS_LONG(value);
2074 if(nbTuplesExpected*nbCompExpected!=1)
2076 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2077 throw INTERP_KERNEL::Exception(oss.str().c_str());
2081 if(PyTuple_Check(value) || PyList_Check(value))
2085 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2086 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2091 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2094 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2095 if(SWIG_IsOK(status))
2097 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2101 if(d->getNumberOfTuples()==nbTuplesExpected)
2103 if(d->getNumberOfComponents()==nbCompExpected)
2105 return d->getConstPointer();
2109 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2110 throw INTERP_KERNEL::Exception(oss.str().c_str());
2115 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2116 throw INTERP_KERNEL::Exception(oss.str().c_str());
2123 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2124 throw INTERP_KERNEL::Exception(oss.str().c_str());
2130 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2131 if(SWIG_IsOK(status))
2133 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2135 if(e->getNumberOfCompo()==nbCompExpected)
2137 if(nbTuplesExpected==1)
2138 return e->getConstPointer();
2141 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2142 throw INTERP_KERNEL::Exception(oss.str().c_str());
2147 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2148 throw INTERP_KERNEL::Exception(oss.str().c_str());
2151 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2155 * if value int -> cpp val sw=1
2156 * if value double -> cpp val sw=1
2157 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2158 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2159 * if value list[int,double] -> cpp std::vector<double> sw=4
2160 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2162 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2163 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples)
2166 if(PyFloat_Check(value))
2168 val=PyFloat_AS_DOUBLE(value);
2170 if(nbCompExpected!=1)
2172 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2173 throw INTERP_KERNEL::Exception(oss.str().c_str());
2178 if(PyInt_Check(value))
2180 val=(double)PyInt_AS_LONG(value);
2182 if(nbCompExpected!=1)
2184 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2185 throw INTERP_KERNEL::Exception(oss.str().c_str());
2190 if(PyTuple_Check(value))
2192 int size=PyTuple_Size(value);
2194 for(int i=0;i<size;i++)
2196 PyObject *o=PyTuple_GetItem(value,i);
2197 if(PyFloat_Check(o))
2198 f[i]=PyFloat_AS_DOUBLE(o);
2199 else if(PyInt_Check(o))
2200 f[i]=(double)PyInt_AS_LONG(o);
2203 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2204 throw INTERP_KERNEL::Exception(oss.str().c_str());
2208 if(size%nbCompExpected!=0)
2210 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2211 throw INTERP_KERNEL::Exception(oss.str().c_str());
2213 nbTuples=size/nbCompExpected;
2216 if(PyList_Check(value))
2218 int size=PyList_Size(value);
2220 for(int i=0;i<size;i++)
2222 PyObject *o=PyList_GetItem(value,i);
2223 if(PyFloat_Check(o))
2224 f[i]=PyFloat_AS_DOUBLE(o);
2225 else if(PyInt_Check(o))
2226 f[i]=(double)PyInt_AS_LONG(o);
2229 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2230 throw INTERP_KERNEL::Exception(oss.str().c_str());
2234 if(size%nbCompExpected!=0)
2236 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2237 throw INTERP_KERNEL::Exception(oss.str().c_str());
2239 nbTuples=size/nbCompExpected;
2243 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2244 if(SWIG_IsOK(status))
2246 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2250 if(d->getNumberOfComponents()==nbCompExpected)
2252 nbTuples=d->getNumberOfTuples();
2253 return d->getConstPointer();
2257 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2258 throw INTERP_KERNEL::Exception(oss.str().c_str());
2265 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2266 throw INTERP_KERNEL::Exception(oss.str().c_str());
2269 { nbTuples=0; return 0; }
2272 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2273 if(SWIG_IsOK(status))
2275 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2279 if(e->getNumberOfCompo()==nbCompExpected)
2282 return e->getConstPointer();
2286 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2287 throw INTERP_KERNEL::Exception(oss.str().c_str());
2294 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2295 throw INTERP_KERNEL::Exception(oss.str().c_str());
2298 { nbTuples=0; return 0; }
2301 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2305 * if value int -> cpp val sw=1
2306 * if value double -> cpp val sw=1
2307 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2308 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2309 * if value list[int,double] -> cpp std::vector<double> sw=4
2310 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2312 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2313 const char *msg, bool throwIfNullPt, int& nbTuples)
2315 MEDCoupling::DataArrayDouble *d=0;
2316 MEDCoupling::DataArrayDoubleTuple *e=0;
2318 if(PyFloat_Check(value))
2320 val=PyFloat_AS_DOUBLE(value);
2325 if(PyInt_Check(value))
2327 val=(double)PyInt_AS_LONG(value);
2332 if(PyTuple_Check(value))
2334 int size=PyTuple_Size(value);
2336 for(int i=0;i<size;i++)
2338 PyObject *o=PyTuple_GetItem(value,i);
2339 if(PyFloat_Check(o))
2340 f[i]=PyFloat_AS_DOUBLE(o);
2341 else if(PyInt_Check(o))
2342 f[i]=(double)PyInt_AS_LONG(o);
2345 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2346 throw INTERP_KERNEL::Exception(oss.str().c_str());
2353 if(PyList_Check(value))
2355 int size=PyList_Size(value);
2357 for(int i=0;i<size;i++)
2359 PyObject *o=PyList_GetItem(value,i);
2360 if(PyFloat_Check(o))
2361 f[i]=PyFloat_AS_DOUBLE(o);
2362 else if(PyInt_Check(o))
2363 f[i]=(double)PyInt_AS_LONG(o);
2366 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2367 throw INTERP_KERNEL::Exception(oss.str().c_str());
2375 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2376 if(SWIG_IsOK(status))
2378 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2382 if(d->getNumberOfComponents()==1)
2384 nbTuples=d->getNumberOfTuples();
2385 return d->getConstPointer();
2389 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2390 throw INTERP_KERNEL::Exception(oss.str().c_str());
2397 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2398 throw INTERP_KERNEL::Exception(oss.str().c_str());
2401 { nbTuples=0; return 0; }
2404 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2405 if(SWIG_IsOK(status))
2407 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2411 nbTuples=e->getNumberOfCompo();
2412 return e->getConstPointer();
2418 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2419 throw INTERP_KERNEL::Exception(oss.str().c_str());
2422 { nbTuples=0; return 0; }
2425 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2428 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2431 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2432 if(!SWIG_IsOK(status))
2434 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2435 if(!SWIG_IsOK(status))
2437 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2438 if(!SWIG_IsOK(status))
2440 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2441 if(!SWIG_IsOK(status))
2443 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2444 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2445 throw INTERP_KERNEL::Exception(oss.str().c_str());
2450 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2453 static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
2455 if(!PyTuple_Check(args))
2457 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2458 throw INTERP_KERNEL::Exception(oss.str().c_str());
2460 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2461 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2462 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2464 PyObject *tmp0(PyTuple_New(1));
2465 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2466 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2468 Py_DECREF(selfMeth);
2469 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==0 )
2470 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2471 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2472 PyObject *tmp3(PyTuple_New(0));
2473 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2476 Py_DECREF(initMeth);
2482 static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral(PyObject *cls, PyObject *args, const char *clsName)
2484 if(!PyTuple_Check(args))
2486 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2487 throw INTERP_KERNEL::Exception(oss.str().c_str());
2489 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2490 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2491 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2493 PyObject *tmp0(PyTuple_New(1));
2494 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2495 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2497 Py_DECREF(selfMeth);
2498 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 )
2499 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2500 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2501 PyObject *zeNumpyRepr(0);
2503 PyObject *tmp1(PyInt_FromLong(0));
2504 zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed
2509 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2510 throw INTERP_KERNEL::Exception(oss.str().c_str());
2517 tmp3=tt(zeNumpyRepr);
2519 catch(INTERP_KERNEL::Exception& e)
2521 std::ostringstream oss; oss << clsName << ".__new__ : Invalid type in input " << " : " << e.what();
2522 throw INTERP_KERNEL::Exception(oss.str());
2525 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2530 Py_DECREF(initMeth);
2535 struct SinglePyObjToBePutInATuple
2537 PyObject *operator()(PyObject *zeNumpyRepr)
2539 PyObject *tmp3(PyTuple_New(1));
2540 PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
2545 struct SinglePyObjExpectToBeAListOfSz2
2547 PyObject *operator()(PyObject *uniqueElt)
2549 if(!PyTuple_Check(uniqueElt) || PyTuple_Size(uniqueElt)!=2)
2550 throw INTERP_KERNEL::Exception("Not a tuple of size 2 !");
2551 Py_XINCREF(uniqueElt);
2556 static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(PyObject *cls, PyObject *args, const char *clsName)
2558 return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral<SinglePyObjToBePutInATuple>(cls,args,clsName);
2561 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2566 Py_XINCREF(Py_None);
2569 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2570 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2572 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2577 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2579 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)";
2580 std::string msg(msgBase);
2582 msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2585 if(PyList_Check(elt0) || PyTuple_Check(elt0))
2589 if(PyInt_Check(nbOfTuples))
2591 int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
2593 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2596 if(PyInt_Check(elt2))
2597 {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2598 int nbOfCompo=PyInt_AS_LONG(elt2);
2600 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2601 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2602 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2603 ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2607 throw INTERP_KERNEL::Exception(msg.c_str());
2610 {//DataArrayDouble.New([1.,3.,4.],3)
2611 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2613 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2614 ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2619 throw INTERP_KERNEL::Exception(msg.c_str());
2622 {// DataArrayDouble.New([1.,3.,4.])
2623 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2624 int tmpp1(-1),tmpp2(-1);
2625 std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2626 ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2630 else if(PyInt_Check(elt0))
2632 int nbOfTuples1(PyInt_AS_LONG(elt0));
2634 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2639 if(PyInt_Check(nbOfTuples))
2640 {//DataArrayDouble.New(5,2)
2641 int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
2643 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2644 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2645 ret->alloc(nbOfTuples1,nbOfCompo);
2649 throw INTERP_KERNEL::Exception(msg.c_str());
2652 throw INTERP_KERNEL::Exception(msg.c_str());
2655 {//DataArrayDouble.New(5)
2656 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2657 ret->alloc(nbOfTuples1,1);
2662 else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2663 {//DataArrayDouble.New(numpyArray)
2664 return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2668 throw INTERP_KERNEL::Exception(msg.c_str());
2669 throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2673 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2675 self->checkAllocated();
2676 const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2677 int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
2681 typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2682 considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2684 std::vector<int> vt1,vc1;
2685 std::pair<int, std::pair<int,int> > pt1,pc1;
2686 MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
2687 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2688 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2696 self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2699 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2700 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2701 self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2704 self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2707 throw INTERP_KERNEL::Exception(msg);
2716 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2719 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2720 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2721 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2724 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2727 throw INTERP_KERNEL::Exception(msg);
2736 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2739 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2740 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2741 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2744 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2747 throw INTERP_KERNEL::Exception(msg);
2756 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2759 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2760 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2761 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2764 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2767 throw INTERP_KERNEL::Exception(msg);
2776 self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2779 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2780 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2781 self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2784 self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2787 throw INTERP_KERNEL::Exception(msg);
2796 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2799 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2800 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2801 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2804 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2807 throw INTERP_KERNEL::Exception(msg);
2816 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2819 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2820 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2821 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2824 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2827 throw INTERP_KERNEL::Exception(msg);
2836 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2839 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2840 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2841 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2844 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2847 throw INTERP_KERNEL::Exception(msg);
2856 self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2859 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2860 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2861 self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2864 self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2867 throw INTERP_KERNEL::Exception(msg);
2876 self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2879 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2880 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2881 self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2884 self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2887 throw INTERP_KERNEL::Exception(msg);
2896 self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2899 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2900 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2901 self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2904 self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2907 throw INTERP_KERNEL::Exception(msg);
2916 self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2919 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2920 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2921 self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2924 self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2927 throw INTERP_KERNEL::Exception(msg);
2936 self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2939 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2940 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2941 self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2944 self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2947 throw INTERP_KERNEL::Exception(msg);
2956 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2959 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2960 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2961 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2964 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2967 throw INTERP_KERNEL::Exception(msg);
2976 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2979 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2980 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2981 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2984 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2987 throw INTERP_KERNEL::Exception(msg);
2996 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2999 tmp=MEDCoupling::Traits<T>::ArrayType::New();
3000 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
3001 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
3004 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3007 throw INTERP_KERNEL::Exception(msg);
3012 throw INTERP_KERNEL::Exception(msg);
3018 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3020 const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3021 const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3022 self->checkAllocated();
3023 int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
3025 std::vector<int> vt1,vc1;
3026 std::pair<int, std::pair<int,int> > pt1,pc1;
3027 MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
3029 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3030 MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3034 if(nbOfComponents==1)
3035 return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3036 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3038 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3040 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3042 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3044 return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3047 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3048 std::vector<int> v2(1,ic1);
3049 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3053 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3054 std::vector<int> v2(1,ic1);
3055 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3059 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3060 std::vector<int> v2(1,ic1);
3061 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3065 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3066 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3070 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3071 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3075 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3076 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3080 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3081 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3085 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3086 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3087 std::vector<int> v2(nbOfComp);
3088 for(int i=0;i<nbOfComp;i++)
3089 v2[i]=pc1.first+i*pc1.second.second;
3090 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3094 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3095 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3096 std::vector<int> v2(nbOfComp);
3097 for(int i=0;i<nbOfComp;i++)
3098 v2[i]=pc1.first+i*pc1.second.second;
3099 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3103 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3104 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3105 std::vector<int> v2(nbOfComp);
3106 for(int i=0;i<nbOfComp;i++)
3107 v2[i]=pc1.first+i*pc1.second.second;
3108 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3112 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3113 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3114 std::vector<int> v2(nbOfComp);
3115 for(int i=0;i<nbOfComp;i++)
3116 v2[i]=pc1.first+i*pc1.second.second;
3117 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3120 throw INTERP_KERNEL::Exception(msg);
3125 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3127 const char msg[]="Unexpected situation in __imul__ !";
3129 typename MEDCoupling::Traits<T>::ArrayType *a;
3130 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3133 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3138 self->applyLin(val,0.);
3139 Py_XINCREF(trueSelf);
3144 self->multiplyEqual(a);
3145 Py_XINCREF(trueSelf);
3150 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3151 self->multiplyEqual(aaa);
3152 Py_XINCREF(trueSelf);
3157 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
3158 self->multiplyEqual(aaa);
3159 Py_XINCREF(trueSelf);
3163 throw INTERP_KERNEL::Exception(msg);
3168 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3170 const char msg[]="Unexpected situation in __idiv__ !";
3172 typename MEDCoupling::Traits<T>::ArrayType *a;
3173 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3176 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3182 throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3183 self->applyLin(1./val,0.);
3184 Py_XINCREF(trueSelf);
3189 self->divideEqual(a);
3190 Py_XINCREF(trueSelf);
3195 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3196 self->divideEqual(aaa);
3197 Py_XINCREF(trueSelf);
3202 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
3203 self->divideEqual(aaa);
3204 Py_XINCREF(trueSelf);
3208 throw INTERP_KERNEL::Exception(msg);
3213 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3215 const char msg[]="Unexpected situation in __iadd__ !";
3217 typename MEDCoupling::Traits<T>::ArrayType *a;
3218 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3221 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3226 self->applyLin(1.,val);
3227 Py_XINCREF(trueSelf);
3233 Py_XINCREF(trueSelf);
3238 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3239 self->addEqual(aaa);
3240 Py_XINCREF(trueSelf);
3245 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
3246 self->addEqual(aaa);
3247 Py_XINCREF(trueSelf);
3251 throw INTERP_KERNEL::Exception(msg);
3256 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3258 const char msg[]="Unexpected situation in __isub__ !";
3260 typename MEDCoupling::Traits<T>::ArrayType *a;
3261 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3264 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3269 self->applyLin(1.,-val);
3270 Py_XINCREF(trueSelf);
3275 self->substractEqual(a);
3276 Py_XINCREF(trueSelf);
3281 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3282 self->substractEqual(aaa);
3283 Py_XINCREF(trueSelf);
3288 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
3289 self->substractEqual(aaa);
3290 Py_XINCREF(trueSelf);
3294 throw INTERP_KERNEL::Exception(msg);
3303 struct SWIGTITraits<double>
3304 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3307 struct SWIGTITraits<float>
3308 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3311 struct SWIGTITraits<int>
3312 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3314 swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
3315 swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3316 swig_type_info *SWIGTITraits<int>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3317 swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
3318 swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3319 swig_type_info *SWIGTITraits<int>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3321 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3323 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3326 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3328 return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3332 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3334 return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3338 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3340 return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3344 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3346 return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3350 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3352 return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3356 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3358 return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);