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 #include "InterpKernelAutoPtr.hxx"
25 #include "MEDCouplingDataArrayTraits.hxx"
30 * This method is an extention of PySlice_GetIndices but less
31 * open than PySlice_GetIndicesEx that accepts too many situations.
33 void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
35 int ret(PySlice_GetIndices(slice,length,start,stop,step));
38 if(*step>0 && *start==*stop && length==*start)
40 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
44 * This method allows to retrieve slice info from \a slice.
46 void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
48 int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
51 if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
53 std::ostringstream oss;
54 oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
55 throw INTERP_KERNEL::Exception(oss.str().c_str());
57 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
60 int InterpreteNegativeInt(int val, int nbelem)
64 int newVal(nbelem+val);
67 std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
68 throw INTERP_KERNEL::Exception(oss.str().c_str());
76 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
77 // in input when an another DataArray is already client of this.
78 template<class MCData>
79 void numarrdeal2(void *pt, void *obj)
81 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
82 void **obj1=(void **)obj;
83 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
84 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
86 Py_XDECREF(weakRefOnOwner);
91 template<class MCData, class T>
92 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
94 int ndim=PyArray_NDIM(elt0);
95 if(ndim!=1 && ndim!=2)
96 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
97 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
99 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
100 throw INTERP_KERNEL::Exception(oss.str().c_str());
102 npy_intp sz0=PyArray_DIM(elt0,0);
103 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
105 int itemSize=PyArray_ITEMSIZE(elt0);
106 if(itemSize!=sizeof(T))
108 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
109 throw INTERP_KERNEL::Exception(oss.str().c_str());
111 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
112 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
114 if(itemSize!=PyArray_STRIDE(elt0,1))
115 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 !");
116 const char *data=PyArray_BYTES(elt0);
117 typename MEDCoupling::MCAuto<MCData> ret=MCData::New();
118 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
120 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
121 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
122 int mask=MED_NUMPY_OWNDATA; mask=~mask;
124 PyObject *deepestObj=elt0;
125 PyObject *base=elt0C->base;
126 if(base) deepestObj=base;
127 bool isSpetialCase(false);
130 if(PyArray_Check(base))
132 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
133 eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
136 if(base) deepestObj=base;
145 {// 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.
146 std::size_t nbOfElems(sz0*sz1);
147 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
148 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
149 ret->useArray(dataCpy,true,MEDCoupling::C_DEALLOC,sz0,sz1);
152 typename MEDCoupling::MemArray<T>& mma=ret->accessToMemArray();
155 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
157 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
158 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
159 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
160 mma.setParameterForDeallocator(objs);
161 mma.setSpecificDeallocator(numarrdeal2<MCData>);
162 //"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 !");
166 ret->useArray(reinterpret_cast<const T *>(data),true,MEDCoupling::C_DEALLOC,sz0,sz1);
167 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
168 typename MEDCoupling::MemArray<T>::Deallocator tmp(MEDCoupling::MemArray<T>::CDeallocator);
169 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
170 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
171 mma.setParameterForDeallocator(objs);
172 mma.setSpecificDeallocator(numarrdeal);
175 else if(PyArray_ISBEHAVED_RO(elt0))
176 ret->useArray(reinterpret_cast<const T *>(data),false,MEDCoupling::CPP_DEALLOC,sz0,sz1);
181 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
184 PyErr_SetString(PyExc_ValueError,
185 "Cannot set the NumPy array 'base' "
186 "dependency to NULL after initialization");
190 * Allow the base to be set only once. Once the object which
191 * owns the data is set, it doesn't make sense to change it.
193 if (PyArray_BASE(arr) != NULL) {
195 PyErr_SetString(PyExc_ValueError,
196 "Cannot set the NumPy array 'base' "
197 "dependency more than once");
202 * Don't allow infinite chains of views, always set the base
203 * to the first owner of the data.
204 * That is, either the first object which isn't an array,
205 * or the first object which owns its own data.
208 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
209 PyArrayObject *obj_arr = (PyArrayObject *)obj;
213 /* If this array owns its own data, stop collapsing */
214 if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
218 tmp = PyArray_BASE(obj_arr);
219 /* If there's no base, stop collapsing */
223 /* Stop the collapse new base when the would not be of the same
224 * type (i.e. different subclass).
226 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
236 /* Disallow circular references */
237 if ((PyObject *)arr == obj) {
239 PyErr_SetString(PyExc_ValueError,
240 "Cannot create a circular NumPy array 'base' dependency");
249 template<class MCData, class T>
250 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
252 if(!self->isAllocated())
254 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
255 throw INTERP_KERNEL::Exception(oss.str().c_str());
257 MEDCoupling::MemArray<T>& mem=self->accessToMemArray();
260 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
261 throw INTERP_KERNEL::Exception(oss.str().c_str());
263 int nbDims=nbComp==1?1:2;
265 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
266 const T *bg=self->getConstPointer();
267 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
268 if(mem.isDeallocatorCalled())
270 if(mem.getDeallocator()!=numarrdeal)
271 {// case for the first call of toNumPyArray
272 PyObject *ref(PyWeakref_NewRef(ret,NULL));
273 typename MEDCoupling::MemArray<T>::Deallocator tmp(mem.getDeallocator());
274 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
275 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
276 mem.setParameterForDeallocator(objs);
277 mem.setSpecificDeallocator(numarrdeal);
281 {// case for the second and other call of toNumPyArray
282 void **objs=(void **)mem.getParameterForDeallocator();
283 PyObject *weakRefOnOwner=(PyObject *)objs[0];
284 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
286 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
288 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
291 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
292 Py_XDECREF(weakRefOnOwner);
293 PyObject *ref=PyWeakref_NewRef(ret,NULL);
301 template<class MCData, class T>
302 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
304 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
307 SWIGINTERN PyObject *MEDCoupling_DataArrayInt_toNumPyArray(MEDCoupling::DataArrayInt *self);
308 SWIGINTERN PyObject *MEDCoupling_DataArrayDouble_toNumPyArray(MEDCoupling::DataArrayDouble *self);
310 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
312 int nbRows((int)m.size());
313 MEDCoupling::MCAuto<MEDCoupling::DataArrayInt> indPtr(MEDCoupling::DataArrayInt::New()),indices(MEDCoupling::DataArrayInt::New());
314 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> data(MEDCoupling::DataArrayDouble::New());
315 indPtr->alloc(nbRows+1,1);
316 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
318 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
320 sz2+=(int)(*it0).size();
323 indices->alloc(sz2,1); data->alloc(sz2,1);
324 int *indices_ptr(indices->getPointer());
325 double *data_ptr(data->getPointer());
326 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
327 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
329 *indices_ptr=(*it1).first;
330 *data_ptr=(*it1).second;
332 PyObject *a(MEDCoupling_DataArrayDouble_toNumPyArray(data)),*b(MEDCoupling_DataArrayInt_toNumPyArray(indices)),*c(MEDCoupling_DataArrayInt_toNumPyArray(indPtr));
334 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
335 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
336 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
337 PyObject *tmp1(PyString_FromString("shape"));
338 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
339 PyObject* pdict=PyDict_New();
340 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
341 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
343 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
344 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
346 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
347 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
348 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
352 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
360 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
361 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
362 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
363 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
365 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
369 static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
377 if(dynamic_cast<MEDCoupling::DataArrayDouble *>(dac))
378 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
379 if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
380 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
381 if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
382 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
383 if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
384 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
385 if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
386 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,owner);
388 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
392 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
394 PyObject *ret=PyList_New(size);
395 for(int i=0;i<size;i++)
396 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
400 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
403 PyObject *ret=PyList_New(size);
404 for(int i=0;i<size;i++)
405 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
409 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
412 PyObject *ret=PyList_New(size);
413 std::set<int>::const_iterator it=v.begin();
414 for(int i=0;i<size;i++,it++)
415 PyList_SetItem(ret,i,PyInt_FromLong(*it));
419 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
421 PyObject *ret=PyList_New(nbOfTuples);
422 for(int i=0;i<nbOfTuples;i++)
424 PyObject *t=PyTuple_New(nbOfComp);
425 for(int j=0;j<nbOfComp;j++)
426 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
427 PyList_SetItem(ret,i,t);
432 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
434 if(PyList_Check(pyLi))
436 *size=PyList_Size(pyLi);
437 int *tmp=new int[*size];
438 for(int i=0;i<*size;i++)
440 PyObject *o=PyList_GetItem(pyLi,i);
443 int val=(int)PyInt_AS_LONG(o);
449 throw INTERP_KERNEL::Exception("list must contain integers only");
454 else if(PyTuple_Check(pyLi))
456 *size=PyTuple_Size(pyLi);
457 int *tmp=new int[*size];
458 for(int i=0;i<*size;i++)
460 PyObject *o=PyTuple_GetItem(pyLi,i);
463 int val=(int)PyInt_AS_LONG(o);
469 throw INTERP_KERNEL::Exception("tuple must contain integers only");
476 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
480 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
482 PyObject *ret=PyList_New(arr.size());
483 for(std::size_t i=0;i<arr.size();i++)
485 PyObject *t=PyTuple_New(2);
486 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
487 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
488 PyList_SetItem(ret,i,t);
493 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
495 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
496 if(PyList_Check(pyLi))
498 int size=PyList_Size(pyLi);
500 for(int i=0;i<size;i++)
502 PyObject *o=PyList_GetItem(pyLi,i);
505 int sz2=PyTuple_Size(o);
507 throw INTERP_KERNEL::Exception(msg);
508 PyObject *o_0=PyTuple_GetItem(o,0);
509 if(!PyInt_Check(o_0))
510 throw INTERP_KERNEL::Exception(msg);
511 PyObject *o_1=PyTuple_GetItem(o,1);
512 if(!PyInt_Check(o_1))
513 throw INTERP_KERNEL::Exception(msg);
514 arr[i].first=(int)PyInt_AS_LONG(o_0);
515 arr[i].second=(int)PyInt_AS_LONG(o_1);
518 throw INTERP_KERNEL::Exception(msg);
521 else if(PyTuple_Check(pyLi))
523 int size=PyTuple_Size(pyLi);
525 for(int i=0;i<size;i++)
527 PyObject *o=PyTuple_GetItem(pyLi,i);
530 int sz2=PyTuple_Size(o);
532 throw INTERP_KERNEL::Exception(msg);
533 PyObject *o_0=PyTuple_GetItem(o,0);
534 if(!PyInt_Check(o_0))
535 throw INTERP_KERNEL::Exception(msg);
536 PyObject *o_1=PyTuple_GetItem(o,1);
537 if(!PyInt_Check(o_1))
538 throw INTERP_KERNEL::Exception(msg);
539 arr[i].first=(int)PyInt_AS_LONG(o_0);
540 arr[i].second=(int)PyInt_AS_LONG(o_1);
543 throw INTERP_KERNEL::Exception(msg);
547 throw INTERP_KERNEL::Exception(msg);
550 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
552 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
553 if(PyList_Check(pyLi))
555 int size=PyList_Size(pyLi);
557 for(int i=0;i<size;i++)
559 PyObject *o=PyList_GetItem(pyLi,i);
562 int sz2=PyTuple_Size(o);
564 throw INTERP_KERNEL::Exception(msg);
565 PyObject *o_0=PyTuple_GetItem(o,0);
566 if(!PyString_Check(o_0))
567 throw INTERP_KERNEL::Exception(msg);
568 PyObject *o_1=PyTuple_GetItem(o,1);
569 if(!PyInt_Check(o_1))
570 throw INTERP_KERNEL::Exception(msg);
571 arr[i].first=PyString_AsString(o_0);
572 arr[i].second=(int)PyInt_AS_LONG(o_1);
575 throw INTERP_KERNEL::Exception(msg);
578 else if(PyTuple_Check(pyLi))
580 int size=PyTuple_Size(pyLi);
582 for(int i=0;i<size;i++)
584 PyObject *o=PyTuple_GetItem(pyLi,i);
587 int sz2=PyTuple_Size(o);
589 throw INTERP_KERNEL::Exception(msg);
590 PyObject *o_0=PyTuple_GetItem(o,0);
591 if(!PyString_Check(o_0))
592 throw INTERP_KERNEL::Exception(msg);
593 PyObject *o_1=PyTuple_GetItem(o,1);
594 if(!PyInt_Check(o_1))
595 throw INTERP_KERNEL::Exception(msg);
596 arr[i].first=PyString_AsString(o_0);
597 arr[i].second=(int)PyInt_AS_LONG(o_1);
600 throw INTERP_KERNEL::Exception(msg);
604 throw INTERP_KERNEL::Exception(msg);
607 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
609 if(PyList_Check(pyLi))
611 int size=PyList_Size(pyLi);
613 for(int i=0;i<size;i++)
615 PyObject *o=PyList_GetItem(pyLi,i);
618 int val=(int)PyInt_AS_LONG(o);
622 throw INTERP_KERNEL::Exception("list must contain integers only");
625 else if(PyTuple_Check(pyLi))
627 int size=PyTuple_Size(pyLi);
629 for(int i=0;i<size;i++)
631 PyObject *o=PyTuple_GetItem(pyLi,i);
634 int val=(int)PyInt_AS_LONG(o);
638 throw INTERP_KERNEL::Exception("tuple must contain integers only");
643 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
647 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
650 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
652 if(PyList_Check(pyLi))
654 int size=PyList_Size(pyLi);
655 for(int i=0;i<size;i++)
657 PyObject *o=PyList_GetItem(pyLi,i);
660 int val=(int)PyInt_AS_LONG(o);
665 std::vector<int> arr2;
666 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
667 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
669 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
670 throw INTERP_KERNEL::Exception(oss.str().c_str());
672 arr.insert(arr.end(),arr2.begin(),arr2.end());
676 else if(PyTuple_Check(pyLi))
678 int size=PyTuple_Size(pyLi);
679 for(int i=0;i<size;i++)
681 PyObject *o=PyTuple_GetItem(pyLi,i);
684 int val=(int)PyInt_AS_LONG(o);
689 std::vector<int> arr2;
690 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
691 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
693 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
694 throw INTERP_KERNEL::Exception(oss.str().c_str());
696 arr.insert(arr.end(),arr2.begin(),arr2.end());
701 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
704 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
708 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
709 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
711 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
712 oss << " whereas nb of components expected is " << nbOfComp << " !";
713 throw INTERP_KERNEL::Exception(oss.str().c_str());
720 if((nbOfTuples!=size1 || nbOfComp!=size2))
722 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
724 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
725 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
726 throw INTERP_KERNEL::Exception(oss.str().c_str());
732 if(nbOfTuples==size1)
736 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
737 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
738 throw INTERP_KERNEL::Exception(oss.str().c_str());
744 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
746 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
747 if(PyInt_Check(pyLi))
749 long val=PyInt_AS_LONG(pyLi);
754 throw INTERP_KERNEL::Exception(MSG);
757 else if(PyList_Check(pyLi))
759 int size=PyList_Size(pyLi);
761 for(int i=0;i<size;i++)
763 PyObject *o=PyList_GetItem(pyLi,i);
765 fillArrayWithPyListInt3(o,tmp1,ret);
773 throw INTERP_KERNEL::Exception(MSG);
776 else if(PyTuple_Check(pyLi))
778 int size=PyTuple_Size(pyLi);
780 for(int i=0;i<size;i++)
782 PyObject *o=PyTuple_GetItem(pyLi,i);
784 fillArrayWithPyListInt3(o,tmp1,ret);
792 throw INTERP_KERNEL::Exception(MSG);
796 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
799 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
801 std::vector<int> ret;
802 int size1=-1,size2=-1;
803 if(PyList_Check(pyLi))
805 size1=PyList_Size(pyLi);
806 for(int i=0;i<size1;i++)
808 PyObject *o=PyList_GetItem(pyLi,i);
809 fillArrayWithPyListInt3(o,size2,ret);
814 else if(PyTuple_Check(pyLi))
816 size1=PyTuple_Size(pyLi);
817 for(int i=0;i<size1;i++)
819 PyObject *o=PyTuple_GetItem(pyLi,i);
820 fillArrayWithPyListInt3(o,size2,ret);
826 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
828 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
832 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
834 if(PyList_Check(pyLi))
836 Py_ssize_t sz=PyList_Size(pyLi);
838 for(int i=0;i<sz;i++)
840 PyObject *o=PyList_GetItem(pyLi,i);
841 if(PyString_Check(o))
842 vec[i]=PyString_AsString(o);
848 else if(PyTuple_Check(pyLi))
850 Py_ssize_t sz=PyTuple_Size(pyLi);
852 for(int i=0;i<sz;i++)
854 PyObject *o=PyTuple_GetItem(pyLi,i);
855 if(PyString_Check(o))
856 vec[i]=PyString_AsString(o);
865 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
867 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
868 if(PyList_Check(pyLi))
870 Py_ssize_t sz=PyList_Size(pyLi);
872 for(int i=0;i<sz;i++)
874 PyObject *o=PyList_GetItem(pyLi,i);
875 if(!fillStringVector(o,arr[i]))
876 throw INTERP_KERNEL::Exception(msg);
879 else if(PyTuple_Check(pyLi))
881 Py_ssize_t sz=PyTuple_Size(pyLi);
883 for(int i=0;i<sz;i++)
885 PyObject *o=PyTuple_GetItem(pyLi,i);
886 if(!fillStringVector(o,arr[i]))
887 throw INTERP_KERNEL::Exception(msg);
891 throw INTERP_KERNEL::Exception(msg);
894 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
896 if(PyList_Check(pyLi))
898 Py_ssize_t sz=PyList_Size(pyLi);
900 for(int i=0;i<sz;i++)
902 PyObject *o=PyList_GetItem(pyLi,i);
904 vec[i]=PyInt_AS_LONG(o);
910 else if(PyTuple_Check(pyLi))
912 Py_ssize_t sz=PyTuple_Size(pyLi);
914 for(int i=0;i<sz;i++)
916 PyObject *o=PyTuple_GetItem(pyLi,i);
918 vec[i]=PyInt_AS_LONG(o);
928 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
930 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
931 if(PyList_Check(pyLi))
933 Py_ssize_t sz=PyList_Size(pyLi);
935 for(int i=0;i<sz;i++)
937 PyObject *o=PyList_GetItem(pyLi,i);
938 if(!fillIntVector(o,arr[i]))
939 throw INTERP_KERNEL::Exception(msg);
942 else if(PyTuple_Check(pyLi))
944 Py_ssize_t sz=PyTuple_Size(pyLi);
946 for(int i=0;i<sz;i++)
948 PyObject *o=PyTuple_GetItem(pyLi,i);
949 if(!fillIntVector(o,arr[i]))
950 throw INTERP_KERNEL::Exception(msg);
954 throw INTERP_KERNEL::Exception(msg);
957 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
959 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
960 if(PyList_Check(pyLi))
962 Py_ssize_t sz=PyList_Size(pyLi);
964 for(int i=0;i<sz;i++)
966 PyObject *o=PyList_GetItem(pyLi,i);
969 int sz2=PyTuple_Size(o);
971 throw INTERP_KERNEL::Exception(msg);
972 std::pair<std::string, std::vector<std::string> > item;
973 PyObject *o_0=PyTuple_GetItem(o,0);
974 if(!PyString_Check(o_0))
975 throw INTERP_KERNEL::Exception(msg);
976 item.first=PyString_AsString(o_0);
977 PyObject *o_1=PyTuple_GetItem(o,1);
978 if(!fillStringVector(o_1,item.second))
979 throw INTERP_KERNEL::Exception(msg);
983 throw INTERP_KERNEL::Exception(msg);
986 else if(PyTuple_Check(pyLi))
988 Py_ssize_t sz=PyTuple_Size(pyLi);
990 for(int i=0;i<sz;i++)
992 PyObject *o=PyTuple_GetItem(pyLi,i);
995 int sz2=PyTuple_Size(o);
997 throw INTERP_KERNEL::Exception(msg);
998 std::pair<std::string, std::vector<std::string> > item;
999 PyObject *o_0=PyTuple_GetItem(o,0);
1000 if(!PyString_Check(o_0))
1001 throw INTERP_KERNEL::Exception(msg);
1002 item.first=PyString_AsString(o_0);
1003 PyObject *o_1=PyTuple_GetItem(o,1);
1004 if(!fillStringVector(o_1,item.second))
1005 throw INTERP_KERNEL::Exception(msg);
1009 throw INTERP_KERNEL::Exception(msg);
1013 throw INTERP_KERNEL::Exception(msg);
1017 PyObject *convertDblArrToPyList(const T *ptr, int size) throw(INTERP_KERNEL::Exception)
1019 PyObject *ret(PyList_New(size));
1020 for(int i=0;i<size;i++)
1021 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1025 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1028 PyObject *ret(PyList_New(size));
1029 for(int i=0;i<size;i++)
1030 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1035 PyObject *convertDblArrToPyListOfTuple(const T *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1037 PyObject *ret(PyList_New(nbOfTuples));
1038 for(int i=0;i<nbOfTuples;i++)
1040 PyObject *t=PyTuple_New(nbOfComp);
1041 for(int j=0;j<nbOfComp;j++)
1042 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1043 PyList_SetItem(ret,i,t);
1048 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1050 PyObject *ret=PyList_New(nbOfTuples);
1051 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1052 for(int i=0;i<nbOfTuples;i++)
1054 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1055 PyList_SetItem(ret,i,PyString_FromString(tmp));
1060 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1062 if(PyList_Check(pyLi))
1064 *size=PyList_Size(pyLi);
1065 double *tmp=(double *)malloc((*size)*sizeof(double));
1066 for(int i=0;i<*size;i++)
1068 PyObject *o=PyList_GetItem(pyLi,i);
1069 if(PyFloat_Check(o))
1071 double val=PyFloat_AS_DOUBLE(o);
1074 else if(PyInt_Check(o))
1076 long val0=PyInt_AS_LONG(o);
1083 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1088 else if(PyTuple_Check(pyLi))
1090 *size=PyTuple_Size(pyLi);
1091 double *tmp=(double *)malloc((*size)*sizeof(double));
1092 for(int i=0;i<*size;i++)
1094 PyObject *o=PyTuple_GetItem(pyLi,i);
1095 if(PyFloat_Check(o))
1097 double val=PyFloat_AS_DOUBLE(o);
1100 else if(PyInt_Check(o))
1102 long val0=PyInt_AS_LONG(o);
1109 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1115 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1118 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1120 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1121 if(PyFloat_Check(pyLi))
1127 throw INTERP_KERNEL::Exception(MSG);
1128 double val=PyFloat_AS_DOUBLE(pyLi);
1131 else if(PyInt_Check(pyLi))
1133 long val0=PyInt_AS_LONG(pyLi);
1139 throw INTERP_KERNEL::Exception(MSG);
1142 else if(PyList_Check(pyLi))
1144 int size=PyList_Size(pyLi);
1146 for(int i=0;i<size;i++)
1148 PyObject *o=PyList_GetItem(pyLi,i);
1150 fillArrayWithPyListDbl3(o,tmp1,ret);
1158 throw INTERP_KERNEL::Exception(MSG);
1161 else if(PyTuple_Check(pyLi))
1163 int size=PyTuple_Size(pyLi);
1165 for(int i=0;i<size;i++)
1167 PyObject *o=PyTuple_GetItem(pyLi,i);
1169 fillArrayWithPyListDbl3(o,tmp1,ret);
1177 throw INTERP_KERNEL::Exception(MSG);
1181 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1184 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1186 std::vector<double> ret;
1187 int size1=-1,size2=-1;
1188 if(PyList_Check(pyLi))
1190 size1=PyList_Size(pyLi);
1191 for(int i=0;i<size1;i++)
1193 PyObject *o=PyList_GetItem(pyLi,i);
1194 fillArrayWithPyListDbl3(o,size2,ret);
1199 else if(PyTuple_Check(pyLi))
1201 size1=PyTuple_Size(pyLi);
1202 for(int i=0;i<size1;i++)
1204 PyObject *o=PyTuple_GetItem(pyLi,i);
1205 fillArrayWithPyListDbl3(o,size2,ret);
1211 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1213 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1217 //convertFromPyObjVectorOfObj<const MEDCoupling::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh,"MEDCouplingUMesh")
1219 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1222 if(PyList_Check(pyLi))
1224 int size=PyList_Size(pyLi);
1226 for(int i=0;i<size;i++)
1228 PyObject *obj=PyList_GetItem(pyLi,i);
1229 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1230 if(!SWIG_IsOK(status))
1232 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1233 throw INTERP_KERNEL::Exception(oss.str().c_str());
1235 T arg=reinterpret_cast< T >(argp);
1239 else if(PyTuple_Check(pyLi))
1241 int size=PyTuple_Size(pyLi);
1243 for(int i=0;i<size;i++)
1245 PyObject *obj=PyTuple_GetItem(pyLi,i);
1246 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1247 if(!SWIG_IsOK(status))
1249 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1250 throw INTERP_KERNEL::Exception(oss.str().c_str());
1252 T arg=reinterpret_cast< T >(argp);
1256 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1259 T arg=reinterpret_cast< T >(argp);
1263 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1267 * if python int -> cpp int sw=1
1268 * if python list[int] -> cpp vector<int> sw=2
1269 * if python tuple[int] -> cpp vector<int> sw=2
1270 * if python DataArrayInt -> cpp DataArrayInt sw=3
1271 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1273 * switch between (int,vector<int>,DataArrayInt)
1275 static void convertIntStarLikePyObjToCpp(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, MEDCoupling::DataArrayInt *& daIntTyypp, MEDCoupling::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1278 if(PyInt_Check(value))
1280 iTyypp=(int)PyInt_AS_LONG(value);
1284 if(PyTuple_Check(value))
1286 int size=PyTuple_Size(value);
1287 stdvecTyypp.resize(size);
1288 for(int i=0;i<size;i++)
1290 PyObject *o=PyTuple_GetItem(value,i);
1292 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1295 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1296 throw INTERP_KERNEL::Exception(oss.str().c_str());
1302 if(PyList_Check(value))
1304 int size=PyList_Size(value);
1305 stdvecTyypp.resize(size);
1306 for(int i=0;i<size;i++)
1308 PyObject *o=PyList_GetItem(value,i);
1310 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1313 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1314 throw INTERP_KERNEL::Exception(oss.str().c_str());
1321 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1322 if(SWIG_IsOK(status))
1324 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1328 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1329 if(SWIG_IsOK(status))
1331 daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1335 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1339 * if python int -> cpp int sw=1
1340 * if python list[int] -> cpp vector<int> sw=2
1341 * if python tuple[int] -> cpp vector<int> sw=2
1342 * if python DataArrayInt -> cpp DataArrayInt sw=3
1343 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1345 * switch between (int,vector<int>,DataArrayInt)
1347 static const int *convertIntStarLikePyObjToCppIntStar(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
1350 if(PyInt_Check(value))
1352 iTyypp=(int)PyInt_AS_LONG(value);
1356 if(PyTuple_Check(value))
1358 int size=PyTuple_Size(value);
1359 stdvecTyypp.resize(size);
1360 for(int i=0;i<size;i++)
1362 PyObject *o=PyTuple_GetItem(value,i);
1364 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1367 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1368 throw INTERP_KERNEL::Exception(oss.str().c_str());
1372 return &stdvecTyypp[0];
1374 if(PyList_Check(value))
1376 int size=PyList_Size(value);
1377 stdvecTyypp.resize(size);
1378 for(int i=0;i<size;i++)
1380 PyObject *o=PyList_GetItem(value,i);
1382 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1385 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1386 throw INTERP_KERNEL::Exception(oss.str().c_str());
1390 return &stdvecTyypp[0];
1393 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1394 if(SWIG_IsOK(status))
1396 MEDCoupling::DataArrayInt *daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1399 sw=3; sz=daIntTyypp->getNbOfElems();
1400 return daIntTyypp->begin();
1408 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1409 if(SWIG_IsOK(status))
1411 MEDCoupling::DataArrayIntTuple *daIntTuple=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1412 sw=4; sz=daIntTuple->getNumberOfCompo();
1413 return daIntTuple->getConstPointer();
1415 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1419 * if python double -> cpp double sw=1
1420 * if python int -> cpp double sw=1
1421 * if python list[double] -> cpp vector<double> sw=2
1422 * if python list[int] -> cpp vector<double> sw=2
1423 * if python tuple[double] -> cpp vector<double> sw=2
1424 * if python tuple[int] -> cpp vector<double> sw=2
1425 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1427 * switch between (int,vector<int>,DataArrayInt)
1430 void considerPyObjAsATStarLikeObject(PyObject *value, int& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti) throw(INTERP_KERNEL::Exception)
1433 if(PyFloat_Check(value))
1435 iTyypp=(T)PyFloat_AS_DOUBLE(value);
1439 if(PyInt_Check(value))
1441 iTyypp=(T)PyInt_AS_LONG(value);
1445 if(PyTuple_Check(value))
1447 int size=PyTuple_Size(value);
1448 stdvecTyypp.resize(size);
1449 for(int i=0;i<size;i++)
1451 PyObject *o=PyTuple_GetItem(value,i);
1452 if(PyFloat_Check(o))
1453 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1454 else if(PyInt_Check(o))
1455 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1458 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1459 throw INTERP_KERNEL::Exception(oss.str().c_str());
1465 if(PyList_Check(value))
1467 int size=PyList_Size(value);
1468 stdvecTyypp.resize(size);
1469 for(int i=0;i<size;i++)
1471 PyObject *o=PyList_GetItem(value,i);
1472 if(PyFloat_Check(o))
1473 stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
1474 else if(PyInt_Check(o))
1475 stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
1478 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1479 throw INTERP_KERNEL::Exception(oss.str().c_str());
1486 int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
1487 if(!SWIG_IsOK(status))
1488 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1489 daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1494 * if python double -> cpp double sw=1
1495 * if python int -> cpp double sw=1
1496 * if python list[double] -> cpp vector<double> sw=2
1497 * if python list[int] -> cpp vector<double> sw=2
1498 * if python tuple[double] -> cpp vector<double> sw=2
1499 * if python tuple[int] -> cpp vector<double> sw=2
1500 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1502 * switch between (int,vector<int>,DataArrayInt)
1504 static void convertDoubleStarLikePyObjToCpp(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1507 if(PyFloat_Check(value))
1509 iTyypp=PyFloat_AS_DOUBLE(value);
1513 if(PyInt_Check(value))
1515 iTyypp=(double)PyInt_AS_LONG(value);
1519 if(PyTuple_Check(value))
1521 int size=PyTuple_Size(value);
1522 stdvecTyypp.resize(size);
1523 for(int i=0;i<size;i++)
1525 PyObject *o=PyTuple_GetItem(value,i);
1526 if(PyFloat_Check(o))
1527 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1528 else if(PyInt_Check(o))
1529 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1532 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1533 throw INTERP_KERNEL::Exception(oss.str().c_str());
1539 if(PyList_Check(value))
1541 int size=PyList_Size(value);
1542 stdvecTyypp.resize(size);
1543 for(int i=0;i<size;i++)
1545 PyObject *o=PyList_GetItem(value,i);
1546 if(PyFloat_Check(o))
1547 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1548 else if(PyInt_Check(o))
1549 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1552 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1553 throw INTERP_KERNEL::Exception(oss.str().c_str());
1560 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
1561 if(!SWIG_IsOK(status))
1562 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1563 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
1568 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)
1571 if(PyFloat_Check(value))
1573 val=PyFloat_AS_DOUBLE(value);
1577 if(PyInt_Check(value))
1579 val=(T)PyInt_AS_LONG(value);
1583 if(PyTuple_Check(value))
1585 int size=PyTuple_Size(value);
1587 for(int i=0;i<size;i++)
1589 PyObject *o=PyTuple_GetItem(value,i);
1590 if(PyFloat_Check(o))
1591 f[i]=PyFloat_AS_DOUBLE(o);
1592 else if(PyInt_Check(o))
1593 f[i]=(T)PyInt_AS_LONG(o);
1596 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1597 throw INTERP_KERNEL::Exception(oss.str().c_str());
1603 if(PyList_Check(value))
1605 int size=PyList_Size(value);
1607 for(int i=0;i<size;i++)
1609 PyObject *o=PyList_GetItem(value,i);
1610 if(PyFloat_Check(o))
1611 f[i]=PyFloat_AS_DOUBLE(o);
1612 else if(PyInt_Check(o))
1613 f[i]=(T)PyInt_AS_LONG(o);
1616 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1617 throw INTERP_KERNEL::Exception(oss.str().c_str());
1624 int status=SWIG_ConvertPtr(value,&argp,ti_da,0|0);
1625 if(SWIG_IsOK(status))
1627 d=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
1631 status=SWIG_ConvertPtr(value,&argp,ti_tuple,0|0);
1632 if(SWIG_IsOK(status))
1634 e=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayTuple * >(argp);
1638 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1642 * if value int -> cpp val sw=1
1643 * if value double -> cpp val sw=1
1644 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1645 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1646 * if value list[int,double] -> cpp std::vector<double> sw=4
1647 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1649 static void convertDoubleStarLikePyObjToCpp_2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f)
1651 convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
1655 * if python int -> cpp int sw=1
1656 * if python list[int] -> cpp vector<int> sw=2
1657 * if python tuple[int] -> cpp vector<int> sw=2
1658 * if python slicp -> cpp pair sw=3 (begin,end,step)
1659 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1661 * switch between (int,vector<int>,DataArrayInt)
1663 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) throw(INTERP_KERNEL::Exception)
1665 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1667 if(PyInt_Check(value))
1669 iTyypp=(int)PyInt_AS_LONG(value);
1673 if(PyTuple_Check(value))
1675 int size=PyTuple_Size(value);
1676 stdvecTyypp.resize(size);
1677 for(int i=0;i<size;i++)
1679 PyObject *o=PyTuple_GetItem(value,i);
1681 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1684 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1685 throw INTERP_KERNEL::Exception(oss.str().c_str());
1691 if(PyList_Check(value))
1693 int size=PyList_Size(value);
1694 stdvecTyypp.resize(size);
1695 for(int i=0;i<size;i++)
1697 PyObject *o=PyList_GetItem(value,i);
1699 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1702 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1703 throw INTERP_KERNEL::Exception(oss.str().c_str());
1709 if(PySlice_Check(value))
1711 Py_ssize_t strt=2,stp=2,step=2;
1712 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1713 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1716 p.second.second=step;
1721 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
1722 if(SWIG_IsOK(status))
1724 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayInt * >(argp);
1727 std::ostringstream oss; oss << msg << " Instance in null !";
1728 throw INTERP_KERNEL::Exception(oss.str().c_str());
1733 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1734 if(SWIG_IsOK(status))
1736 MEDCoupling::DataArrayIntTuple *tmp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1739 std::ostringstream oss; oss << msg << " Instance in null !";
1740 throw INTERP_KERNEL::Exception(oss.str().c_str());
1742 stdvecTyypp.resize(tmp->getNumberOfCompo());
1743 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1747 throw INTERP_KERNEL::Exception(msg);
1751 * Idem than convertIntStarOrSliceLikePyObjToCpp
1753 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) throw(INTERP_KERNEL::Exception)
1755 convertIntStarOrSliceLikePyObjToCpp(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1758 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1763 * if python int -> cpp int sw=1
1764 * if python tuple[int] -> cpp vector<int> sw=2
1765 * if python list[int] -> cpp vector<int> sw=2
1766 * if python slice -> cpp pair sw=3
1767 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1769 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) throw(INTERP_KERNEL::Exception)
1772 if(PyInt_Check(value))
1774 iTyypp=(int)PyInt_AS_LONG(value);
1778 if(PyTuple_Check(value))
1780 int size=PyTuple_Size(value);
1781 stdvecTyypp.resize(size);
1782 for(int i=0;i<size;i++)
1784 PyObject *o=PyTuple_GetItem(value,i);
1786 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1789 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1790 throw INTERP_KERNEL::Exception(oss.str().c_str());
1796 if(PyList_Check(value))
1798 int size=PyList_Size(value);
1799 stdvecTyypp.resize(size);
1800 for(int i=0;i<size;i++)
1802 PyObject *o=PyList_GetItem(value,i);
1804 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1807 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1808 throw INTERP_KERNEL::Exception(oss.str().c_str());
1814 if(PySlice_Check(value))
1816 Py_ssize_t strt=2,stp=2,step=2;
1817 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1818 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1821 p.second.second=step;
1826 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayIntTuple,0|0);
1827 if(!SWIG_IsOK(status))
1828 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1829 daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayIntTuple * >(argp);
1834 * if python string with size one -> cpp char sw=1
1835 * if python string with size different from one -> cpp string sw=2
1836 * if python tuple[string] or list[string] -> vector<string> sw=3
1837 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1838 * switch between (int,string,vector<string>,DataArrayChar)
1840 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, MEDCoupling::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1842 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1844 if(PyString_Check(value))
1846 const char *pt=PyString_AsString(value);
1847 Py_ssize_t sz=PyString_Size(value);
1861 if(PyTuple_Check(value))
1863 int size=PyTuple_Size(value);
1864 vsType.resize(size);
1865 for(int i=0;i<size;i++)
1867 PyObject *o=PyTuple_GetItem(value,i);
1868 if(PyString_Check(o))
1869 vsType[i]=PyString_AsString(o);
1872 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1873 throw INTERP_KERNEL::Exception(oss.str().c_str());
1879 if(PyList_Check(value))
1881 int size=PyList_Size(value);
1882 vsType.resize(size);
1883 for(int i=0;i<size;i++)
1885 PyObject *o=PyList_GetItem(value,i);
1886 if(PyString_Check(o))
1887 vsType[i]=PyString_AsString(o);
1890 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1891 throw INTERP_KERNEL::Exception(oss.str().c_str());
1898 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayChar,0|0);
1899 if(SWIG_IsOK(status))
1901 dacType=reinterpret_cast< MEDCoupling::DataArrayChar * >(argp);
1904 std::ostringstream oss; oss << msg << " Instance in null !";
1905 throw INTERP_KERNEL::Exception(oss.str().c_str());
1910 throw INTERP_KERNEL::Exception(msg);
1914 * if value int -> cpp it sw=1
1915 * if value list[int] -> vt sw=2
1916 * if value tuple[int] -> vt sw=2
1917 * if value slice -> pt sw=3
1918 * if value DataArrayInt -> dt sw=4
1919 * if value tuple [int,int] -> cpp it,ip sw=5
1920 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1921 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1922 * if value tuple [slice,int] -> cpp pt,ip sw=7
1923 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1924 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1925 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1926 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1927 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1928 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1929 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1930 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1931 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1932 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1933 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1934 * if value tuple [int,slice] -> cpp it,pc sw=13
1935 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1936 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1937 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1938 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1940 * switch between (int,vector<int>,DataArrayInt)
1942 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1943 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1944 MEDCoupling::DataArrayInt *&dt, MEDCoupling::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1946 if(!PyTuple_Check(value))
1948 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1953 int sz=PyTuple_Size(value);
1955 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1956 PyObject *ob0=PyTuple_GetItem(value,0);
1958 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1959 PyObject *ob1=PyTuple_GetItem(value,1);
1960 convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1966 * if value int -> cpp val sw=1
1967 * if value double -> cpp val sw=1
1968 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1969 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1970 * if value list[int,double] -> cpp std::vector<double> sw=4
1971 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1973 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
1974 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1977 if(PyFloat_Check(value))
1979 val=PyFloat_AS_DOUBLE(value);
1981 if(nbTuplesExpected*nbCompExpected!=1)
1983 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1984 throw INTERP_KERNEL::Exception(oss.str().c_str());
1988 if(PyInt_Check(value))
1990 val=(double)PyInt_AS_LONG(value);
1992 if(nbTuplesExpected*nbCompExpected!=1)
1994 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1995 throw INTERP_KERNEL::Exception(oss.str().c_str());
1999 if(PyTuple_Check(value) || PyList_Check(value))
2003 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2004 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2009 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2012 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2013 if(SWIG_IsOK(status))
2015 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2019 if(d->getNumberOfTuples()==nbTuplesExpected)
2021 if(d->getNumberOfComponents()==nbCompExpected)
2023 return d->getConstPointer();
2027 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2028 throw INTERP_KERNEL::Exception(oss.str().c_str());
2033 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2034 throw INTERP_KERNEL::Exception(oss.str().c_str());
2041 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2042 throw INTERP_KERNEL::Exception(oss.str().c_str());
2048 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2049 if(SWIG_IsOK(status))
2051 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2053 if(e->getNumberOfCompo()==nbCompExpected)
2055 if(nbTuplesExpected==1)
2056 return e->getConstPointer();
2059 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2060 throw INTERP_KERNEL::Exception(oss.str().c_str());
2065 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2066 throw INTERP_KERNEL::Exception(oss.str().c_str());
2069 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2073 * if value int -> cpp val sw=1
2074 * if value double -> cpp val sw=1
2075 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2076 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2077 * if value list[int,double] -> cpp std::vector<double> sw=4
2078 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2080 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, MEDCoupling::DataArrayDouble *&d, MEDCoupling::DataArrayDoubleTuple *&e, std::vector<double>& f,
2081 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2084 if(PyFloat_Check(value))
2086 val=PyFloat_AS_DOUBLE(value);
2088 if(nbCompExpected!=1)
2090 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2091 throw INTERP_KERNEL::Exception(oss.str().c_str());
2096 if(PyInt_Check(value))
2098 val=(double)PyInt_AS_LONG(value);
2100 if(nbCompExpected!=1)
2102 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2103 throw INTERP_KERNEL::Exception(oss.str().c_str());
2108 if(PyTuple_Check(value))
2110 int size=PyTuple_Size(value);
2112 for(int i=0;i<size;i++)
2114 PyObject *o=PyTuple_GetItem(value,i);
2115 if(PyFloat_Check(o))
2116 f[i]=PyFloat_AS_DOUBLE(o);
2117 else if(PyInt_Check(o))
2118 f[i]=(double)PyInt_AS_LONG(o);
2121 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2122 throw INTERP_KERNEL::Exception(oss.str().c_str());
2126 if(size%nbCompExpected!=0)
2128 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2129 throw INTERP_KERNEL::Exception(oss.str().c_str());
2131 nbTuples=size/nbCompExpected;
2134 if(PyList_Check(value))
2136 int size=PyList_Size(value);
2138 for(int i=0;i<size;i++)
2140 PyObject *o=PyList_GetItem(value,i);
2141 if(PyFloat_Check(o))
2142 f[i]=PyFloat_AS_DOUBLE(o);
2143 else if(PyInt_Check(o))
2144 f[i]=(double)PyInt_AS_LONG(o);
2147 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2148 throw INTERP_KERNEL::Exception(oss.str().c_str());
2152 if(size%nbCompExpected!=0)
2154 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2155 throw INTERP_KERNEL::Exception(oss.str().c_str());
2157 nbTuples=size/nbCompExpected;
2161 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2162 if(SWIG_IsOK(status))
2164 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2168 if(d->getNumberOfComponents()==nbCompExpected)
2170 nbTuples=d->getNumberOfTuples();
2171 return d->getConstPointer();
2175 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2176 throw INTERP_KERNEL::Exception(oss.str().c_str());
2183 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2184 throw INTERP_KERNEL::Exception(oss.str().c_str());
2187 { nbTuples=0; return 0; }
2190 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2191 if(SWIG_IsOK(status))
2193 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2197 if(e->getNumberOfCompo()==nbCompExpected)
2200 return e->getConstPointer();
2204 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2205 throw INTERP_KERNEL::Exception(oss.str().c_str());
2212 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2213 throw INTERP_KERNEL::Exception(oss.str().c_str());
2216 { nbTuples=0; return 0; }
2219 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2223 * if value int -> cpp val sw=1
2224 * if value double -> cpp val sw=1
2225 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2226 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2227 * if value list[int,double] -> cpp std::vector<double> sw=4
2228 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2230 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2231 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2233 MEDCoupling::DataArrayDouble *d=0;
2234 MEDCoupling::DataArrayDoubleTuple *e=0;
2236 if(PyFloat_Check(value))
2238 val=PyFloat_AS_DOUBLE(value);
2243 if(PyInt_Check(value))
2245 val=(double)PyInt_AS_LONG(value);
2250 if(PyTuple_Check(value))
2252 int size=PyTuple_Size(value);
2254 for(int i=0;i<size;i++)
2256 PyObject *o=PyTuple_GetItem(value,i);
2257 if(PyFloat_Check(o))
2258 f[i]=PyFloat_AS_DOUBLE(o);
2259 else if(PyInt_Check(o))
2260 f[i]=(double)PyInt_AS_LONG(o);
2263 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2264 throw INTERP_KERNEL::Exception(oss.str().c_str());
2271 if(PyList_Check(value))
2273 int size=PyList_Size(value);
2275 for(int i=0;i<size;i++)
2277 PyObject *o=PyList_GetItem(value,i);
2278 if(PyFloat_Check(o))
2279 f[i]=PyFloat_AS_DOUBLE(o);
2280 else if(PyInt_Check(o))
2281 f[i]=(double)PyInt_AS_LONG(o);
2284 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2285 throw INTERP_KERNEL::Exception(oss.str().c_str());
2293 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2294 if(SWIG_IsOK(status))
2296 d=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
2300 if(d->getNumberOfComponents()==1)
2302 nbTuples=d->getNumberOfTuples();
2303 return d->getConstPointer();
2307 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2308 throw INTERP_KERNEL::Exception(oss.str().c_str());
2315 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2316 throw INTERP_KERNEL::Exception(oss.str().c_str());
2319 { nbTuples=0; return 0; }
2322 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple,0|0);
2323 if(SWIG_IsOK(status))
2325 e=reinterpret_cast< MEDCoupling::DataArrayDoubleTuple * >(argp);
2329 nbTuples=e->getNumberOfCompo();
2330 return e->getConstPointer();
2336 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2337 throw INTERP_KERNEL::Exception(oss.str().c_str());
2340 { nbTuples=0; return 0; }
2343 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2346 static MEDCoupling::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2349 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArray,0|0);
2350 if(!SWIG_IsOK(status))
2352 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
2353 if(!SWIG_IsOK(status))
2355 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayInt,0|0);
2356 if(!SWIG_IsOK(status))
2358 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayAsciiChar,0|0);
2359 if(!SWIG_IsOK(status))
2361 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_MEDCoupling__DataArrayByte,0|0);
2362 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2363 throw INTERP_KERNEL::Exception(oss.str().c_str());
2368 return reinterpret_cast< MEDCoupling::DataArray * >(aBasePtrVS);
2371 static PyObject *NewMethWrapCallInitOnlyIfEmptyDictInInput(PyObject *cls, PyObject *args, const char *clsName)
2373 if(!PyTuple_Check(args))
2375 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2376 throw INTERP_KERNEL::Exception(oss.str().c_str());
2378 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2379 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2380 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2382 PyObject *tmp0(PyTuple_New(1));
2383 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2384 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2386 Py_DECREF(selfMeth);
2387 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==0 )
2388 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2389 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2390 PyObject *tmp3(PyTuple_New(0));
2391 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2394 Py_DECREF(initMeth);
2399 static PyObject *NewMethWrapCallInitOnlyIfDictWithSingleEltInInput(PyObject *cls, PyObject *args, const char *clsName)
2401 if(!PyTuple_Check(args))
2403 std::ostringstream oss; oss << clsName << ".__new__ : the args in input is expected to be a tuple !";
2404 throw INTERP_KERNEL::Exception(oss.str().c_str());
2406 PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
2407 PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
2408 PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
2410 PyObject *tmp0(PyTuple_New(1));
2411 PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
2412 PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
2414 Py_DECREF(selfMeth);
2415 if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 )
2416 {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
2417 PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
2418 PyObject *zeNumpyRepr(0);
2420 PyObject *tmp1(PyInt_FromLong(0));
2421 zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed
2425 PyObject *tmp3(PyTuple_New(1));
2426 PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr);
2427 PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
2431 Py_DECREF(initMeth);
2436 static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owner) throw(INTERP_KERNEL::Exception)
2441 Py_XINCREF(Py_None);
2444 if(dynamic_cast<MEDCoupling::DataArrayPartDefinition *>(pd))
2445 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__DataArrayPartDefinition,owner);
2447 ret=SWIG_NewPointerObj((void*)pd,SWIGTYPE_p_MEDCoupling__SlicePartDefinition,owner);
2452 static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
2454 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)";
2455 std::string msg(msgBase);
2457 msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
2460 if(PyList_Check(elt0) || PyTuple_Check(elt0))
2464 if(PyInt_Check(nbOfTuples))
2466 int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
2468 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2471 if(PyInt_Check(elt2))
2472 {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
2473 int nbOfCompo=PyInt_AS_LONG(elt2);
2475 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2476 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2477 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
2478 ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2482 throw INTERP_KERNEL::Exception(msg.c_str());
2485 {//DataArrayDouble.New([1.,3.,4.],3)
2486 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2488 std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
2489 ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2494 throw INTERP_KERNEL::Exception(msg.c_str());
2497 {// DataArrayDouble.New([1.,3.,4.])
2498 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2499 int tmpp1(-1),tmpp2(-1);
2500 std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
2501 ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
2505 else if(PyInt_Check(elt0))
2507 int nbOfTuples1(PyInt_AS_LONG(elt0));
2509 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
2514 if(PyInt_Check(nbOfTuples))
2515 {//DataArrayDouble.New(5,2)
2516 int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
2518 throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
2519 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2520 ret->alloc(nbOfTuples1,nbOfCompo);
2524 throw INTERP_KERNEL::Exception(msg.c_str());
2527 throw INTERP_KERNEL::Exception(msg.c_str());
2530 {//DataArrayDouble.New(5)
2531 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
2532 ret->alloc(nbOfTuples1,1);
2537 else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
2538 {//DataArrayDouble.New(numpyArray)
2539 return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
2543 throw INTERP_KERNEL::Exception(msg.c_str());
2544 throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
2548 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
2550 self->checkAllocated();
2551 const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
2552 int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
2556 typename MEDCoupling::Traits<T>::ArrayType *d1=0;
2557 considerPyObjAsATStarLikeObject<T>(value,sw1,i1,v1,d1,ti);
2559 std::vector<int> vt1,vc1;
2560 std::pair<int, std::pair<int,int> > pt1,pc1;
2561 MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
2562 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2563 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
2571 self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
2574 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2575 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2576 self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
2579 self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
2582 throw INTERP_KERNEL::Exception(msg);
2591 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2594 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2595 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2596 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
2599 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
2602 throw INTERP_KERNEL::Exception(msg);
2611 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2614 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2615 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2616 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
2619 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
2622 throw INTERP_KERNEL::Exception(msg);
2631 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2634 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2635 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2636 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
2639 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
2642 throw INTERP_KERNEL::Exception(msg);
2651 self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
2654 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2655 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2656 self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
2659 self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
2662 throw INTERP_KERNEL::Exception(msg);
2671 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2674 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2675 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2676 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
2679 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
2682 throw INTERP_KERNEL::Exception(msg);
2691 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2694 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2695 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2696 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
2699 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
2702 throw INTERP_KERNEL::Exception(msg);
2711 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2714 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2715 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2716 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
2719 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
2722 throw INTERP_KERNEL::Exception(msg);
2731 self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2734 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2735 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2736 self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
2739 self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
2742 throw INTERP_KERNEL::Exception(msg);
2751 self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2754 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2755 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2756 self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
2759 self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
2762 throw INTERP_KERNEL::Exception(msg);
2771 self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2774 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2775 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2776 self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
2779 self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
2782 throw INTERP_KERNEL::Exception(msg);
2791 self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2794 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2795 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2796 self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
2799 self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
2802 throw INTERP_KERNEL::Exception(msg);
2811 self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2814 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2815 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2816 self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
2819 self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
2822 throw INTERP_KERNEL::Exception(msg);
2831 self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2834 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2835 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2836 self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
2839 self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
2842 throw INTERP_KERNEL::Exception(msg);
2851 self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2854 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2855 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2856 self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
2859 self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
2862 throw INTERP_KERNEL::Exception(msg);
2871 self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2874 tmp=MEDCoupling::Traits<T>::ArrayType::New();
2875 tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
2876 self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
2879 self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
2882 throw INTERP_KERNEL::Exception(msg);
2887 throw INTERP_KERNEL::Exception(msg);
2893 PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
2895 const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
2896 const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
2897 self->checkAllocated();
2898 int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
2900 std::vector<int> vt1,vc1;
2901 std::pair<int, std::pair<int,int> > pt1,pc1;
2902 MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
2904 convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
2905 MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
2909 if(nbOfComponents==1)
2910 return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
2911 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
2913 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
2915 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
2917 return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
2919 return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
2922 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
2923 std::vector<int> v2(1,ic1);
2924 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2928 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
2929 std::vector<int> v2(1,ic1);
2930 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2934 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
2935 std::vector<int> v2(1,ic1);
2936 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2940 ret=self->selectByTupleIdSafe(&it1,&it1+1);
2941 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
2945 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
2946 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
2950 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
2951 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
2955 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
2956 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
2960 ret=self->selectByTupleIdSafe(&it1,&it1+1);
2961 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
2962 std::vector<int> v2(nbOfComp);
2963 for(int i=0;i<nbOfComp;i++)
2964 v2[i]=pc1.first+i*pc1.second.second;
2965 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2969 ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
2970 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
2971 std::vector<int> v2(nbOfComp);
2972 for(int i=0;i<nbOfComp;i++)
2973 v2[i]=pc1.first+i*pc1.second.second;
2974 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2978 ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
2979 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
2980 std::vector<int> v2(nbOfComp);
2981 for(int i=0;i<nbOfComp;i++)
2982 v2[i]=pc1.first+i*pc1.second.second;
2983 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2987 ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
2988 int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
2989 std::vector<int> v2(nbOfComp);
2990 for(int i=0;i<nbOfComp;i++)
2991 v2[i]=pc1.first+i*pc1.second.second;
2992 return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
2995 throw INTERP_KERNEL::Exception(msg);
3000 PyObject *DataArrayT_imul__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3002 const char msg[]="Unexpected situation in __imul__ !";
3004 typename MEDCoupling::Traits<T>::ArrayType *a;
3005 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3008 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3013 self->applyLin(val,0.);
3014 Py_XINCREF(trueSelf);
3019 self->multiplyEqual(a);
3020 Py_XINCREF(trueSelf);
3025 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3026 self->multiplyEqual(aaa);
3027 Py_XINCREF(trueSelf);
3032 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());
3033 self->multiplyEqual(aaa);
3034 Py_XINCREF(trueSelf);
3038 throw INTERP_KERNEL::Exception(msg);
3043 PyObject *DataArrayT_idiv__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3045 const char msg[]="Unexpected situation in __idiv__ !";
3047 typename MEDCoupling::Traits<T>::ArrayType *a;
3048 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3051 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3057 throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !");
3058 self->applyLin(1./val,0.);
3059 Py_XINCREF(trueSelf);
3064 self->divideEqual(a);
3065 Py_XINCREF(trueSelf);
3070 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3071 self->divideEqual(aaa);
3072 Py_XINCREF(trueSelf);
3077 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());
3078 self->divideEqual(aaa);
3079 Py_XINCREF(trueSelf);
3083 throw INTERP_KERNEL::Exception(msg);
3088 PyObject *DataArrayT_iadd__internal(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self, swig_type_info *ti_da, swig_type_info *ti_tuple)
3090 const char msg[]="Unexpected situation in __iadd__ !";
3092 typename MEDCoupling::Traits<T>::ArrayType *a;
3093 typename MEDCoupling::Traits<T>::ArrayTuple *aa;
3096 convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,ti_da,ti_tuple);
3101 self->applyLin(1.,val);
3102 Py_XINCREF(trueSelf);
3108 Py_XINCREF(trueSelf);
3113 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3114 self->addEqual(aaa);
3115 Py_XINCREF(trueSelf);
3120 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());
3121 self->addEqual(aaa);
3122 Py_XINCREF(trueSelf);
3126 throw INTERP_KERNEL::Exception(msg);
3131 PyObject *DataArrayT_isub__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 __isub__ !";
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(1.,-val);
3145 Py_XINCREF(trueSelf);
3150 self->substractEqual(a);
3151 Py_XINCREF(trueSelf);
3156 MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > aaa(aa->buildDA(1,self->getNumberOfComponents()));
3157 self->substractEqual(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->substractEqual(aaa);
3165 Py_XINCREF(trueSelf);
3169 throw INTERP_KERNEL::Exception(msg);
3178 struct SWIGTITraits<double>
3179 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3182 struct SWIGTITraits<float>
3183 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3186 struct SWIGTITraits<int>
3187 { static swig_type_info *TI; static swig_type_info *TI_TUPLE; };
3189 swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
3190 swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3191 swig_type_info *SWIGTITraits<int>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3192 swig_type_info *SWIGTITraits<double>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
3193 swig_type_info *SWIGTITraits<float>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3194 swig_type_info *SWIGTITraits<int>::TI_TUPLE=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
3196 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
3198 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
3201 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
3203 return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
3207 PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
3209 return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
3213 PyObject *DataArrayT_imul(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3215 return DataArrayT_imul__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3219 PyObject *DataArrayT_idiv(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3221 return DataArrayT_idiv__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3225 PyObject *DataArrayT_iadd(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3227 return DataArrayT_iadd__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
3231 PyObject *DataArrayT_isub(PyObject *trueSelf, PyObject *obj, typename MEDCoupling::Traits<T>::ArrayType *self)
3233 return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);