From 9ba2f99f106ca7cd1b61a7610e72f10b80d5fb5d Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 5 Jun 2013 12:42:54 +0000 Subject: [PATCH] DataArrayInt::count and DataArrayDouble::count --- src/MEDCoupling/MEDCouplingMemArray.cxx | 48 +++++++++++++++++++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 2 + src/MEDCoupling_Swig/MEDCouplingMemArray.i | 2 + 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 83afc4cc6..bb9f48c3f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2947,6 +2947,29 @@ double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP return ret; } +/*! + * This method returns the number of values in \a this that are equals ( within an absolute precision of \a eps ) to input parameter \a value. + * This method only works for single component array. + * + * \return a value in [ 0, \c this->getNumberOfTuples() ) + * + * \throw If \a this is not allocated + * + */ +int DataArrayDouble::count(double value, double eps) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::count : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !"); + const double *vals=begin(); + int nbOfTuples=getNumberOfTuples(); + for(int i=0;i& vals) const throw(INTERP_K return -1; } +/*! + * This method returns the number of values in \a this that are equals to input parameter \a value. + * This method only works for single component array. + * + * \return a value in [ 0, \c this->getNumberOfTuples() ) + * + * \throw If \a this is not allocated + * + */ +int DataArrayInt::count(int value) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::count : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !"); + const int *vals=begin(); + int nbOfTuples=getNumberOfTuples(); + for(int i=0;i& a /*! * Returns the maximal value and its location within \a this one-dimensional array. * \param [out] tupleId - index of the tuple holding the maximal value. - * \return double - the maximal value among all values of \a this array. + * \return int - the maximal value among all values of \a this array. * \throw If \a this->getNumberOfComponents() != 1 * \throw If \a this->getNumberOfTuples() < 1 */ diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 8ef2c62fb..50b0a8e85 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -289,6 +289,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT double getMinValueInArray() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int count(double value, double eps) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getAverageValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double norm2() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double normMax() const throw(INTERP_KERNEL::Exception); @@ -515,6 +516,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool presenceOfTuple(const std::vector& 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 int count(int value) 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); diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 5e09c02ab..434650919 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -238,6 +238,7 @@ namespace ParaMEDMEM double getMaxValueInArray() const throw(INTERP_KERNEL::Exception); double getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception); double getMinValueInArray() const throw(INTERP_KERNEL::Exception); + int count(double value, double eps) const throw(INTERP_KERNEL::Exception); double getAverageValue() const throw(INTERP_KERNEL::Exception); double norm2() const throw(INTERP_KERNEL::Exception); double normMax() const throw(INTERP_KERNEL::Exception); @@ -2257,6 +2258,7 @@ namespace ParaMEDMEM bool presenceOfTuple(const std::vector& tupl) const throw(INTERP_KERNEL::Exception); bool presenceOfValue(int value) const throw(INTERP_KERNEL::Exception); bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + int count(int value) const throw(INTERP_KERNEL::Exception); void accumulate(int *res) const throw(INTERP_KERNEL::Exception); int accumulate(int compId) const throw(INTERP_KERNEL::Exception); int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); -- 2.39.2