From: Anthony Geay Date: Thu, 26 Jan 2017 10:30:01 +0000 (+0100) Subject: Small tools X-Git-Tag: V8_3_0a2~35 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ceeb5f2d01a3cc079e7bb31f3be3b7705adc221;p=tools%2Fmedcoupling.git Small tools --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 573b2da90..aea13c23d 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -215,7 +215,8 @@ namespace MEDCoupling class DataArrayTemplate : public DataArray { public: - static MCAuto< typename Traits::ArrayTypeCh > NewFromStdVector(const typename std::vector& v); + MEDCOUPLING_EXPORT static MCAuto< typename Traits::ArrayTypeCh > NewFromStdVector(const typename std::vector& v); + MEDCOUPLING_EXPORT std::vector< MCAuto< typename Traits::ArrayTypeCh > > explodeComponents() const; // std::size_t getHeapMemorySizeWithoutChildren() const; // diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index dcb942da1..cbf43aecd 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -490,6 +490,30 @@ namespace MEDCoupling return ret; } + template + std::vector< MCAuto< typename Traits::ArrayTypeCh > > DataArrayTemplate::explodeComponents() const + { + checkAllocated(); + std::size_t sz(getNumberOfComponents()); + int nbTuples(getNumberOfTuples()); + std::string name(getName()); + std::vector compNames(getInfoOnComponents()); + std::vector< MCAuto< typename Traits::ArrayTypeCh > > ret(sz); + const T *thisPt(begin()); + for(std::size_t i=0;i::ArrayTypeCh > part(Traits::ArrayTypeCh::New()); + part->alloc(nbTuples,1); + part->setName(name); + part->setInfoOnComponent(0,compNames[i]); + T *otherPt(part->getPointer()); + for(int j=0;j std::size_t DataArrayTemplate::getHeapMemorySizeWithoutChildren() const { diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 5c523f0fd..b6e54dd72 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4543,6 +4543,30 @@ class MEDCouplingBasicsTest5(unittest.TestCase): d3Exp=DataArrayInt([3,2,1,6,5,4],2,3) ; d3Exp.setInfoOnComponents(["c","b","a"]) self.assertTrue(d3Exp.isEqual(d2)) pass + + def testDAExplodeComponents1(self): + d=DataArrayDouble([(1,2),(3,4),(5,6)]) + d.setName("toto") + d.setInfoOnComponents(["a","b"]) + d2=d.explodeComponents() + self.assertEqual(len(d2),2) + # + d3=DataArrayDouble([1,3,5]) ; d3.setName("toto") ; d3.setInfoOnComponents(["a"]) + self.assertTrue(d3.isEqual(d2[0],1e-14)) + d4=DataArrayDouble([2,4,6]) ; d4.setName("toto") ; d4.setInfoOnComponents(["b"]) + self.assertTrue(d4.isEqual(d2[1],1e-14)) + # + d=DataArrayInt([(1,2),(3,4),(5,6)]) + d.setName("toto") + d.setInfoOnComponents(["a","b"]) + d2=d.explodeComponents() + self.assertEqual(len(d2),2) + # + d3=DataArrayInt([1,3,5]) ; d3.setName("toto") ; d3.setInfoOnComponents(["a"]) + self.assertTrue(d3.isEqual(d2[0])) + d4=DataArrayInt([2,4,6]) ; d4.setName("toto") ; d4.setInfoOnComponents(["b"]) + self.assertTrue(d4.isEqual(d2[1])) + pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index dfb31875e..2396c3cb3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -1119,6 +1119,16 @@ namespace MEDCoupling convertPyToNewIntArr3(li,tmp); self->setSelectedComponents(a,tmp); } + + PyObject *explodeComponents() const throw(INTERP_KERNEL::Exception) + { + std::vector< MCAuto > retCpp(self->explodeComponents()); + std::size_t sz(retCpp.size()); + PyObject *res(PyList_New(sz)); + for(std::size_t i=0;isetSelectedComponents(a,tmp); } + PyObject *explodeComponents() const throw(INTERP_KERNEL::Exception) + { + std::vector< MCAuto > retCpp(self->explodeComponents()); + std::size_t sz(retCpp.size()); + PyObject *res(PyList_New(sz)); + for(std::size_t i=0;igetNumberOfComponents();