Salome HOME
MEDCouplingUMesh::computePlaneEquationOf3DFaces method to localize warpped faces
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMemArray.cxx
index ca8343508e47afbb028b5ee5e479200e2b84917b..fec8fe9db520b8e9bbe5902367af9d9e2a34c4cb 100644 (file)
@@ -3818,6 +3818,28 @@ DataArrayDouble *DataArrayDouble::magnitude() const
   return ret;
 }
 
+/*!
+ * Computes for each tuple the sum of number of components values in the tuple and return it.
+ * 
+ * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+ *          same number of tuples as \a this array and one component.
+ *          The caller is to delete this result array using decrRef() as it is no more
+ *          needed.
+ *  \throw If \a this is not allocated.
+ */
+DataArrayDouble *DataArrayDouble::sumPerTuple() const
+{
+  checkAllocated();
+  int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
+  ret->alloc(nbOfTuple,1);
+  const double *src(getConstPointer());
+  double *dest(ret->getPointer());
+  for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
+    *dest=std::accumulate(src,src+nbOfComp,0.);
+  return ret.retn();
+}
+
 /*!
  * Computes the maximal value within every tuple of \a this array.
  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
@@ -6456,6 +6478,28 @@ void DataArrayInt::sort(bool asc)
   declareAsNew();
 }
 
+/*!
+ * Computes for each tuple the sum of number of components values in the tuple and return it.
+ * 
+ * \return DataArrayInt * - the new instance of DataArrayInt containing the
+ *          same number of tuples as \a this array and one component.
+ *          The caller is to delete this result array using decrRef() as it is no more
+ *          needed.
+ *  \throw If \a this is not allocated.
+ */
+DataArrayInt *DataArrayInt::sumPerTuple() const
+{
+  checkAllocated();
+  int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
+  ret->alloc(nbOfTuple,1);
+  const int *src(getConstPointer());
+  int *dest(ret->getPointer());
+  for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
+    *dest=std::accumulate(src,src+nbOfComp,0);
+  return ret.retn();
+}
+
 /*!
  * Reverse the array values.
  *  \throw If \a this->getNumberOfComponents() < 1.