From c6207631a37b96ace004f70c7cea1da8724b8e1c Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Sun, 19 Apr 2020 23:58:02 +0200 Subject: [PATCH] To test on big case --- src/MEDCoupling/MEDCouplingSkyLineArray.cxx | 22 +++++++++++++++++++ src/MEDCoupling/MEDCouplingSkyLineArray.hxx | 1 + .../MEDCouplingBasicsTest7.py | 13 +++++++++-- src/MEDCoupling_Swig/MEDCouplingCommon.i | 2 ++ src/ParaMEDMEM/ParaSkyLineArray.cxx | 15 +++++++++++-- src/ParaMEDMEM/ParaSkyLineArray.hxx | 2 ++ src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i | 18 +++++++++++++++ 7 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index bc216096a..8e7951138 100755 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -326,6 +326,28 @@ MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::groupPacks(const DataArrayIdTy return ret.retn(); } +MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::uniqueNotSortedByPack() const +{ + mcIdType nbPacks(this->getNumberOf()); + MCAuto retIndex(DataArrayIdType::New()); retIndex->alloc(nbPacks+1,1); + const mcIdType *valuesPtr(this->_values->begin()),*indexPtr(this->_index->begin()); + mcIdType *retIndexPtr(retIndex->getPointer()); *retIndexPtr = 0; + for(mcIdType i = 0 ; i < nbPacks ; ++i, ++retIndexPtr) + { + std::set s(valuesPtr+indexPtr[i],valuesPtr+indexPtr[i+1]); + retIndexPtr[1] = retIndexPtr[0] + ToIdType(s.size()); + } + MCAuto retValues(DataArrayIdType::New()); retValues->alloc(retIndex->back(),1); + mcIdType *retValuesPtr(retValues->getPointer()); + for(mcIdType i = 0 ; i < nbPacks ; ++i) + { + std::set s(valuesPtr+indexPtr[i],valuesPtr+indexPtr[i+1]); + retValuesPtr = std::copy(s.begin(),s.end(),retValuesPtr); + } + MCAuto ret(MEDCouplingSkyLineArray::New(retIndex,retValues)); + return ret.retn(); +} + /** * For a 2- or 3-level SkyLine array, return a copy of the absolute pack with given identifier. */ diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index 21fba35eb..a51412781 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -108,6 +108,7 @@ namespace MEDCoupling std::string simpleRepr() const; MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const; + MEDCouplingSkyLineArray *uniqueNotSortedByPack() const; void getSimplePackSafe(const mcIdType absolutePackId, std::vector & pack) const; const mcIdType * getSimplePackSafePtr(const mcIdType absolutePackId, mcIdType & packSize) const; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 953d72927..b11d10b1c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -757,7 +757,7 @@ class MEDCouplingBasicsTest7(unittest.TestCase): def testDAIOccurenceRankInThis(self): arr=DataArrayInt([5,3,2,1,4,5,2,1,0,11,5,4]) - self.assertTrue(arr.occurenceRankInThis().isEqual(DataArrayInt([0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 2, 1]))) + self.assertTrue(arr.occurenceRankInThis().isEqual(DataArrayInt([0,0,0,0,0,1,1,1,0,0,2,1]))) def testDAIFindPermutationFromFirstToSecondDuplicate(self): arr0 = DataArrayInt([5,3,2,1,4,5,2,1,0,11,5,4]) @@ -767,7 +767,7 @@ class MEDCouplingBasicsTest7(unittest.TestCase): def testDAIIndexOfSameConsecutiveValueGroups(self): arr = DataArrayInt([0,1,1,2,2,3,4,4,5,5,5,11]) - self.assertTrue(arr.indexOfSameConsecutiveValueGroups().isEqual(DataArrayInt([0, 1, 3, 5, 6, 8, 11, 12]))) + self.assertTrue(arr.indexOfSameConsecutiveValueGroups().isEqual(DataArrayInt([0,1,3,5,6,8,11,12]))) def testSkyLineGroupPacks(self): arr = DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11,4,5,9,12,13,4,5,6,8,10,12,13,14,5,6,7,9,11,13,14,15,6,7,10,14,15,8,9,13,8,9,10,12,14,9,10,11,13,15,10,11,14]) @@ -777,6 +777,15 @@ class MEDCouplingBasicsTest7(unittest.TestCase): sk2 = sk.groupPacks(part) self.assertTrue(sk2.getValuesArray().isEqual(arr)) self.assertTrue(sk2.getIndexArray().isEqual(DataArrayInt([0,13,16,37,84]))) + + def testSkyLineUniqueNotSortedByPack(self): + arrI = DataArrayInt([0,3,9,15,18,24,36,48,54]) + arr = DataArrayInt([1,4,5,0,4,5,2,5,6,3,6,7,1,5,6,2,6,7,0,1,5,5,8,9,0,1,4,6,9,10,1,2,4,6,8,9,2,3,5,7,9,10,1,2,5,7,10,11,2,3,6,6,10,11]) + sk = MEDCouplingSkyLineArray(arrI,arr) + sk2 = sk.uniqueNotSortedByPack() + self.assertTrue(sk2.getIndexArray().isEqual(DataArrayInt([0,3,8,13,16,21,29,37,42]))) + self.assertTrue(sk2.getValuesArray().isEqual(DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11]))) + pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index b3b806995..cc5ab47be 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -467,6 +467,7 @@ typedef long int mcIdType; %newobject MEDCoupling::MEDCouplingSkyLineArray::getIndexArray; %newobject MEDCoupling::MEDCouplingSkyLineArray::getValuesArray; %newobject MEDCoupling::MEDCouplingSkyLineArray::groupPacks; +%newobject MEDCoupling::MEDCouplingSkyLineArray::uniqueNotSortedByPack; %feature("unref") MEDCouplingPointSet "$this->decrRef();" %feature("unref") MEDCouplingMesh "$this->decrRef();" @@ -1299,6 +1300,7 @@ namespace MEDCoupling void deleteSimplePacks(const DataArrayIdType* idx); MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const; + MEDCouplingSkyLineArray *uniqueNotSortedByPack() const; %extend { diff --git a/src/ParaMEDMEM/ParaSkyLineArray.cxx b/src/ParaMEDMEM/ParaSkyLineArray.cxx index 49fe857aa..586c0c4a8 100644 --- a/src/ParaMEDMEM/ParaSkyLineArray.cxx +++ b/src/ParaMEDMEM/ParaSkyLineArray.cxx @@ -42,6 +42,16 @@ ParaSkyLineArray *ParaSkyLineArray::New(MEDCouplingSkyLineArray *ska, DataArrayI return new ParaSkyLineArray(ska,globalIds); } +MEDCouplingSkyLineArray *ParaSkyLineArray::getSkyLineArray() const +{ + return this->_ska.iAmATrollConstCast(); +} + +DataArrayIdType *ParaSkyLineArray::getGlobalIdsArray() const +{ + return this->_global_ids.iAmATrollConstCast(); +} + ParaSkyLineArray::ParaSkyLineArray(MEDCouplingSkyLineArray *ska, DataArrayIdType *globalIds) { _ska.takeRef(ska); @@ -117,8 +127,9 @@ MCAuto ParaSkyLineArray::equiRedistribute(mcIdType nbOfEntitie MCAuto idxOfSameIds(aggregatedIdsSort->indexOfSameConsecutiveValueGroups()); // MCAuto globalIdsOut(aggregatedIdsSort->buildUnique()); - MCAuto skOut(MEDCouplingSkyLineArray::New(valuesSorted,indicesSorted)); - skOut = skOut->groupPacks(idxOfSameIds); + MCAuto skOut(MEDCouplingSkyLineArray::New(indicesSorted,valuesSorted)); + skOut = skOut->groupPacks(idxOfSameIds);//group partial packs coming from different procs + skOut = skOut->uniqueNotSortedByPack();//remove duplicates MCAuto ret(ParaSkyLineArray::New(skOut,globalIdsOut)); return ret.retn(); } \ No newline at end of file diff --git a/src/ParaMEDMEM/ParaSkyLineArray.hxx b/src/ParaMEDMEM/ParaSkyLineArray.hxx index 19dad005a..7e3ba1962 100644 --- a/src/ParaMEDMEM/ParaSkyLineArray.hxx +++ b/src/ParaMEDMEM/ParaSkyLineArray.hxx @@ -39,6 +39,8 @@ namespace MEDCoupling public: static ParaSkyLineArray *New(MEDCouplingSkyLineArray *ska, DataArrayIdType *globalIds); MCAuto equiRedistribute(mcIdType nbOfEntities) const; + MEDCouplingSkyLineArray *getSkyLineArray() const; + DataArrayIdType *getGlobalIdsArray() const; virtual ~ParaSkyLineArray() { } private: ParaSkyLineArray(MEDCouplingSkyLineArray *ska, DataArrayIdType *globalIds); diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i index ce4483313..6cde35541 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i @@ -60,6 +60,8 @@ using namespace ICoCo; %newobject MEDCoupling::ParaUMesh::getCellIdsLyingOnNodes; %newobject MEDCoupling::ParaSkyLineArray::equiRedistribute; +%newobject MEDCoupling::ParaSkyLineArray::getSkyLineArray; +%newobject MEDCoupling::ParaSkyLineArray::getGlobalIdsArray; %feature("unref") ParaSkyLineArray "$this->decrRef();" @@ -157,6 +159,22 @@ namespace MEDCoupling MCAuto ret(self->equiRedistribute(nbOfEntities)); return ret.retn(); } + + MEDCouplingSkyLineArray *getSkyLineArray() const + { + MEDCouplingSkyLineArray *ret(self->getSkyLineArray()); + if(ret) + ret->incrRef(); + return ret; + } + + DataArrayIdType *getGlobalIdsArray() const + { + DataArrayIdType *ret(self->getGlobalIdsArray()); + if(ret) + ret->incrRef(); + return ret; + } } }; } -- 2.39.2