From: Anthony Geay Date: Sun, 10 May 2020 22:28:48 +0000 (+0200) Subject: Addition of MEDCouplingSkyLineArray.thresholdPerPack method X-Git-Tag: V9_5_0b1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=46cc4ffda3ffc8afc0b25757fa9f419c6fd12557;p=tools%2Fmedcoupling.git Addition of MEDCouplingSkyLineArray.thresholdPerPack method --- diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index 8ab51c2d6..ca2948b99 100755 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -325,6 +325,36 @@ std::string MEDCouplingSkyLineArray::simpleRepr() const return oss.str(); } +/*! + * Returns 2 SkyLineArrays with same number of packs than \a this. + * Each pack in \a this is split in 2 parts using \a threshold parameter as cut point. + * \a left part contains ids in \a this pack strictly lower than \a threshold + * \a right part contains ids in \a this pack greater or equal to \a threshold + */ +void MEDCouplingSkyLineArray::thresholdPerPack(mcIdType threshold, MCAuto& left, MCAuto& right) const +{ + mcIdType nbPacks(this->getNumberOf()); + MCAuto lCount(DataArrayIdType::New()); lCount->alloc(nbPacks,1); lCount->fillWithZero(); + mcIdType *lCountPtr(lCount->getPointerSilent()); + const mcIdType *valuesPtr(this->_values->begin()),*indexPtr(this->_index->begin()); + for(mcIdType i = 0 ; i < nbPacks ; ++i, ++lCountPtr) + { + *lCountPtr = ToIdType(std::count_if(valuesPtr+indexPtr[i],valuesPtr+indexPtr[i+1],[threshold](mcIdType elt) { return elt sizeOfPacks(this->_index->deltaShiftIndex()); + sizeOfPacks->substractEqual(lCount); + mcIdType leftNbOfVal(lCount->accumulate(std::size_t(0))),rightNbOfVal(sizeOfPacks->accumulate(std::size_t(0))); + lCount->computeOffsetsFull(); sizeOfPacks->computeOffsetsFull(); + MCAuto leftValues(DataArrayIdType::New()); leftValues->alloc(leftNbOfVal,1); + MCAuto rightValues(DataArrayIdType::New()); rightValues->alloc(rightNbOfVal,1); + mcIdType *rvPtr(rightValues->getPointerSilent()),*lvPtr(leftValues->getPointerSilent()); + for(mcIdType i = 0 ; i < nbPacks ; ++i) + { + std::for_each(valuesPtr+indexPtr[i],valuesPtr+indexPtr[i+1],[threshold,&rvPtr,&lvPtr](mcIdType elt) { if(eltcheckAllocated(); diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index b4f0d2509..e2dca0b59 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -108,6 +108,8 @@ namespace MEDCoupling std::string simpleRepr() const; + void thresholdPerPack(mcIdType threshold, MCAuto& left, MCAuto& right) const; + MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const; MEDCouplingSkyLineArray *uniqueNotSortedByPack() const; static MEDCouplingSkyLineArray *AggregatePacks(const std::vector& sks); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index a0c376146..69e5f13fd 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -875,6 +875,16 @@ class MEDCouplingBasicsTest7(unittest.TestCase): self.assertTrue(a) self.assertTrue(b.isEqual(DataArrayInt([2,2,2,6,6,2,6,10,10]))) + def testSkyLineArrayThreshold(self): + x = DataArrayInt([0, 1, 2, 11, 12, 13, 3, 4, 5, 6, 14, 15, 16, 17, 9, 10, 18, 19]) + xi = DataArrayInt([0, 6, 14, 18]) + sk = MEDCouplingSkyLineArray(xi,x) + lsk,rsk = sk.thresholdPerPack(11) + self.assertTrue(lsk.getValuesArray().isEqual(DataArrayInt([0, 1, 2, 3, 4, 5, 6, 9, 10]))) + self.assertTrue(lsk.getIndexArray().isEqual(DataArrayInt([0, 3, 7, 9]))) + self.assertTrue(rsk.getValuesArray().isEqual(DataArrayInt([11, 12, 13, 14, 15, 16, 17, 18, 19]))) + self.assertTrue(rsk.getIndexArray().isEqual(DataArrayInt([0, 3, 7, 9]))) + pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 5aedce0e3..38f2d0f3c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1420,6 +1420,16 @@ namespace MEDCoupling PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTITraits::TI, SWIG_POINTER_OWN | 0 )); return ret; } + + PyObject *thresholdPerPack(mcIdType threshold) const + { + MCAuto left, right; + self->thresholdPerPack(threshold,left,right); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(left.retn()),SWIGTYPE_p_MEDCoupling__MEDCouplingSkyLineArray, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(right.retn()),SWIGTYPE_p_MEDCoupling__MEDCouplingSkyLineArray, SWIG_POINTER_OWN | 0 )); + return ret; + } } }; }