From: ageay Date: Fri, 25 Jan 2013 15:54:13 +0000 (+0000) Subject: DataArrayInt::accumulate X-Git-Tag: V6_main_FINAL~410 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d6d56e68b2d911cd71f355e5d0da56e9746168af;p=tools%2Fmedcoupling.git DataArrayInt::accumulate --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 08105454b..363310fca 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -5184,6 +5184,32 @@ bool DataArrayInt::presenceOfValue(const std::vector& vals) const throw(INT return locateValue(vals)!=-1; } + +void DataArrayInt::accumulate(int *res) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const int *ptr=getConstPointer(); + int nbTuple=getNumberOfTuples(); + int nbComps=getNumberOfComponents(); + std::fill(res,res+nbComps,0); + for(int i=0;i()); +} + +int DataArrayInt::accumulate(int compId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + const int *ptr=getConstPointer(); + int nbTuple=getNumberOfTuples(); + int nbComps=getNumberOfComponents(); + if(compId>=nbComps) + throw INTERP_KERNEL::Exception("DataArrayInt::accumulate : Invalid compId specified : No such nb of components !"); + int ret=0; + for(int i=0;i& tupl) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool presenceOfValue(int value) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void accumulate(int *res) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int accumulate(int compId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMaxValueInArray() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 8739c3ef1..e72abcdf7 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -10853,6 +10853,25 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(m1.checkConsecutiveCellTypesForMEDFileFrmt()) pass + def testSwigDAAccumulate1(self): + d=DataArrayInt(10) ; d.iota(0) + self.assertEqual([45],d.accumulate()) + self.assertEqual(45,d.accumulate(0)) + d=DataArrayInt(30) ; d.iota(0) ; d.rearrange(3) + self.assertEqual([135,145,155],d.accumulate()) + self.assertEqual(135,d.accumulate(0)) + self.assertEqual(145,d.accumulate(1)) + self.assertEqual(155,d.accumulate(2)) + d=DataArrayDouble(10) ; d.iota(0.) + self.assertEqual([45.],d.accumulate()) + self.assertEqual(45.,d.accumulate(0)) + d=DataArrayDouble(30) ; d.iota(0) ; d.rearrange(3) + self.assertEqual([135.,145.,155.],d.accumulate()) + self.assertEqual(135.,d.accumulate(0)) + self.assertEqual(145.,d.accumulate(1)) + self.assertEqual(155.,d.accumulate(2)) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index ecd13e555..4ebecefac 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -4624,7 +4624,15 @@ namespace ParaMEDMEM { return self->iterator(); } - + + PyObject *accumulate() const throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfComponents(); + INTERP_KERNEL::AutoPtr tmp=new int[sz]; + self->accumulate(tmp); + return convertIntArrToPyList(tmp,sz); + } + static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, PyObject *arr, PyObject *arrI) throw(INTERP_KERNEL::Exception) { int newNbOfTuples=-1;