From: Anthony Geay Date: Thu, 4 May 2017 21:47:11 +0000 (+0200) Subject: To be continued X-Git-Tag: V8_4_0a1~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2e1bc4ce1f74e78364197deb6f83a340adf5c266;p=tools%2Fmedcoupling.git To be continued --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index a6e0f23e7..3d4bed67a 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -2603,46 +2603,6 @@ void DataArrayDouble::sortPerTuple(bool asc) declareAsNew(); } -/*! - * Converts every value of \a this array to its absolute value. - * \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()); - std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun(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(fabs)); - newArr->copyStringInfoFrom(*this); - return newArr; -} - /*! * Modify all elements of \a this array, so that * an element _x_ becomes \f$ numerator / x \f$. @@ -5656,46 +5616,6 @@ void DataArrayInt::getMinMaxValues(int& minValue, int& maxValue) const } } -/*! - * Converts every value of \a this array to its absolute value. - * \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()); - std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun(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(std::abs)); - newArr->copyStringInfoFrom(*this); - return newArr; -} - /*! * Modify all elements of \a this array, so that * an element _x_ becomes \f$ numerator / x \f$. diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 81b5784c3..d1db9e759 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -332,6 +332,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void meldWith(const typename Traits::ArrayType *other); MEDCOUPLING_EXPORT typename Traits::ArrayType *duplicateEachTupleNTimes(int nbTimes) const; MEDCOUPLING_EXPORT void aggregate(const typename Traits::ArrayType *other); + MEDCOUPLING_EXPORT void abs(); + MEDCOUPLING_EXPORT typename Traits::ArrayType *computeAbs() const; protected: static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); template @@ -472,8 +474,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrix() 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 applyInv(double numerator); MEDCOUPLING_EXPORT void applyPow(double val); MEDCOUPLING_EXPORT void applyRPow(double val); @@ -601,8 +601,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT int accumulate(int compId) const; MEDCOUPLING_EXPORT DataArrayInt *accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const; MEDCOUPLING_EXPORT void getMinMaxValues(int& minValue, int& maxValue) const; - MEDCOUPLING_EXPORT void abs(); - MEDCOUPLING_EXPORT DataArrayInt *computeAbs() const; MEDCOUPLING_EXPORT void applyInv(int numerator); MEDCOUPLING_EXPORT void applyDivideBy(int val); MEDCOUPLING_EXPORT void applyModulus(int val); diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 1f45f1325..365c0ce07 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -3148,6 +3148,48 @@ struct NotInRange throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !"); this->_mem.insertAtTheEnd(other->begin(),other->end()); } + + /*! + * Converts every value of \a this array to its absolute value. + * \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 + */ + template + void DataArrayTemplateClassic::abs() + { + this->checkAllocated(); + T *ptr(this->getPointer()); + std::size_t nbOfElems(this->getNbOfElems()); + std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun(std::abs)); + this->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 + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::computeAbs() const + { + this->checkAllocated(); + MCAuto::ArrayType> newArr(Traits::ArrayType::New()); + int nbOfTuples(this->getNumberOfTuples()); + int nbOfComp(this->getNumberOfComponents()); + newArr->alloc(nbOfTuples,nbOfComp); + std::transform(this->begin(),this->end(),newArr->getPointer(),std::ptr_fun(std::abs)); + newArr->copyStringInfoFrom(*this); + return newArr.retn(); + } /*! * Checks if all values in \a this array are equal to \a val at precision \a eps.