X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingMemArray.i;h=ce219c7749ecc698cdec2ba48a863a2a0eed7a90;hb=8210342873f7be4a650c18c7875cc4ec2a8e4d86;hp=d30ed5bb6ea67008a908c59a27e6aa549c92b18e;hpb=6b29741613e4edeb511ea88701218f90044bc078;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index d30ed5bb6..ce219c774 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) //////////////////// %typemap(out) MEDCoupling::DataArray* @@ -40,6 +40,26 @@ { $result=convertDataArrayChar($1,$owner); } + +%typemap(out) MCAuto +{ + $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt,SWIG_POINTER_OWN|0); +} + +%typemap(out) MCAuto +{ + $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIG_POINTER_OWN|0); +} + +%typemap(out) MCAuto +{ + $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIG_POINTER_OWN|0); +} + +%typemap(out) MCAuto +{ + $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__MapII,SWIG_POINTER_OWN|0); +} //$$$$$$$$$$$$$$$$$$ %newobject MEDCoupling::DataArray::deepCopy; @@ -49,9 +69,13 @@ %newobject MEDCoupling::DataArray::selectByTupleIdSafe; %newobject MEDCoupling::DataArray::selectByTupleIdSafeSlice; %newobject MEDCoupling::DataArray::Aggregate; +%newobject MEDCoupling::DataArrayFloat::New; +%newobject MEDCoupling::DataArrayFloat::iterator; +%newobject MEDCoupling::DataArrayFloat::__iter__; +%newobject MEDCoupling::DataArrayFloat::Meld; +%newobject MEDCoupling::DataArrayFloat::__rmul__; %newobject MEDCoupling::DataArrayInt::New; %newobject MEDCoupling::DataArrayInt::__iter__; -%newobject MEDCoupling::DataArrayInt::convertToDblArr; %newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef; %newobject MEDCoupling::DataArrayInt::subArray; %newobject MEDCoupling::DataArrayInt::changeNbOfComponents; @@ -69,12 +93,13 @@ %newobject MEDCoupling::DataArrayInt::findIdsEqualList; %newobject MEDCoupling::DataArrayInt::findIdsNotEqualList; %newobject MEDCoupling::DataArrayInt::findIdsEqualTuple; +%newobject MEDCoupling::DataArrayInt::findIdForEach; %newobject MEDCoupling::DataArrayInt::sumPerTuple; %newobject MEDCoupling::DataArrayInt::negate; %newobject MEDCoupling::DataArrayInt::computeAbs; %newobject MEDCoupling::DataArrayInt::findIdsInRange; %newobject MEDCoupling::DataArrayInt::findIdsNotInRange; -%newobject MEDCoupling::DataArrayInt::findIdsStricltyNegative; +%newobject MEDCoupling::DataArrayInt::findIdsStrictlyNegative; %newobject MEDCoupling::DataArrayInt::Aggregate; %newobject MEDCoupling::DataArrayInt::AggregateIndexes; %newobject MEDCoupling::DataArrayInt::Meld; @@ -86,6 +111,7 @@ %newobject MEDCoupling::DataArrayInt::BuildUnion; %newobject MEDCoupling::DataArrayInt::BuildIntersection; %newobject MEDCoupling::DataArrayInt::Range; +%newobject MEDCoupling::DataArrayInt::indicesOfSubPart; %newobject MEDCoupling::DataArrayInt::fromNoInterlace; %newobject MEDCoupling::DataArrayInt::toNoInterlace; %newobject MEDCoupling::DataArrayInt::buildComplement; @@ -140,7 +166,6 @@ %newobject MEDCoupling::DataArrayAsciiCharTuple::buildDAAsciiChar; %newobject MEDCoupling::DataArrayDouble::New; %newobject MEDCoupling::DataArrayDouble::__iter__; -%newobject MEDCoupling::DataArrayDouble::convertToIntArr; %newobject MEDCoupling::DataArrayDouble::performCopyOrIncrRef; %newobject MEDCoupling::DataArrayDouble::Aggregate; %newobject MEDCoupling::DataArrayDouble::Meld; @@ -151,11 +176,13 @@ %newobject MEDCoupling::DataArrayDouble::Multiply; %newobject MEDCoupling::DataArrayDouble::Divide; %newobject MEDCoupling::DataArrayDouble::Pow; +%newobject MEDCoupling::DataArrayDouble::symmetry3DPlane; %newobject MEDCoupling::DataArrayDouble::subArray; %newobject MEDCoupling::DataArrayDouble::changeNbOfComponents; %newobject MEDCoupling::DataArrayDouble::accumulatePerChunck; %newobject MEDCoupling::DataArrayDouble::findIdsInRange; %newobject MEDCoupling::DataArrayDouble::findIdsNotInRange; +%newobject MEDCoupling::DataArrayDouble::findIdsStrictlyNegative; %newobject MEDCoupling::DataArrayDouble::negate; %newobject MEDCoupling::DataArrayDouble::computeAbs; %newobject MEDCoupling::DataArrayDouble::applyFunc; @@ -182,6 +209,10 @@ %newobject MEDCoupling::DataArrayDouble::fromPolarToCart; %newobject MEDCoupling::DataArrayDouble::fromCylToCart; %newobject MEDCoupling::DataArrayDouble::fromSpherToCart; +%newobject MEDCoupling::DataArrayDouble::fromCartToPolar; +%newobject MEDCoupling::DataArrayDouble::fromCartToCyl; +%newobject MEDCoupling::DataArrayDouble::fromCartToSpher; +%newobject MEDCoupling::DataArrayDouble::fromCartToCylGiven; %newobject MEDCoupling::DataArrayDouble::cartesianize; %newobject MEDCoupling::DataArrayDouble::getDifferentValues; %newobject MEDCoupling::DataArrayDouble::findClosestTupleId; @@ -196,6 +227,15 @@ %newobject MEDCoupling::DataArrayDouble::__rpow__; %newobject MEDCoupling::DataArrayDoubleTuple::buildDADouble; +%newobject MEDCoupling::PartDefinition::New; +%newobject MEDCoupling::PartDefinition::toDAI; +%newobject MEDCoupling::PartDefinition::__add__; +%newobject MEDCoupling::PartDefinition::composeWith; +%newobject MEDCoupling::PartDefinition::tryToSimplify; +%newobject MEDCoupling::DataArrayPartDefinition::New; +%newobject MEDCoupling::SlicePartDefinition::New; + + %feature("unref") DataArray "$this->decrRef();" %feature("unref") DataArrayDouble "$this->decrRef();" %feature("unref") DataArrayInt "$this->decrRef();" @@ -203,6 +243,11 @@ %feature("unref") DataArrayAsciiChar "$this->decrRef();" %feature("unref") DataArrayByte "$this->decrRef();" +%feature("unref") MapII "$this->decrRef();" +%feature("unref") PartDefinition "$this->decrRef();" +%feature("unref") DataArrayPartDefinition "$this->decrRef();" +%feature("unref") SlicePartDefinition "$this->decrRef();" + namespace MEDCoupling { typedef enum @@ -212,6 +257,115 @@ namespace MEDCoupling AX_SPHER = 5 } MEDCouplingAxisType; + class DataArrayInt; + + class MapII : public RefCountObject, public TimeLabel + { + public: + static MCAuto< MapII > New(); + }; + + class PartDefinition : public RefCountObject, public TimeLabel + { + public: + static PartDefinition *New(int start, int stop, int step) throw(INTERP_KERNEL::Exception); + static PartDefinition *New(DataArrayInt *listOfIds) throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *toDAI() const throw(INTERP_KERNEL::Exception); + virtual int getNumberOfElems() const throw(INTERP_KERNEL::Exception); + virtual std::string getRepr() const throw(INTERP_KERNEL::Exception); + virtual PartDefinition *composeWith(const PartDefinition *other) const throw(INTERP_KERNEL::Exception); + virtual void checkConsistencyLight() const throw(INTERP_KERNEL::Exception); + virtual PartDefinition *tryToSimplify() const throw(INTERP_KERNEL::Exception); + %extend + { + virtual PartDefinition *__add__(const PartDefinition& other) const throw(INTERP_KERNEL::Exception) + { + return (*self)+other; + } + + virtual PyObject *isEqual(const PartDefinition *other) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0(self->isEqual(other,ret1)); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + + virtual PyObject *deepCopy() const throw(INTERP_KERNEL::Exception) + { + return convertPartDefinition(self->deepCopy(),SWIG_POINTER_OWN | 0); + } + } + protected: + virtual ~PartDefinition(); + }; + + class DataArrayPartDefinition : public PartDefinition + { + public: + static DataArrayPartDefinition *New(DataArrayInt *listOfIds) throw(INTERP_KERNEL::Exception); + %extend + { + DataArrayPartDefinition(DataArrayInt *listOfIds) throw(INTERP_KERNEL::Exception) + { + return DataArrayPartDefinition::New(listOfIds); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->getRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; oss << "DataArrayPartDefinition C++ instance at " << self << "." << std::endl; + oss << self->getRepr(); + return oss.str(); + } + } + protected: + virtual ~DataArrayPartDefinition(); + }; + + class SlicePartDefinition : public PartDefinition + { + public: + static SlicePartDefinition *New(int start, int stop, int step) throw(INTERP_KERNEL::Exception); + int getEffectiveStop() const throw(INTERP_KERNEL::Exception); + %extend + { + SlicePartDefinition(int start, int stop, int step) throw(INTERP_KERNEL::Exception) + { + return SlicePartDefinition::New(start,stop,step); + } + + PyObject *getSlice() const throw(INTERP_KERNEL::Exception) + { + int a,b,c; + self->getSlice(a,b,c); + return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(c)); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->getRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; oss << "SlicePartDefinition C++ instance at " << self << "." << std::endl; + oss << self->getRepr(); + return oss.str(); + } + } + protected: + virtual ~SlicePartDefinition(); + }; + class DataArray : public RefCountObject, public TimeLabel { public: @@ -244,6 +398,9 @@ namespace MEDCoupling virtual DataArray *buildNewEmptyInstance() const throw(INTERP_KERNEL::Exception); virtual DataArray *selectByTupleIdSafeSlice(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); virtual void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); + virtual void circularPermutation(int nbOfShift=1) throw(INTERP_KERNEL::Exception); + virtual void circularPermutationPerTuple(int nbOfShift=1) throw(INTERP_KERNEL::Exception); + virtual void reversePerTuple() throw(INTERP_KERNEL::Exception); void checkNbOfTuples(int nbOfTuples, const std::string& msg) const throw(INTERP_KERNEL::Exception); void checkNbOfComps(int nbOfCompo, const std::string& msg) const throw(INTERP_KERNEL::Exception); void checkNbOfTuplesAndComp(const DataArray& other, const std::string& msg) const throw(INTERP_KERNEL::Exception); @@ -422,8 +579,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetSlice (wrap) : the input slice is invalid !"); + GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetSlice (wrap) : the input slice is invalid !"); int a,b; DataArray::GetSlice(strt,stp,step,sliceId,nbOfSlices,a,b); return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step)); @@ -434,8 +590,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArray::getSlice (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getSlice (wrap) : the input slice is invalid !"); + GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getSlice (wrap) : the input slice is invalid !"); int a,b; DataArray::GetSlice(strt,stp,step,sliceId,nbOfSlices,a,b); return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step)); @@ -446,8 +601,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !"); + GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBES(strt,stp,step,""); } @@ -456,8 +610,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); + GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,""); } @@ -473,8 +626,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBES (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !"); + GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBES(strt,stp,step,""); } @@ -483,8 +635,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBESRelative (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); + GetIndicesOfSlice(slic,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,""); } @@ -513,17 +664,205 @@ namespace MEDCoupling if(sz!=2) throw INTERP_KERNEL::Exception("DataArrayDouble.__setstate__ : invalid tuple in input ! Should be of size 2 ! Invalid overwrite of __getstate__ ?"); PyObject *a0(PyTuple_GetItem(inp,0)); - if(!PyString_Check(a0)) - throw INTERP_KERNEL::Exception(MSG); + self->setName(convertPyObjectToStr(a0,MSG)); PyObject *a1(PyTuple_GetItem(inp,1)); std::vector a1cpp; if(!fillStringVector(a1,a1cpp)) throw INTERP_KERNEL::Exception(MSG); - self->setName(PyString_AsString(a0)); self->setInfoOnComponents(a1cpp); } } }; + + class DataArrayDouble; + + class DataArrayFloat : public DataArray + { + public: + static DataArrayFloat *New(); + void fillWithValue(float val) throw(INTERP_KERNEL::Exception); + bool isEqual(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception); + bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception); + bool isUniform(float val, float eps) const throw(INTERP_KERNEL::Exception); + void pushBackSilent(float val) throw(INTERP_KERNEL::Exception); + void iota(float init=0.) throw(INTERP_KERNEL::Exception); + DataArrayFloatIterator *iterator() throw(INTERP_KERNEL::Exception); + MCAuto convertToDblArr() const throw(INTERP_KERNEL::Exception); + static DataArrayFloat *Meld(const DataArrayFloat *a1, const DataArrayFloat *a2) throw(INTERP_KERNEL::Exception); + %extend + { + DataArrayFloat() throw(INTERP_KERNEL::Exception) + { + return DataArrayFloat::New(); + } + + static DataArrayFloat *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_New(elt0,nbOfTuples,elt2); + } + + DataArrayFloat(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) + { + return MEDCoupling_DataArrayFloat_New__SWIG_1(elt0,nbOfTuples,elt2); + } + + DataArrayFloatIterator *__iter__() throw(INTERP_KERNEL::Exception) + { + return self->iterator(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->reprNotTooLong(); + } + + int __len__() const throw(INTERP_KERNEL::Exception) + { + if(self->isAllocated()) + { + return self->getNumberOfTuples(); + } + else + { + throw INTERP_KERNEL::Exception("DataArrayFloat::__len__ : Instance is NOT allocated !"); + } + } + + PyObject *getValues() const throw(INTERP_KERNEL::Exception) + { + const float *vals(self->begin()); + return convertDblArrToPyList(vals,self->getNbOfElems()); + } + + PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) + { + const float *vals(self->begin()); + int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples()); + return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + PyObject *isEqualIfNotWhy(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception) + { + std::string ret1; + bool ret0=self->isEqualIfNotWhy(other,prec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str())); + return ret; + } + + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT__getitem(self,obj); + } + + DataArrayFloat *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + return DataArrayT__setitem__(self,obj,value); + } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_iadd(trueSelf,obj,self); + } + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_isub(trueSelf,obj,self); + } + + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_imul(trueSelf,obj,self); + } + + DataArrayFloat *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayFPT_rmul(self,obj); + } + + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_idiv(trueSelf,obj,self); + } + +#ifdef WITH_NUMPY + PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug ! + { + return ToNumPyArray(self,NPY_FLOAT,"DataArrayFloat"); + } +#endif + } + }; + + class DataArrayFloatTuple; + + class DataArrayFloatIterator + { + public: + DataArrayFloatIterator(DataArrayFloat *da); + ~DataArrayFloatIterator(); + %extend + { + PyObject *next() + { + DataArrayFloatTuple *ret=self->nextt(); + if(ret) + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple,SWIG_POINTER_OWN|0); + else + { + PyErr_SetString(PyExc_StopIteration,"No more data."); + return 0; + } + } + } + }; + + class DataArrayFloatTuple + { + public: + int getNumberOfCompo() const throw(INTERP_KERNEL::Exception); + DataArrayFloat *buildDAFloat(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception); + %extend + { + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->repr(); + } + + float __float__() const throw(INTERP_KERNEL::Exception) + { + return self->floatValue(); + } + + DataArrayFloat *buildDAFloat() throw(INTERP_KERNEL::Exception) + { + return self->buildDAFloat(1,self->getNumberOfCompo()); + } + + /*PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MCAuto ret=self->buildDAFloat(1,self->getNumberOfCompo()); + MEDCoupling_DataArrayFloat____imul___(ret,0,obj); + Py_XINCREF(trueSelf); + return trueSelf; + }*/ + + PyObject *__len__() throw(INTERP_KERNEL::Exception) + { + return PyInt_FromLong(self->getNumberOfCompo()); + } + } + }; class DataArrayInt; class DataArrayDoubleIterator; @@ -555,7 +894,6 @@ namespace MEDCoupling std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception); bool isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception); - DataArrayInt *convertToIntArr() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); @@ -579,9 +917,8 @@ namespace MEDCoupling void checkNoNullValues() const throw(INTERP_KERNEL::Exception); DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const throw(INTERP_KERNEL::Exception); void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception); - double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); double getMaxValueInArray() const throw(INTERP_KERNEL::Exception); - double getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + double getMaxAbsValueInArray() const throw(INTERP_KERNEL::Exception); double getMinValueInArray() const throw(INTERP_KERNEL::Exception); int count(double value, double eps) const throw(INTERP_KERNEL::Exception); double getAverageValue() const throw(INTERP_KERNEL::Exception); @@ -592,6 +929,9 @@ namespace MEDCoupling DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromCylToCart() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromSpherToCart() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *fromCartToPolar() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *fromCartToCyl() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *fromCartToSpher() const throw(INTERP_KERNEL::Exception); DataArrayDouble *cartesianize(MEDCouplingAxisType atOfThis) const throw(INTERP_KERNEL::Exception); DataArrayDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); DataArrayDouble *determinant() const throw(INTERP_KERNEL::Exception); @@ -624,6 +964,7 @@ namespace MEDCoupling void applyFuncFast64(const std::string& func) throw(INTERP_KERNEL::Exception); DataArrayInt *findIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); DataArrayInt *findIdsNotInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); + DataArrayInt *findIdsStrictlyNegative() const throw(INTERP_KERNEL::Exception); static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); static DataArrayDouble *Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); @@ -640,112 +981,30 @@ namespace MEDCoupling void divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception); void powEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + MCAuto findIdsGreaterOrEqualTo(double val) const throw(INTERP_KERNEL::Exception); + MCAuto findIdsGreaterThan(double val) const throw(INTERP_KERNEL::Exception); + MCAuto findIdsLowerOrEqualTo(double val) const throw(INTERP_KERNEL::Exception); + MCAuto findIdsLowerThan(double val) const throw(INTERP_KERNEL::Exception); + MCAuto convertToIntArr() const throw(INTERP_KERNEL::Exception); + MCAuto selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception); + MCAuto cumSum() const throw(INTERP_KERNEL::Exception); + MCAuto convertToFloatArr() const throw(INTERP_KERNEL::Exception); %extend { DataArrayDouble() throw(INTERP_KERNEL::Exception) - { - return DataArrayDouble::New(); - } + { + return DataArrayDouble::New(); + } static DataArrayDouble *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) { - 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)"; - std::string msg(msgBase); -#ifdef WITH_NUMPY - msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)"; -#endif - msg+=" !"; - if(PyList_Check(elt0) || PyTuple_Check(elt0)) - { - if(nbOfTuples) - { - if(PyInt_Check(nbOfTuples)) - { - int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !"); - if(elt2) - { - if(PyInt_Check(elt2)) - {//DataArrayDouble.New([1.,3.,4.,5.],2,2) - int nbOfCompo=PyInt_AS_LONG(elt2); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); - MCAuto ret=DataArrayDouble::New(); - std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo); - ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg.c_str()); - } - else - {//DataArrayDouble.New([1.,3.,4.],3) - MCAuto ret=DataArrayDouble::New(); - int tmpp1=-1; - std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1); - ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else - throw INTERP_KERNEL::Exception(msg.c_str()); - } - else - {// DataArrayDouble.New([1.,3.,4.]) - MCAuto ret=DataArrayDouble::New(); - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2); - ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - return ret.retn(); - } - } - else if(PyInt_Check(elt0)) - { - int nbOfTuples1=PyInt_AS_LONG(elt0); - if(nbOfTuples1<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !"); - if(nbOfTuples) - { - if(!elt2) - { - if(PyInt_Check(nbOfTuples)) - {//DataArrayDouble.New(5,2) - int nbOfCompo=PyInt_AS_LONG(nbOfTuples); - if(nbOfCompo<0) - throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); - MCAuto ret=DataArrayDouble::New(); - ret->alloc(nbOfTuples1,nbOfCompo); - return ret.retn(); - } - else - throw INTERP_KERNEL::Exception(msg.c_str()); - } - else - throw INTERP_KERNEL::Exception(msg.c_str()); - } - else - {//DataArrayDouble.New(5) - MCAuto ret=DataArrayDouble::New(); - ret->alloc(nbOfTuples1,1); - return ret.retn(); - } - } -#ifdef WITH_NUMPY - else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL) - {//DataArrayDouble.New(numpyArray) - return BuildNewInstance(elt0,NPY_DOUBLE,&PyCallBackDataArrayDouble_RefType,"FLOAT64"); - } -#endif - else - throw INTERP_KERNEL::Exception(msg.c_str()); - throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy + return DataArrayT_New(elt0,nbOfTuples,elt2); } DataArrayDouble(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) - { - return MEDCoupling_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2); - } + { + return MEDCoupling_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2); + } void pushBackValsSilent(PyObject *li) throw(INTERP_KERNEL::Exception) { @@ -786,6 +1045,22 @@ namespace MEDCoupling } } + PyObject *asArcOfCircle() const throw(INTERP_KERNEL::Exception) + { + double center[2],radius,ang; + self->asArcOfCircle(center,radius,ang); + PyObject *ret(PyTuple_New(3)); + { + PyObject *ret0(PyList_New(2)); + PyList_SetItem(ret0,0,PyFloat_FromDouble(center[0])); + PyList_SetItem(ret0,1,PyFloat_FromDouble(center[1])); + PyTuple_SetItem(ret,0,ret0); + } + PyTuple_SetItem(ret,1,PyFloat_FromDouble(radius)); + PyTuple_SetItem(ret,2,PyFloat_FromDouble(ang)); + return ret; + } + DataArrayDoubleIterator *__iter__() throw(INTERP_KERNEL::Exception) { return self->iterator(); @@ -839,8 +1114,8 @@ namespace MEDCoupling PyObject *getValues() const throw(INTERP_KERNEL::Exception) { - const double *vals=self->getConstPointer(); - return convertDblArrToPyList(vals,self->getNbOfElems()); + const double *vals(self->begin()); + return convertDblArrToPyList(vals,self->getNbOfElems()); } #ifdef WITH_NUMPY @@ -864,12 +1139,52 @@ namespace MEDCoupling PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception) { - const double *vals=self->getConstPointer(); - int nbOfComp=self->getNumberOfComponents(); - int nbOfTuples=self->getNumberOfTuples(); - return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + const double *vals(self->begin()); + int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples()); + return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + DataArrayDouble *symmetry3DPlane(PyObject *point, PyObject *normalVector) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Python wrap of DataArrayDouble::symmetry3DPlane : "; + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const double *centerPtr(convertObjToPossibleCpp5_Safe(point,sw,val,a,aa,bb,msg,1,3,true)); + const double *vectorPtr(convertObjToPossibleCpp5_Safe(normalVector,sw,val2,a2,aa2,bb2,msg,1,3,true)); + MCAuto ret(self->symmetry3DPlane(centerPtr,vectorPtr)); + return ret.retn(); + } + + static PyObject *GiveBaseForPlane(PyObject *normalVector) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Python wrap of DataArrayDouble::GiveBaseForPlane : "; + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const double *vectorPtr(convertObjToPossibleCpp5_Safe(normalVector,sw,val,a,aa,bb,msg,1,3,true)); + double res[9]; + DataArrayDouble::GiveBaseForPlane(vectorPtr,res); + return convertDblArrToPyListOfTuple(res,3,3); } + DataArrayDouble *fromCartToCylGiven(const DataArrayDouble *coords, PyObject *center, PyObject *vector) const + { + const char msg[]="Python wrap of DataArrayDouble::fromCartToCylGiven : "; + double val,val2; + DataArrayDouble *a,*a2; + DataArrayDoubleTuple *aa,*aa2; + std::vector bb,bb2; + int sw; + const double *centerPtr=convertObjToPossibleCpp5_Safe(center,sw,val,a,aa,bb,msg,1,3,true); + const double *vectorPtr=convertObjToPossibleCpp5_Safe(vector,sw,val2,a2,aa2,bb2,msg,1,3,true); + return self->fromCartToCylGiven(coords,centerPtr,vectorPtr); + } + DataArrayDouble *renumber(PyObject *li) throw(INTERP_KERNEL::Exception) { void *da=0; @@ -978,6 +1293,16 @@ namespace MEDCoupling return ret; } + PyObject *getMaxAbsValue() const throw(INTERP_KERNEL::Exception) + { + std::size_t tmp; + double r1=self->getMaxAbsValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyFloat_FromDouble(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } + PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception) { DataArrayInt *tmp; @@ -1010,10 +1335,10 @@ namespace MEDCoupling PyObject *getMinMaxPerComponent() const throw(INTERP_KERNEL::Exception) { - int nbOfCompo=self->getNumberOfComponents(); - INTERP_KERNEL::AutoPtr tmp=new double[2*nbOfCompo]; + int nbOfCompo(self->getNumberOfComponents()); + INTERP_KERNEL::AutoPtr tmp(new double[2*nbOfCompo]); self->getMinMaxPerComponent(tmp); - PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,nbOfCompo); + PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,nbOfCompo); return ret; } @@ -1022,14 +1347,14 @@ namespace MEDCoupling int sz=self->getNumberOfComponents(); INTERP_KERNEL::AutoPtr tmp=new double[sz]; self->accumulate(tmp); - return convertDblArrToPyList(tmp,sz); + return convertDblArrToPyList(tmp,sz); } DataArrayDouble *accumulatePerChunck(PyObject *indexArr) const throw(INTERP_KERNEL::Exception) { int sw,sz,val; std::vector val2; - const int *bg=convertObjToPossibleCpp1_Safe(indexArr,sw,sz,val,val2); + const int *bg=convertIntStarLikePyObjToCppIntStar(indexArr,sw,sz,val,val2); return self->accumulatePerChunck(bg,bg+sz); } @@ -1066,13 +1391,23 @@ namespace MEDCoupling convertPyToNewIntArr3(li,tmp); self->setSelectedComponents(a,tmp); } + + PyObject *explodeComponents() const throw(INTERP_KERNEL::Exception) + { + std::vector< MCAuto > retCpp(self->explodeComponents()); + std::size_t sz(retCpp.size()); + PyObject *res(PyList_New(sz)); + for(std::size_t i=0;igetNumberOfComponents(); INTERP_KERNEL::AutoPtr tmp=new double[sz]; self->getTuple(tupleId,tmp); - return convertDblArrToPyList(tmp,sz); + return convertDblArrToPyList(tmp,sz); } static DataArrayDouble *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception) @@ -1122,454 +1457,12 @@ namespace MEDCoupling PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !"; - const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; - self->checkAllocated(); - int nbOfTuples=self->getNumberOfTuples(); - int nbOfComponents=self->getNumberOfComponents(); - int it1,ic1; - std::vector vt1,vc1; - std::pair > pt1,pc1; - DataArrayInt *dt1=0,*dc1=0; - int sw; - convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); - MCAuto ret; - switch(sw) - { - case 1: - if(nbOfComponents==1) - return PyFloat_FromDouble(self->getIJSafe(it1,0)); - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 2: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 3: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 4: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - case 5: - return PyFloat_FromDouble(self->getIJSafe(it1,ic1)); - case 6: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 7: - { - ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 8: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - std::vector v2(1,ic1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 9: - { - ret=self->selectByTupleIdSafe(&it1,&it1+1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 10: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 11: - { - ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 12: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 13: - { - ret=self->selectByTupleIdSafe(&it1,&it1+1); - int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 14: - { - ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 15: - { - ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second); - int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - case 16: - { - ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2); - std::vector v2(nbOfComp); - for(int i=0;ikeepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ); - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT__getitem(self,obj); } DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) { - self->checkAllocated(); - const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !"; - int nbOfTuples=self->getNumberOfTuples(); - int nbOfComponents=self->getNumberOfComponents(); - int sw1,sw2; - double i1; - std::vector v1; - DataArrayDouble *d1=0; - convertObjToPossibleCpp4(value,sw1,i1,v1,d1); - int it1,ic1; - std::vector vt1,vc1; - std::pair > pt1,pc1; - DataArrayInt *dt1=0,*dc1=0; - convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1); - MCAuto tmp; - switch(sw2) - { - case 1: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 2: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 3: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 4: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 5: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 6: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 7: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 8: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 9: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 10: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 11: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 12: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false); - return self; - case 3: - self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size()); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 13: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 14: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 15: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - case 16: - { - switch(sw1) - { - case 1: - self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - case 2: - tmp=DataArrayDouble::New(); - tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size()); - self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false); - return self; - case 3: - self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second); - return self; - default: - throw INTERP_KERNEL::Exception(msg); - } - break; - } - default: - throw INTERP_KERNEL::Exception(msg); - } - return self; + return DataArrayT__setitem__(self,obj,value); } DataArrayDouble *__neg__() const throw(INTERP_KERNEL::Exception) @@ -1603,7 +1496,7 @@ namespace MEDCoupling } #endif // - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -1639,71 +1532,34 @@ namespace MEDCoupling DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MCAuto ret=self->deepCopy(); - ret->applyLin(1.,val); - return ret.retn(); - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Add(self,aaa); - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Add(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } - } - - PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) - { - const char msg[]="Unexpected situation in __iadd__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: { - self->applyLin(1.,val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->addEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; + MCAuto ret=self->deepCopy(); + ret->applyLin(1.,val); + return ret.retn(); } case 3: { MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->addEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; + return DataArrayDouble::Add(self,aaa); } case 4: { MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->addEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; + return DataArrayDouble::Add(self,aaa); } default: throw INTERP_KERNEL::Exception(msg); } } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + return DataArrayT_iadd(trueSelf,obj,self); + } PyObject *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) { @@ -1731,7 +1587,7 @@ namespace MEDCoupling } #endif // - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -1767,7 +1623,7 @@ namespace MEDCoupling DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -1793,44 +1649,7 @@ namespace MEDCoupling PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __isub__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyLin(1,-val); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->substractEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->substractEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->substractEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_isub(trueSelf,obj,self); } PyObject *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -1859,7 +1678,7 @@ namespace MEDCoupling } #endif // - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -1889,76 +1708,12 @@ namespace MEDCoupling DataArrayDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __rmul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MCAuto ret=self->deepCopy(); - ret->applyLin(val,0.); - return ret.retn(); - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Multiply(self,aaa); - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Multiply(self,aaa); - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayFPT_rmul(self,obj); } PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __imul__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - self->applyLin(val,0.); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->multiplyEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->multiplyEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->multiplyEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_imul(trueSelf,obj,self); } PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -1987,7 +1742,7 @@ namespace MEDCoupling } #endif // - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -2025,7 +1780,7 @@ namespace MEDCoupling DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -2051,46 +1806,7 @@ namespace MEDCoupling PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __idiv__ !"; - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(val==0.) - throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); - self->applyLin(1./val,0.); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 2: - { - self->divideEqual(a); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 3: - { - MCAuto aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - self->divideEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - case 4: - { - MCAuto aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - self->divideEqual(aaa); - Py_XINCREF(trueSelf); - return trueSelf; - } - default: - throw INTERP_KERNEL::Exception(msg); - } + return DataArrayT_idiv(trueSelf,obj,self); } DataArrayDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -2101,7 +1817,7 @@ namespace MEDCoupling DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -2137,7 +1853,7 @@ namespace MEDCoupling DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -2169,7 +1885,7 @@ namespace MEDCoupling DataArrayDoubleTuple *aa; std::vector bb; int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb); switch(sw) { case 1: @@ -2223,59 +1939,6 @@ namespace MEDCoupling PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } - - // serialization - static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception) - { - static const char MSG[]="DataArrayDouble.__new__ : the args in input is expected to be a tuple !"; - if(!PyTuple_Check(args)) - throw INTERP_KERNEL::Exception(MSG); - PyObject *builtinsd(PyEval_GetBuiltins());//borrowed - PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed - PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__")); - // - PyObject *tmp0(PyTuple_New(1)); - PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls); - PyObject *instance(PyObject_CallObject(selfMeth,tmp0)); - Py_DECREF(tmp0); - Py_DECREF(selfMeth); - PyObject *initMeth(PyObject_GetAttrString(instance,"__init__")); - int sz(PyTuple_Size(args)); - - if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 ) - {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ ! - PyObject *zeNumpyRepr(0); - PyObject *tmp1(PyInt_FromLong(0)); - zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed - Py_DECREF(tmp1); - PyObject *tmp3(PyTuple_New(1)); - PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr); - PyObject *tmp2(PyObject_CallObject(initMeth,tmp3)); - Py_XDECREF(tmp2); - Py_DECREF(tmp3); - } - Py_DECREF(initMeth); - return instance; - } - - PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception) - { -#ifdef WITH_NUMPY - if(!self->isAllocated()) - throw INTERP_KERNEL::Exception("PyWrap of DataArrayDouble.__getnewargs__ : self is not allocated !"); - PyObject *ret(PyTuple_New(1)); - PyObject *ret0(PyDict_New()); - PyObject *numpyArryObj(MEDCoupling_DataArrayDouble_toNumPyArray(self)); - {// create a dict to discriminite in __new__ if __init__ should be called. Not beautiful but not idea ... - PyObject *tmp1(PyInt_FromLong(0)); - PyDict_SetItem(ret0,tmp1,numpyArryObj); Py_DECREF(tmp1); Py_DECREF(numpyArryObj); - PyTuple_SetItem(ret,0,ret0); - } - return ret; -#else - throw INTERP_KERNEL::Exception("PyWrap of DataArrayDouble.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !"); -#endif - } } }; @@ -2371,7 +2034,7 @@ namespace MEDCoupling MEDCoupling::DataArrayInt *daIntTyypp=0; const double *pt=self->getConstPointer(); int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: @@ -2435,13 +2098,13 @@ namespace MEDCoupling std::vector multiValV; MEDCoupling::DataArrayDoubleTuple *daIntTyyppV=0; int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp44(value,sw1,singleValV,multiValV,daIntTyyppV); + convertDoubleStarLikePyObjToCpp(value,sw1,singleValV,multiValV,daIntTyyppV); int singleVal; std::vector multiVal; std::pair > slic; MEDCoupling::DataArrayInt *daIntTyypp=0; double *pt=self->getPointer(); - convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); + convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); switch(sw2) { case 1: @@ -2618,7 +2281,8 @@ namespace MEDCoupling DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const throw(INTERP_KERNEL::Exception); DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const throw(INTERP_KERNEL::Exception); DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *convertToDblArr() const throw(INTERP_KERNEL::Exception); + MCAuto< MapII > invertArrayN2O2O2NOptimized() const throw(INTERP_KERNEL::Exception); + DataArrayInt *indicesOfSubPart(const DataArrayInt& partOfThis) const throw(INTERP_KERNEL::Exception); DataArrayInt *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayInt *toNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayInt *selectByTupleIdSafeSlice(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); @@ -2626,6 +2290,7 @@ namespace MEDCoupling DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception); bool isIota(int sizeExpected) const throw(INTERP_KERNEL::Exception); bool isUniform(int val) const throw(INTERP_KERNEL::Exception); + int checkUniformAndGuess() const throw(INTERP_KERNEL::Exception); bool hasUniqueValues() const throw(INTERP_KERNEL::Exception); DataArrayInt *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); @@ -2658,9 +2323,8 @@ namespace MEDCoupling bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); int count(int value) const throw(INTERP_KERNEL::Exception); int accumulate(int compId) const throw(INTERP_KERNEL::Exception); - int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); int getMaxValueInArray() const throw(INTERP_KERNEL::Exception); - int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); + int getMaxAbsValueInArray() const throw(INTERP_KERNEL::Exception); int getMinValueInArray() const throw(INTERP_KERNEL::Exception); void abs() throw(INTERP_KERNEL::Exception); DataArrayInt *computeAbs() const throw(INTERP_KERNEL::Exception); @@ -2675,7 +2339,7 @@ namespace MEDCoupling void applyRPow(int val) throw(INTERP_KERNEL::Exception); DataArrayInt *findIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception); DataArrayInt *findIdsNotInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception); - DataArrayInt *findIdsStricltyNegative() const throw(INTERP_KERNEL::Exception); + DataArrayInt *findIdsStrictlyNegative() const throw(INTERP_KERNEL::Exception); bool checkAllIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception); static DataArrayInt *Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2) throw(INTERP_KERNEL::Exception); static DataArrayInt *Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); @@ -2711,6 +2375,14 @@ namespace MEDCoupling void modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); void powEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); + MCAuto fromLinkedListOfPairToList() const throw(INTERP_KERNEL::Exception); + MCAuto findIdsGreaterOrEqualTo(int val) const throw(INTERP_KERNEL::Exception); + MCAuto findIdsGreaterThan(int val) const throw(INTERP_KERNEL::Exception); + MCAuto findIdsLowerOrEqualTo(int val) const throw(INTERP_KERNEL::Exception); + MCAuto findIdsLowerThan(int val) const throw(INTERP_KERNEL::Exception); + MCAuto selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception); + MCAuto convertToDblArr() const throw(INTERP_KERNEL::Exception); + MCAuto convertToFloatArr() const throw(INTERP_KERNEL::Exception); public: static DataArrayInt *Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception); %extend @@ -2819,7 +2491,7 @@ namespace MEDCoupling { return MEDCoupling_DataArrayInt_New__SWIG_1(elt0,nbOfTuples,nbOfComp); } - + std::string __str__() const throw(INTERP_KERNEL::Exception) { return self->reprNotTooLong(); @@ -2859,7 +2531,7 @@ namespace MEDCoupling { int sw,sz,val; std::vector val2; - const int *bg=convertObjToPossibleCpp1_Safe(indexArr,sw,sz,val,val2); + const int *bg=convertIntStarLikePyObjToCppIntStar(indexArr,sw,sz,val,val2); return self->accumulatePerChunck(bg,bg+sz); } @@ -2867,10 +2539,19 @@ namespace MEDCoupling { int sw,sz,val; std::vector val2; - const int *bg(convertObjToPossibleCpp1_Safe(inputTuple,sw,sz,val,val2)); + const int *bg(convertIntStarLikePyObjToCppIntStar(inputTuple,sw,sz,val,val2)); return self->findIdsEqualTuple(bg,bg+sz); } + DataArrayInt *findIdForEach(PyObject *vals) const throw(INTERP_KERNEL::Exception) + { + int sw,sz,val; + std::vector val2; + const int *bg(convertIntStarLikePyObjToCppIntStar(vals,sw,sz,val,val2)); + MCAuto ret(self->findIdForEach(bg,bg+sz)); + return ret.retn(); + } + PyObject *splitInBalancedSlices(int nbOfSlices) const throw(INTERP_KERNEL::Exception) { std::vector< std::pair > slcs(self->splitInBalancedSlices(nbOfSlices)); @@ -2885,8 +2566,7 @@ namespace MEDCoupling if(!PySlice_Check(slic)) throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : expecting a pyslice as second (first) parameter !"); Py_ssize_t strt=2,stp=2,step=2; - PySliceObject *sly=reinterpret_cast(slic); - GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice is invalid !"); + GetIndicesOfSliceExplicitely(slic,&strt,&stp,&step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice is invalid !"); if(strt==std::numeric_limits::max() || stp==std::numeric_limits::max()) throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice contains some unknowns that can't be determined in static method ! Call DataArray::getSlice (non static) instead !"); return self->buildExplicitArrOfSliceOnScaledArr(strt,stp,step); @@ -2907,8 +2587,8 @@ namespace MEDCoupling int newNbOfTuples=-1; int szArr,szArrI,sw,iTypppArr,iTypppArrI; std::vector stdvecTyyppArr,stdvecTyyppArrI; - const int *arrPtr=convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr); - const int *arrIPtr=convertObjToPossibleCpp1_Safe(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI); + const int *arrPtr=convertIntStarLikePyObjToCppIntStar(arr,sw,szArr,iTypppArr,stdvecTyyppArr); + const int *arrIPtr=convertIntStarLikePyObjToCppIntStar(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI); DataArrayInt *ret0=MEDCoupling::DataArrayInt::ConvertIndexArrayToO2N(nbOfOldTuples,arrPtr,arrIPtr,arrIPtr+szArrI,newNbOfTuples); PyObject *ret=PyTuple_New(2); PyTuple_SetItem(ret,0,SWIG_NewPointerObj((void*)ret0,SWIGTYPE_p_MEDCoupling__DataArrayInt,SWIG_POINTER_OWN | 0)); @@ -2921,7 +2601,7 @@ namespace MEDCoupling MCAuto ret(DataArrayInt::New()); int szArr,sw,iTypppArr; std::vector stdvecTyyppArr; - const int *arrPtr(convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr)); + const int *arrPtr(convertIntStarLikePyObjToCppIntStar(arr,sw,szArr,iTypppArr,stdvecTyyppArr)); int *pt(MEDCoupling::DataArrayInt::CheckAndPreparePermutation(arrPtr,arrPtr+szArr)); ret->useArray(pt,true,MEDCoupling::C_DEALLOC,szArr,1); return ret.retn(); @@ -2932,14 +2612,14 @@ namespace MEDCoupling const char *msg="MEDCoupling::DataArrayInt::setValues : Available API are : \n-DataArrayInt.setValues([1,3,4])\n-DataArrayInt.setValues([1,3,4],3)\n-DataArrayInt.setValues([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n !"; if(PyList_Check(li) || PyTuple_Check(li)) { - if(nbOfTuples) + if(nbOfTuples && nbOfTuples != Py_None) { if(PyInt_Check(nbOfTuples)) { int nbOfTuples1=PyInt_AS_LONG(nbOfTuples); if(nbOfTuples<0) throw INTERP_KERNEL::Exception("DataArrayInt::setValue : should be a positive set of allocated memory !"); - if(nbOfComp) + if(nbOfComp && nbOfComp != Py_None) { if(PyInt_Check(nbOfComp)) {//DataArrayInt.setValues([1,3,4,5],2,2) @@ -3025,12 +2705,21 @@ namespace MEDCoupling void transformWithIndArr(PyObject *li) throw(INTERP_KERNEL::Exception) { void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 ); + int res1(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 )); if (!SWIG_IsOK(res1)) { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - self->transformWithIndArr(tmp,tmp+size); + int res2(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__MapII, 0 | 0 )); + if(SWIG_IsOK(res2)) + { + MapII *m=reinterpret_cast(da); + self->transformWithIndArr(*m); + } + else + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + self->transformWithIndArr(tmp,tmp+size); + } } else { @@ -3046,7 +2735,7 @@ namespace MEDCoupling std::vector multiVal; std::pair > slic; MEDCoupling::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); + convertIntStarOrSliceLikePyObjToCpp(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: @@ -3067,7 +2756,7 @@ namespace MEDCoupling std::vector multiVal; std::pair > slic; MEDCoupling::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); + convertIntStarOrSliceLikePyObjToCpp(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: @@ -3218,6 +2907,16 @@ namespace MEDCoupling self->setSelectedComponents(a,tmp); } + PyObject *explodeComponents() const throw(INTERP_KERNEL::Exception) + { + std::vector< MCAuto > retCpp(self->explodeComponents()); + std::size_t sz(retCpp.size()); + PyObject *res(PyList_New(sz)); + for(std::size_t i=0;igetNumberOfComponents(); @@ -3281,6 +2980,16 @@ namespace MEDCoupling PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); return ret; } + + PyObject *getMaxAbsValue(std::size_t& tupleId) const throw(INTERP_KERNEL::Exception) + { + std::size_t tmp; + int r1=self->getMaxAbsValue(tmp); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(r1)); + PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); + return ret; + } PyObject *getMinValue() const throw(INTERP_KERNEL::Exception) { @@ -3462,7 +3171,7 @@ namespace MEDCoupling std::vector v1; DataArrayInt *d1=0; DataArrayIntTuple *dd1=0; - convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1); + convertIntStarLikePyObjToCpp(value,sw1,i1,v1,d1,dd1); int it1,ic1; std::vector vt1,vc1; std::pair > pt1,pc1; @@ -3874,7 +3583,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -3910,7 +3619,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -3942,7 +3651,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -3984,7 +3693,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4020,7 +3729,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4052,7 +3761,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4094,7 +3803,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4130,7 +3839,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4162,7 +3871,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4204,7 +3913,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4240,7 +3949,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4272,7 +3981,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4314,7 +4023,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4350,7 +4059,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4386,7 +4095,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4421,7 +4130,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4457,7 +4166,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4493,7 +4202,7 @@ namespace MEDCoupling std::vector aa; DataArrayIntTuple *aaa; int sw; - convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + convertIntStarLikePyObjToCpp(obj,sw,val,aa,a,aaa); switch(sw) { case 1: @@ -4531,7 +4240,7 @@ namespace MEDCoupling { int szArr,sw,iTypppArr; std::vector stdvecTyyppArr; - const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + const int *tmp=convertIntStarLikePyObjToCppIntStar(li,sw,szArr,iTypppArr,stdvecTyyppArr); self->pushBackValsSilent(tmp,tmp+szArr); } @@ -4581,59 +4290,6 @@ namespace MEDCoupling PyTuple_SetItem(pyRet,1,ret1Py); return pyRet; } - - // serialization - static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception) - { - static const char MSG[]="DataArrayInt.__new__ : the args in input is expected to be a tuple !"; - if(!PyTuple_Check(args)) - throw INTERP_KERNEL::Exception(MSG); - PyObject *builtinsd(PyEval_GetBuiltins());//borrowed - PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed - PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__")); - // - PyObject *tmp0(PyTuple_New(1)); - PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls); - PyObject *instance(PyObject_CallObject(selfMeth,tmp0)); - Py_DECREF(tmp0); - Py_DECREF(selfMeth); - PyObject *initMeth(PyObject_GetAttrString(instance,"__init__")); - int sz(PyTuple_Size(args)); - - if(PyTuple_Size(args)==2 && PyDict_Check(PyTuple_GetItem(args,1)) && PyDict_Size(PyTuple_GetItem(args,1))==1 ) - {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ ! - PyObject *zeNumpyRepr(0); - PyObject *tmp1(PyInt_FromLong(0)); - zeNumpyRepr=PyDict_GetItem(PyTuple_GetItem(args,1),tmp1);//borrowed - Py_DECREF(tmp1); - PyObject *tmp3(PyTuple_New(1)); - PyTuple_SetItem(tmp3,0,zeNumpyRepr); Py_XINCREF(zeNumpyRepr); - PyObject *tmp2(PyObject_CallObject(initMeth,tmp3)); - Py_XDECREF(tmp2); - Py_DECREF(tmp3); - } - Py_DECREF(initMeth); - return instance; - } - - PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception) - { -#ifdef WITH_NUMPY - if(!self->isAllocated()) - throw INTERP_KERNEL::Exception("PyWrap of DataArrayInt.__getnewargs__ : self is not allocated !"); - PyObject *ret(PyTuple_New(1)); - PyObject *ret0(PyDict_New()); - PyObject *numpyArryObj(MEDCoupling_DataArrayInt_toNumPyArray(self)); - {// create a dict to discriminite in __new__ if __init__ should be called. Not beautiful but not idea ... - PyObject *tmp1(PyInt_FromLong(0)); - PyDict_SetItem(ret0,tmp1,numpyArryObj); Py_DECREF(tmp1); Py_DECREF(numpyArryObj); - PyTuple_SetItem(ret,0,ret0); - } - return ret; -#else - throw INTERP_KERNEL::Exception("PyWrap of DataArrayInt.__getnewargs__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !"); -#endif - } } }; @@ -4705,7 +4361,6 @@ namespace MEDCoupling Py_XINCREF(trueSelf); return trueSelf; } - PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { MCAuto ret=self->buildDAInt(1,self->getNumberOfCompo()); @@ -4737,7 +4392,7 @@ namespace MEDCoupling MEDCoupling::DataArrayInt *daIntTyypp=0; const int *pt=self->getConstPointer(); int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: @@ -4808,7 +4463,7 @@ namespace MEDCoupling std::pair > slic; MEDCoupling::DataArrayInt *daIntTyypp=0; int *pt=self->getPointer(); - convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); + convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); switch(sw2) { case 1: @@ -4976,7 +4631,7 @@ namespace MEDCoupling DataArrayChar *subArray(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); DataArrayChar *changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception); void meldWith(const DataArrayChar *other) throw(INTERP_KERNEL::Exception); - void setPartOfValuesAdv(const DataArrayChar *a, const DataArrayChar *tuplesSelec) throw(INTERP_KERNEL::Exception); + void setPartOfValuesAdv(const DataArrayChar *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); char front() const throw(INTERP_KERNEL::Exception); char back() const throw(INTERP_KERNEL::Exception); void setIJ(int tupleId, int compoId, char newVal) throw(INTERP_KERNEL::Exception); @@ -5217,6 +4872,12 @@ namespace MEDCoupling return ret.retn(); } } +#ifdef WITH_NUMPY + else if(PyArray_Check(elt0) && nbOfTuples==NULL && nbOfComp==NULL) + {//DataArrayDouble.New(numpyArray) + return BuildNewInstance(elt0,NPY_INT8,&PyCallBackDataArrayChar_RefType,"INT8"); + } +#endif else throw INTERP_KERNEL::Exception(msg); } @@ -5270,7 +4931,7 @@ namespace MEDCoupling { int sz=-1,sw=-1; int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); + const int *pt=convertIntStarLikePyObjToCppIntStar(tupl,sw,sz,ival,ivval); std::vector vals(sz); std::copy(pt,pt+sz,vals.begin()); return self->presenceOfTuple(vals); @@ -5280,7 +4941,7 @@ namespace MEDCoupling { int sz=-1,sw=-1; int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); + const int *pt=convertIntStarLikePyObjToCppIntStar(vals,sw,sz,ival,ivval); std::vector vals2(sz); std::copy(pt,pt+sz,vals2.begin()); return self->presenceOfValue(vals2); @@ -5290,7 +4951,7 @@ namespace MEDCoupling { int sz=-1,sw=-1; int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(vals,sw,sz,ival,ivval); + const int *pt=convertIntStarLikePyObjToCppIntStar(vals,sw,sz,ival,ivval); std::vector vals2(sz); std::copy(pt,pt+sz,vals2.begin()); return self->findIdFirstEqual(vals2); @@ -5300,7 +4961,7 @@ namespace MEDCoupling { int sz=-1,sw=-1; int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(tupl,sw,sz,ival,ivval); + const int *pt=convertIntStarLikePyObjToCppIntStar(tupl,sw,sz,ival,ivval); std::vector vals(sz); std::copy(pt,pt+sz,vals.begin()); return self->findIdFirstEqualTuple(vals); @@ -5310,7 +4971,7 @@ namespace MEDCoupling { int sz=-1,sw=-1; int ival=-1; std::vector ivval; - const int *pt=convertObjToPossibleCpp1_Safe(strOrListOfInt,sw,sz,ival,ivval); + const int *pt=convertIntStarLikePyObjToCppIntStar(strOrListOfInt,sw,sz,ival,ivval); std::vector vals(sz); std::copy(pt,pt+sz,vals.begin()); return self->findIdSequence(vals); @@ -5387,6 +5048,13 @@ namespace MEDCoupling return MEDCoupling_DataArrayByte_presenceOfTuple(self,obj); } } + +#ifdef WITH_NUMPY + PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug ! + { + return ToNumPyArray(self,NPY_INT8,"DataArrayByte"); + } +#endif DataArrayByte *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) { @@ -5398,7 +5066,7 @@ namespace MEDCoupling std::vector v1; DataArrayInt *d1=0; DataArrayIntTuple *dd1=0; - convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1); + convertIntStarLikePyObjToCpp(value,sw1,i1,v1,d1,dd1); int it1,ic1; std::vector vt1,vc1; std::pair > pt1,pc1; @@ -5703,6 +5371,19 @@ namespace MEDCoupling else throw INTERP_KERNEL::Exception(msg); } +%#if PY_VERSION_HEX >= 0x03000000 + else if(PyUnicode_Check(nbOfTuples)) + { + if(PyUnicode_GET_LENGTH(nbOfTuples)!=1) + throw INTERP_KERNEL::Exception(msg); + //DataArrayAsciiChar.New(["abc","de","fghi"],"t") + std::vector tmp; + if(fillStringVector(elt0,tmp)) + return DataArrayAsciiChar::New(tmp,PyUnicode_AsUTF8(nbOfTuples)[0]); + else + throw INTERP_KERNEL::Exception(msg); + } +%#endif else throw INTERP_KERNEL::Exception(msg); } @@ -5811,6 +5492,15 @@ namespace MEDCoupling std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); return self->presenceOfTuple(vals); } +%#if PY_VERSION_HEX >= 0x03000000 + else if(PyUnicode_Check(tupl)) + { + Py_ssize_t sz=PyUnicode_GET_LENGTH(tupl); + std::vector vals(sz); + std::copy(PyUnicode_AsUTF8(tupl),PyUnicode_AsUTF8(tupl)+sz,vals.begin()); + return self->presenceOfTuple(vals); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfTuple : only strings in input supported !"); } @@ -5824,6 +5514,15 @@ namespace MEDCoupling std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); return self->presenceOfValue(vals2); } +%#if PY_VERSION_HEX >= 0x03000000 + if(PyUnicode_Check(vals)) + { + Py_ssize_t sz=PyUnicode_GET_LENGTH(vals); + std::vector vals2(sz); + std::copy(PyUnicode_AsUTF8(vals),PyUnicode_AsUTF8(vals)+sz,vals2.begin()); + return self->presenceOfValue(vals2); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::presenceOfValue : only strings in input supported !"); } @@ -5837,6 +5536,15 @@ namespace MEDCoupling std::copy(PyString_AsString(vals),PyString_AsString(vals)+sz,vals2.begin()); return self->findIdFirstEqual(vals2); } +%#if PY_VERSION_HEX >= 0x03000000 + if(PyUnicode_Check(vals)) + { + Py_ssize_t sz=PyUnicode_GET_LENGTH(vals); + std::vector vals2(sz); + std::copy(PyUnicode_AsUTF8(vals),PyUnicode_AsUTF8(vals)+sz,vals2.begin()); + return self->findIdFirstEqual(vals2); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::findIdFirstEqual : only strings in input supported !"); } @@ -5850,6 +5558,15 @@ namespace MEDCoupling std::copy(PyString_AsString(tupl),PyString_AsString(tupl)+sz,vals.begin()); return self->findIdFirstEqualTuple(vals); } +%#if PY_VERSION_HEX >= 0x03000000 + if(PyUnicode_Check(tupl)) + { + Py_ssize_t sz=PyUnicode_GET_LENGTH(tupl); + std::vector vals(sz); + std::copy(PyUnicode_AsUTF8(tupl),PyUnicode_AsUTF8(tupl)+sz,vals.begin()); + return self->findIdFirstEqualTuple(vals); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::findIdFirstEqualTuple : only strings in input supported !"); } @@ -5863,6 +5580,15 @@ namespace MEDCoupling std::copy(PyString_AsString(strOrListOfInt),PyString_AsString(strOrListOfInt)+sz,vals.begin()); return self->findIdSequence(vals); } +%#if PY_VERSION_HEX >= 0x03000000 + else if(PyUnicode_Check(strOrListOfInt)) + { + Py_ssize_t sz=PyUnicode_GET_LENGTH(strOrListOfInt); + std::vector vals(sz); + std::copy(PyUnicode_AsUTF8(strOrListOfInt),PyUnicode_AsUTF8(strOrListOfInt)+sz,vals.begin()); + return self->findIdSequence(vals); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !"); } @@ -5913,6 +5639,17 @@ namespace MEDCoupling else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !"); } +%#if PY_VERSION_HEX >= 0x03000000 + if(PyUnicode_Check(obj)) + { + Py_ssize_t sz; + char *pt=PyUnicode_AsUTF8AndSize(obj, &sz); + if(sz==1) + return self->findIdFirstEqual(pt[0]); + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find a string with size different from 1 !"); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::index : 'this' contains one component and trying to find an element which is not an integer !"); } @@ -5939,6 +5676,17 @@ namespace MEDCoupling else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !"); } +%#if PY_VERSION_HEX >= 0x03000000 + if(PyUnicode_Check(obj)) + { + Py_ssize_t sz; + char *pt=PyUnicode_AsUTF8AndSize(obj, &sz); + if(sz==1) + return self->presenceOfValue(pt[0]); + else + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find a string with size different from 1 !"); + } +%#endif else throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__contains__ : 'this' contains one component and trying to find an element which is not an integer !"); } @@ -5953,7 +5701,7 @@ namespace MEDCoupling std::vector stdvecTyyppArr; std::pair > sTyyppArr; MEDCoupling::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2WithNegIntInterp(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); switch(sw) { case 1: @@ -5978,7 +5726,7 @@ namespace MEDCoupling MEDCoupling::DataArrayInt *daIntTyypp=0; int nbOfCompo=self->getNumberOfComponents(); int nbOfTuples=self->getNumberOfTuples(); - convertObjToPossibleCpp2WithNegIntInterp(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + convertIntStarOrSliceLikePyObjToCppWithNegIntInterp(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); int sw2; char vc; std::string sc; std::vector vsc; DataArrayChar *dacc=0; convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc); @@ -6171,3 +5919,32 @@ namespace MEDCoupling } }; } + +%pythoncode %{ +def MEDCouplingStdReduceFunct(cls,params): + a,b=params + ret=object.__new__(cls) + ret.__init__(*a) + ret.__setstate__(b) + return ret + +def MEDCouplingDataArrayDoubleReduce(self): + if not MEDCouplingHasNumPyBindings(): + raise InterpKernelException("PyWrap of DataArrayDouble.__reduce__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !") + return MEDCouplingStdReduceFunct,(DataArrayDouble,((self.toNumPyArray(),),(self.__getstate__()),)) + +def MEDCouplingDataArrayIntReduce(self): + if not MEDCouplingHasNumPyBindings(): + raise InterpKernelException("PyWrap of DataArrayInt.__reduce__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !") + return MEDCouplingStdReduceFunct,(DataArrayInt,((self.toNumPyArray(),),(self.__getstate__()),)) + +def MEDCouplingDataArrayByteReduce(self): + if not MEDCouplingHasNumPyBindings(): + raise InterpKernelException("PyWrap of DataArrayByte.__reduce__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !") + return MEDCouplingStdReduceFunct,(DataArrayByte,((self.toNumPyArray(),),(self.__getstate__()),)) + +def MEDCouplingDataArrayFloatReduce(self): + if not MEDCouplingHasNumPyBindings(): + raise InterpKernelException("PyWrap of DataArrayFloat.__reduce__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !") + return MEDCouplingStdReduceFunct,(DataArrayFloat,((self.toNumPyArray(),),(self.__getstate__()),)) +%}