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());
112 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
113 // in input when an another DataArray is already client of this.
114 template<class MCData>
115 void numarrdeal2(void *pt, void *obj)
117 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
118 void **obj1=(void **)obj;
119 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
120 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
122 Py_XDECREF(weakRefOnOwner);
127 template<class MCData, class T>
128 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
130 int ndim=PyArray_NDIM(elt0);
131 if(ndim!=1 && ndim!=2)
132 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
133 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
135 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
136 throw INTERP_KERNEL::Exception(oss.str().c_str());
138 npy_intp sz0=PyArray_DIM(elt0,0);
139 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
141 int itemSize=PyArray_ITEMSIZE(elt0);
142 if(itemSize!=sizeof(T))
144 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
145 throw INTERP_KERNEL::Exception(oss.str().c_str());
147 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
148 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
150 if(itemSize!=PyArray_STRIDE(elt0,1))
151 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays for component #1 !");
152 const char *data=PyArray_BYTES(elt0);
153 typename MEDCoupling::MCAuto<MCData> ret=MCData::New();
154 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
156 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
157 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
158 int mask=MED_NUMPY_OWNDATA; mask=~mask;
160 PyObject *deepestObj=elt0;
161 PyObject *base=elt0C->base;
162 if(base) deepestObj=base;
163 bool isSpetialCase(false);
166 if(PyArray_Check(base))
168 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
169 eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
172 if(base) deepestObj=base;
181 {// this case is present for numpy arrayint coming from load of pickelized string. The owner of elt0 is not an array -> A copy is requested.
182 std::size_t nbOfElems(sz0*sz1);
183 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
184 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
185 ret->useArray(dataCpy,true,MEDCoupling::C_DEALLOC,sz0,sz1);
188 typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
191 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
193 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
194 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
195 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
196 mma.setParameterForDeallocator(objs);
197 mma.setSpecificDeallocator(numarrdeal2<MCData>);
198 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
202 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
203 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
204 typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::CDeallocator);
205 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
206 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
207 mma.setParameterForDeallocator(objs);
208 mma.setSpecificDeallocator(numarrdeal);
211 else if(PyArray_ISBEHAVED_RO(elt0))
212 ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::CPP_DEALLOC,sz0,sz1);
217 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
220 PyErr_SetString(PyExc_ValueError,
221 "Cannot set the NumPy array 'base' "
222 "dependency to NULL after initialization");
226 * Allow the base to be set only once. Once the object which
227 * owns the data is set, it doesn't make sense to change it.
229 if (PyArray_BASE(arr) != NULL) {
231 PyErr_SetString(PyExc_ValueError,
232 "Cannot set the NumPy array 'base' "
233 "dependency more than once");
238 * Don't allow infinite chains of views, always set the base
239 * to the first owner of the data.
240 * That is, either the first object which isn't an array,
241 * or the first object which owns its own data.
244 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
245 PyArrayObject *obj_arr = (PyArrayObject *)obj;
249 /* If this array owns its own data, stop collapsing */
250 if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
254 tmp = PyArray_BASE(obj_arr);
255 /* If there's no base, stop collapsing */
259 /* Stop the collapse new base when the would not be of the same
260 * type (i.e. different subclass).
262 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
272 /* Disallow circular references */
273 if ((PyObject *)arr == obj) {
275 PyErr_SetString(PyExc_ValueError,
276 "Cannot create a circular NumPy array 'base' dependency");
285 template<class MCData, class T>
286 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
288 if(!self->isAllocated())
290 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
291 throw INTERP_KERNEL::Exception(oss.str().c_str());
293 MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
296 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
297 throw INTERP_KERNEL::Exception(oss.str().c_str());
299 int nbDims=nbComp==1?1:2;
301 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
302 const T *bg=self->getConstPointer();
303 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
304 if(mem.isDeallocatorCalled())
306 if(mem.getDeallocator()!=numarrdeal)
307 {// case for the first call of toNumPyArray
308 PyObject *ref(PyWeakref_NewRef(ret,NULL));
309 typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
310 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
311 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
312 mem.setParameterForDeallocator(objs);
313 mem.setSpecificDeallocator(numarrdeal);
317 {// case for the second and other call of toNumPyArray
318 void **objs=(void **)mem.getParameterForDeallocator();
319 PyObject *weakRefOnOwner=(PyObject *)objs[0];
320 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
322 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
324 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
327 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
328 Py_XDECREF(weakRefOnOwner);
329 PyObject *ref=PyWeakref_NewRef(ret,NULL);
337 template<class MCData, class T>
338 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
340 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
343 SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
344 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
349 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols)
351 int nbRows((int)m.size());
352 MEDCoupling::MCAuto<MEDCoupling::DataArrayInt> indPtr(MEDCoupling::DataArrayInt::New()),indices(MEDCoupling::DataArrayInt::New());
353 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
354 indPtr->alloc(nbRows+1,1);
355 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
357 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
359 sz2+=(int)(*it0).size();
362 indices->alloc(sz2,1); data->alloc(sz2,1);
363 int *indices_ptr(indices->getPointer());
364 double *data_ptr(data->getPointer());
365 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
366 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
368 *indices_ptr=(*it1).first;
369 *data_ptr=(*it1).second;
371 PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt_toNumPyArray(indPtr));
373 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
374 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
375 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
376 PyObject *tmp1(PyString_FromString("shape"));
377 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
378 PyObject* pdict=PyDict_New();
379 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
380 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
382 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
383 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
385 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
386 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
387 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
393 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner)
401 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
402 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
403 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
404 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
406 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
410 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner)
418 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
419 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
420 if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
421 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
422 if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
423 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
424 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
425 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
426 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
427 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
429 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
433 static PyObject *convertIntArrToPyList(const int *ptr, int size)
435 PyObject *ret=PyList_New(size);
436 for(int i=0;i<size;i++)
437 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
441 static PyObject *convertIntArrToPyList2(const std::vector<int>& v)
444 PyObject *ret=PyList_New(size);
445 for(int i=0;i<size;i++)
446 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
450 static PyObject *convertIntArrToPyList3(const std::set<int>& v)
453 PyObject *ret=PyList_New(size);
454 std::set<int>::const_iterator it=v.begin();
455 for(int i=0;i<size;i++,it++)
456 PyList_SetItem(ret,i,PyInt_FromLong(*it));
460 static bool convertPyObjectToStrNT(PyObject *obj, std::string& ret)
462 if(PyString_Check(obj))
464 ret=PyString_AsString(obj);
467 #if PY_VERSION_HEX >= 0x03000000
468 else if(PyUnicode_Check(obj))
470 ret=PyUnicode_AsUTF8(obj);
477 static std::string convertPyObjectToStr(PyObject *obj, const char *msg=NULL)
480 if(PyString_Check(obj))
481 ret=PyString_AsString(obj);
482 #if PY_VERSION_HEX >= 0x03000000
483 else if(PyUnicode_Check(obj))
484 ret=PyUnicode_AsUTF8(obj);
488 std::ostringstream oss;
492 oss << "PyWrap convertPyObjectToStr : expect a sting like py object !";
493 throw INTERP_KERNEL::Exception(oss.str());
498 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples)
500 PyObject *ret=PyList_New(nbOfTuples);
501 for(int i=0;i<nbOfTuples;i++)
503 PyObject *t=PyTuple_New(nbOfComp);
504 for(int j=0;j<nbOfComp;j++)
505 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
506 PyList_SetItem(ret,i,t);
511 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size)
513 if(PyList_Check(pyLi))
515 *size=PyList_Size(pyLi);
516 int *tmp=new int[*size];
517 for(int i=0;i<*size;i++)
519 PyObject *o=PyList_GetItem(pyLi,i);
522 int val=(int)PyInt_AS_LONG(o);
528 throw INTERP_KERNEL::Exception("list must contain integers only");
533 else if(PyTuple_Check(pyLi))
535 *size=PyTuple_Size(pyLi);
536 int *tmp=new int[*size];
537 for(int i=0;i<*size;i++)
539 PyObject *o=PyTuple_GetItem(pyLi,i);
542 int val=(int)PyInt_AS_LONG(o);
548 throw INTERP_KERNEL::Exception("tuple must contain integers only");
555 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
559 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr)
561 PyObject *ret=PyList_New(arr.size());
562 for(std::size_t i=0;i<arr.size();i++)
564 PyObject *t=PyTuple_New(2);
565 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
566 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
567 PyList_SetItem(ret,i,t);
572 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr)
574 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
575 if(PyList_Check(pyLi))
577 int size=PyList_Size(pyLi);
579 for(int i=0;i<size;i++)
581 PyObject *o=PyList_GetItem(pyLi,i);
584 int sz2=PyTuple_Size(o);
586 throw INTERP_KERNEL::Exception(msg);
587 PyObject *o_0=PyTuple_GetItem(o,0);
588 if(!PyInt_Check(o_0))
589 throw INTERP_KERNEL::Exception(msg);
590 PyObject *o_1=PyTuple_GetItem(o,1);
591 if(!PyInt_Check(o_1))
592 throw INTERP_KERNEL::Exception(msg);
593 arr[i].first=(int)PyInt_AS_LONG(o_0);
594 arr[i].second=(int)PyInt_AS_LONG(o_1);
597 throw INTERP_KERNEL::Exception(msg);
600 else if(PyTuple_Check(pyLi))
602 int size=PyTuple_Size(pyLi);
604 for(int i=0;i<size;i++)
606 PyObject *o=PyTuple_GetItem(pyLi,i);
609 int sz2=PyTuple_Size(o);
611 throw INTERP_KERNEL::Exception(msg);
612 PyObject *o_0=PyTuple_GetItem(o,0);
613 if(!PyInt_Check(o_0))
614 throw INTERP_KERNEL::Exception(msg);
615 PyObject *o_1=PyTuple_GetItem(o,1);
616 if(!PyInt_Check(o_1))
617 throw INTERP_KERNEL::Exception(msg);
618 arr[i].first=(int)PyInt_AS_LONG(o_0);
619 arr[i].second=(int)PyInt_AS_LONG(o_1);
622 throw INTERP_KERNEL::Exception(msg);
626 throw INTERP_KERNEL::Exception(msg);
629 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
631 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
632 if(PyList_Check(pyLi))
634 int size=PyList_Size(pyLi);
636 for(int i=0;i<size;i++)
638 PyObject *o=PyList_GetItem(pyLi,i);
641 int sz2=PyTuple_Size(o);
643 throw INTERP_KERNEL::Exception(msg);
644 PyObject *o_0=PyTuple_GetItem(o,0);
645 PyObject *o_1=PyTuple_GetItem(o,1);
646 arr[i].first=convertPyObjectToStr(o_0,msg);
647 if(!PyInt_Check(o_1))
648 throw INTERP_KERNEL::Exception(msg);
649 arr[i].second=(int)PyInt_AS_LONG(o_1);
652 throw INTERP_KERNEL::Exception(msg);
655 else if(PyTuple_Check(pyLi))
657 int size=PyTuple_Size(pyLi);
659 for(int i=0;i<size;i++)
661 PyObject *o=PyTuple_GetItem(pyLi,i);
664 int sz2=PyTuple_Size(o);
666 throw INTERP_KERNEL::Exception(msg);
667 PyObject *o_0=PyTuple_GetItem(o,0);
668 PyObject *o_1=PyTuple_GetItem(o,1);
669 arr[i].first=convertPyObjectToStr(o_0,msg);
670 if(!PyInt_Check(o_1))
671 throw INTERP_KERNEL::Exception(msg);
672 arr[i].second=(int)PyInt_AS_LONG(o_1);
675 throw INTERP_KERNEL::Exception(msg);
679 throw INTERP_KERNEL::Exception(msg);
682 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr)
684 if(PyList_Check(pyLi))
686 int size=PyList_Size(pyLi);
688 for(int i=0;i<size;i++)
690 PyObject *o=PyList_GetItem(pyLi,i);
693 int val=(int)PyInt_AS_LONG(o);
697 throw INTERP_KERNEL::Exception("list must contain integers only");
700 else if(PyTuple_Check(pyLi))
702 int size=PyTuple_Size(pyLi);
704 for(int i=0;i<size;i++)
706 PyObject *o=PyTuple_GetItem(pyLi,i);
709 int val=(int)PyInt_AS_LONG(o);
713 throw INTERP_KERNEL::Exception("tuple must contain integers only");
718 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
722 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr)
725 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
727 if(PyList_Check(pyLi))
729 int size=PyList_Size(pyLi);
730 for(int i=0;i<size;i++)
732 PyObject *o=PyList_GetItem(pyLi,i);
735 int val=(int)PyInt_AS_LONG(o);
740 std::vector<int> arr2;
741 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
742 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
744 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
745 throw INTERP_KERNEL::Exception(oss.str().c_str());
747 arr.insert(arr.end(),arr2.begin(),arr2.end());
751 else if(PyTuple_Check(pyLi))
753 int size=PyTuple_Size(pyLi);
754 for(int i=0;i<size;i++)
756 PyObject *o=PyTuple_GetItem(pyLi,i);
759 int val=(int)PyInt_AS_LONG(o);
764 std::vector<int> arr2;
765 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
766 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
768 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
769 throw INTERP_KERNEL::Exception(oss.str().c_str());
771 arr.insert(arr.end(),arr2.begin(),arr2.end());
776 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
779 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp)
783 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
784 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
786 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
787 oss << " whereas nb of components expected is " << nbOfComp << " !";
788 throw INTERP_KERNEL::Exception(oss.str().c_str());
795 if((nbOfTuples!=size1 || nbOfComp!=size2))
797 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
799 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
800 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
801 throw INTERP_KERNEL::Exception(oss.str().c_str());
807 if(nbOfTuples==size1)
811 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
812 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
813 throw INTERP_KERNEL::Exception(oss.str().c_str());
819 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
821 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
822 if(PyInt_Check(pyLi))
824 long val=PyInt_AS_LONG(pyLi);
829 throw INTERP_KERNEL::Exception(MSG);
832 else if(PyList_Check(pyLi))
834 int size=PyList_Size(pyLi);
836 for(int i=0;i<size;i++)
838 PyObject *o=PyList_GetItem(pyLi,i);
840 fillArrayWithPyListInt3(o,tmp1,ret);
848 throw INTERP_KERNEL::Exception(MSG);
851 else if(PyTuple_Check(pyLi))
853 int size=PyTuple_Size(pyLi);
855 for(int i=0;i<size;i++)
857 PyObject *o=PyTuple_GetItem(pyLi,i);
859 fillArrayWithPyListInt3(o,tmp1,ret);
867 throw INTERP_KERNEL::Exception(MSG);
871 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
874 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp)
876 std::vector<int> ret;
877 int size1=-1,size2=-1;
878 if(PyList_Check(pyLi))
880 size1=PyList_Size(pyLi);
881 for(int i=0;i<size1;i++)
883 PyObject *o=PyList_GetItem(pyLi,i);
884 fillArrayWithPyListInt3(o,size2,ret);
889 else if(PyTuple_Check(pyLi))
891 size1=PyTuple_Size(pyLi);
892 for(int i=0;i<size1;i++)
894 PyObject *o=PyTuple_GetItem(pyLi,i);
895 fillArrayWithPyListInt3(o,size2,ret);
901 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
903 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
907 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec)
909 if(PyList_Check(pyLi))
911 Py_ssize_t sz=PyList_Size(pyLi);
913 for(int i=0;i<sz;i++)
915 PyObject *o=PyList_GetItem(pyLi,i);
916 if(!convertPyObjectToStrNT(o,vec[i]))
921 else if(PyTuple_Check(pyLi))
923 Py_ssize_t sz=PyTuple_Size(pyLi);
925 for(int i=0;i<sz;i++)
927 PyObject *o=PyTuple_GetItem(pyLi,i);
928 if(!convertPyObjectToStrNT(o,vec[i]))
936 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr)
938 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
939 if(PyList_Check(pyLi))
941 Py_ssize_t sz=PyList_Size(pyLi);
943 for(int i=0;i<sz;i++)
945 PyObject *o=PyList_GetItem(pyLi,i);
946 if(!fillStringVector(o,arr[i]))
947 throw INTERP_KERNEL::Exception(msg);
950 else if(PyTuple_Check(pyLi))
952 Py_ssize_t sz=PyTuple_Size(pyLi);
954 for(int i=0;i<sz;i++)
956 PyObject *o=PyTuple_GetItem(pyLi,i);
957 if(!fillStringVector(o,arr[i]))
958 throw INTERP_KERNEL::Exception(msg);
962 throw INTERP_KERNEL::Exception(msg);
965 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec)
967 if(PyList_Check(pyLi))
969 Py_ssize_t sz=PyList_Size(pyLi);
971 for(int i=0;i<sz;i++)
973 PyObject *o=PyList_GetItem(pyLi,i);
975 vec[i]=PyInt_AS_LONG(o);
981 else if(PyTuple_Check(pyLi))
983 Py_ssize_t sz=PyTuple_Size(pyLi);
985 for(int i=0;i<sz;i++)
987 PyObject *o=PyTuple_GetItem(pyLi,i);
989 vec[i]=PyInt_AS_LONG(o);
999 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr)
1001 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1002 if(PyList_Check(pyLi))
1004 Py_ssize_t sz=PyList_Size(pyLi);
1006 for(int i=0;i<sz;i++)
1008 PyObject *o=PyList_GetItem(pyLi,i);
1009 if(!fillIntVector(o,arr[i]))
1010 throw INTERP_KERNEL::Exception(msg);
1013 else if(PyTuple_Check(pyLi))
1015 Py_ssize_t sz=PyTuple_Size(pyLi);
1017 for(int i=0;i<sz;i++)
1019 PyObject *o=PyTuple_GetItem(pyLi,i);
1020 if(!fillIntVector(o,arr[i]))
1021 throw INTERP_KERNEL::Exception(msg);
1025 throw INTERP_KERNEL::Exception(msg);
1028 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr)
1030 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1031 if(PyList_Check(pyLi))
1033 Py_ssize_t sz=PyList_Size(pyLi);
1035 for(int i=0;i<sz;i++)
1037 PyObject *o=PyList_GetItem(pyLi,i);
1038 if(PyTuple_Check(o))
1040 int sz2=PyTuple_Size(o);
1042 throw INTERP_KERNEL::Exception(msg);
1043 std::pair<std::string, std::vector<std::string> > item;
1044 PyObject *o_0=PyTuple_GetItem(o,0);
1045 item.first=convertPyObjectToStr(o_0,msg);
1046 PyObject *o_1=PyTuple_GetItem(o,1);
1047 if(!fillStringVector(o_1,item.second))
1048 throw INTERP_KERNEL::Exception(msg);
1052 throw INTERP_KERNEL::Exception(msg);
1055 else if(PyTuple_Check(pyLi))
1057 Py_ssize_t sz=PyTuple_Size(pyLi);
1059 for(int i=0;i<sz;i++)
1061 PyObject *o=PyTuple_GetItem(pyLi,i);
1062 if(PyTuple_Check(o))
1064 int sz2=PyTuple_Size(o);
1066 throw INTERP_KERNEL::Exception(msg);
1067 std::pair<std::string, std::vector<std::string> > item;
1068 PyObject *o_0=PyTuple_GetItem(o,0);
1069 item.first=convertPyObjectToStr(o_0,msg);
1070 PyObject *o_1=PyTuple_GetItem(o,1);
1071 if(!fillStringVector(o_1,item.second))
1072 throw INTERP_KERNEL::Exception(msg);
1076 throw INTERP_KERNEL::Exception(msg);
1080 throw INTERP_KERNEL::Exception(msg);
1084 PyObject *convertDblArrToPyList(const T *ptr, int size)
1086 PyObject *ret(PyList_New(size));
1087 for(int i=0;i<size;i++)
1088 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1092 static PyObject *convertDblArrToPyList2(const std::vector<double>& v)
1095 PyObject *ret(PyList_New(size));
1096 for(int i=0;i<size;i++)
1097 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1102 PyObject *convertDblArrToPyListOfTuple(const T *vals, int nbOfComp, int nbOfTuples)
1104 PyObject *ret(PyList_New(nbOfTuples));
1105 for(int i=0;i<nbOfTuples;i++)
1107 PyObject *t=PyTuple_New(nbOfComp);
1108 for(int j=0;j<nbOfComp;j++)
1109 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1110 PyList_SetItem(ret,i,t);
1115 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples)
1117 PyObject *ret=PyList_New(nbOfTuples);
1118 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1119 for(int i=0;i<nbOfTuples;i++)
1121 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1122 PyList_SetItem(ret,i,PyString_FromString(tmp));
1127 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size)
1129 if(PyList_Check(pyLi))
1131 *size=PyList_Size(pyLi);
1132 double *tmp=(double *)malloc((*size)*sizeof(double));
1133 for(int i=0;i<*size;i++)
1135 PyObject *o=PyList_GetItem(pyLi,i);
1136 if(PyFloat_Check(o))
1138 double val=PyFloat_AS_DOUBLE(o);
1141 else if(PyInt_Check(o))
1143 long val0=PyInt_AS_LONG(o);
1150 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1155 else if(PyTuple_Check(pyLi))
1157 *size=PyTuple_Size(pyLi);
1158 double *tmp=(double *)malloc((*size)*sizeof(double));
1159 for(int i=0;i<*size;i++)
1161 PyObject *o=PyTuple_GetItem(pyLi,i);
1162 if(PyFloat_Check(o))
1164 double val=PyFloat_AS_DOUBLE(o);
1167 else if(PyInt_Check(o))
1169 long val0=PyInt_AS_LONG(o);
1176 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1182 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1185 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1187 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1188 if(PyFloat_Check(pyLi))
1194 throw INTERP_KERNEL::Exception(MSG);
1195 double val=PyFloat_AS_DOUBLE(pyLi);
1198 else if(PyInt_Check(pyLi))
1200 long val0=PyInt_AS_LONG(pyLi);
1206 throw INTERP_KERNEL::Exception(MSG);
1209 else if(PyList_Check(pyLi))
1211 int size=PyList_Size(pyLi);
1213 for(int i=0;i<size;i++)
1215 PyObject *o=PyList_GetItem(pyLi,i);
1217 fillArrayWithPyListDbl3(o,tmp1,ret);
1225 throw INTERP_KERNEL::Exception(MSG);
1228 else if(PyTuple_Check(pyLi))
1230 int size=PyTuple_Size(pyLi);
1232 for(int i=0;i<size;i++)
1234 PyObject *o=PyTuple_GetItem(pyLi,i);
1236 fillArrayWithPyListDbl3(o,tmp1,ret);
1244 throw INTERP_KERNEL::Exception(MSG);
1248 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1251 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp)
1253 std::vector<double> ret;
1254 int size1=-1,size2=-1;
1255 if(PyList_Check(pyLi))
1257 size1=PyList_Size(pyLi);
1258 for(int i=0;i<size1;i++)
1260 PyObject *o=PyList_GetItem(pyLi,i);
1261 fillArrayWithPyListDbl3(o,size2,ret);
1266 else if(PyTuple_Check(pyLi))
1268 size1=PyTuple_Size(pyLi);
1269 for(int i=0;i<size1;i++)
1271 PyObject *o=PyTuple_GetItem(pyLi,i);
1272 fillArrayWithPyListDbl3(o,size2,ret);
1278 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1280 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1284 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1286 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1289 if(PyList_Check(pyLi))
1291 int size=PyList_Size(pyLi);
1293 for(int i=0;i<size;i++)
1295 PyObject *obj=PyList_GetItem(pyLi,i);
1296 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1297 if(!SWIG_IsOK(status))
1299 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1300 throw INTERP_KERNEL::Exception(oss.str().c_str());
1302 T arg=reinterpret_cast< T >(argp);
1306 else if(PyTuple_Check(pyLi))
1308 int size=PyTuple_Size(pyLi);
1310 for(int i=0;i<size;i++)
1312 PyObject *obj=PyTuple_GetItem(pyLi,i);
1313 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1314 if(!SWIG_IsOK(status))
1316 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1317 throw INTERP_KERNEL::Exception(oss.str().c_str());
1319 T arg=reinterpret_cast< T >(argp);
1323 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1326 T arg=reinterpret_cast< T >(argp);
1330 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1334 * if python int -> cpp int sw=1
1335 * if python list[int] -> cpp vector<int> sw=2
1336 * if python tuple[int] -> cpp vector<int> sw=2
1337 * if python DataArrayInt -> cpp DataArrayInt sw=3
1338 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1340 * switch between (int,vector<int>,DataArrayInt)
1342 static void convertIntStarLikePyObjToCpp(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple)
1345 if(PyInt_Check(value))
1347 iTyypp=(int)PyInt_AS_LONG(value);
1351 if(PyTuple_Check(value))
1353 int size=PyTuple_Size(value);
1354 stdvecTyypp.resize(size);
1355 for(int i=0;i<size;i++)
1357 PyObject *o=PyTuple_GetItem(value,i);
1359 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1362 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1363 throw INTERP_KERNEL::Exception(oss.str().c_str());
1369 if(PyList_Check(value))
1371 int size=PyList_Size(value);
1372 stdvecTyypp.resize(size);
1373 for(int i=0;i<size;i++)
1375 PyObject *o=PyList_GetItem(value,i);
1377 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1380 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1381 throw INTERP_KERNEL::Exception(oss.str().c_str());
1388 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1389 if(SWIG_IsOK(status))
1391 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1395 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1396 if(SWIG_IsOK(status))
1398 daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1402 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1406 * if python int -> cpp int sw=1
1407 * if python list[int] -> cpp vector<int> sw=2
1408 * if python tuple[int] -> cpp vector<int> sw=2
1409 * if python DataArrayInt -> cpp DataArrayInt sw=3
1410 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1412 * switch between (int,vector<int>,DataArrayInt)
1414 static const int *convertIntStarLikePyObjToCppIntStar(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp)
1417 if(PyInt_Check(value))
1419 iTyypp=(int)PyInt_AS_LONG(value);
1423 if(PyTuple_Check(value))
1425 int size=PyTuple_Size(value);
1426 stdvecTyypp.resize(size);
1427 for(int i=0;i<size;i++)
1429 PyObject *o=PyTuple_GetItem(value,i);
1431 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1434 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1435 throw INTERP_KERNEL::Exception(oss.str().c_str());
1439 return &stdvecTyypp[0];
1441 if(PyList_Check(value))
1443 int size=PyList_Size(value);
1444 stdvecTyypp.resize(size);
1445 for(int i=0;i<size;i++)
1447 PyObject *o=PyList_GetItem(value,i);
1449 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1452 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1453 throw INTERP_KERNEL::Exception(oss.str().c_str());
1457 return &stdvecTyypp[0];
1460 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1461 if(SWIG_IsOK(status))
1463 MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1466 sw=3; sz=daIntTyypp->getNbOfElems();
1467 return daIntTyypp->begin();
1475 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1476 if(SWIG_IsOK(status))
1478 MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1479 sw=4; sz=daIntTuple->getNumberOfCompo();
1480 return daIntTuple->getConstPointer();
1482 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1486 * if python double -> cpp double sw=1
1487 * if python int -> cpp double sw=1
1488 * if python list[double] -> cpp vector<double> sw=2
1489 * if python list[int] -> cpp vector<double> sw=2
1490 * if python tuple[double] -> cpp vector<double> sw=2
1491 * if python tuple[int] -> cpp vector<double> sw=2
1492 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1494 * switch between (int,vector<int>,DataArrayInt)
1497 void considerPyObjAsATStarLikeObject(PyObject *value, int& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti)
1500 if(PyFloat_Check(value))
1502 iTyypp=(T)PyFloat_AS_DOUBLE(value);
1506 if(PyInt_Check(value))
1508 iTyypp=(T)PyInt_AS_LONG(value);
1512 if(PyTuple_Check(value))
1514 int size=PyTuple_Size(value);
1515 stdvecTyypp.resize(size);
1516 for(int i=0;i<size;i++)
1518 PyObject *o=PyTuple_GetItem(value,i);
1519 if(PyFloat_Check(o))
1520 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1521 else if(PyInt_Check(o))
1522 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1525 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1526 throw INTERP_KERNEL::Exception(oss.str().c_str());
1532 if(PyList_Check(value))
1534 int size=PyList_Size(value);
1535 stdvecTyypp.resize(size);
1536 for(int i=0;i<size;i++)
1538 PyObject *o=PyList_GetItem(value,i);
1539 if(PyFloat_Check(o))
1540 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1541 else if(PyInt_Check(o))
1542 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1545 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1546 throw INTERP_KERNEL::Exception(oss.str().c_str());
1553 int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1554 if(!SWIG_IsOK(status))
1555 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1556 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1561 * if python double -> cpp double sw=1
1562 * if python int -> cpp double sw=1
1563 * if python list[double] -> cpp vector<double> sw=2
1564 * if python list[int] -> cpp vector<double> sw=2
1565 * if python tuple[double] -> cpp vector<double> sw=2
1566 * if python tuple[int] -> cpp vector<double> sw=2
1567 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1569 * switch between (int,vector<int>,DataArrayInt)
1571 static void convertDoubleStarLikePyObjToCpp(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp)
1574 if(PyFloat_Check(value))
1576 iTyypp=PyFloat_AS_DOUBLE(value);
1580 if(PyInt_Check(value))
1582 iTyypp=(double)PyInt_AS_LONG(value);
1586 if(PyTuple_Check(value))
1588 int size=PyTuple_Size(value);
1589 stdvecTyypp.resize(size);
1590 for(int i=0;i<size;i++)
1592 PyObject *o=PyTuple_GetItem(value,i);
1593 if(PyFloat_Check(o))
1594 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1595 else if(PyInt_Check(o))
1596 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1599 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1600 throw INTERP_KERNEL::Exception(oss.str().c_str());
1606 if(PyList_Check(value))
1608 int size=PyList_Size(value);
1609 stdvecTyypp.resize(size);
1610 for(int i=0;i<size;i++)
1612 PyObject *o=PyList_GetItem(value,i);
1613 if(PyFloat_Check(o))
1614 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1615 else if(PyInt_Check(o))
1616 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1619 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1620 throw INTERP_KERNEL::Exception(oss.str().c_str());
1627 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1628 if(!SWIG_IsOK(status))
1629 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1630 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1635 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)
1638 if(PyFloat_Check(value))
1640 val=PyFloat_AS_DOUBLE(value);
1644 if(PyInt_Check(value))
1646 val=(T)PyInt_AS_LONG(value);
1650 if(PyTuple_Check(value))
1652 int size=PyTuple_Size(value);
1654 for(int i=0;i<size;i++)
1656 PyObject *o=PyTuple_GetItem(value,i);
1657 if(PyFloat_Check(o))
1658 f[i]=PyFloat_AS_DOUBLE(o);
1659 else if(PyInt_Check(o))
1660 f[i]=(T)PyInt_AS_LONG(o);
1663 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1664 throw INTERP_KERNEL::Exception(oss.str().c_str());
1670 if(PyList_Check(value))
1672 int size=PyList_Size(value);
1674 for(int i=0;i<size;i++)
1676 PyObject *o=PyList_GetItem(value,i);
1677 if(PyFloat_Check(o))
1678 f[i]=PyFloat_AS_DOUBLE(o);
1679 else if(PyInt_Check(o))
1680 f[i]=(T)PyInt_AS_LONG(o);
1683 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1684 throw INTERP_KERNEL::Exception(oss.str().c_str());
1691 int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1692 if(SWIG_IsOK(status))
1694 d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1698 status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1699 if(SWIG_IsOK(status))
1701 e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1705 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1709 * if value int -> cpp val sw=1
1710 * if value double -> cpp val sw=1
1711 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1712 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1713 * if value list[int,double] -> cpp std::vector<double> sw=4
1714 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1716 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1718 convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1722 * if python int -> cpp int sw=1
1723 * if python list[int] -> cpp vector<int> sw=2
1724 * if python tuple[int] -> cpp vector<int> sw=2
1725 * if python slicp -> cpp pair sw=3 (begin,end,step)
1726 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1728 * switch between (int,vector<int>,DataArrayInt)
1730 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)
1732 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1734 if(PyInt_Check(value))
1736 iTyypp=(int)PyInt_AS_LONG(value);
1740 if(PyTuple_Check(value))
1742 int size=PyTuple_Size(value);
1743 stdvecTyypp.resize(size);
1744 for(int i=0;i<size;i++)
1746 PyObject *o=PyTuple_GetItem(value,i);
1748 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1751 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1752 throw INTERP_KERNEL::Exception(oss.str().c_str());
1758 if(PyList_Check(value))
1760 int size=PyList_Size(value);
1761 stdvecTyypp.resize(size);
1762 for(int i=0;i<size;i++)
1764 PyObject *o=PyList_GetItem(value,i);
1766 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1769 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1770 throw INTERP_KERNEL::Exception(oss.str().c_str());
1776 if(PySlice_Check(value))
1778 Py_ssize_t strt=2,stp=2,step=2;
1779 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1782 p.second.second=step;
1787 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1788 if(SWIG_IsOK(status))
1790 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1793 std::ostringstream oss; oss << msg << " Instance in null !";
1794 throw INTERP_KERNEL::Exception(oss.str().c_str());
1799 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1800 if(SWIG_IsOK(status))
1802 MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1805 std::ostringstream oss; oss << msg << " Instance in null !";
1806 throw INTERP_KERNEL::Exception(oss.str().c_str());
1808 stdvecTyypp.resize(tmp->getNumberOfCompo());
1809 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1813 throw INTERP_KERNEL::Exception(msg);
1817 * Idem than convertIntStarOrSliceLikePyObjToCpp
1819 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)
1821 convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1824 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1829 * if python int -> cpp int sw=1
1830 * if python tuple[int] -> cpp vector<int> sw=2
1831 * if python list[int] -> cpp vector<int> sw=2
1832 * if python slice -> cpp pair sw=3
1833 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1835 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)
1838 if(PyInt_Check(value))
1840 iTyypp=(int)PyInt_AS_LONG(value);
1844 if(PyTuple_Check(value))
1846 int size=PyTuple_Size(value);
1847 stdvecTyypp.resize(size);
1848 for(int i=0;i<size;i++)
1850 PyObject *o=PyTuple_GetItem(value,i);
1852 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1855 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1856 throw INTERP_KERNEL::Exception(oss.str().c_str());
1862 if(PyList_Check(value))
1864 int size=PyList_Size(value);
1865 stdvecTyypp.resize(size);
1866 for(int i=0;i<size;i++)
1868 PyObject *o=PyList_GetItem(value,i);
1870 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1873 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1874 throw INTERP_KERNEL::Exception(oss.str().c_str());
1880 if(PySlice_Check(value))
1882 Py_ssize_t strt=2,stp=2,step=2;
1883 GetIndicesOfSlice(value,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1886 p.second.second=step;
1891 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1892 if(!SWIG_IsOK(status))
1893 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1894 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1899 * if python string with size one -> cpp char sw=1
1900 * if python string with size different from one -> cpp string sw=2
1901 * if python tuple[string] or list[string] -> vector<string> sw=3
1902 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1903 * switch between (int,string,vector<string>,DataArrayChar)
1905 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType)
1907 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1909 if(PyString_Check(value))
1911 const char *pt=PyString_AsString(value);
1912 Py_ssize_t sz=PyString_Size(value);
1926 #if PY_VERSION_HEX >= 0x03000000
1927 if(PyUnicode_Check(value))
1930 const char *pt = PyUnicode_AsUTF8AndSize(value, &sz);
1945 if(PyTuple_Check(value))
1947 int size=PyTuple_Size(value);
1948 vsType.resize(size);
1949 for(int i=0;i<size;i++)
1951 PyObject *o=PyTuple_GetItem(value,i);
1954 vsType[i]=convertPyObjectToStr(o);
1956 catch(INTERP_KERNEL::Exception& e)
1958 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1959 throw INTERP_KERNEL::Exception(oss.str().c_str());
1965 if(PyList_Check(value))
1967 int size=PyList_Size(value);
1968 vsType.resize(size);
1969 for(int i=0;i<size;i++)
1971 PyObject *o=PyList_GetItem(value,i);
1974 vsType[i]=convertPyObjectToStr(o);
1976 catch(INTERP_KERNEL::Exception& e)
1978 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1979 throw INTERP_KERNEL::Exception(oss.str().c_str());
1986 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
1987 if(SWIG_IsOK(status))
1989 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
1992 std::ostringstream oss; oss << msg << " Instance in null !";
1993 throw INTERP_KERNEL::Exception(oss.str().c_str());
1998 throw INTERP_KERNEL::Exception(msg);
2002 * if value int -> cpp it sw=1
2003 * if value list[int] -> vt sw=2
2004 * if value tuple[int] -> vt sw=2
2005 * if value slice -> pt sw=3
2006 * if value DataArrayInt -> dt sw=4
2007 * if value tuple [int,int] -> cpp it,ip sw=5
2008 * if value tuple [list[int],int] -> cpp vt,ip sw=6
2009 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
2010 * if value tuple [slice,int] -> cpp pt,ip sw=7
2011 * if value tuple [DaI,int] -> cpp dt,ip sw=8
2012 * if value tuple [int,list[int]] -> cpp it,vc sw=9
2013 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
2014 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
2015 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
2016 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
2017 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
2018 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
2019 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
2020 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
2021 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
2022 * if value tuple [int,slice] -> cpp it,pc sw=13
2023 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
2024 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
2025 * if value tuple [slice,slice] -> cpp pt,pc sw=15
2026 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
2028 * switch between (int,vector<int>,DataArrayInt)
2030 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
2031 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
2032 MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc)
2034 if(!PyTuple_Check(value))
2036 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
2041 int sz=PyTuple_Size(value);
2043 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
2044 PyObject *ob0=PyTuple_GetItem(value,0);
2046 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
2047 PyObject *ob1=PyTuple_GetItem(value,1);
2048 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
2054 * if value int -> cpp val sw=1
2055 * if value double -> cpp val sw=1
2056 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2057 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2058 * if value list[int,double] -> cpp std::vector<double> sw=4
2059 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2061 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2062 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt)
2065 if(PyFloat_Check(value))
2067 val=PyFloat_AS_DOUBLE(value);
2069 if(nbTuplesExpected*nbCompExpected!=1)
2071 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2072 throw INTERP_KERNEL::Exception(oss.str().c_str());
2076 if(PyInt_Check(value))
2078 val=(double)PyInt_AS_LONG(value);
2080 if(nbTuplesExpected*nbCompExpected!=1)
2082 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2083 throw INTERP_KERNEL::Exception(oss.str().c_str());
2087 if(PyTuple_Check(value) || PyList_Check(value))
2091 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2092 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2097 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2100 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2101 if(SWIG_IsOK(status))
2103 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2107 if(d->getNumberOfTuples()==nbTuplesExpected)
2109 if(d->getNumberOfComponents()==nbCompExpected)
2111 return d->getConstPointer();
2115 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2116 throw INTERP_KERNEL::Exception(oss.str().c_str());
2121 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2122 throw INTERP_KERNEL::Exception(oss.str().c_str());
2129 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2130 throw INTERP_KERNEL::Exception(oss.str().c_str());
2136 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2137 if(SWIG_IsOK(status))
2139 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2141 if(e->getNumberOfCompo()==nbCompExpected)
2143 if(nbTuplesExpected==1)
2144 return e->getConstPointer();
2147 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2148 throw INTERP_KERNEL::Exception(oss.str().c_str());
2153 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2154 throw INTERP_KERNEL::Exception(oss.str().c_str());
2157 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2161 * if value int -> cpp val sw=1
2162 * if value double -> cpp val sw=1
2163 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2164 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2165 * if value list[int,double] -> cpp std::vector<double> sw=4
2166 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2168 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2169 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples)
2172 if(PyFloat_Check(value))
2174 val=PyFloat_AS_DOUBLE(value);
2176 if(nbCompExpected!=1)
2178 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2179 throw INTERP_KERNEL::Exception(oss.str().c_str());
2184 if(PyInt_Check(value))
2186 val=(double)PyInt_AS_LONG(value);
2188 if(nbCompExpected!=1)
2190 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2191 throw INTERP_KERNEL::Exception(oss.str().c_str());
2196 if(PyTuple_Check(value))
2198 int size=PyTuple_Size(value);
2200 for(int i=0;i<size;i++)
2202 PyObject *o=PyTuple_GetItem(value,i);
2203 if(PyFloat_Check(o))
2204 f[i]=PyFloat_AS_DOUBLE(o);
2205 else if(PyInt_Check(o))
2206 f[i]=(double)PyInt_AS_LONG(o);
2209 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2210 throw INTERP_KERNEL::Exception(oss.str().c_str());
2214 if(size%nbCompExpected!=0)
2216 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2217 throw INTERP_KERNEL::Exception(oss.str().c_str());
2219 nbTuples=size/nbCompExpected;
2222 if(PyList_Check(value))
2224 int size=PyList_Size(value);
2226 for(int i=0;i<size;i++)
2228 PyObject *o=PyList_GetItem(value,i);
2229 if(PyFloat_Check(o))
2230 f[i]=PyFloat_AS_DOUBLE(o);
2231 else if(PyInt_Check(o))
2232 f[i]=(double)PyInt_AS_LONG(o);
2235 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2236 throw INTERP_KERNEL::Exception(oss.str().c_str());
2240 if(size%nbCompExpected!=0)
2242 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2243 throw INTERP_KERNEL::Exception(oss.str().c_str());
2245 nbTuples=size/nbCompExpected;
2249 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2250 if(SWIG_IsOK(status))
2252 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2256 if(d->getNumberOfComponents()==nbCompExpected)
2258 nbTuples=d->getNumberOfTuples();
2259 return d->getConstPointer();
2263 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2264 throw INTERP_KERNEL::Exception(oss.str().c_str());
2271 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2272 throw INTERP_KERNEL::Exception(oss.str().c_str());
2275 { nbTuples=0; return 0; }
2278 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2279 if(SWIG_IsOK(status))
2281 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2285 if(e->getNumberOfCompo()==nbCompExpected)
2288 return e->getConstPointer();
2292 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2293 throw INTERP_KERNEL::Exception(oss.str().c_str());
2300 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2301 throw INTERP_KERNEL::Exception(oss.str().c_str());
2304 { nbTuples=0; return 0; }
2307 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2311 * if value int -> cpp val sw=1
2312 * if value double -> cpp val sw=1
2313 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2314 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2315 * if value list[int,double] -> cpp std::vector<double> sw=4
2316 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2318 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2319 const char *msg, bool throwIfNullPt, int& nbTuples)
2321 MEDCoupling::DataArrayDouble *d=0;
2322 MEDCoupling::DataArrayDoubleTuple *e=0;
2324 if(PyFloat_Check(value))
2326 val=PyFloat_AS_DOUBLE(value);
2331 if(PyInt_Check(value))
2333 val=(double)PyInt_AS_LONG(value);
2338 if(PyTuple_Check(value))
2340 int size=PyTuple_Size(value);
2342 for(int i=0;i<size;i++)
2344 PyObject *o=PyTuple_GetItem(value,i);
2345 if(PyFloat_Check(o))
2346 f[i]=PyFloat_AS_DOUBLE(o);
2347 else if(PyInt_Check(o))
2348 f[i]=(double)PyInt_AS_LONG(o);
2351 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2352 throw INTERP_KERNEL::Exception(oss.str().c_str());
2359 if(PyList_Check(value))
2361 int size=PyList_Size(value);
2363 for(int i=0;i<size;i++)
2365 PyObject *o=PyList_GetItem(value,i);
2366 if(PyFloat_Check(o))
2367 f[i]=PyFloat_AS_DOUBLE(o);
2368 else if(PyInt_Check(o))
2369 f[i]=(double)PyInt_AS_LONG(o);
2372 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2373 throw INTERP_KERNEL::Exception(oss.str().c_str());
2381 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2382 if(SWIG_IsOK(status))
2384 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2388 if(d->getNumberOfComponents()==1)
2390 nbTuples=d->getNumberOfTuples();
2391 return d->getConstPointer();
2395 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2396 throw INTERP_KERNEL::Exception(oss.str().c_str());
2403 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2404 throw INTERP_KERNEL::Exception(oss.str().c_str());
2407 { nbTuples=0; return 0; }
2410 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2411 if(SWIG_IsOK(status))
2413 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2417 nbTuples=e->getNumberOfCompo();
2418 return e->getConstPointer();
2424 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2425 throw INTERP_KERNEL::Exception(oss.str().c_str());
2428 { nbTuples=0; return 0; }
2431 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2434 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2437 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2438 if(!SWIG_IsOK(status))
2440 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2441 if(!SWIG_IsOK(status))
2443 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2444 if(!SWIG_IsOK(status))
2446 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2447 if(!SWIG_IsOK(status))
2449 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2450 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2451 throw INTERP_KERNEL::Exception(oss.str().c_str());
2456 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2459 static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
2461 if(!PyTuple_Check(args))
2463 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2464 throw INTERP_KERNEL::Exception(oss.str().c_str());
2466 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2467 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2468 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2470 PyObject *tmp0(PyTuple_New(1));
2471 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2472 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2474 Py_DECREF(selfMeth);
2475 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==0 )
2476 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2477 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2478 PyObject *tmp3(PyTuple_New(0));
2479 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2482 Py_DECREF(initMeth);
2488 static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral(PyObject *cls, PyObject *args, const char *clsName)
2490 if(!PyTuple_Check(args))
2492 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2493 throw INTERP_KERNEL::Exception(oss.str().c_str());
2495 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2496 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2497 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2499 PyObject *tmp0(PyTuple_New(1));
2500 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2501 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2503 Py_DECREF(selfMeth);
2504 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 )
2505 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2506 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2507 PyObject *zeNumpyRepr(0);
2509 PyObject *tmp1(PyInt_FromLong(0));
2510 zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed
2515 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2516 throw INTERP_KERNEL::Exception(oss.str().c_str());
2523 tmp3=tt(zeNumpyRepr);
2525 catch(INTERP_KERNEL::Exception& e)
2527 std::ostringstream oss; oss << clsName << ".__new__ : Invalid type in input " << " : " << e.what();
2528 throw INTERP_KERNEL::Exception(oss.str());
2531 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2536 Py_DECREF(initMeth);
2541 struct SinglePyObjToBePutInATuple
2543 PyObject *operator()(PyObject *zeNumpyRepr)
2545 PyObject *tmp3(PyTuple_New(1));
2546 PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
2551 struct SinglePyObjExpectToBeAListOfSz2
2553 PyObject *operator()(PyObject *uniqueElt)
2555 if(!PyTuple_Check(uniqueElt) || PyTuple_Size(uniqueElt)!=2)
2556 throw INTERP_KERNEL::Exception("Not a tuple of size 2 !");
2557 Py_XINCREF(uniqueElt);
2562 static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(PyObject *cls, PyObject *args, const char *clsName)
2564 return NewMethWrapCallInitOnlyIfDictWithSingleEltInInputGeneral<SinglePyObjToBePutInATuple>(cls,args,clsName);
2567 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner)
2572 Py_XINCREF(Py_None);
2575 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2576 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2578 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2583 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2585 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)";
2586 std::string msg(msgBase);
2588 msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2591 if(PyList_Check(elt0) || PyTuple_Check(elt0))
2595 if(PyInt_Check(nbOfTuples))
2597 int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
2599 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2602 if(PyInt_Check(elt2))
2603 {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2604 int nbOfCompo=PyInt_AS_LONG(elt2);
2606 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2607 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2608 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2609 ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2613 throw INTERP_KERNEL::Exception(msg.c_str());
2616 {//DataArrayDouble.New([1.,3.,4.],3)
2617 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2619 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2620 ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2625 throw INTERP_KERNEL::Exception(msg.c_str());
2628 {// DataArrayDouble.New([1.,3.,4.])
2629 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2630 int tmpp1(-1),tmpp2(-1);
2631 std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2632 ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2636 else if(PyInt_Check(elt0))
2638 int nbOfTuples1(PyInt_AS_LONG(elt0));
2640 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2645 if(PyInt_Check(nbOfTuples))
2646 {//DataArrayDouble.New(5,2)
2647 int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
2649 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2650 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2651 ret->alloc(nbOfTuples1,nbOfCompo);
2655 throw INTERP_KERNEL::Exception(msg.c_str());
2658 throw INTERP_KERNEL::Exception(msg.c_str());
2661 {//DataArrayDouble.New(5)
2662 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2663 ret->alloc(nbOfTuples1,1);
2668 else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2669 {//DataArrayDouble.New(numpyArray)
2670 return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2674 throw INTERP_KERNEL::Exception(msg.c_str());
2675 throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2679 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2681 self->checkAllocated();
2682 const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2683 int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
2687 typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2688 considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2690 std::vector<int> vt1,vc1;
2691 std::pair<int, std::pair<int,int> > pt1,pc1;
2692 MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
2693 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2694 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2702 self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2705 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2706 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2707 self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2710 self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2713 throw INTERP_KERNEL::Exception(msg);
2722 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2725 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2726 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2727 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2730 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2733 throw INTERP_KERNEL::Exception(msg);
2742 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2745 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2746 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2747 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2750 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2753 throw INTERP_KERNEL::Exception(msg);
2762 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2765 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2766 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2767 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2770 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2773 throw INTERP_KERNEL::Exception(msg);
2782 self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2785 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2786 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2787 self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2790 self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2793 throw INTERP_KERNEL::Exception(msg);
2802 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2805 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2806 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2807 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2810 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2813 throw INTERP_KERNEL::Exception(msg);
2822 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2825 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2826 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2827 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2830 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2833 throw INTERP_KERNEL::Exception(msg);
2842 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2845 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2846 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2847 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2850 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2853 throw INTERP_KERNEL::Exception(msg);
2862 self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2865 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2866 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2867 self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2870 self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2873 throw INTERP_KERNEL::Exception(msg);
2882 self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2885 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2886 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2887 self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2890 self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2893 throw INTERP_KERNEL::Exception(msg);
2902 self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2905 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2906 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2907 self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2910 self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2913 throw INTERP_KERNEL::Exception(msg);
2922 self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2925 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2926 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2927 self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2930 self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2933 throw INTERP_KERNEL::Exception(msg);
2942 self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2945 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2946 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2947 self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2950 self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2953 throw INTERP_KERNEL::Exception(msg);
2962 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2965 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2966 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2967 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2970 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2973 throw INTERP_KERNEL::Exception(msg);
2982 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2985 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2986 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2987 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2990 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2993 throw INTERP_KERNEL::Exception(msg);
3002 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3005 tmp=MEDCoupling::Traits<T>::ArrayType::New();
3006 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
3007 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
3010 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
3013 throw INTERP_KERNEL::Exception(msg);
3018 throw INTERP_KERNEL::Exception(msg);
3024 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
3026 const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
3027 const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
3028 self->checkAllocated();
3029 int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
3031 std::vector<int> vt1,vc1;
3032 std::pair<int, std::pair<int,int> > pt1,pc1;
3033 MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
3035 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
3036 MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
3040 if(nbOfComponents==1)
3041 return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
3042 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
3044 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
3046 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
3048 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
3050 return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
3053 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
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->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
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(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3066 std::vector<int> v2(1,ic1);
3067 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3071 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3072 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3076 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
3077 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3081 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3082 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3086 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3087 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
3091 ret=self->selectByTupleIdSafe(&it1,&it1+1);
3092 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3093 std::vector<int> 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(&vt1[0],&vt1[0]+vt1.size());
3101 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3102 std::vector<int> 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 );
3109 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
3110 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3111 std::vector<int> v2(nbOfComp);
3112 for(int i=0;i<nbOfComp;i++)
3113 v2[i]=pc1.first+i*pc1.second.second;
3114 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3118 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
3119 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
3120 std::vector<int> v2(nbOfComp);
3121 for(int i=0;i<nbOfComp;i++)
3122 v2[i]=pc1.first+i*pc1.second.second;
3123 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
3126 throw INTERP_KERNEL::Exception(msg);
3131 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3133 const char msg[]="Unexpected situation in __imul__ !";
3135 typename MEDCoupling::Traits<T>::ArrayType *a;
3136 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3139 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3144 self->applyLin(val,0.);
3145 Py_XINCREF(trueSelf);
3150 self->multiplyEqual(a);
3151 Py_XINCREF(trueSelf);
3156 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3157 self->multiplyEqual(aaa);
3158 Py_XINCREF(trueSelf);
3163 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());
3164 self->multiplyEqual(aaa);
3165 Py_XINCREF(trueSelf);
3169 throw INTERP_KERNEL::Exception(msg);
3174 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3176 const char msg[]="Unexpected situation in __idiv__ !";
3178 typename MEDCoupling::Traits<T>::ArrayType *a;
3179 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3182 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3188 throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3189 self->applyLin(1./val,0.);
3190 Py_XINCREF(trueSelf);
3195 self->divideEqual(a);
3196 Py_XINCREF(trueSelf);
3201 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3202 self->divideEqual(aaa);
3203 Py_XINCREF(trueSelf);
3208 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());
3209 self->divideEqual(aaa);
3210 Py_XINCREF(trueSelf);
3214 throw INTERP_KERNEL::Exception(msg);
3219 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3221 const char msg[]="Unexpected situation in __iadd__ !";
3223 typename MEDCoupling::Traits<T>::ArrayType *a;
3224 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3227 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3232 self->applyLin(1.,val);
3233 Py_XINCREF(trueSelf);
3239 Py_XINCREF(trueSelf);
3244 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3245 self->addEqual(aaa);
3246 Py_XINCREF(trueSelf);
3251 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());
3252 self->addEqual(aaa);
3253 Py_XINCREF(trueSelf);
3257 throw INTERP_KERNEL::Exception(msg);
3262 PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3264 const char msg[]="Unexpected situation in __isub__ !";
3266 typename MEDCoupling::Traits<T>::ArrayType *a;
3267 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3270 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3275 self->applyLin(1.,-val);
3276 Py_XINCREF(trueSelf);
3281 self->substractEqual(a);
3282 Py_XINCREF(trueSelf);
3287 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3288 self->substractEqual(aaa);
3289 Py_XINCREF(trueSelf);
3294 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());
3295 self->substractEqual(aaa);
3296 Py_XINCREF(trueSelf);
3300 throw INTERP_KERNEL::Exception(msg);
3309 struct SWIGTITraits<double>
3310 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3313 struct SWIGTITraits<float>
3314 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3317 struct SWIGTITraits<int>
3318 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3320 swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
3321 swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3322 swig_type_info *SWIGTITraits<int>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3323 swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
3324 swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3325 swig_type_info *SWIGTITraits<int>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3327 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3329 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3332 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3334 return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3338 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3340 return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3344 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3346 return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3350 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3352 return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3356 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3358 return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3362 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3364 return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);