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<nbTuple;i++)
+ std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<int>());
+}
+
+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<nbTuple;i++)
+ ret+=ptr[i*nbComps+compId];
+ return ret;
+}
+
DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
{
if(!a1 || !a2)
MEDCOUPLING_EXPORT bool presenceOfTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool presenceOfValue(int value) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector<int>& 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);
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
{
return self->iterator();
}
-
+
+ PyObject *accumulate() const throw(INTERP_KERNEL::Exception)
+ {
+ int sz=self->getNumberOfComponents();
+ INTERP_KERNEL::AutoPtr<int> 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;