X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingMemArray.i;h=3e4010867a2cb4537847020b86776a334c68ed88;hb=56e7b97b6270ad0b2d523070f937e0b8ebae0d30;hp=620c02a0f48530b1dc45354860958a4c3566bdd6;hpb=d841bf0f548baf1321a64cad715c7dff9110dd3b;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 620c02a0f..3e4010867 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,18 +18,201 @@ // // Author : Anthony Geay (CEA/DEN) +//////////////////// +%typemap(out) ParaMEDMEM::DataArray* +{ + $result=convertDataArray($1,$owner); +} + +%typemap(out) DataArray* +{ + $result=convertDataArray($1,$owner); +} +//$$$$$$$$$$$$$$$$$$ + +//////////////////// +%typemap(out) ParaMEDMEM::DataArrayChar* +{ + $result=convertDataArrayChar($1,$owner); +} + +%typemap(out) DataArrayChar* +{ + $result=convertDataArrayChar($1,$owner); +} +//$$$$$$$$$$$$$$$$$$ + +%newobject ParaMEDMEM::DataArray::deepCpy; +%newobject ParaMEDMEM::DataArray::selectByTupleRanges; +%newobject ParaMEDMEM::DataArray::selectByTupleId; +%newobject ParaMEDMEM::DataArray::selectByTupleIdSafe; +%newobject ParaMEDMEM::DataArray::selectByTupleId2; +%newobject ParaMEDMEM::DataArray::Aggregate; +%newobject ParaMEDMEM::DataArrayInt::New; +%newobject ParaMEDMEM::DataArrayInt::__iter__; +%newobject ParaMEDMEM::DataArrayInt::convertToDblArr; +%newobject ParaMEDMEM::DataArrayInt::performCpy; +%newobject ParaMEDMEM::DataArrayInt::substr; +%newobject ParaMEDMEM::DataArrayInt::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayInt::accumulatePerChunck; +%newobject ParaMEDMEM::DataArrayInt::checkAndPreparePermutation; +%newobject ParaMEDMEM::DataArrayInt::transformWithIndArrR; +%newobject ParaMEDMEM::DataArrayInt::renumber; +%newobject ParaMEDMEM::DataArrayInt::renumberR; +%newobject ParaMEDMEM::DataArrayInt::renumberAndReduce; +%newobject ParaMEDMEM::DataArrayInt::invertArrayO2N2N2O; +%newobject ParaMEDMEM::DataArrayInt::invertArrayN2O2O2N; +%newobject ParaMEDMEM::DataArrayInt::invertArrayO2N2N2OBis; +%newobject ParaMEDMEM::DataArrayInt::getIdsEqual; +%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqual; +%newobject ParaMEDMEM::DataArrayInt::getIdsEqualList; +%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList; +%newobject ParaMEDMEM::DataArrayInt::getIdsEqualTuple; +%newobject ParaMEDMEM::DataArrayInt::sumPerTuple; +%newobject ParaMEDMEM::DataArrayInt::negate; +%newobject ParaMEDMEM::DataArrayInt::computeAbs; +%newobject ParaMEDMEM::DataArrayInt::getIdsInRange; +%newobject ParaMEDMEM::DataArrayInt::getIdsNotInRange; +%newobject ParaMEDMEM::DataArrayInt::getIdsStrictlyNegative; +%newobject ParaMEDMEM::DataArrayInt::Aggregate; +%newobject ParaMEDMEM::DataArrayInt::AggregateIndexes; +%newobject ParaMEDMEM::DataArrayInt::Meld; +%newobject ParaMEDMEM::DataArrayInt::Add; +%newobject ParaMEDMEM::DataArrayInt::Substract; +%newobject ParaMEDMEM::DataArrayInt::Multiply; +%newobject ParaMEDMEM::DataArrayInt::Divide; +%newobject ParaMEDMEM::DataArrayInt::Pow; +%newobject ParaMEDMEM::DataArrayInt::BuildUnion; +%newobject ParaMEDMEM::DataArrayInt::BuildIntersection; +%newobject ParaMEDMEM::DataArrayInt::Range; +%newobject ParaMEDMEM::DataArrayInt::fromNoInterlace; +%newobject ParaMEDMEM::DataArrayInt::toNoInterlace; +%newobject ParaMEDMEM::DataArrayInt::buildComplement; +%newobject ParaMEDMEM::DataArrayInt::buildUnion; +%newobject ParaMEDMEM::DataArrayInt::buildSubstraction; +%newobject ParaMEDMEM::DataArrayInt::buildSubstractionOptimized; +%newobject ParaMEDMEM::DataArrayInt::buildIntersection; +%newobject ParaMEDMEM::DataArrayInt::buildUnique; +%newobject ParaMEDMEM::DataArrayInt::buildUniqueNotSorted; +%newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; +%newobject ParaMEDMEM::DataArrayInt::buildExplicitArrByRanges; +%newobject ParaMEDMEM::DataArrayInt::buildExplicitArrOfSliceOnScaledArr; +%newobject ParaMEDMEM::DataArrayInt::findRangeIdForEachTuple; +%newobject ParaMEDMEM::DataArrayInt::findIdInRangeForEachTuple; +%newobject ParaMEDMEM::DataArrayInt::duplicateEachTupleNTimes; +%newobject ParaMEDMEM::DataArrayInt::buildPermutationArr; +%newobject ParaMEDMEM::DataArrayInt::buildPermArrPerLevel; +%newobject ParaMEDMEM::DataArrayInt::getDifferentValues; +%newobject ParaMEDMEM::DataArrayInt::FindPermutationFromFirstToSecond; +%newobject ParaMEDMEM::DataArrayInt::CheckAndPreparePermutation; +%newobject ParaMEDMEM::DataArrayInt::__neg__; +%newobject ParaMEDMEM::DataArrayInt::__add__; +%newobject ParaMEDMEM::DataArrayInt::__radd__; +%newobject ParaMEDMEM::DataArrayInt::__sub__; +%newobject ParaMEDMEM::DataArrayInt::__rsub__; +%newobject ParaMEDMEM::DataArrayInt::__mul__; +%newobject ParaMEDMEM::DataArrayInt::__rmul__; +%newobject ParaMEDMEM::DataArrayInt::__div__; +%newobject ParaMEDMEM::DataArrayInt::__rdiv__; +%newobject ParaMEDMEM::DataArrayInt::__mod__; +%newobject ParaMEDMEM::DataArrayInt::__rmod__; +%newobject ParaMEDMEM::DataArrayInt::__pow__; +%newobject ParaMEDMEM::DataArrayInt::__rpow__; +%newobject ParaMEDMEM::DataArrayIntTuple::buildDAInt; +%newobject ParaMEDMEM::DataArrayChar::convertToIntArr; +%newobject ParaMEDMEM::DataArrayChar::renumber; +%newobject ParaMEDMEM::DataArrayChar::renumberR; +%newobject ParaMEDMEM::DataArrayChar::renumberAndReduce; +%newobject ParaMEDMEM::DataArrayChar::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayChar::getIdsEqual; +%newobject ParaMEDMEM::DataArrayChar::getIdsNotEqual; +%newobject ParaMEDMEM::DataArrayChar::Aggregate; +%newobject ParaMEDMEM::DataArrayChar::Meld; +%newobject ParaMEDMEM::DataArrayByte::New; +%newobject ParaMEDMEM::DataArrayByte::__iter__; +%newobject ParaMEDMEM::DataArrayByte::performCpy; +%newobject ParaMEDMEM::DataArrayByteTuple::buildDAByte; +%newobject ParaMEDMEM::DataArrayChar::substr; +%newobject ParaMEDMEM::DataArrayAsciiChar::New; +%newobject ParaMEDMEM::DataArrayAsciiChar::__iter__; +%newobject ParaMEDMEM::DataArrayAsciiChar::performCpy; +%newobject ParaMEDMEM::DataArrayAsciiCharTuple::buildDAAsciiChar; +%newobject ParaMEDMEM::DataArrayDouble::New; +%newobject ParaMEDMEM::DataArrayDouble::__iter__; +%newobject ParaMEDMEM::DataArrayDouble::convertToIntArr; +%newobject ParaMEDMEM::DataArrayDouble::performCpy; +%newobject ParaMEDMEM::DataArrayDouble::Aggregate; +%newobject ParaMEDMEM::DataArrayDouble::Meld; +%newobject ParaMEDMEM::DataArrayDouble::Dot; +%newobject ParaMEDMEM::DataArrayDouble::CrossProduct; +%newobject ParaMEDMEM::DataArrayDouble::Add; +%newobject ParaMEDMEM::DataArrayDouble::Substract; +%newobject ParaMEDMEM::DataArrayDouble::Multiply; +%newobject ParaMEDMEM::DataArrayDouble::Divide; +%newobject ParaMEDMEM::DataArrayDouble::Pow; +%newobject ParaMEDMEM::DataArrayDouble::substr; +%newobject ParaMEDMEM::DataArrayDouble::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayDouble::accumulatePerChunck; +%newobject ParaMEDMEM::DataArrayDouble::getIdsInRange; +%newobject ParaMEDMEM::DataArrayDouble::getIdsNotInRange; +%newobject ParaMEDMEM::DataArrayDouble::negate; +%newobject ParaMEDMEM::DataArrayDouble::computeAbs; +%newobject ParaMEDMEM::DataArrayDouble::applyFunc; +%newobject ParaMEDMEM::DataArrayDouble::applyFunc2; +%newobject ParaMEDMEM::DataArrayDouble::applyFunc3; +%newobject ParaMEDMEM::DataArrayDouble::doublyContractedProduct; +%newobject ParaMEDMEM::DataArrayDouble::determinant; +%newobject ParaMEDMEM::DataArrayDouble::eigenValues; +%newobject ParaMEDMEM::DataArrayDouble::eigenVectors; +%newobject ParaMEDMEM::DataArrayDouble::inverse; +%newobject ParaMEDMEM::DataArrayDouble::trace; +%newobject ParaMEDMEM::DataArrayDouble::deviator; +%newobject ParaMEDMEM::DataArrayDouble::magnitude; +%newobject ParaMEDMEM::DataArrayDouble::maxPerTuple; +%newobject ParaMEDMEM::DataArrayDouble::sumPerTuple; +%newobject ParaMEDMEM::DataArrayDouble::computeBBoxPerTuple; +%newobject ParaMEDMEM::DataArrayDouble::buildEuclidianDistanceDenseMatrix; +%newobject ParaMEDMEM::DataArrayDouble::buildEuclidianDistanceDenseMatrixWith; +%newobject ParaMEDMEM::DataArrayDouble::renumber; +%newobject ParaMEDMEM::DataArrayDouble::renumberR; +%newobject ParaMEDMEM::DataArrayDouble::renumberAndReduce; +%newobject ParaMEDMEM::DataArrayDouble::fromNoInterlace; +%newobject ParaMEDMEM::DataArrayDouble::toNoInterlace; +%newobject ParaMEDMEM::DataArrayDouble::fromPolarToCart; +%newobject ParaMEDMEM::DataArrayDouble::fromCylToCart; +%newobject ParaMEDMEM::DataArrayDouble::fromSpherToCart; +%newobject ParaMEDMEM::DataArrayDouble::getDifferentValues; +%newobject ParaMEDMEM::DataArrayDouble::findClosestTupleId; +%newobject ParaMEDMEM::DataArrayDouble::computeNbOfInteractionsWith; +%newobject ParaMEDMEM::DataArrayDouble::duplicateEachTupleNTimes; +%newobject ParaMEDMEM::DataArrayDouble::__neg__; +%newobject ParaMEDMEM::DataArrayDouble::__radd__; +%newobject ParaMEDMEM::DataArrayDouble::__rsub__; +%newobject ParaMEDMEM::DataArrayDouble::__rmul__; +%newobject ParaMEDMEM::DataArrayDouble::__rdiv__; +%newobject ParaMEDMEM::DataArrayDouble::__pow__; +%newobject ParaMEDMEM::DataArrayDouble::__rpow__; +%newobject ParaMEDMEM::DataArrayDoubleTuple::buildDADouble; + +%feature("unref") DataArray "$this->decrRef();" +%feature("unref") DataArrayDouble "$this->decrRef();" +%feature("unref") DataArrayInt "$this->decrRef();" +%feature("unref") DataArrayChar "$this->decrRef();" +%feature("unref") DataArrayAsciiChar "$this->decrRef();" +%feature("unref") DataArrayByte "$this->decrRef();" + namespace ParaMEDMEM { class DataArray : public RefCountObject, public TimeLabel { public: - void setName(const char *name); + void setName(const std::string& name); void copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception); void copyPartOfStringInfoFrom(const DataArray& other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); void copyPartOfStringInfoFrom2(const std::vector& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception); bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const throw(INTERP_KERNEL::Exception); bool areInfoEquals(const DataArray& other) const throw(INTERP_KERNEL::Exception); - std::string cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception); + std::string cppRepr(const std::string& varName) const throw(INTERP_KERNEL::Exception); std::string getName() const; void setInfoOnComponents(const std::vector& info) throw(INTERP_KERNEL::Exception); void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); @@ -38,7 +221,7 @@ namespace ParaMEDMEM std::string getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception); std::string getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception); std::string getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception); - void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception); + void setInfoOnComponent(int i, const std::string& info) throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const; virtual void alloc(int nbOfTuple, int nbOfCompo=1) throw(INTERP_KERNEL::Exception); virtual void reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception); @@ -48,16 +231,20 @@ namespace ParaMEDMEM virtual int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); virtual std::size_t getNbOfElems() const throw(INTERP_KERNEL::Exception); virtual std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception); - void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); - void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); - void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); - void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); - void checkNbOfElems(std::size_t nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception); - static int GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception); - static int GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception); + virtual DataArray *deepCpy() const throw(INTERP_KERNEL::Exception); + virtual DataArray *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); + virtual void rearrange(int newNbOfCompo) 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); + void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const std::string& msg) const throw(INTERP_KERNEL::Exception); + void checkNbOfElems(std::size_t nbOfElems, const std::string& msg) const throw(INTERP_KERNEL::Exception); + static int GetNumberOfItemGivenBES(int begin, int end, int step, const std::string& msg) throw(INTERP_KERNEL::Exception); + static int GetNumberOfItemGivenBESRelative(int begin, int end, int step, const std::string& msg) throw(INTERP_KERNEL::Exception); static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception); static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit) throw(INTERP_KERNEL::Exception); void updateTime() const; %extend { @@ -171,6 +358,46 @@ namespace ParaMEDMEM return self->selectByTupleRanges(ranges); } + virtual DataArray *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleId(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + + virtual DataArray *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->selectByTupleIdSafe(tmp,tmp+size); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); + } + } + virtual PyObject *keepSelectedComponents(PyObject *li) const throw(INTERP_KERNEL::Exception) { std::vector tmp; @@ -185,10 +412,7 @@ namespace ParaMEDMEM 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); - if(PySlice_GetIndices(sly,std::numeric_limits::max(),&strt,&stp,&step)!=0) - throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : the input slice is invalid !"); - if(strt==std::numeric_limits::max() || stp==std::numeric_limits::max()) - throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : the input slice contains some unknowns that can't be determined in static method ! Call DataArray::getSlice (non static) instead !"); + GetIndicesOfSliceExplicitely(sly,&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)); @@ -200,8 +424,7 @@ namespace ParaMEDMEM 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); - if(PySlice_GetIndices(sly,self->getNumberOfTuples(),&strt,&stp,&step)!=0) - throw INTERP_KERNEL::Exception("DataArray::getSlice (wrap) : the input slice is invalid !"); + GetIndicesOfSlice(sly,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)); @@ -213,10 +436,7 @@ namespace ParaMEDMEM 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); - if(PySlice_GetIndices(sly,std::numeric_limits::max(),&strt,&stp,&step)!=0) - throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !"); - if(strt==std::numeric_limits::max() || stp==std::numeric_limits::max()) - throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : the input slice contains some unknowns that can't be determined in static method !"); + GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBES(strt,stp,step,""); } @@ -226,12 +446,16 @@ namespace ParaMEDMEM 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); - if(PySlice_GetIndices(sly,std::numeric_limits::max(),&strt,&stp,&step)!=0) - throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); - if(strt==std::numeric_limits::max() || stp==std::numeric_limits::max()) - throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice contains some unknowns that can't be determined in static method !"); + GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,""); } + + static DataArray *Aggregate(PyObject *arrs) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(arrs,SWIGTYPE_p_ParaMEDMEM__DataArray,"DataArray",tmp); + return DataArray::Aggregate(tmp); + } int getNumberOfItemGivenBES(PyObject *slic) const throw(INTERP_KERNEL::Exception) { @@ -239,8 +463,7 @@ namespace ParaMEDMEM 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); - if(PySlice_GetIndices(sly,self->getNumberOfTuples(),&strt,&stp,&step)!=0) - throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !"); + GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBES(strt,stp,step,""); } @@ -250,10 +473,44 @@ namespace ParaMEDMEM 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); - if(PySlice_GetIndices(sly,self->getNumberOfTuples(),&strt,&stp,&step)!=0) - throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); + GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !"); return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,""); } + + PyObject *__getstate__() const throw(INTERP_KERNEL::Exception) + { + PyObject *ret(PyTuple_New(2)); + std::string a0(self->getName()); + const std::vector &a1(self->getInfoOnComponents()); + PyTuple_SetItem(ret,0,PyString_FromString(a0.c_str())); + // + int sz(a1.size()); + PyObject *ret1(PyList_New(sz)); + for(int i=0;i a1cpp; + if(!fillStringVector(a1,a1cpp)) + throw INTERP_KERNEL::Exception(MSG); + self->setName(PyString_AsString(a0)); + self->setInfoOnComponents(a1cpp); + } } }; @@ -266,12 +523,10 @@ namespace ParaMEDMEM static DataArrayDouble *New(); double doubleValue() const throw(INTERP_KERNEL::Exception); bool empty() const throw(INTERP_KERNEL::Exception); - DataArrayDouble *deepCpy() const throw(INTERP_KERNEL::Exception); DataArrayDouble *performCpy(bool deepCpy) const throw(INTERP_KERNEL::Exception); void cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception); void reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception); void pushBackSilent(double val) throw(INTERP_KERNEL::Exception); - void pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception); double popBackSilent() throw(INTERP_KERNEL::Exception); void pack() const throw(INTERP_KERNEL::Exception); void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); @@ -285,20 +540,20 @@ namespace ParaMEDMEM bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception); std::string repr() const throw(INTERP_KERNEL::Exception); std::string reprZip() const throw(INTERP_KERNEL::Exception); + 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 *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); - void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const throw(INTERP_KERNEL::Exception); DataArrayInt *findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const throw(INTERP_KERNEL::Exception); void setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception); void setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception); void setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception); @@ -320,6 +575,7 @@ namespace ParaMEDMEM double getAverageValue() const throw(INTERP_KERNEL::Exception); double norm2() const throw(INTERP_KERNEL::Exception); double normMax() const throw(INTERP_KERNEL::Exception); + double normMin() const throw(INTERP_KERNEL::Exception); double accumulate(int compId) const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception); DataArrayDouble *fromCylToCart() const throw(INTERP_KERNEL::Exception); @@ -333,10 +589,12 @@ namespace ParaMEDMEM DataArrayDouble *deviator() const throw(INTERP_KERNEL::Exception); DataArrayDouble *magnitude() const throw(INTERP_KERNEL::Exception); DataArrayDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *sumPerTuple() const throw(INTERP_KERNEL::Exception); DataArrayDouble *buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception); DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception); void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); void abs() throw(INTERP_KERNEL::Exception); + DataArrayDouble *computeAbs() const throw(INTERP_KERNEL::Exception); void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception); void applyLin(double a, double b) throw(INTERP_KERNEL::Exception); void applyInv(double numerator) throw(INTERP_KERNEL::Exception); @@ -344,13 +602,15 @@ namespace ParaMEDMEM void applyRPow(double val) throw(INTERP_KERNEL::Exception); DataArrayDouble *negate() const throw(INTERP_KERNEL::Exception); DataArrayDouble *applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *applyFunc(const char *func) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); - DataArrayDouble *applyFunc3(int nbOfComp, const std::vector& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception); - void applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception); - void applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc(int nbOfComp, const std::string& func, bool isSafe=true) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc(const std::string& func, bool isSafe=true) const throw(INTERP_KERNEL::Exception); + void applyFuncOnThis(const std::string& func, bool isSafe=true) throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc2(int nbOfComp, const std::string& func, bool isSafe=true) const throw(INTERP_KERNEL::Exception); + DataArrayDouble *applyFunc3(int nbOfComp, const std::vector& varsOrder, const std::string& func, bool isSafe=true) const throw(INTERP_KERNEL::Exception); + void applyFuncFast32(const std::string& func) throw(INTERP_KERNEL::Exception); + void applyFuncFast64(const std::string& func) throw(INTERP_KERNEL::Exception); DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsNotInRange(double vmin, double vmax) 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); @@ -466,6 +726,7 @@ namespace ParaMEDMEM #endif else throw INTERP_KERNEL::Exception(msg.c_str()); + throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy } DataArrayDouble(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception) @@ -492,7 +753,7 @@ namespace ParaMEDMEM std::string __str__() const throw(INTERP_KERNEL::Exception) { - return self->repr(); + return self->reprNotTooLong(); } double __float__() const throw(INTERP_KERNEL::Exception) @@ -683,46 +944,6 @@ namespace ParaMEDMEM } } - DataArrayDouble *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleId(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayDouble *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - PyObject *minimalDistanceTo(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception) { int thisTupleId,otherTupleId; @@ -1352,6 +1573,7 @@ namespace ParaMEDMEM std::vector bb; int sw; // +#ifndef WITHOUT_AUTOFIELD void *argp; if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { @@ -1366,6 +1588,7 @@ namespace ParaMEDMEM else throw INTERP_KERNEL::Exception(msg); } +#endif // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) @@ -1478,6 +1701,7 @@ namespace ParaMEDMEM std::vector bb; int sw; // +#ifndef WITHOUT_AUTOFIELD void *argp; if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { @@ -1492,6 +1716,7 @@ namespace ParaMEDMEM else throw INTERP_KERNEL::Exception(msg); } +#endif // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) @@ -1604,6 +1829,7 @@ namespace ParaMEDMEM std::vector bb; int sw; // +#ifndef WITHOUT_AUTOFIELD void *argp; if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { @@ -1618,6 +1844,7 @@ namespace ParaMEDMEM else throw INTERP_KERNEL::Exception(msg); } +#endif // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) @@ -1730,6 +1957,7 @@ namespace ParaMEDMEM std::vector bb; int sw; // +#ifndef WITHOUT_AUTOFIELD void *argp; if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) { @@ -1744,6 +1972,7 @@ namespace ParaMEDMEM else throw INTERP_KERNEL::Exception(msg); } +#endif // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) @@ -1981,6 +2210,59 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__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(ParaMEDMEM_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 + } } }; @@ -2061,6 +2343,11 @@ namespace ParaMEDMEM return trueSelf; } + PyObject *__len__() throw(INTERP_KERNEL::Exception) + { + return PyInt_FromLong(self->getNumberOfCompo()); + } + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { const char msg2[]="DataArrayDoubleTuple::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; @@ -2071,7 +2358,7 @@ namespace ParaMEDMEM ParaMEDMEM::DataArrayInt *daIntTyypp=0; const double *pt=self->getConstPointer(); int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: @@ -2080,7 +2367,8 @@ namespace ParaMEDMEM { std::ostringstream oss; oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + PyErr_SetString(PyExc_StopIteration,oss.str().c_str()); + return 0; } if(singleVal>=0) return PyFloat_FromDouble(pt[singleVal]); @@ -2140,7 +2428,7 @@ namespace ParaMEDMEM std::pair > slic; ParaMEDMEM::DataArrayInt *daIntTyypp=0; double *pt=self->getPointer(); - convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); + convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); switch(sw2) { case 1: @@ -2289,7 +2577,6 @@ namespace ParaMEDMEM int intValue() const throw(INTERP_KERNEL::Exception); int getHashCode() const throw(INTERP_KERNEL::Exception); bool empty() const throw(INTERP_KERNEL::Exception); - DataArrayInt *deepCpy() const throw(INTERP_KERNEL::Exception); DataArrayInt *performCpy(bool deepCpy) const throw(INTERP_KERNEL::Exception); void cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception); void reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception); @@ -2301,6 +2588,7 @@ namespace ParaMEDMEM bool isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception); + DataArrayInt *sumPerTuple() const throw(INTERP_KERNEL::Exception); void sort(bool asc=true) throw(INTERP_KERNEL::Exception); void reverse() throw(INTERP_KERNEL::Exception); void checkMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception); @@ -2310,8 +2598,10 @@ namespace ParaMEDMEM void fillWithZero() throw(INTERP_KERNEL::Exception); void fillWithValue(int val) throw(INTERP_KERNEL::Exception); void iota(int init=0) throw(INTERP_KERNEL::Exception); + void replaceOneValByInThis(int valToBeReplaced, int replacedBy) throw(INTERP_KERNEL::Exception); std::string repr() const throw(INTERP_KERNEL::Exception); std::string reprZip() const throw(INTERP_KERNEL::Exception); + std::string reprNotTooLong() const throw(INTERP_KERNEL::Exception); 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); @@ -2322,9 +2612,9 @@ namespace ParaMEDMEM DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception); bool isIdentity() const throw(INTERP_KERNEL::Exception); + bool isIdentity2(int sizeExpected) const throw(INTERP_KERNEL::Exception); bool isUniform(int val) const throw(INTERP_KERNEL::Exception); DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); - void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception); void meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); @@ -2360,6 +2650,7 @@ namespace ParaMEDMEM int getMinValue(int& tupleId) 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); void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception); void applyLin(int a, int b) throw(INTERP_KERNEL::Exception); void applyInv(int numerator) throw(INTERP_KERNEL::Exception); @@ -2370,24 +2661,29 @@ namespace ParaMEDMEM void applyPow(int val) throw(INTERP_KERNEL::Exception); void applyRPow(int val) throw(INTERP_KERNEL::Exception); DataArrayInt *getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsNotInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsStrictlyNegative() 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); static DataArrayInt *MakePartition(const std::vector& groups, int newNb, std::vector< std::vector >& fidsOfGroups) throw(INTERP_KERNEL::Exception); static DataArrayInt *BuildUnion(const std::vector& arr) throw(INTERP_KERNEL::Exception); static DataArrayInt *BuildIntersection(const std::vector& arr) throw(INTERP_KERNEL::Exception); + static DataArrayInt *FindPermutationFromFirstToSecond(const DataArrayInt *ids1, const DataArrayInt *ids2) throw(INTERP_KERNEL::Exception); DataArrayInt *buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnique() const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildUniqueNotSorted() const throw(INTERP_KERNEL::Exception); DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); void computeOffsets() throw(INTERP_KERNEL::Exception); void computeOffsets2() throw(INTERP_KERNEL::Exception); DataArrayInt *buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception); DataArrayInt *findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); + void sortEachPairToMakeALinkedList() throw(INTERP_KERNEL::Exception); DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); DataArrayInt *getDifferentValues() const throw(INTERP_KERNEL::Exception); static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); @@ -2498,11 +2794,12 @@ namespace ParaMEDMEM #ifdef WITH_NUMPY else if(PyArray_Check(elt0) && nbOfTuples==NULL && nbOfComp==NULL) {//DataArrayInt.New(numpyArray) - return BuildNewInstance(elt0,NPY_INT,&PyCallBackDataArrayInt_RefType,"INT32"); + return BuildNewInstance(elt0,NPY_INT32,&PyCallBackDataArrayInt_RefType,"INT32"); } #endif else throw INTERP_KERNEL::Exception(msg.c_str()); + throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy } DataArrayInt(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) @@ -2512,7 +2809,7 @@ namespace ParaMEDMEM std::string __str__() const throw(INTERP_KERNEL::Exception) { - return self->repr(); + return self->reprNotTooLong(); } int __len__() const throw(INTERP_KERNEL::Exception) @@ -2552,6 +2849,45 @@ namespace ParaMEDMEM const int *bg=convertObjToPossibleCpp1_Safe(indexArr,sw,sz,val,val2); return self->accumulatePerChunck(bg,bg+sz); } + + DataArrayInt *getIdsEqualTuple(PyObject *inputTuple) const throw(INTERP_KERNEL::Exception) + { + int sw,sz,val; + std::vector val2; + const int *bg(convertObjToPossibleCpp1_Safe(inputTuple,sw,sz,val,val2)); + return self->getIdsEqualTuple(bg,bg+sz); + } + + PyObject *splitInBalancedSlices(int nbOfSlices) const throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > slcs(self->splitInBalancedSlices(nbOfSlices)); + PyObject *ret=PyList_New(slcs.size()); + for(std::size_t i=0;i(slic); + GetIndicesOfSliceExplicitely(sly,&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); + } + + PyObject *getMinMaxValues() const throw(INTERP_KERNEL::Exception) + { + int a,b; + self->getMinMaxValues(a,b); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(a)); + PyTuple_SetItem(ret,1,PyInt_FromLong(b)); + return ret; + } static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, PyObject *arr, PyObject *arrI) throw(INTERP_KERNEL::Exception) { @@ -2567,6 +2903,17 @@ namespace ParaMEDMEM return ret; } + static DataArrayInt *CheckAndPreparePermutation(PyObject *arr) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *arrPtr(convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr)); + int *pt(ParaMEDMEM::DataArrayInt::CheckAndPreparePermutation(arrPtr,arrPtr+szArr)); + ret->useArray(pt,true,ParaMEDMEM::C_DEALLOC,szArr,1); + return ret.retn(); + } + void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) { const char *msg="ParaMEDMEM::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 !"; @@ -2622,7 +2969,7 @@ namespace ParaMEDMEM #ifdef WITH_NUMPY PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug ! { - return ToNumPyArray(self,NPY_INT,"DataArrayInt"); + return ToNumPyArray(self,NPY_INT32,"DataArrayInt"); } #endif @@ -2852,46 +3199,6 @@ namespace ParaMEDMEM } } - DataArrayInt *selectByTupleId(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleId(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleId(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - - DataArrayInt *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - void setSelectedComponents(const DataArrayInt *a, PyObject *li) throw(INTERP_KERNEL::Exception) { std::vector tmp; @@ -4243,6 +4550,78 @@ namespace ParaMEDMEM PyTuple_SetItem(pyRet,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return pyRet; } + + PyObject *isRange() const throw(INTERP_KERNEL::Exception) + { + int a(0),b(0),c(0); + bool ret(self->isRange(a,b,c)); + PyObject *pyRet=PyTuple_New(2); + PyObject *ret0Py=ret?Py_True:Py_False,*ret1Py(0); + Py_XINCREF(ret0Py); + PyTuple_SetItem(pyRet,0,ret0Py); + if(ret) + ret1Py=PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(c)); + else + { + ret1Py=Py_None; + Py_XINCREF(ret1Py); + } + 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(ParaMEDMEM_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 + } } }; @@ -4330,6 +4709,11 @@ namespace ParaMEDMEM Py_XINCREF(trueSelf); return trueSelf; } + + PyObject *__len__() throw(INTERP_KERNEL::Exception) + { + return PyInt_FromLong(self->getNumberOfCompo()); + } PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { @@ -4341,7 +4725,7 @@ namespace ParaMEDMEM ParaMEDMEM::DataArrayInt *daIntTyypp=0; const int *pt=self->getConstPointer(); int nbc=self->getNumberOfCompo(); - convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp); switch(sw) { case 1: @@ -4350,7 +4734,8 @@ namespace ParaMEDMEM { std::ostringstream oss; oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + PyErr_SetString(PyExc_StopIteration,oss.str().c_str()); + return 0; } if(singleVal>=0) return PyInt_FromLong(pt[singleVal]); @@ -4411,7 +4796,7 @@ namespace ParaMEDMEM std::pair > slic; ParaMEDMEM::DataArrayInt *daIntTyypp=0; int *pt=self->getPointer(); - convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); + convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp); switch(sw2) { case 1: @@ -4555,13 +4940,11 @@ namespace ParaMEDMEM { public: virtual DataArrayChar *buildEmptySpecializedDAChar() const throw(INTERP_KERNEL::Exception); - virtual DataArrayChar *deepCpy() const throw(INTERP_KERNEL::Exception); int getHashCode() const throw(INTERP_KERNEL::Exception); bool empty() const throw(INTERP_KERNEL::Exception); void cpyFrom(const DataArrayChar& other) throw(INTERP_KERNEL::Exception); void reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception); void pushBackSilent(char val) throw(INTERP_KERNEL::Exception); - void pushBackValsSilent(const char *valsBg, const char *valsEnd) throw(INTERP_KERNEL::Exception); char popBackSilent() throw(INTERP_KERNEL::Exception); void pack() const throw(INTERP_KERNEL::Exception); void allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception); @@ -4576,10 +4959,7 @@ namespace ParaMEDMEM DataArrayChar *renumber(const int *old2New) const throw(INTERP_KERNEL::Exception); DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); - DataArrayChar *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); - DataArrayChar *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); bool isUniform(char val) const throw(INTERP_KERNEL::Exception); - void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); DataArrayChar *substr(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); @@ -4713,26 +5093,6 @@ namespace ParaMEDMEM } } - DataArrayChar *selectByTupleIdSafe(PyObject *li) const throw(INTERP_KERNEL::Exception) - { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); - if (!SWIG_IsOK(res1)) - { - int size; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); - return self->selectByTupleIdSafe(tmp,tmp+size); - } - else - { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); - if(!da2) - throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); - da2->checkAllocated(); - return self->selectByTupleIdSafe(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems()); - } - } - static DataArrayChar *Aggregate(PyObject *dachs) throw(INTERP_KERNEL::Exception) { std::vector tmp; @@ -5014,6 +5374,223 @@ namespace ParaMEDMEM return ParaMEDMEM_DataArrayByte_presenceOfTuple(self,obj); } } + + DataArrayByte *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + self->checkAllocated(); + const char msg[]="Unexpected situation in __setitem__ !"; + int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents()); + int sw1,sw2; + int i1; + std::vector v1; + DataArrayInt *d1=0; + DataArrayIntTuple *dd1=0; + convertObjToPossibleCpp1(value,sw1,i1,v1,d1,dd1); + 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); + MEDCouplingAutoRefCountObjectPtr tmp; + switch(sw2) + { + case 1: + { + switch(sw1) + { + case 1: + self->setPartOfValuesSimple1(i1,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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + 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; + default: + throw INTERP_KERNEL::Exception(msg); + } + break; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + return self; + } } }; @@ -5363,7 +5940,7 @@ namespace ParaMEDMEM std::vector stdvecTyyppArr; std::pair > sTyyppArr; ParaMEDMEM::DataArrayInt *daIntTyypp=0; - convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + convertObjToPossibleCpp2WithNegIntInterp(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); switch(sw) { case 1: @@ -5388,7 +5965,7 @@ namespace ParaMEDMEM ParaMEDMEM::DataArrayInt *daIntTyypp=0; int nbOfCompo=self->getNumberOfComponents(); int nbOfTuples=self->getNumberOfTuples(); - convertObjToPossibleCpp2(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + convertObjToPossibleCpp2WithNegIntInterp(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);