From: Anthony Geay Date: Tue, 17 Oct 2017 08:57:27 +0000 (+0200) Subject: Add test for new SkyLineMethods X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6295f83f54e9edcec993a686c684f6a89ec19270;p=tools%2Fmedcoupling.git Add test for new SkyLineMethods --- diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index fa64244d3..881a89a26 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -412,27 +412,25 @@ void MEDCouplingSkyLineArray::deletePack(const int superIdx, const int idx) void MEDCouplingSkyLineArray::deleteSimplePack(const int idx) { - using namespace std; - validIndex("deleteSimplePack", idx); int* iP(_index->getPointer()); - const int start = iP[idx], end = iP[idx+1]; + const int start(iP[idx]), end(iP[idx+1]); // _values - int initValSz = _values->getNbOfElems(); - int deltaSz = start-end; // should be negative + int initValSz( _values->getNbOfElems() ); + int deltaSz( start-end ); // should be negative int *vP(_values->getPointer()); - if (deltaSz < 0){ - copy(vP+end, vP+initValSz, vP+start); + if (deltaSz < 0) + { + std::copy(vP+end, vP+initValSz, vP+start); _values->reAlloc(initValSz+deltaSz); - } + } else throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePack"); - // _index - int nt = _index->getNbOfElems(); - copy(iP+idx+1, iP+nt, iP+idx); + int nt(_index->getNbOfElems()); + std::copy(iP+idx+1, iP+nt, iP+idx); for(int ii = idx; ii < nt-1; ii++) iP[ii] += deltaSz; _index->reAlloc(nt-1); @@ -443,43 +441,43 @@ void MEDCouplingSkyLineArray::replaceSimplePacks(const DataArrayInt* idx, const if (idx->empty()) return; - for (auto id = idx->begin(); id != idx->end(); id++) + for (const int * id = idx->begin(); id != idx->end(); id++) validIndex("deleteSimplePacks", *id); if (idx->getNbOfElems() != packs.size()) throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePacks: size of list of pack is incorrect"); // copy _index, _values into a deque> - std::deque> valuesByIdx; + std::deque< std::set > valuesByIdx; int* vP(_values->getPointer()); int* iP(_index->getPointer()); - int nt = _index->getNbOfElems(); + std::size_t nt ( _index->getNbOfElems() ); for (int ii = 0; ii < nt-1; ii++) valuesByIdx.push_back(std::set(vP+iP[ii], vP+iP[ii+1])); // modify the deque> according to idx and packs - int ii = 0; - for (auto id = idx->begin(); id != idx->end(); id++){ + int ii(0); + for (const int *id = idx->begin(); id != idx->end(); id++) + { valuesByIdx[*id] = std::set(packs[ii]->begin(), packs[ii]->end()); ii++; - } - + } // copy back the deque> into _index, _values - int valSz = 0; + int valSz(0); *iP = 0; - for (auto values : valuesByIdx){ - valSz += values.size(); + for (std::deque< std::set >::const_iterator values=valuesByIdx.begin();values!=valuesByIdx.end();values++) + { + valSz += (*values).size(); *(++iP) = valSz; - } - + } _values->reAlloc(valSz); iP = _index->getPointer(); vP = _values->getPointer(); - for (auto values : valuesByIdx){ - copy(values.begin(), values.end(), vP+(*iP)); + for (auto values : valuesByIdx) + { + std::copy(values.begin(), values.end(), vP+(*iP)); iP++; - } - + } } void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx){ @@ -495,17 +493,17 @@ void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx){ int* iP(_index->getPointer()); int initValSz = _values->getNbOfElems(); int *vP(_values->getPointer()); - int end_prec = 0; - int start_prec = 0; - for (auto ii : packsToDelete){ - int start = iP[ii]; + int end_prec(0),start_prec(0); + for(std::set::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++) + { + int start = iP[*ii]; if (end_prec != 0) - copy(vP+end_prec, vP+start, vP+start_prec); + copy(vP+end_prec, vP+start, vP+start_prec); start_prec += start-end_prec; - end_prec = iP[ii+1]; - } + end_prec = iP[*ii+1]; + } if (end_prec != 0) - copy(vP+end_prec, vP+initValSz, vP+start_prec); + copy(vP+end_prec, vP+initValSz, vP+start_prec); _values->reAlloc(initValSz-(end_prec-start_prec)); // _index @@ -514,22 +512,25 @@ void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx){ end_prec = 0; start_prec = 0; int deleted = 0; - for (auto ii : packsToDelete){ - if (end_prec != 0){ - copy(iP+end_prec, iP+ii, iP+start_prec); - for (int i=start_prec; i::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++) + { + if (end_prec != 0) + { + copy(iP+end_prec, iP+*ii, iP+start_prec); + for (int i=start_prec; i<*ii; i++) + iP[i] -= offset; + } + offset += iP[*ii+1] - iP[*ii]; + start_prec = *ii-deleted; + end_prec = *ii+1; deleted += 1; - } - if (end_prec != 0){ + } + if (end_prec != 0) + { copy(iP+end_prec, iP+nt, iP+start_prec); for (int i=start_prec; ireAlloc(nt-deleted); } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py index f767558e0..722081ba9 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest6.py @@ -106,6 +106,24 @@ class MEDCouplingBasicsTest6(unittest.TestCase): level3(self) gtumesh(self) pass + + def testSKLAReplaceDeletePacks(self): + index=DataArrayInt([0,3,5,6,6]) + value=DataArrayInt([1,2,3, 2,3, 3 ]) + sla=MEDCouplingSkyLineArray(index,value) + idx=DataArrayInt([0,3]) + packs=[DataArrayInt([4,5]),DataArrayInt([6,7,8])] + sla.replaceSimplePacks(idx,packs) + self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,4,5,8]))) + self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([4,5, 2,3, 3, 6,7,8]))) + sla.deleteSimplePacks(idx) + self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,3]))) + self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3, 3]))) + sla.deleteSimplePack(1) + self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2]))) + self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3]))) + pass + pass if __name__ == '__main__':