From 66f9e5714223cdf49e93c45dfbb3683a673348c7 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 3 Dec 2019 21:57:34 +0300 Subject: [PATCH] finish LOT3: fix DataArrayInt.i, MEDCouplingBasicsTest7.py and their dependency --- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 1 - src/MEDCoupling/MEDCouplingMemArray.hxx | 2 +- src/MEDCoupling/MEDCouplingMemArray.txx | 2 +- src/MEDCoupling_Swig/DataArrayInt.i | 99 ++++++------- .../MEDCouplingBasicsTest7.py | 18 +-- src/MEDCoupling_Swig/MEDCouplingCommon.i | 25 +++- .../MEDCouplingDataArrayTypemaps.i | 2 +- src/MEDCoupling_Swig/MEDCouplingFinalize.i | 130 ++++++++++-------- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 26 +++- 9 files changed, 178 insertions(+), 127 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 6d4b572a5..91ced90cb 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -119,7 +119,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void changeNbOfComponents(std::size_t newNbOfComp, double dftValue=0.); MEDCOUPLING_EXPORT MEDCouplingFieldDouble *keepSelectedComponents(const std::vector& compoIds) const; MEDCOUPLING_EXPORT void setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds); - MEDCOUPLING_EXPORT void setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector& compoIds); MEDCOUPLING_EXPORT void sortPerTuple(bool asc); MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); MEDCOUPLING_EXPORT static MEDCouplingFieldDouble *MergeFields(const std::vector& a); diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index c27d9673a..28d3ddec4 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -642,7 +642,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static mcIdType *CheckAndPreparePermutation(const T *start, const T *end); MEDCOUPLING_EXPORT static DataArrayType *BuildListOfSwitchedOn(const std::vector& v); MEDCOUPLING_EXPORT static DataArrayType *BuildListOfSwitchedOff(const std::vector& v); - MEDCOUPLING_EXPORT static DataArrayIdType *ConvertIndexArrayToO2N(mcIdType nbOfOldTuples, const T *arr, const mcIdType *arrIBg, const mcIdType *arrIEnd, mcIdType &newNbOfTuples); + MEDCOUPLING_EXPORT static DataArrayIdType *ConvertIndexArrayToO2N(mcIdType nbOfOldTuples, const mcIdType *arr, const mcIdType *arrIBg, const mcIdType *arrIEnd, mcIdType &newNbOfTuples); MEDCOUPLING_EXPORT static DataArrayIdType *MakePartition(const std::vector& groups, mcIdType newNb, std::vector< std::vector >& fidsOfGroups); public: MEDCOUPLING_EXPORT static void ExtractFromIndexedArrays(const mcIdType *idsOfSelectBg, const mcIdType *idsOfSelectEnd, diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 303dbe245..68980ddac 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -7425,7 +7425,7 @@ struct NotInRange * \throw If any value of \a arr breaks condition ( 0 <= \a arr[ i ] < \a nbOfOldTuples ). */ template - DataArrayIdType *DataArrayDiscrete::ConvertIndexArrayToO2N(mcIdType nbOfOldTuples, const T *arr, const mcIdType *arrIBg, const mcIdType *arrIEnd, mcIdType &newNbOfTuples) + DataArrayIdType *DataArrayDiscrete::ConvertIndexArrayToO2N(mcIdType nbOfOldTuples, const mcIdType *arr, const mcIdType *arrIBg, const mcIdType *arrIEnd, mcIdType &newNbOfTuples) { MCAuto ret=DataArrayIdType::New(); ret->alloc(nbOfOldTuples,1); diff --git a/src/MEDCoupling_Swig/DataArrayInt.i b/src/MEDCoupling_Swig/DataArrayInt.i index e33fc70a7..f24a21d11 100644 --- a/src/MEDCoupling_Swig/DataArrayInt.i +++ b/src/MEDCoupling_Swig/DataArrayInt.i @@ -44,7 +44,7 @@ bool isEqual(const ARRAY& other) const; bool isEqualWithoutConsideringStr(const ARRAY& other) const; bool isEqualWithoutConsideringStrAndOrder(const ARRAY& other) const; - ARRAY *buildPermutationArr(const ARRAY& other) const; + DataArrayIdType *buildPermutationArr(const ARRAY& other) const; ARRAY *sumPerTuple() const; void sort(bool asc=true); void reverse(); @@ -61,25 +61,25 @@ ARRAY *invertArrayO2N2N2O(INT newNbOfElem) const; ARRAY *invertArrayN2O2O2N(INT oldNbOfElem) const; ARRAY *invertArrayO2N2N2OBis(INT newNbOfElem) const; - ARRAY *indicesOfSubPart(const ARRAY& partOfThis) const; + DataArrayIdType *indicesOfSubPart(const ARRAY& partOfThis) const; ARRAY *fromNoInterlace() const; ARRAY *toNoInterlace() const; ARRAY *selectByTupleIdSafeSlice(INT bg, INT end, INT step) const; - ARRAY *checkAndPreparePermutation() const; - ARRAY *buildPermArrPerLevel() const; + DataArrayIdType *checkAndPreparePermutation() const; + DataArrayIdType *buildPermArrPerLevel() const; bool isIota(INT sizeExpected) const; bool isUniform(INT val) const; INT checkUniformAndGuess() const; bool hasUniqueValues() const; ARRAY *subArray(INT tupleIdBg, INT tupleIdEnd=-1) const; void transpose(); - ARRAY *changeNbOfComponents(INT newNbOfComp, INT dftValue) const; + ARRAY *changeNbOfComponents(std::size_t newNbOfComp, INT dftValue) const; void meldWith(const ARRAY *other); void setPartOfValues1(const ARRAY *a, INT bgTuples, INT endTuples, INT stepTuples, INT bgComp, INT endComp, INT stepComp, bool strictCompoCompare=true); void setPartOfValuesSimple1(INT a, INT bgTuples, INT endTuples, INT stepTuples, INT bgComp, INT endComp, INT stepComp); void setPartOfValuesAdv(const ARRAY *a, const DataArrayIdType *tuplesSelec); void getTuple(INT tupleId, INT *res) const; - INT getIJ(INT tupleId, INT compoId) const; + INT getIJ(std::size_t tupleId, std::size_t compoId) const; INT getIJSafe(INT tupleId, INT compoId) const; INT front() const; INT back() const; @@ -90,13 +90,13 @@ ARRAY ## Iterator *iterator(); const INT *begin() const; const INT *end() const; - ARRAY *findIdsEqual(INT val) const; - ARRAY *findIdsNotEqual(INT val) const; - INT changeValue(INT oldValue, INT newValue); - INT findIdFirstEqualTuple(const std::vector& tupl) const; - INT findIdFirstEqual(INT value) const; - INT findIdFirstEqual(const std::vector& vals) const; - INT findIdSequence(const std::vector& vals) const; + DataArrayIdType *findIdsEqual(INT val) const; + DataArrayIdType *findIdsNotEqual(INT val) const; + mcIdType changeValue(INT oldValue, INT newValue); + mcIdType findIdFirstEqualTuple(const std::vector& tupl) const; + mcIdType findIdFirstEqual(INT value) const; + mcIdType findIdFirstEqual(const std::vector& vals) const; + mcIdType findIdSequence(const std::vector& vals) const; bool presenceOfTuple(const std::vector& tupl) const; bool presenceOfValue(INT value) const; bool presenceOfValue(const std::vector& vals) const; @@ -125,8 +125,8 @@ static DataArrayIdType *MakePartition(const std::vector& groups, mcIdType newNb, std::vector< std::vector >& fidsOfGroups); static ARRAY *BuildUnion(const std::vector& arr); static ARRAY *BuildIntersection(const std::vector& arr); - static ARRAY *FindPermutationFromFirstToSecond(const ARRAY *ids1, const ARRAY *ids2); - ARRAY *buildComplement(INT nbOfElement) const; + static DataArrayIdType *FindPermutationFromFirstToSecond(const ARRAY *ids1, const ARRAY *ids2); + DataArrayIdType *buildComplement(mcIdType nbOfElement) const; ARRAY *buildSubstraction(const ARRAY *other) const; ARRAY *buildSubstractionOptimized(const ARRAY *other) const; ARRAY *buildUnion(const ARRAY *other) const; @@ -137,7 +137,7 @@ void computeOffsets(); void computeOffsetsFull(); ARRAY *buildExplicitArrByRanges(const ARRAY *offsets) const; - ARRAY *findRangeIdForEachTuple(const ARRAY *ranges) const; + DataArrayIdType *findRangeIdForEachTuple(const ARRAY *ranges) const; ARRAY *findIdInRangeForEachTuple(const ARRAY *ranges) const; void sortEachPairToMakeALinkedList(); ARRAY *duplicateEachTupleNTimes(INT nbTimes) const; @@ -364,11 +364,10 @@ static PyObject *ConvertIndexArrayToO2N(mcIdType nbOfOldTuples, PyObject *arr, PyObject *arrI) { mcIdType newNbOfTuples=-1; - mcIdType szArr,szArrI,sw,iTypppArrI; - INT iTypppArr; - std::vector stdvecTyyppArr; + mcIdType szArr,szArrI,sw,iTypppArr,iTypppArrI; + std::vector stdvecTyyppArr; std::vector stdvecTyyppArrI; - const INT *arrPtr=convertIntStarLikePyObjToCppIntStar(arr,sw,szArr,iTypppArr,stdvecTyyppArr); + const mcIdType *arrPtr=convertIntStarLikePyObjToCppIntStar(arr,sw,szArr,iTypppArr,stdvecTyyppArr); const mcIdType *arrIPtr=convertIntStarLikePyObjToCppIntStar(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI); DataArrayIdType *ret0=MEDCoupling::ARRAY::ConvertIndexArrayToO2N(nbOfOldTuples,arrPtr,arrIPtr,arrIPtr+szArrI,newNbOfTuples); PyObject *ret=PyTuple_New(2); @@ -465,7 +464,7 @@ { std::vector groups; std::vector< std::vector > fidsOfGroups; - convertFromPyObjVectorOfObj(gps,SWIGTITraits::TI,"ARRAY",groups); + convertFromPyObjVectorOfObj(gps,SWIGTITraits::TI,"ARRAY",groups); DataArrayIdType *ret0=MEDCoupling::ARRAY::MakePartition(groups,newNb,fidsOfGroups); PyObject *ret = PyList_New(2); PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); @@ -523,7 +522,7 @@ { ARRAY *ret0=0,*ret1=0,*ret2=0; void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTITraits::TI, 0 | 0 ); + int res1=SWIG_ConvertPtr(li,&da,SWIGTITraits::TI, 0 | 0 ); if (!SWIG_IsOK(res1)) { mcIdType size; @@ -539,16 +538,16 @@ self->splitByValueRange(da2->begin(),da2->end(),ret0,ret1,ret2); } PyObject *ret = PyList_New(3); - PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); return ret; } DataArrayIdType *transformWithIndArrR(PyObject *li) const { void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTITraits::TI, 0 | 0 ); + int res1=SWIG_ConvertPtr(li,&da,SWIGTITraits::TI, 0 | 0 ); if (!SWIG_IsOK(res1)) { mcIdType size; @@ -688,35 +687,35 @@ static ARRAY *Meld(PyObject *li) { std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); + convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); return ARRAY::Meld(tmp); } static ARRAY *Aggregate(PyObject *li) { std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); + convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); return ARRAY::Aggregate(tmp); } static ARRAY *AggregateIndexes(PyObject *li) { std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); + convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); return ARRAY::AggregateIndexes(tmp); } static ARRAY *BuildUnion(PyObject *li) { std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); + convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); return ARRAY::BuildUnion(tmp); } static ARRAY *BuildIntersection(PyObject *li) { std::vector tmp; - convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); + convertFromPyObjVectorOfObj(li,SWIGTITraits::TI,"ARRAY",tmp); return ARRAY::BuildIntersection(tmp); } @@ -822,53 +821,53 @@ { if(nbOfComponents==1) return PyInt_FromLong(self->getIJSafe(it1,0)); - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 2: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); case 3: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); case 4: - return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); case 5: return PyInt_FromLong(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)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, 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)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, 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)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 9: { ret=self->selectByTupleIdSafe(&it1,&it1+1); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 10: { ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, 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)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 12: { ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 13: { @@ -877,7 +876,7 @@ std::vector v2(nbOfComp); for(INT i=0;ikeepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 14: { @@ -886,7 +885,7 @@ std::vector v2(nbOfComp); for(INT i=0;ikeepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 15: { @@ -895,7 +894,7 @@ std::vector v2(nbOfComp); for(mcIdType i=0;ikeepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } case 16: { @@ -904,7 +903,7 @@ std::vector v2(nbOfComp); for(INT i=0;ikeepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 ); } default: throw INTERP_KERNEL::Exception(msg); @@ -2529,7 +2528,7 @@ void transformWithIndArr(PyObject *li) { void *da=0; - int res1(SWIG_ConvertPtr(li,&da,SWIGTITraits::TI, 0 | 0 )); + int res1(SWIG_ConvertPtr(li,&da,SWIGTITraits::TI, 0 | 0 )); if (!SWIG_IsOK(res1)) { int res2(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__MapII, 0 | 0 )); @@ -2555,6 +2554,10 @@ void transformWithIndArr(PyObject *li) namespace MEDCoupling { + typedef int Int32; + typedef long int Int64; + + class DataArrayInt32Iterator; class DataArrayInt32 : public DataArray @@ -2606,5 +2609,5 @@ namespace MEDCoupling TRANSFORMWITHINDARR( DataArrayInt64, Int64 ) #endif }; - + } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 6e2e84d90..1b655eb78 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -277,6 +277,8 @@ class MEDCouplingBasicsTest7(unittest.TestCase): pass def testDAITransformWithIndArr1(self): + if not MEDCouplingUse64BitIDs(): + return tab1=[17,18,22,19] tab2=[0,1,1,3,3,0,1,3,2,2,3,0] expected=[17,18,18,19,19,17,18,19,22,22,19,17] @@ -488,9 +490,9 @@ class MEDCouplingBasicsTest7(unittest.TestCase): def testDAIBuildOld2NewArrayFromSurjectiveFormat2(self): arr=[0,3, 5,7,9] arrI=[0,2,5] - a=DataArrayInt64.New(); + a=DataArrayInt.New(); a.setValues(arr,5,1); - b=DataArrayInt64.New(); + b=DataArrayInt.New(); b.setValues(arrI,3,1); ret,newNbTuple=DataArrayInt64.ConvertIndexArrayToO2N(10,a,b); expected=[0,1,2,0,3,4,5,4,6,4] @@ -655,7 +657,7 @@ class MEDCouplingBasicsTest7(unittest.TestCase): a=DataArrayInt64([9,10,0,6,4,11,3,8]) b=DataArrayInt64([6,0,11,8]) c=a.indicesOfSubPart(b) - self.assertTrue(c.isEqual(DataArrayInt64([3,2,5,7]))) + self.assertTrue(c.isEqual(DataArrayInt([3,2,5,7]))) # d=DataArrayInt64([9,10,0,6,4,11,0,8]) self.assertRaises(InterpKernelException,d.indicesOfSubPart,b) # 0 appears twice in the d array @@ -683,10 +685,10 @@ class MEDCouplingBasicsTest7(unittest.TestCase): def testDAIfindIdsExt1(self): d=DataArrayInt64([4,6,-2,3,7,0,10]) - self.assertTrue(d.findIdsGreaterOrEqualTo(3).isEqual(DataArrayInt64([0,1,3,4,6]))) - self.assertTrue(d.findIdsGreaterThan(3).isEqual(DataArrayInt64([0,1,4,6]))) - self.assertTrue(d.findIdsLowerThan(3).isEqual(DataArrayInt64([2,5]))) - self.assertTrue(d.findIdsLowerOrEqualTo(3).isEqual(DataArrayInt64([2,3,5]))) + self.assertTrue(d.findIdsGreaterOrEqualTo(3).isEqual(DataArrayInt([0,1,3,4,6]))) + self.assertTrue(d.findIdsGreaterThan(3).isEqual(DataArrayInt([0,1,4,6]))) + self.assertTrue(d.findIdsLowerThan(3).isEqual(DataArrayInt([2,5]))) + self.assertTrue(d.findIdsLowerOrEqualTo(3).isEqual(DataArrayInt([2,3,5]))) pass def testDAICheckUniformAndGuess1(self): @@ -708,7 +710,7 @@ class MEDCouplingBasicsTest7(unittest.TestCase): a1=DataArrayInt64([17,27,2,10,-4,3,12,27,16]) b1=DataArrayInt64([3,16,-4,27,17]) ret=a1.findIdForEach(b1) - self.assertTrue(ret.isEqual(DataArrayInt64([5,8,4,7,0]))) + self.assertTrue(ret.isEqual(DataArrayInt([5,8,4,7,0]))) self.assertTrue(a1[ret].isEqual(b1)) b2=DataArrayInt64([3,16,22,27,17]) self.assertRaises(InterpKernelException,a1.findIdForEach,b2) # 22 not in a1 ! diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index c2fd2a2f0..ca1dd0943 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -27,6 +27,7 @@ %{ #include "MEDCouplingMemArray.hxx" +#include "MEDCouplingMemArray.txx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMappedExtrudedMesh.hxx" #include "MEDCouplingCMesh.hxx" @@ -61,9 +62,23 @@ using namespace INTERP_KERNEL; %} %template(ivec) std::vector; +%template(lvec) std::vector; %template(dvec) std::vector; %template(svec) std::vector; +//%include stdint.i + +#ifndef MEDCOUPLING_USE_64BIT_IDS +//typedef std::int32_t mcIdType; +typedef int mcIdType; +typedef DataArrayInt32 DataArrayIdType; +#else +//typedef std::int64_t mcIdType; +typedef long int mcIdType; +typedef DataArrayInt64 DataArrayIdType; +#endif + + //////////////////// %typemap(out) MEDCoupling::MEDCouplingMesh* { @@ -2362,7 +2377,7 @@ namespace MEDCoupling bool checkConsecutiveCellTypesAndOrder(PyObject *li) const { mcIdType sz; - INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + INTERP_KERNEL::AutoPtr order=convertPyToNewIntArr2(li,&sz); bool ret=self->checkConsecutiveCellTypesAndOrder(order,order+sz); return ret; } @@ -2370,7 +2385,7 @@ namespace MEDCoupling DataArrayIdType *getRenumArrForConsecutiveCellTypesSpec(PyObject *li) const { mcIdType sz; - INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + INTERP_KERNEL::AutoPtr order=convertPyToNewIntArr2(li,&sz); DataArrayIdType *ret=self->getRenumArrForConsecutiveCellTypesSpec(order,(INTERP_KERNEL::NormalizedCellType *)order+sz); return ret; } @@ -2449,7 +2464,7 @@ namespace MEDCoupling PyObject *getLevArrPerCellTypes(PyObject *li) const { mcIdType sz; - INTERP_KERNEL::AutoPtr order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + INTERP_KERNEL::AutoPtr order=convertPyToNewIntArr2(li,&sz); DataArrayIdType *tmp0,*tmp1=0; tmp0=self->getLevArrPerCellTypes(order,(INTERP_KERNEL::NormalizedCellType *)order+sz,tmp1); PyObject *ret=PyTuple_New(2); @@ -3956,7 +3971,7 @@ namespace MEDCoupling MEDCouplingFieldDouble *deviator() const; MEDCouplingFieldDouble *magnitude() const; MEDCouplingFieldDouble *maxPerTuple() const; - void changeNbOfComponents(int newNbOfComp, double dftValue=0.); + void changeNbOfComponents(std::size_t newNbOfComp, double dftValue=0.); void sortPerTuple(bool asc); MEDCouplingFieldDouble &operator=(double value); void fillFromAnalytic(int nbOfComp, const std::string& func); @@ -4321,7 +4336,7 @@ namespace MEDCoupling void setSelectedComponents(const MEDCouplingFieldDouble *f, PyObject *li) { - std::vector tmp; + std::vector tmp; convertPyToNewIntArr3(li,tmp); self->setSelectedComponents(f,tmp); } diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index ed875b23e..b23df939f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -591,7 +591,7 @@ static T *convertPyToNewIntArr2(PyObject *pyLi, mcIdType *size) PyObject *o=PyTuple_GetItem(pyLi,i); if(PyInt_Check(o)) { - mcIdType val=(int)PyInt_AS_LONG(o); + T val=(T)PyInt_AS_LONG(o); tmp[i]=val; } else diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index f2801968e..801152b81 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -33,33 +33,33 @@ DataArrayDouble.__floordiv__=DataArrayDouble.__div__ DataArrayDouble.__ifloordiv__=MEDCouplingDataArrayDoubleIdiv DataArrayDouble.__rfloordiv__=DataArrayDouble.__rdiv__ -DataArrayInt32.__reduce__=MEDCouplingDataArrayIntReduce -DataArrayInt32.__iadd__=MEDCouplingDataArrayIntIadd -DataArrayInt32.__isub__=MEDCouplingDataArrayIntIsub -DataArrayInt32.__imul__=MEDCouplingDataArrayIntImul -DataArrayInt32.__idiv__=MEDCouplingDataArrayIntIdiv -DataArrayInt32.__imod__=MEDCouplingDataArrayIntImod -DataArrayInt32.__ipow__=MEDCouplingDataArrayIntIpow -DataArrayInt32.__truediv__=DataArrayInt.__div__ -DataArrayInt32.__itruediv__=MEDCouplingDataArrayIntIdiv -DataArrayInt32.__rtruediv__=DataArrayInt.__rdiv__ -DataArrayInt32.__floordiv__=DataArrayInt.__div__ -DataArrayInt32.__ifloordiv__=MEDCouplingDataArrayIntIdiv -DataArrayInt32.__rfloordiv__=DataArrayInt.__rdiv__ - -DataArrayInt64.__reduce__=MEDCouplingDataArrayIntReduce -DataArrayInt64.__iadd__=MEDCouplingDataArrayIntIadd -DataArrayInt64.__isub__=MEDCouplingDataArrayIntIsub -DataArrayInt64.__imul__=MEDCouplingDataArrayIntImul -DataArrayInt64.__idiv__=MEDCouplingDataArrayIntIdiv -DataArrayInt64.__imod__=MEDCouplingDataArrayIntImod -DataArrayInt64.__ipow__=MEDCouplingDataArrayIntIpow -DataArrayInt64.__truediv__=DataArrayInt.__div__ -DataArrayInt64.__itruediv__=MEDCouplingDataArrayIntIdiv -DataArrayInt64.__rtruediv__=DataArrayInt.__rdiv__ -DataArrayInt64.__floordiv__=DataArrayInt.__div__ -DataArrayInt64.__ifloordiv__=MEDCouplingDataArrayIntIdiv -DataArrayInt64.__rfloordiv__=DataArrayInt.__rdiv__ +DataArrayInt32.__reduce__=MEDCouplingDataArrayInt32Reduce +DataArrayInt32.__iadd__=MEDCouplingDataArrayInt32Iadd +DataArrayInt32.__isub__=MEDCouplingDataArrayInt32Isub +DataArrayInt32.__imul__=MEDCouplingDataArrayInt32Imul +DataArrayInt32.__idiv__=MEDCouplingDataArrayInt32Idiv +DataArrayInt32.__imod__=MEDCouplingDataArrayInt32Imod +DataArrayInt32.__ipow__=MEDCouplingDataArrayInt32Ipow +DataArrayInt32.__truediv__=DataArrayInt32.__div__ +DataArrayInt32.__itruediv__=MEDCouplingDataArrayInt32Idiv +DataArrayInt32.__rtruediv__=DataArrayInt32.__rdiv__ +DataArrayInt32.__floordiv__=DataArrayInt32.__div__ +DataArrayInt32.__ifloordiv__=MEDCouplingDataArrayInt32Idiv +DataArrayInt32.__rfloordiv__=DataArrayInt32.__rdiv__ + +DataArrayInt64.__reduce__=MEDCouplingDataArrayInt64Reduce +DataArrayInt64.__iadd__=MEDCouplingDataArrayInt64Iadd +DataArrayInt64.__isub__=MEDCouplingDataArrayInt64Isub +DataArrayInt64.__imul__=MEDCouplingDataArrayInt64Imul +DataArrayInt64.__idiv__=MEDCouplingDataArrayInt64Idiv +DataArrayInt64.__imod__=MEDCouplingDataArrayInt64Imod +DataArrayInt64.__ipow__=MEDCouplingDataArrayInt64Ipow +DataArrayInt64.__truediv__=DataArrayInt64.__div__ +DataArrayInt64.__itruediv__=MEDCouplingDataArrayInt64Idiv +DataArrayInt64.__rtruediv__=DataArrayInt64.__rdiv__ +DataArrayInt64.__floordiv__=DataArrayInt64.__div__ +DataArrayInt64.__ifloordiv__=MEDCouplingDataArrayInt64Idiv +DataArrayInt64.__rfloordiv__=DataArrayInt64.__rdiv__ DataArrayByte.__reduce__=MEDCouplingDataArrayByteReduce @@ -86,8 +86,7 @@ MEDCouplingFieldDouble.__ifloordiv__=MEDCouplingFieldDoubleIdiv MEDCouplingFieldTemplate.__reduce__=MEDCouplingFieldTemplateReduce -MEDCouplingFieldInt32.__reduce__=MEDCouplingFieldIntReduce -MEDCouplingFieldInt64.__reduce__=MEDCouplingFieldIntReduce +MEDCouplingFieldInt.__reduce__=MEDCouplingFieldIntReduce MEDCouplingFieldFloat.__reduce__=MEDCouplingFieldFloatReduce @@ -98,21 +97,21 @@ DataArrayDoubleTuple.__idiv__=MEDCouplingDataArrayDoubleTupleIdiv DataArrayDoubleTuple.__itruediv__=MEDCouplingDataArrayDoubleTupleIdiv DataArrayDoubleTuple.__ifloordiv__=MEDCouplingDataArrayDoubleTupleIdiv -DataArrayInt32Tuple.__iadd__=MEDCouplingDataArrayIntTupleIadd -DataArrayInt32Tuple.__isub__=MEDCouplingDataArrayIntTupleIsub -DataArrayInt32Tuple.__imul__=MEDCouplingDataArrayIntTupleImul -DataArrayInt32Tuple.__idiv__=MEDCouplingDataArrayIntTupleIdiv -DataArrayInt32Tuple.__itruediv__=MEDCouplingDataArrayIntTupleIdiv -DataArrayInt32Tuple.__ifloordiv__=MEDCouplingDataArrayIntTupleIdiv -DataArrayInt32Tuple.__imod__=MEDCouplingDataArrayIntTupleImod - -DataArrayInt64Tuple.__iadd__=MEDCouplingDataArrayIntTupleIadd -DataArrayInt64Tuple.__isub__=MEDCouplingDataArrayIntTupleIsub -DataArrayInt64Tuple.__imul__=MEDCouplingDataArrayIntTupleImul -DataArrayInt64Tuple.__idiv__=MEDCouplingDataArrayIntTupleIdiv -DataArrayInt64Tuple.__itruediv__=MEDCouplingDataArrayIntTupleIdiv -DataArrayInt64Tuple.__ifloordiv__=MEDCouplingDataArrayIntTupleIdiv -DataArrayInt64Tuple.__imod__=MEDCouplingDataArrayIntTupleImod +DataArrayInt32Tuple.__iadd__=MEDCouplingDataArrayInt32TupleIadd +DataArrayInt32Tuple.__isub__=MEDCouplingDataArrayInt32TupleIsub +DataArrayInt32Tuple.__imul__=MEDCouplingDataArrayInt32TupleImul +DataArrayInt32Tuple.__idiv__=MEDCouplingDataArrayInt32TupleIdiv +DataArrayInt32Tuple.__itruediv__=MEDCouplingDataArrayInt32TupleIdiv +DataArrayInt32Tuple.__ifloordiv__=MEDCouplingDataArrayInt32TupleIdiv +DataArrayInt32Tuple.__imod__=MEDCouplingDataArrayInt32TupleImod + +DataArrayInt64Tuple.__iadd__=MEDCouplingDataArrayInt64TupleIadd +DataArrayInt64Tuple.__isub__=MEDCouplingDataArrayInt64TupleIsub +DataArrayInt64Tuple.__imul__=MEDCouplingDataArrayInt64TupleImul +DataArrayInt64Tuple.__idiv__=MEDCouplingDataArrayInt64TupleIdiv +DataArrayInt64Tuple.__itruediv__=MEDCouplingDataArrayInt64TupleIdiv +DataArrayInt64Tuple.__ifloordiv__=MEDCouplingDataArrayInt64TupleIdiv +DataArrayInt64Tuple.__imod__=MEDCouplingDataArrayInt64TupleImod DenseMatrix.__iadd__=MEDCouplingDenseMatrixIadd DenseMatrix.__isub__=MEDCouplingDenseMatrixIsub @@ -134,44 +133,59 @@ MEDCouplingUMeshCellByTypeIterator.__next__ = MEDCouplingUMeshCellByTypeIterator del INTERPKERNELExceptionReduce -del MEDCoupling1DGTUMeshReduce del MEDCoupling1SGTUMeshReduce del MEDCouplingCMeshReduce del MEDCouplingCurveLinearMeshReduce del MEDCouplingDataArrayByteReduce del MEDCouplingDataArrayDoubleIadd +del MEDCouplingDataArrayDoubleIdiv del MEDCouplingDataArrayDoubleImul del MEDCouplingDataArrayDoubleIpow del MEDCouplingDataArrayDoubleIsub del MEDCouplingDataArrayDoubleReduce del MEDCouplingDataArrayDoubleTupleIadd +del MEDCouplingDataArrayDoubleTupleIdiv del MEDCouplingDataArrayDoubleTupleImul del MEDCouplingDataArrayDoubleTupleIsub del MEDCouplingDataArrayFloatIadd +del MEDCouplingDataArrayFloatIdiv del MEDCouplingDataArrayFloatImul del MEDCouplingDataArrayFloatIsub del MEDCouplingDataArrayFloatReduce -del MEDCouplingDataArrayIntIadd -del MEDCouplingDataArrayIntIadd -del MEDCouplingDataArrayIntImod -del MEDCouplingDataArrayIntImul -del MEDCouplingDataArrayIntIpow -del MEDCouplingDataArrayIntIsub -del MEDCouplingDataArrayIntReduce -del MEDCouplingDataArrayIntTupleIadd -del MEDCouplingDataArrayIntTupleIdiv -del MEDCouplingDataArrayIntTupleImod -del MEDCouplingDataArrayIntTupleImul -del MEDCouplingDataArrayIntTupleIsub +del MEDCouplingDataArrayInt32Iadd +del MEDCouplingDataArrayInt32Idiv +del MEDCouplingDataArrayInt32Imod +del MEDCouplingDataArrayInt32Imul +del MEDCouplingDataArrayInt32Ipow +del MEDCouplingDataArrayInt32Isub +del MEDCouplingDataArrayInt32Reduce +del MEDCouplingDataArrayInt32TupleIadd +del MEDCouplingDataArrayInt32TupleIdiv +del MEDCouplingDataArrayInt32TupleImod +del MEDCouplingDataArrayInt32TupleImul +del MEDCouplingDataArrayInt32TupleIsub +del MEDCouplingDataArrayInt64Iadd +del MEDCouplingDataArrayInt64Idiv +del MEDCouplingDataArrayInt64Imod +del MEDCouplingDataArrayInt64Imul +del MEDCouplingDataArrayInt64Ipow +del MEDCouplingDataArrayInt64Isub +del MEDCouplingDataArrayInt64Reduce +del MEDCouplingDataArrayInt64TupleIadd +del MEDCouplingDataArrayInt64TupleIdiv +del MEDCouplingDataArrayInt64TupleImod +del MEDCouplingDataArrayInt64TupleImul +del MEDCouplingDataArrayInt64TupleIsub del MEDCouplingDenseMatrixIadd del MEDCouplingDenseMatrixIsub del MEDCouplingFieldDoubleIadd +del MEDCouplingFieldDoubleIdiv del MEDCouplingFieldDoubleImul del MEDCouplingFieldDoubleIpow del MEDCouplingFieldDoubleIsub del MEDCouplingFieldDoubleReduce del MEDCouplingFieldFloatReduce -del MEDCouplingFieldIntReduce +del MEDCouplingFieldIntReduce del MEDCouplingFieldTemplateReduce del MEDCouplingIMeshReduce del MEDCouplingMappedExtrudedMeshReduce diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 99a0dc6e8..d999ded1a 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -51,6 +51,11 @@ $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayInt64,SWIG_POINTER_OWN|0); } +%typemap(out) MCAuto +{ + $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTITraits::TI,SWIG_POINTER_OWN|0); +} + %typemap(out) MCAuto { $result=SWIG_NewPointerObj(SWIG_as_voidptr($1.retn()),SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIG_POINTER_OWN|0); @@ -338,6 +343,14 @@ namespace MEDCoupling class DataArrayInt32; class DataArrayInt64; +#ifndef MEDCOUPLING_USE_64BIT_IDS +typedef DataArrayInt32 DataArrayIdType; +#define DataArrayIdType DataArrayInt32 +#else +typedef DataArrayInt64 DataArrayIdType; +#define DataArrayIdType DataArrayInt64 +#endif + class MapII : public RefCountObject, public TimeLabel { public: @@ -976,7 +989,7 @@ namespace MEDCoupling DataArrayDouble *toNoInterlace() const; DataArrayDouble *subArray(int tupleIdBg, int tupleIdEnd=-1) const; void transpose(); - DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const; + DataArrayDouble *changeNbOfComponents(std::size_t newNbOfComp, double dftValue) const; void meldWith(const DataArrayDouble *other); DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const; DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const; @@ -2378,7 +2391,7 @@ namespace MEDCoupling bool isUniform(char val) const; void sort(bool asc=true); DataArrayChar *subArray(mcIdType tupleIdBg, mcIdType tupleIdEnd=-1) const; - DataArrayChar *changeNbOfComponents(int newNbOfComp, char dftValue) const; + DataArrayChar *changeNbOfComponents(std::size_t newNbOfComp, char dftValue) const; void meldWith(const DataArrayChar *other); void setPartOfValuesAdv(const DataArrayChar *a, const DataArrayIdType *tuplesSelec); char front() const; @@ -3684,10 +3697,15 @@ def MEDCouplingDataArrayDoubleReduce(self): 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): +def MEDCouplingDataArrayInt32Reduce(self): + if not MEDCouplingHasNumPyBindings(): + raise InterpKernelException("PyWrap of DataArrayIdType.__reduce__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !") + return MEDCouplingStdReduceFunct,(DataArrayInt32,((self.toNumPyArray(),),(self.__getstate__()),)) + +def MEDCouplingDataArrayInt64Reduce(self): if not MEDCouplingHasNumPyBindings(): raise InterpKernelException("PyWrap of DataArrayIdType.__reduce__ : not implemented because numpy is not active in your configuration ! No serialization/unserialization available without numpy !") - return MEDCouplingStdReduceFunct,(DataArrayIdType,((self.toNumPyArray(),),(self.__getstate__()),)) + return MEDCouplingStdReduceFunct,(DataArrayInt64,((self.toNumPyArray(),),(self.__getstate__()),)) def MEDCouplingDataArrayByteReduce(self): if not MEDCouplingHasNumPyBindings(): -- 2.39.2