From: Anthony Geay Date: Tue, 30 May 2017 21:25:45 +0000 (+0200) Subject: On the road X-Git-Tag: V8_4_0a1~25^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cefc68f71bbdf67780083bfb364c14b542f3df18;p=tools%2Fmedcoupling.git On the road --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 7eb1baf14..566c07976 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -809,16 +809,6 @@ DataArrayDouble *DataArrayDouble::deepCopy() const return new DataArrayDouble(*this); } -/*! - * Assign zero to all values in \a this array. To know more on filling arrays see - * \ref MEDCouplingArrayFill. - * \throw If \a this is not allocated. - */ -void DataArrayDouble::fillWithZero() -{ - fillWithValue(0.); -} - /*! * Checks that \a this array is consistently **increasing** or **decreasing** in value, * with at least absolute difference value of |\a eps| at each step. @@ -2405,28 +2395,6 @@ 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()); - MCAuto ret(DataArrayDouble::New()); - ret->alloc(nbOfTuple,1); - const double *src(getConstPointer()); - double *dest(ret->getPointer()); - for(int i=0;igetNumberOfComponents() != 1 - * \throw If \a this is not allocated. - */ -void DataArrayInt::iota(int init) -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); - int *ptr=getPointer(); - int ntuples=getNumberOfTuples(); - for(int i=0;i > DataArrayInt::invertArrayN2O2O2NOptimized() const return ret; } -/*! - * 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()); - MCAuto ret(DataArrayInt::New()); - ret->alloc(nbOfTuple,1); - const int *src(getConstPointer()); - int *dest(ret->getPointer()); - for(int i=0;igetNumberOfComponents() != 1. - * \throw If \a this is not allocated. - */ -void DataArrayInt::checkMonotonic(bool increasing) const -{ - if(!isMonotonic(increasing)) - { - if (increasing) - throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !"); - else - throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !"); - } -} - -/*! - * Checks that \a this array is consistently **increasing** or **decreasing** in value. - * \param [in] increasing - if \a true, array values should be increasing. - * \return bool - \a true if values change in accordance with \a increasing arg. - * \throw If \a this->getNumberOfComponents() != 1. - * \throw If \a this is not allocated. - */ -bool DataArrayInt::isMonotonic(bool increasing) const -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !"); - int nbOfElements=getNumberOfTuples(); - const int *ptr=getConstPointer(); - if(nbOfElements==0) - return true; - int ref=ptr[0]; - if(increasing) - { - for(int i=1;i=ref) - ref=ptr[i]; - else - return false; - } - } - else - { - for(int i=1;iref) - ref=ptr[i]; - else - return false; - } - } - else - { - for(int i=1;i ret(DataArrayInt::New()); - ret->alloc(nbTuples,1); - int *retPt(ret->getPointer()); - std::map m; - for(int i=0;i::const_iterator it(m.find(*pt)); - if(it!=m.end()) - *retPt=(*it).second; - else - { - std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !"; - throw INTERP_KERNEL::Exception(oss.str()); - } - } - return ret.retn(); -} - /*! * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode. * This map, if applied to \a this array, would make it sorted. For example, if diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index ac91081aa..d2bcc3dea 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -292,6 +292,7 @@ namespace MEDCoupling void insertAtTheEnd(InputIterator first, InputIterator last); MEDCOUPLING_EXPORT static void SetArrayIn(typename Traits::ArrayType *newArray, typename Traits::ArrayType* &arrayToSet); MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, T element0, const T *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } + MEDCOUPLING_EXPORT void fillWithZero(); public: MEDCOUPLING_EXPORT MemArray& accessToMemArray() { return _mem; } MEDCOUPLING_EXPORT const MemArray& accessToMemArray() const { return _mem; } @@ -339,6 +340,8 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void abs(); MEDCOUPLING_EXPORT typename Traits::ArrayType *computeAbs() const; MEDCOUPLING_EXPORT typename Traits::ArrayType *performCopyOrIncrRef(bool dCpy) const; + MEDCOUPLING_EXPORT typename Traits::ArrayType *sumPerTuple() const; + MEDCOUPLING_EXPORT void iota(T init=(T)0); protected: static typename Traits::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits::ArrayType& self); template @@ -355,7 +358,6 @@ namespace MEDCoupling { public: MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const; - MEDCOUPLING_EXPORT void iota(T init=0.); }; } @@ -405,7 +407,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT double doubleValue() const; MEDCOUPLING_EXPORT DataArrayDouble *deepCopy() const; MEDCOUPLING_EXPORT DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); } - MEDCOUPLING_EXPORT void fillWithZero(); MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const; MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const; MEDCOUPLING_EXPORT std::string repr() const; @@ -471,7 +472,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayDouble *trace() const; MEDCOUPLING_EXPORT DataArrayDouble *deviator() const; MEDCOUPLING_EXPORT DataArrayDouble *magnitude() const; - MEDCOUPLING_EXPORT DataArrayDouble *sumPerTuple() const; MEDCOUPLING_EXPORT DataArrayDouble *maxPerTuple() const; MEDCOUPLING_EXPORT DataArrayDouble *maxPerTupleWithCompoId(DataArrayInt32* &compoIdOfMaxPerTuple) const; MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrix() const; @@ -533,6 +533,11 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void switchOnTupleEqualTo(T val, std::vector& vec) const; MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(T val, std::vector& vec) const; MEDCOUPLING_EXPORT DataArrayIdType *buildPermutationArr(const DataArrayDiscrete& other) const; + MEDCOUPLING_EXPORT DataArrayIdType *indicesOfSubPart(const DataArrayDiscrete& partOfThis) const; + MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const; + MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const; + MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const; + MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const; protected: template void switchOnTupleAlg(T val, std::vector& vec, ALG algo) const; @@ -559,14 +564,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT int getHashCode() const; MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok - MEDCOUPLING_EXPORT DataArrayInt32 *indicesOfSubPart(const DataArrayInt32& partOfThis) const; - MEDCOUPLING_EXPORT DataArrayInt32 *sumPerTuple() const; - MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const; - MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const; - MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const; - MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const; - MEDCOUPLING_EXPORT void fillWithZero(); - MEDCOUPLING_EXPORT void iota(int init=0); MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; MEDCOUPLING_EXPORT std::string reprNotTooLong() const; @@ -710,7 +707,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT bool isEqual(const DataArrayChar& other) const; MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayChar& other) const; - MEDCOUPLING_EXPORT void fillWithZero(); MEDCOUPLING_EXPORT std::string repr() const; MEDCOUPLING_EXPORT std::string reprZip() const; MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const; diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 2f05e5cbe..7813e5417 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -2343,6 +2343,19 @@ namespace MEDCoupling } } + /*! + * Assign zero to all values in \a this array. To know more on filling arrays see + * \ref MEDCouplingArrayFill. + * \throw If \a this is not allocated. + */ + template + void DataArrayTemplate::fillWithZero() + { + fillWithValue((T)0); + } + + ////////////////////////////// + template template MCAuto< typename Traits::ArrayType > DataArrayTemplateClassic::convertToOtherTypeOfArr() const @@ -3205,6 +3218,51 @@ struct NotInRange const typename Traits::ArrayType *thisC(static_cast::ArrayType *>(this)); return DataArrayTemplateClassic::PerformCopyOrIncrRef(dCpy,*thisC); } + + /*! + * 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. + */ + template + typename Traits::ArrayType *DataArrayTemplateClassic::sumPerTuple() const + { + this->checkAllocated(); + std::size_t nbOfComp(this->getNumberOfComponents()),nbOfTuple(this->getNumberOfTuples()); + MCAuto::ArrayType> ret(Traits::ArrayType::New()); + ret->alloc(nbOfTuple,1); + const T *src(this->begin()); + T *dest(ret->getPointer()); + for(std::size_t i=0;igetNumberOfComponents() != 1 + * \throw If \a this is not allocated. + */ + template + void DataArrayTemplateClassic::iota(T init) + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); + T *ptr(this->getPointer()); + std::size_t ntuples(this->getNumberOfTuples()); + for(std::size_t i=0;ideclareAsNew(); + } + + ///////////////////////////////// /*! * Checks if all values in \a this array are equal to \a val at precision \a eps. @@ -3230,26 +3288,6 @@ struct NotInRange return true; } - /*! - * Set all values in \a this array so that the i-th element equals to \a init + i - * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill. - * \param [in] init - value to assign to the first element of array. - * \throw If \a this->getNumberOfComponents() != 1 - * \throw If \a this is not allocated. - */ - template - void DataArrayTemplateFP::iota(T init) - { - this->checkAllocated(); - if(this->getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); - T *ptr(this->getPointer()); - int ntuples(this->getNumberOfTuples()); - for(int i=0;ideclareAsNew(); - } - /*! * Equivalent to DataArrayInt::isEqual except that if false the reason of * mismatch is given. @@ -3403,6 +3441,165 @@ struct NotInRange return ret.retn(); } + /*! + * Elements of \a partOfThis are expected to be included in \a this. + * The returned array \a ret is so that this[ret]==partOfThis + * + * For example, if \a this array contents are [9,10,0,6,4,11,3,8] and if \a partOfThis contains [6,0,11,8] + * the return array will contain [3,2,5,7]. + * + * \a this is expected to be a 1 compo allocated array. + * \param [in] partOfThis - A 1 compo allocated array + * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis. + * \throw if two same element is present twice in \a this + * \throw if an element in \a partOfThis is \b NOT in \a this. + */ + template + DataArrayIdType *DataArrayDiscrete::indicesOfSubPart(const DataArrayDiscrete& partOfThis) const + { + if(this->getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !"); + this->checkAllocated(); partOfThis.checkAllocated(); + std::size_t thisNbTuples(this->getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples()); + const T *thisPt(this->begin()),*pt(partOfThis.begin()); + MCAuto ret(DataArrayIdType::New()); + ret->alloc(nbTuples,1); + T *retPt(ret->getPointer()); + std::map m; + for(mcIdType i=0;i::const_iterator it(m.find(*pt)); + if(it!=m.end()) + *retPt=(*it).second; + else + { + std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } + return ret.retn(); + } + + /*! + * Checks that \a this array is consistently **increasing** or **decreasing** in value. + * If not an exception is thrown. + * \param [in] increasing - if \a true, the array values should be increasing. + * \throw If sequence of values is not strictly monotonic in agreement with \a + * increasing arg. + * \throw If \a this->getNumberOfComponents() != 1. + * \throw If \a this is not allocated. + */ + template + void DataArrayDiscrete::checkMonotonic(bool increasing) const + { + if(!isMonotonic(increasing)) + { + if (increasing) + throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !"); + else + throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !"); + } + } + + /*! + * Checks that \a this array is consistently **increasing** or **decreasing** in value. + * \param [in] increasing - if \a true, array values should be increasing. + * \return bool - \a true if values change in accordance with \a increasing arg. + * \throw If \a this->getNumberOfComponents() != 1. + * \throw If \a this is not allocated. + */ + template + bool DataArrayDiscrete::isMonotonic(bool increasing) const + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !"); + std::size_t nbOfElements(this->getNumberOfTuples()); + const T *ptr(this->begin()); + if(nbOfElements==0) + return true; + T ref(ptr[0]); + if(increasing) + { + for(std::size_t i=1;i=ref) + ref=ptr[i]; + else + return false; + } + } + else + { + for(std::size_t i=1;i + bool DataArrayDiscrete::isStrictlyMonotonic(bool increasing) const + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !"); + std::size_t nbOfElements(this->getNumberOfTuples()); + const T *ptr(this->begin()); + if(nbOfElements==0) + return true; + T ref(ptr[0]); + if(increasing) + { + for(std::size_t i=1;iref) + ref=ptr[i]; + else + return false; + } + } + else + { + for(std::size_t i=1;i + void DataArrayDiscrete::checkStrictlyMonotonic(bool increasing) const + { + if(!isStrictlyMonotonic(increasing)) + { + if (increasing) + throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !"); + else + throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !"); + } + } + + //////////////////////////////////// + /*! * This method compares content of input vector \a v and \a this. * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned. diff --git a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx index 590423fdb..07b75d39a 100644 --- a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx @@ -93,16 +93,6 @@ bool DataArrayChar::isEqualWithoutConsideringStr(const DataArrayChar& other) con return _mem.isEqual(other._mem,0,tmp); } -/*! - * Assign zero to all values in \a this array. To know more on filling arrays see - * \ref MEDCouplingArrayFill. - * \throw If \a this is not allocated. - */ -void DataArrayChar::fillWithZero() -{ - fillWithValue(0); -} - /*! * Returns a textual and human readable representation of \a this instance of * DataArrayChar. This text is shown when a DataArrayChar is printed in Python.