X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.txx;h=941326a87b3a26b7a52341cddaba9a9abc3f5c16;hb=bc69ae91f0e6c8e5043650f26897a8a0ac2056fb;hp=1f45f132546ade6c7fc9669c503b3bb072d74f21;hpb=5d735f30f7338e7784fbe27497c48f4c628ed9b6;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 1f45f1325..941326a87 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -31,6 +31,7 @@ #include #include +#include #include namespace MEDCoupling @@ -3148,6 +3149,62 @@ 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(); + } + + /*! + * Returns either a \a deep or \a shallow copy of this array. For more info see + * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow. + * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one. + * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy + * == \a true) or \a this instance (if \a dCpy == \a false). + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::performCopyOrIncrRef(bool dCpy) const + { + const typename Traits::ArrayType *thisC(static_cast::ArrayType *>(this)); + return DataArrayTemplateClassic::PerformCopyOrIncrRef(dCpy,*thisC); + } /*! * Checks if all values in \a this array are equal to \a val at precision \a eps.