-// Copyright (C) 2007-2020 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// Author : Anthony Geay (EDF R&D)
-#ifndef __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
-#define __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
+#pragma once
#include "MEDCoupling.hxx"
#include "MCType.hxx"
#include <string>
#include <vector>
#include <iterator>
+#include <functional>
namespace MEDCoupling
{
// -- WARNING this enum must be synchronized with MEDCouplingCommon.i file ! --
class PartDefinition;
-
+
template<class T>
class MEDCouplingPointer
{
void setPartOfValuesBase3(const DataArray *aBase, const mcIdType *bgTuples, const mcIdType *endTuples, mcIdType bgComp, mcIdType endComp, mcIdType stepComp, bool strictCompoCompare=true);
virtual void *getVoidStarPointer() = 0;
virtual DataArray *deepCopy() const = 0;
+ virtual DataArray *copySorted(bool asc=true) const = 0;
virtual DataArray *buildNewEmptyInstance() const = 0;
virtual bool isAllocated() const = 0;
virtual void checkAllocated() const = 0;
static mcIdType GetNumberOfItemGivenBES(mcIdType begin, mcIdType end, mcIdType step, const std::string& msg);
static mcIdType GetNumberOfItemGivenBESRelative(mcIdType begin, mcIdType end, mcIdType step, const std::string& msg);
static mcIdType GetPosOfItemGivenBESRelativeNoThrow(mcIdType value, mcIdType begin, mcIdType end, mcIdType step);
+ static std::vector<std::string> SplitStringInChuncks(const std::string st, std::size_t sz);
static std::string GetVarNameFromInfo(const std::string& info);
static std::string GetUnitFromInfo(const std::string& info);
static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit);
typedef T Type;
public:
static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromStdVector(const typename std::vector<T>& v);
+ static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromArray(const T *arrBegin, const T *arrEnd);
std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > explodeComponents() const;
//
+ void printForDebug(std::ostream& oss) const
+ {
+ this->checkAllocated();
+ char comma[3] = {'\0',' ','\0'};
+ std::for_each(this->begin(),this->end(),[&comma,&oss](const T& elt) { oss << comma << elt; comma[0]=','; } );
+ oss << std::endl;
+ }
std::size_t getHeapMemorySizeWithoutChildren() const;
void updateTime() const { }
//
T getIJ(std::size_t tupleId, std::size_t compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
void setIJ(std::size_t tupleId, std::size_t compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); }
void setIJSilent(std::size_t tupleId, std::size_t compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; }
- T *getPointer() { return _mem.getPointer(); declareAsNew(); }
+ T *getPointer() { declareAsNew(); return getPointerSilent(); }
+ T *getPointerSilent() { return _mem.getPointer(); }
void pack() const;
bool isAllocated() const override;
void checkAllocated() const;
MemArray<T>& accessToMemArray() { return _mem; }
const MemArray<T>& accessToMemArray() const { return _mem; }
protected:
+ typename Traits<T>::ArrayTypeCh *copySortedImpl(bool asc) const;
typename Traits<T>::ArrayType *mySelectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const;
typename Traits<T>::ArrayType *mySelectByTupleId(const DataArrayIdType& di) const;
typename Traits<T>::ArrayType *mySelectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const;
public:
MCAuto<DataArrayDouble> convertToDblArr() const;
MCAuto<DataArrayInt> convertToIntArr() const;
+ MCAuto<DataArrayInt64> convertToInt64Arr() const;
MCAuto<DataArrayFloat> convertToFloatArr() const;
void applyLin(T a, T b, std::size_t compoId);
void applyLin(T a, T b);
template<class FCT>
void somethingEqual(const typename Traits<T>::ArrayType *other);
};
-
+
template<class T>
class DataArrayTemplateFP : public DataArrayTemplateClassic<T>
{
static DataArrayFloat *New();
public:// abstract method overload
DataArrayFloat *deepCopy() const;
+ DataArrayFloat *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
std::string getClassName() const override { return std::string("DataArrayFloat"); }
DataArrayFloat *buildNewEmptyInstance() const { return DataArrayFloat::New(); }
DataArrayFloat *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return DataArrayTemplateFP<float>::mySelectByTupleRanges(ranges); }
static DataArrayDouble *New();
double doubleValue() const;
DataArrayDouble *deepCopy() const;
+ DataArrayDouble *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
std::string getClassName() const override { return std::string("DataArrayDouble"); }
DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
void checkMonotonic(bool increasing, double eps) const;
DataArrayDouble *trace() const;
DataArrayDouble *deviator() const;
DataArrayDouble *magnitude() const;
+ DataArrayDouble *minPerTuple() const;
DataArrayDouble *maxPerTuple() const;
DataArrayDouble *maxPerTupleWithCompoId(DataArrayIdType* &compoIdOfMaxPerTuple) const;
DataArrayDouble *buildEuclidianDistanceDenseMatrix() const;
bool resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI);
void finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
public:
- template<mcIdType SPACEDIM>
+ template<int SPACEDIM>
void findCommonTuplesAlg(const double *bbox, mcIdType nbNodes, mcIdType limitNodeId, double prec, DataArrayIdType *c, DataArrayIdType *cI) const;
- template<mcIdType SPACEDIM>
+ template<int SPACEDIM>
static void FindClosestTupleIdAlg(const BBTreePts<SPACEDIM,mcIdType>& myTree, double dist, const double *pos, mcIdType nbOfTuples, const double *thisPt, mcIdType thisNbOfTuples, mcIdType *res);
- template<mcIdType SPACEDIM>
+ template<int SPACEDIM>
static void FindTupleIdsNearTuplesAlg(const BBTreePts<SPACEDIM,mcIdType>& myTree, const double *pos, mcIdType nbOfTuples, double eps,
DataArrayIdType *c, DataArrayIdType *cI);
+ private:
+ DataArrayDouble *operatePerTuple(std::function<double(const double *bg, const double *endd)> func) const;
private:
~DataArrayDouble() { }
DataArrayDouble() { }
class DataArrayDiscrete : public DataArrayTemplateClassic<T>
{
public:
- typedef typename Traits<T>::ArrayType DataArrayType;
+ using DataArrayType = typename Traits<T>::ArrayType;
public:
static DataArrayType *New();
T intValue() const;
bool isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const;
void switchOnTupleEqualTo(T val, std::vector<bool>& vec) const;
void switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const;
+ DataArrayIdType *occurenceRankInThis() const;
DataArrayIdType *buildPermutationArr(const DataArrayDiscrete<T>& other) const;
DataArrayIdType *indicesOfSubPart(const DataArrayDiscrete<T>& partOfThis) const;
void checkMonotonic(bool increasing) const;
DataArrayIdType *findIdsEqual(T val) const;
DataArrayIdType *transformWithIndArrR(const T *indArr2Bg, const T *indArrEnd) const;
void splitByValueRange(const T *arrBg, const T *arrEnd,
- DataArrayType *& castArr, DataArrayType *& rankInsideCast, DataArrayType *& castsPresent) const;
+ DataArrayType *& castArr, DataArrayType *& rankInsideCast, DataArrayType *& castsPresent) const;
bool isRange(T& strt, T& sttoopp, T& stteepp) const;
DataArrayIdType *invertArrayO2N2N2O(mcIdType newNbOfElem) const;
DataArrayIdType *invertArrayN2O2O2N(mcIdType oldNbOfElem) const;
T checkUniformAndGuess() const;
bool hasUniqueValues() const;
void setSelectedComponents(const DataArrayType *a, const std::vector<std::size_t>& compoIds);
+ DataArrayIdType *locateComponentId(const DataArrayType *valToSearchIntoTuples, const DataArrayIdType *tupleIdHint) const;
DataArrayIdType *findIdsNotEqual(T val) const;
DataArrayIdType *findIdsEqualTuple(const T *tupleBg, const T *tupleEnd) const;
DataArrayIdType *findIdsEqualList(const T *valsBg, const T *valsEnd) const;
DataArrayType *buildSubstractionOptimized(const DataArrayType *other) const;
DataArrayType *buildUnion(const DataArrayType *other) const;
DataArrayType *buildIntersection(const DataArrayType *other) const;
+ DataArrayIdType *indexOfSameConsecutiveValueGroups() const;
DataArrayType *buildUnique() const;
DataArrayType *buildUniqueNotSorted() const;
DataArrayType *deltaShiftIndex() const;
DataArrayIdType *findRangeIdForEachTuple(const DataArrayType *ranges) const;
DataArrayType *findIdInRangeForEachTuple(const DataArrayType *ranges) const;
void sortEachPairToMakeALinkedList();
+ void sortToHaveConsecutivePairs();
MCAuto<DataArrayType> fromLinkedListOfPairToList() const;
DataArrayType *getDifferentValues() const;
std::vector<DataArrayIdType *> partitionByDifferentValues(std::vector<T>& differentIds) const;
//const MemArray<T>& accessToMemArray() const { return _mem; }
public:
static DataArrayIdType *FindPermutationFromFirstToSecond(const DataArrayType *ids1, const DataArrayType *ids2);
+ static DataArrayIdType *FindPermutationFromFirstToSecondDuplicate(const DataArrayType *ids1, const DataArrayType *ids2);
static mcIdType *CheckAndPreparePermutation(const T *start, const T *end);
static DataArrayType *BuildListOfSwitchedOn(const std::vector<bool>& v);
static DataArrayType *BuildListOfSwitchedOff(const std::vector<bool>& v);
protected:
~DataArrayDiscrete() { }
};
-
+
template<class T>
class DataArrayDiscreteSigned : public DataArrayDiscrete<T>
{
{
friend class DataArrayDiscrete<Int32>;
public:
- DataArrayInt32 *deepCopy() const;//ok
- DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok
+ DataArrayInt32 *deepCopy() const;
+ DataArrayInt32 *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
+ DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }
+ MCAuto<DataArrayInt64> convertToInt64Arr() const;
public:
DataArrayInt32 *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
DataArrayInt32 *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
friend class DataArrayDiscrete<Int64>;
public:
DataArrayInt64 *deepCopy() const;
+ DataArrayInt64 *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
DataArrayInt64 *buildNewEmptyInstance() const { return DataArrayInt64::New(); }//ok
+ MCAuto<DataArrayInt32> convertToInt32Arr() const;
public:
DataArrayInt64 *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
DataArrayInt64 *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
DataArrayChar *buildEmptySpecializedDAChar() const;
DataArrayByteIterator *iterator();
DataArrayByte *deepCopy() const;
+ DataArrayByte *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
DataArrayByte *performCopyOrIncrRef(bool deepCopy) const;
DataArrayByte *buildNewEmptyInstance() const { return DataArrayByte::New(); }
char byteValue() const;
DataArrayChar *buildEmptySpecializedDAChar() const;
DataArrayAsciiCharIterator *iterator();
DataArrayAsciiChar *deepCopy() const;
+ DataArrayAsciiChar *copySorted(bool asc=true) const override { (void)asc;throw INTERP_KERNEL::Exception("DataArrayAsciiChar::copySorted : not implemented for DataArrayByte"); }
DataArrayAsciiChar *performCopyOrIncrRef(bool deepCopy) const;
DataArrayAsciiChar *buildNewEmptyInstance() const { return DataArrayAsciiChar::New(); }
char asciiCharValue() const;
float floatValue() const;
DataArrayFloat *buildDAFloat(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
};
-
+
class MEDCOUPLING_EXPORT DataArrayInt32Iterator : public DataArrayIterator<Int32>
{
public:
char *_pt;
std::size_t _nb_of_compo;
};
-
+
class DataArrayByteTuple;
class MEDCOUPLING_EXPORT DataArrayByteIterator
throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");
}
}
-
-#endif