/*!
* Returns the maximum norm of the vector defined by \a this array.
+ * This method works even if the number of components is diferent from one.
+ * If the number of elements in \a this is 0, -1. is returned.
* \return double - the value of the maximum norm, i.e.
- * the maximal absolute value among values of \a this array.
+ * the maximal absolute value among values of \a this array (whatever its number of components).
* \throw If \a this is not allocated.
*/
double DataArrayDouble::normMax() const
{
checkAllocated();
- double ret=-1.;
- std::size_t nbOfElems=getNbOfElems();
- const double *pt=getConstPointer();
+ double ret(-1.);
+ std::size_t nbOfElems(getNbOfElems());
+ const double *pt(getConstPointer());
for(std::size_t i=0;i<nbOfElems;i++,pt++)
{
- double val=std::abs(*pt);
+ double val(std::abs(*pt));
if(val>ret)
ret=val;
}
return ret;
}
+/*!
+ * Returns the minimum norm (absolute value) of the vector defined by \a this array.
+ * This method works even if the number of components is diferent from one.
+ * If the number of elements in \a this is 0, std::numeric_limits<double>::max() is returned.
+ * \return double - the value of the minimum norm, i.e.
+ * the minimal absolute value among values of \a this array (whatever its number of components).
+ * \throw If \a this is not allocated.
+ */
+double DataArrayDouble::normMin() const
+{
+ checkAllocated();
+ double ret(std::numeric_limits<double>::max());
+ std::size_t nbOfElems(getNbOfElems());
+ const double *pt(getConstPointer());
+ for(std::size_t i=0;i<nbOfElems;i++,pt++)
+ {
+ double val(std::abs(*pt));
+ if(val<ret)
+ ret=val;
+ }
+ return ret;
+}
+
/*!
* Accumulates values of each component of \a this array.
* \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
/*!
* Converts every value of \a this array to its absolute value.
- * \throw If \a this is not allocated.
+ * \b WARNING this method is non const. If a new DataArrayDouble instance should be built containing the result of abs DataArrayDouble::computeAbs
+ * should be called instead.
+ *
+ * \throw If \a this is not allocated.
+ * \sa DataArrayDouble::computeAbs
*/
void DataArrayDouble::abs()
{
checkAllocated();
- double *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
+ double *ptr(getPointer());
+ std::size_t nbOfElems(getNbOfElems());
std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
declareAsNew();
}
+/*!
+ * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
+ * This method is a const method (that do not change any values in \a this) contrary to DataArrayDouble::abs method.
+ *
+ * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+ * same number of tuples and component as \a this array.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If \a this is not allocated.
+ * \sa DataArrayDouble::abs
+ */
+DataArrayDouble *DataArrayDouble::computeAbs() const
+{
+ checkAllocated();
+ DataArrayDouble *newArr(DataArrayDouble::New());
+ int nbOfTuples(getNumberOfTuples());
+ int nbOfComp(getNumberOfComponents());
+ newArr->alloc(nbOfTuples,nbOfComp);
+ std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<double,double>(fabs));
+ newArr->copyStringInfoFrom(*this);
+ return newArr;
+}
+
/*!
* Apply a liner function to a given component of \a this array, so that
* an array element <em>(x)</em> becomes \f$ a * x + b \f$.
/*!
* Converts every value of \a this array to its absolute value.
- * \throw If \a this is not allocated.
+ * \b WARNING this method is non const. If a new DataArrayInt instance should be built containing the result of abs DataArrayInt::computeAbs
+ * should be called instead.
+ *
+ * \throw If \a this is not allocated.
+ * \sa DataArrayInt::computeAbs
*/
void DataArrayInt::abs()
{
checkAllocated();
- int *ptr=getPointer();
- std::size_t nbOfElems=getNbOfElems();
+ int *ptr(getPointer());
+ std::size_t nbOfElems(getNbOfElems());
std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
declareAsNew();
}
+/*!
+ * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
+ * This method is a const method (that do not change any values in \a this) contrary to DataArrayInt::abs method.
+ *
+ * \return DataArrayInt * - the new instance of DataArrayInt containing the
+ * same number of tuples and component as \a this array.
+ * The caller is to delete this result array using decrRef() as it is no more
+ * needed.
+ * \throw If \a this is not allocated.
+ * \sa DataArrayInt::abs
+ */
+DataArrayInt *DataArrayInt::computeAbs() const
+{
+ checkAllocated();
+ DataArrayInt *newArr(DataArrayInt::New());
+ int nbOfTuples(getNumberOfTuples());
+ int nbOfComp(getNumberOfComponents());
+ newArr->alloc(nbOfTuples,nbOfComp);
+ std::transform(begin(),end(),newArr->getPointer(),std::ptr_fun<int,int>(std::abs));
+ newArr->copyStringInfoFrom(*this);
+ return newArr;
+}
+
/*!
* Apply a liner function to a given component of \a this array, so that
* an array element <em>(x)</em> becomes \f$ a * x + b \f$.
MEDCOUPLING_EXPORT double getAverageValue() const;
MEDCOUPLING_EXPORT double norm2() const;
MEDCOUPLING_EXPORT double normMax() const;
+ MEDCOUPLING_EXPORT double normMin() const;
MEDCOUPLING_EXPORT void accumulate(double *res) const;
MEDCOUPLING_EXPORT double accumulate(int compId) const;
MEDCOUPLING_EXPORT DataArrayDouble *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const;
MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const;
MEDCOUPLING_EXPORT void sortPerTuple(bool asc);
MEDCOUPLING_EXPORT void abs();
+ MEDCOUPLING_EXPORT DataArrayDouble *computeAbs() const;
MEDCOUPLING_EXPORT void applyLin(double a, double b, int compoId);
MEDCOUPLING_EXPORT void applyLin(double a, double b);
MEDCOUPLING_EXPORT void applyInv(double numerator);
MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const;
MEDCOUPLING_EXPORT int getMinValueInArray() const;
MEDCOUPLING_EXPORT void abs();
+ MEDCOUPLING_EXPORT DataArrayInt *computeAbs() const;
MEDCOUPLING_EXPORT void applyLin(int a, int b, int compoId);
MEDCOUPLING_EXPORT void applyLin(int a, int b);
MEDCOUPLING_EXPORT void applyInv(int numerator);
pass
pass
+ def testSwig2normMinComputeAbs1(self):
+ d=DataArrayDouble([4,-5,2,6.1,-7.33,1,-1,3e2,0.07,-0.009,-6,-1e30],4,3)
+ d.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0=d.computeAbs()
+ dExp=d.deepCpy() ; dExp.abs()
+ self.assertTrue(dExp.isEqual(d0,1e-12))
+ e=d0-DataArrayDouble([4,5,2,6.1,7.33,1,1,3e2,0.07,0.009,6,1e30],4,3)
+ self.assertAlmostEqual(0.,e.normMin(),13)
+ self.assertAlmostEqual(0.009,d.normMin(),13)
+ #
+ di=DataArrayInt([3,-12,5,6,14,16,-23,100,23,-1,0,-6],4,3)
+ di.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0i=di.computeAbs()
+ diExp=di.deepCpy() ; diExp.abs()
+ self.assertTrue(diExp.isEqual(d0i))
+ self.assertEqual([3,12,5,6,14,16,23,100,23,1,0,6],d0i.getValues())
+ pass
+
def setUp(self):
pass
pass
%newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList;
%newobject ParaMEDMEM::DataArrayInt::sumPerTuple;
%newobject ParaMEDMEM::DataArrayInt::negate;
+%newobject ParaMEDMEM::DataArrayInt::computeAbs;
%newobject ParaMEDMEM::DataArrayInt::getIdsInRange;
%newobject ParaMEDMEM::DataArrayInt::getIdsNotInRange;
%newobject ParaMEDMEM::DataArrayInt::Aggregate;
%newobject ParaMEDMEM::DataArrayDouble::getIdsInRange;
%newobject ParaMEDMEM::DataArrayDouble::getIdsNotInRange;
%newobject ParaMEDMEM::DataArrayDouble::negate;
+%newobject ParaMEDMEM::DataArrayDouble::computeAbs;
%newobject ParaMEDMEM::DataArrayDouble::applyFunc;
%newobject ParaMEDMEM::DataArrayDouble::applyFunc2;
%newobject ParaMEDMEM::DataArrayDouble::applyFunc3;
double getAverageValue() const throw(INTERP_KERNEL::Exception);
double norm2() const throw(INTERP_KERNEL::Exception);
double normMax() const throw(INTERP_KERNEL::Exception);
+ double normMin() const throw(INTERP_KERNEL::Exception);
double accumulate(int compId) const throw(INTERP_KERNEL::Exception);
DataArrayDouble *fromPolarToCart() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *fromCylToCart() const throw(INTERP_KERNEL::Exception);
DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception);
void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception);
void abs() throw(INTERP_KERNEL::Exception);
+ DataArrayDouble *computeAbs() const throw(INTERP_KERNEL::Exception);
void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception);
void applyLin(double a, double b) throw(INTERP_KERNEL::Exception);
void applyInv(double numerator) throw(INTERP_KERNEL::Exception);
int getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception);
int getMinValueInArray() const throw(INTERP_KERNEL::Exception);
void abs() throw(INTERP_KERNEL::Exception);
+ DataArrayInt *computeAbs() const throw(INTERP_KERNEL::Exception);
void applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception);
void applyLin(int a, int b) throw(INTERP_KERNEL::Exception);
void applyInv(int numerator) throw(INTERP_KERNEL::Exception);