From af2a4cc6b401cc10bb870841e146f3f6c4d10218 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 21 Apr 2020 08:45:31 +0200 Subject: [PATCH] WIP --- src/MEDCoupling/MEDCouplingMemArray.txx | 2 +- src/MEDCoupling/MEDCouplingSkyLineArray.cxx | 50 +++++++++++++++++++++ src/MEDCoupling/MEDCouplingSkyLineArray.hxx | 21 +++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 373e9201b..1c7357cb8 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -5715,7 +5715,7 @@ struct NotInRange * - \a this : [0, 1, 1, 2, 2, 3, 4, 4, 5, 5, 5, 11] * - \a return is : [0, 1, 3, 5, 6, 8, 11, 12] * - * \return a newly allocated array containing the indexed array of + * \return a newly allocated array containing the indexed array format of groups by same consecutive value. * \throw if \a this is not allocated or if \a this has not exactly one component or if number of tuples is equal to 0. * \sa DataArrayInt::buildUnique, MEDCouplingSkyLineArray::groupPacks */ diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index 5fdc66fa8..28dd21de0 100755 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -347,6 +347,56 @@ MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::uniqueNotSortedByPack() const MCAuto ret(MEDCouplingSkyLineArray::New(retIndex,retValues)); return ret.retn(); } +/*! + * Take as input skylinearrays containing the same number of packs ( \a this->getNumberOf ). + * For each packs, this method aggregates corresponding pack in \a sks. + * + * \throw if either a lenght of not nullptr instances in \a sks is zero or if number of packs of not nullptr instances in \a sks is not the same. + * \return a newly allocated skyline array that is the aggregated packs of inputs + */ +MEDCouplingSkyLineArray *MEDCouplingSkyLineArray::AggregatePacks(const std::vector& sks) +{ + std::vectorsksEff; + mcIdType nbOfPacks(std::numeric_limits::max()); + constexpr char MSG[]="MEDCouplingSkyLineArray::AggregatePacks : "; + for(auto sk : sks) + { + if(!sk) + { + mcIdType curNbPacks(sk->getNumberOf()); + if(sksEff.empty()) + nbOfPacks = curNbPacks; + if(nbOfPacks != curNbPacks) + { + std::ostringstream oss; oss << MSG << "first not null input ska has " << nbOfPacks << " whereas there is presence of ska with " << curNbPacks << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + sksEff.push_back(sk); + } + } + if(sksEff.empty()) + { + std::ostringstream oss; oss << MSG << "input vector contains no not nullptr elements !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + // + MCAuto index(DataArrayIdType::New()); index->alloc(nbOfPacks+1,1); + mcIdType *indexPtr(index->getPointer()); *indexPtr=0; + std::vector indicesIn(SkyLineArrayIndexIterator(0,&sksEff),SkyLineArrayIndexIterator(sksEff.size(),&sksEff)); + for( mcIdType packId = 0 ; packId < nbOfPacks ; ++packId, ++indexPtr ) + { + mcIdType nbOfAggPacks(0); + std::for_each(indicesIn.begin(),indicesIn.end(),[packId,&nbOfPacks](const mcIdType *elt) { nbOfPacks+=elt[packId]; }); + indexPtr[1] = indexPtr[0] + nbOfAggPacks; + } + mcIdType nbOfTuplesOut(index->back()); + MCAuto values(DataArrayIdType::New()); values->alloc(nbOfTuplesOut,1); + mcIdType *valuesPtr(values->getPointer()); + std::vector valuesIn(SkyLineArrayValuesIterator(0,&sksEff),SkyLineArrayValuesIterator(sksEff.size(),&sksEff)); + // + MCAuto ret; + return ret.retn(); +} /** * For a 2- or 3-level SkyLine array, return a copy of the absolute pack with given identifier. diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index a56d94b9a..74a63fea7 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -109,6 +109,7 @@ namespace MEDCoupling MEDCouplingSkyLineArray *groupPacks(const DataArrayIdType *indexedPacks) const; MEDCouplingSkyLineArray *uniqueNotSortedByPack() const; + static MEDCouplingSkyLineArray *AggregatePacks(const std::vector& sks); void getSimplePackSafe(const mcIdType absolutePackId, std::vector & pack) const; const mcIdType * getSimplePackSafePtr(const mcIdType absolutePackId, mcIdType & packSize) const; @@ -141,5 +142,25 @@ namespace MEDCoupling MCAuto _values; }; + template + class SkyLineArrayGenIterator : public std::iterator< std::input_iterator_tag, const mcIdType *, mcIdType, const mcIdType **, const mcIdType *> + { + std::size_t _num = 0; + std::vector *_data = nullptr; + public: + explicit SkyLineArrayGenIterator(std::size_t num , std::vector *data) : _num(num),_data(data) {} + SkyLineArrayGenIterator& operator++() { ++_num; return *this; } + bool operator==(const SkyLineArrayGenIterator& other) const { return _num == other._num; } + bool operator!=(const SkyLineArrayGenIterator& other) const { return !(*this == other); } + reference operator*() const { T tt; return tt((*_data)[_num]); } + }; + + struct SkyLineArrayIndexPtrFunctor { const mcIdType *operator()(const MEDCouplingSkyLineArray *ska) { return ska->getIndex(); } }; + + using SkyLineArrayIndexIterator = SkyLineArrayGenIterator; + + struct SkyLineArrayValuesPtrFunctor { const mcIdType *operator()(const MEDCouplingSkyLineArray *ska) { return ska->getValues(); } }; + + using SkyLineArrayValuesIterator = SkyLineArrayGenIterator; } # endif -- 2.39.2