From 57670a95d5cd9e410f7e2d5a0ea284eceed5318b Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 26 May 2017 23:14:00 +0200 Subject: [PATCH] On the road --- src/MEDCoupling/MEDCouplingMemArray.cxx | 151 +----------------------- src/MEDCoupling/MEDCouplingMemArray.hxx | 40 +++++-- src/MEDCoupling/MEDCouplingMemArray.txx | 149 +++++++++++++++++++++++ 3 files changed, 182 insertions(+), 158 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 98826e68f..211e39df7 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) #include "MEDCouplingMemArray.txx" @@ -45,6 +45,8 @@ template class MEDCoupling::DataArrayTemplateClassic; template class MEDCoupling::DataArrayTemplateFP; template class MEDCoupling::DataArrayIterator; template class MEDCoupling::DataArrayIterator; +template class MEDCoupling::DataArrayDiscrete; +template class MEDCoupling::DataArrayDiscreteSigned; template void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const @@ -3740,9 +3742,9 @@ int DataArrayInt::getHashCode() const * \ref MEDCouplingArrayBasicsCopyDeep. * \return DataArrayInt * - a new instance of DataArrayInt. */ -DataArrayInt *DataArrayInt::deepCopy() const +DataArrayInt32 *DataArrayInt32::deepCopy() const { - return new DataArrayInt(*this); + return new DataArrayInt32(*this); } /*! @@ -4347,149 +4349,6 @@ MCAuto< MapKeyVal > DataArrayInt::invertArrayN2O2O2NOptimized() const return ret; } -/*! - * Equivalent to DataArrayInt::isEqual except that if false the reason of - * mismatch is given. - * - * \param [in] other the instance to be compared with \a this - * \param [out] reason In case of inequality returns the reason. - * \sa DataArrayInt::isEqual - */ -bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const -{ - if(!areInfoEqualsIfNotWhy(other,reason)) - return false; - return _mem.isEqual(other._mem,0,reason); -} - -/*! - * Checks if \a this and another DataArrayInt are fully equal. For more info see - * \ref MEDCouplingArrayBasicsCompare. - * \param [in] other - an instance of DataArrayInt to compare with \a this one. - * \return bool - \a true if the two arrays are equal, \a false else. - */ -bool DataArrayInt::isEqual(const DataArrayInt& other) const -{ - std::string tmp; - return isEqualIfNotWhy(other,tmp); -} - -/*! - * Checks if values of \a this and another DataArrayInt are equal. For more info see - * \ref MEDCouplingArrayBasicsCompare. - * \param [in] other - an instance of DataArrayInt to compare with \a this one. - * \return bool - \a true if the values of two arrays are equal, \a false else. - */ -bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const -{ - std::string tmp; - return _mem.isEqual(other._mem,0,tmp); -} - -/*! - * Checks if values of \a this and another DataArrayInt are equal. Comparison is - * performed on sorted value sequences. - * For more info see\ref MEDCouplingArrayBasicsCompare. - * \param [in] other - an instance of DataArrayInt to compare with \a this one. - * \return bool - \a true if the sorted values of two arrays are equal, \a false else. - */ -bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const -{ - MCAuto a=deepCopy(); - MCAuto b=other.deepCopy(); - a->sort(); - b->sort(); - return a->isEqualWithoutConsideringStr(*b); -} - -/*! - * 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. - * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown. - * - * \param [in] v - the vector of 'flags' to be compared with \a this. - * - * \throw If \a this is not sorted ascendingly. - * \throw If \a this has not exactly one component. - * \throw If \a this is not allocated. - */ -bool DataArrayInt::isFittingWith(const std::vector& v) const -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !"); - const int *w(begin()),*end2(end()); - int refVal=-std::numeric_limits::max(); - int i=0; - std::vector::const_iterator it(v.begin()); - for(;it!=v.end();it++,i++) - { - if(*it) - { - if(w!=end2) - { - if(*w++==i) - { - if(i>refVal) - refVal=i; - else - { - std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(begin(),w-1) << " this is not sorted ascendingly !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - return false; - } - else - return false; - } - } - return w==end2; -} - -/*! - * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val - * put True to the corresponding entry in \a vec. - * \a vec is expected to be with the same size than the number of tuples of \a this. - * - * \sa DataArrayInt::switchOnTupleNotEqualTo. - */ -void DataArrayInt::switchOnTupleEqualTo(int val, std::vector& vec) const -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !"); - int nbOfTuples(getNumberOfTuples()); - if(nbOfTuples!=(int)vec.size()) - throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !"); - const int *pt(begin()); - for(int i=0;i& vec) const -{ - checkAllocated(); - if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !"); - int nbOfTuples(getNumberOfTuples()); - if(nbOfTuples!=(int)vec.size()) - throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of tuples of this should be equal to size of input vector of bool !"); - const int *pt(begin()); - for(int i=0;i + class DataArrayDiscrete : public DataArrayTemplateClassic + { + public: + MEDCOUPLING_EXPORT bool isEqual(const DataArrayDiscrete& other) const; + MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDiscrete& other, std::string& reason) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDiscrete& other) const; + MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const typename Traits::ArrayType& other) const; + MEDCOUPLING_EXPORT void switchOnTupleEqualTo(T val, std::vector& vec) const; + MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(T val, std::vector& vec) const; + protected: + ~DataArrayDiscrete() { } + }; + + template + class DataArrayDiscreteSigned : public DataArrayDiscrete + { + public: + MEDCOUPLING_EXPORT bool isFittingWith(const std::vector& v) const; + protected: + ~DataArrayDiscreteSigned() { } + }; + class DataArrayInt32Iterator; - class DataArrayInt32 : public DataArrayTemplateClassic + class DataArrayInt32 : public DataArrayDiscreteSigned { public: MEDCOUPLING_EXPORT static DataArrayInt32 *New(); MEDCOUPLING_EXPORT int intValue() const; MEDCOUPLING_EXPORT int getHashCode() const; - MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const; - MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); } - MEDCOUPLING_EXPORT bool isEqual(const DataArrayInt32& other) const; - MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayInt32& other, std::string& reason) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt32& other) const; - MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt32& other) const; - MEDCOUPLING_EXPORT bool isFittingWith(const std::vector& v) const; - MEDCOUPLING_EXPORT void switchOnTupleEqualTo(int val, std::vector& vec) const; - MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(int val, std::vector& vec) const; + MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok + MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok MEDCOUPLING_EXPORT DataArrayInt32 *buildPermutationArr(const DataArrayInt32& other) const; MEDCOUPLING_EXPORT DataArrayInt32 *indicesOfSubPart(const DataArrayInt32& partOfThis) const; MEDCOUPLING_EXPORT DataArrayInt32 *sumPerTuple() const; @@ -661,7 +677,7 @@ namespace MEDCoupling DataArrayInt32() { } }; - class DataArrayInt64 : public DataArrayTemplateClassic + class DataArrayInt64 : public DataArrayDiscrete { }; diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 941326a87..b66c6a667 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -3249,6 +3249,155 @@ struct NotInRange ptr[i]=init+T(i); this->declareAsNew(); } + + /*! + * Equivalent to DataArrayInt::isEqual except that if false the reason of + * mismatch is given. + * + * \param [in] other the instance to be compared with \a this + * \param [out] reason In case of inequality returns the reason. + * \sa DataArrayInt::isEqual + */ + template + bool DataArrayDiscrete::isEqualIfNotWhy(const DataArrayDiscrete& other, std::string& reason) const + { + if(!this->areInfoEqualsIfNotWhy(other,reason)) + return false; + return this->_mem.isEqual(other._mem,0,reason); + } + + /*! + * Checks if \a this and another DataArrayInt are fully equal. For more info see + * \ref MEDCouplingArrayBasicsCompare. + * \param [in] other - an instance of DataArrayInt to compare with \a this one. + * \return bool - \a true if the two arrays are equal, \a false else. + */ + template + bool DataArrayDiscrete::isEqual(const DataArrayDiscrete& other) const + { + std::string tmp; + return isEqualIfNotWhy(other,tmp); + } + + /*! + * Checks if values of \a this and another DataArrayInt are equal. For more info see + * \ref MEDCouplingArrayBasicsCompare. + * \param [in] other - an instance of DataArrayInt to compare with \a this one. + * \return bool - \a true if the values of two arrays are equal, \a false else. + */ + template + bool DataArrayDiscrete::isEqualWithoutConsideringStr(const DataArrayDiscrete& other) const + { + std::string tmp; + return this->_mem.isEqual(other._mem,0,tmp); + } + + /*! + * Checks if values of \a this and another DataArrayInt are equal. Comparison is + * performed on sorted value sequences. + * For more info see\ref MEDCouplingArrayBasicsCompare. + * \param [in] other - an instance of DataArrayInt to compare with \a this one. + * \return bool - \a true if the sorted values of two arrays are equal, \a false else. + */ + template + bool DataArrayDiscrete::isEqualWithoutConsideringStrAndOrder(const typename Traits::ArrayType& other) const + { + MCAuto a(static_cast::ArrayType *>(this)->deepCopy()),b(other.deepCopy()); + a->sort(); + b->sort(); + return a->isEqualWithoutConsideringStr(*b); + } + + /*! + * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple equal to \a val + * put True to the corresponding entry in \a vec. + * \a vec is expected to be with the same size than the number of tuples of \a this. + * + * \sa DataArrayInt::switchOnTupleNotEqualTo. + */ + template + void DataArrayDiscrete::switchOnTupleEqualTo(T val, std::vector& vec) const + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !"); + int nbOfTuples(this->getNumberOfTuples()); + if(nbOfTuples!=(int)vec.size()) + throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !"); + const T *pt(this->begin()); + for(int i=0;i + void DataArrayDiscrete::switchOnTupleNotEqualTo(T val, std::vector& vec) const + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of components of this should be equal to one !"); + int nbOfTuples(this->getNumberOfTuples()); + if(nbOfTuples!=(int)vec.size()) + throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleNotEqualTo : number of tuples of this should be equal to size of input vector of bool !"); + const T *pt(this->begin()); + for(int i=0;i + bool DataArrayDiscreteSigned::isFittingWith(const std::vector& v) const + { + this->checkAllocated(); + if(this->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !"); + const T *w(this->begin()),*end2(this->end()); + T refVal=-std::numeric_limits::max(); + int i=0; + std::vector::const_iterator it(v.begin()); + for(;it!=v.end();it++,i++) + { + if(*it) + { + if(w!=end2) + { + if(*w++==i) + { + if(i>refVal) + refVal=i; + else + { + std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(this->begin(),w-1) << " this is not sorted ascendingly !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + else + return false; + } + else + return false; + } + } + return w==end2; + } } #endif -- 2.39.2