1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
23 #include "MEDCoupling.hxx"
26 #include "MEDCouplingTimeLabel.hxx"
27 #include "MEDCouplingRefCountObject.hxx"
28 #include "InterpKernelException.hxx"
29 #include "MEDCouplingTraits.hxx"
30 #include "MEDCouplingMap.hxx"
31 #include "BBTreePts.txx"
45 } MEDCouplingAxisType;
46 // -- WARNING this enum must be synchronized with MEDCouplingCommon.i file ! --
51 class MEDCouplingPointer
54 MEDCouplingPointer():_internal(0),_external(0) { }
55 void null() { _internal=0; _external=0; }
56 bool isNull() const { return _internal==0 && _external==0; }
57 void setInternal(T *pointer);
58 void setExternal(const T *pointer);
59 const T *getConstPointer() const { if(_internal) return _internal; else return _external; }
60 const T *getConstPointerLoc(std::size_t offset) const { if(_internal) return _internal+offset; else return _external+offset; }
61 T *getPointer() { if(_internal) return _internal; if(_external) throw INTERP_KERNEL::Exception("Trying to write on an external pointer."); else return 0; }
71 typedef void (*Deallocator)(void *,void *);
73 MemArray():_nb_of_elem(0),_nb_of_elem_alloc(0),_ownership(false),_dealloc(0),_param_for_deallocator(0) { }
74 MemArray(const MemArray<T>& other);
75 bool isNull() const { return _pointer.isNull(); }
76 const T *getConstPointerLoc(std::size_t offset) const { return _pointer.getConstPointerLoc(offset); }
77 const T *getConstPointer() const { return _pointer.getConstPointer(); }
78 std::size_t getNbOfElem() const { return _nb_of_elem; }
79 std::size_t getNbOfElemAllocated() const { return _nb_of_elem_alloc; }
80 T *getPointer() { return _pointer.getPointer(); }
81 MemArray<T> &operator=(const MemArray<T>& other);
82 T operator[](std::size_t id) const { return _pointer.getConstPointer()[id]; }
83 T& operator[](std::size_t id) { return _pointer.getPointer()[id]; }
84 bool isEqual(const MemArray<T>& other, T prec, std::string& reason) const;
85 void repr(mcIdType sl, std::ostream& stream) const;
86 bool reprHeader(mcIdType sl, std::ostream& stream) const;
87 void reprZip(mcIdType sl, std::ostream& stream) const;
88 void reprNotTooLong(mcIdType sl, std::ostream& stream) const;
89 void fillWithValue(const T& val);
90 T *fromNoInterlace(std::size_t nbOfComp) const;
91 T *toNoInterlace(std::size_t nbOfComp) const;
93 void reverse(std::size_t nbOfComp);
94 void alloc(std::size_t nbOfElements);
95 void reserve(std::size_t newNbOfElements);
96 void reAlloc(std::size_t newNbOfElements);
97 void useArray(const T *array, bool ownership, DeallocType type, std::size_t nbOfElem);
98 void useExternalArrayWithRWAccess(const T *array, std::size_t nbOfElem);
99 void writeOnPlace(std::size_t id, T element0, const T *others, std::size_t sizeOfOthers);
100 template<class InputIterator>
101 void insertAtTheEnd(InputIterator first, InputIterator last);
102 void pushBack(T elem);
105 bool isDeallocatorCalled() const { return _ownership; }
106 Deallocator getDeallocator() const { return _dealloc; }
107 void setSpecificDeallocator(Deallocator dealloc) { _dealloc=dealloc; }
108 void setParameterForDeallocator(void *param) { _param_for_deallocator=param; }
109 void *getParameterForDeallocator() const { return _param_for_deallocator; }
111 ~MemArray() { destroy(); }
113 static void CPPDeallocator(void *pt, void *param);
114 static void CDeallocator(void *pt, void *param);
115 static void COffsetDeallocator(void *pt, void *param);
117 static void DestroyPointer(T *pt, Deallocator dealloc, void *param);
118 static Deallocator BuildFromType(DeallocType type);
120 std::size_t _nb_of_elem;
121 std::size_t _nb_of_elem_alloc;
123 MEDCouplingPointer<T> _pointer;
124 Deallocator _dealloc;
125 void *_param_for_deallocator;
128 template <class T> class DataArrayTools
131 static void GetSlice(T start, T stop, T step, mcIdType sliceId, mcIdType nbOfSlices, T& startSlice, T& stopSlice);
132 static mcIdType GetNumberOfItemGivenBES(T begin, T end, T step, const std::string& msg);
133 static mcIdType GetNumberOfItemGivenBESRelative(T begin, T end, T step, const std::string& msg);
134 static mcIdType GetPosOfItemGivenBESRelativeNoThrow(T value, T begin, T end, T step);
140 MEDCOUPLING_EXPORT void DACheckNbOfTuplesAndComp(const DataArray *da, mcIdType nbOfTuples, std::size_t nbOfCompo, const std::string& msg);
142 class MEDCOUPLING_EXPORT DataArray : public RefCountObject, public TimeLabel
145 std::size_t getHeapMemorySizeWithoutChildren() const;
146 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
147 void setName(const std::string& name);
148 void copyStringInfoFrom(const DataArray& other);
149 void copyPartOfStringInfoFrom(const DataArray& other, const std::vector<std::size_t>& compoIds);
150 void copyPartOfStringInfoFrom2(const std::vector<std::size_t>& compoIds, const DataArray& other);
151 bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const;
152 bool areInfoEquals(const DataArray& other) const;
153 std::string cppRepr(const std::string& varName) const;
154 std::string getName() const { return _name; }
155 const std::vector<std::string> &getInfoOnComponents() const { return _info_on_compo; }
156 std::vector<std::string> &getInfoOnComponents() { return _info_on_compo; }
157 void setInfoOnComponents(const std::vector<std::string>& info);
158 void setInfoAndChangeNbOfCompo(const std::vector<std::string>& info);
159 std::vector<std::string> getVarsOnComponent() const;
160 std::vector<std::string> getUnitsOnComponent() const;
161 std::string getInfoOnComponent(std::size_t i) const;
162 std::string getVarOnComponent(std::size_t i) const;
163 std::string getUnitOnComponent(std::size_t i) const;
164 void setInfoOnComponent(std::size_t i, const std::string& info);
165 std::size_t getNumberOfComponents() const { return _info_on_compo.size(); }
166 void setPartOfValuesBase3(const DataArray *aBase, const mcIdType *bgTuples, const mcIdType *endTuples, mcIdType bgComp, mcIdType endComp, mcIdType stepComp, bool strictCompoCompare=true);
167 virtual void *getVoidStarPointer() = 0;
168 virtual DataArray *deepCopy() const = 0;
169 virtual DataArray *copySorted(bool asc=true) const = 0;
170 virtual DataArray *buildNewEmptyInstance() const = 0;
171 virtual bool isAllocated() const = 0;
172 virtual void checkAllocated() const = 0;
173 virtual void desallocate() = 0;
174 virtual mcIdType getNumberOfTuples() const = 0;
175 virtual mcIdType getNbOfElems() const = 0;
176 virtual std::size_t getNbOfElemAllocated() const = 0;
177 virtual void alloc(std::size_t nbOfTuple, std::size_t nbOfCompo=1) = 0;
178 virtual void reAlloc(std::size_t newNbOfTuple) = 0;
179 virtual void renumberInPlace(const mcIdType *old2New) = 0;
180 virtual void renumberInPlaceR(const mcIdType *new2Old) = 0;
181 virtual void setContigPartOfSelectedValues(mcIdType tupleIdStart, const DataArray *aBase, const DataArrayIdType *tuplesSelec) = 0;
182 virtual void setContigPartOfSelectedValuesSlice(mcIdType tupleIdStart, const DataArray *aBase, mcIdType bg, mcIdType end2, mcIdType step) = 0;
183 virtual DataArray *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const = 0;
184 virtual DataArray *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const = 0;
185 virtual DataArray *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const = 0;
186 virtual DataArray *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const = 0;
187 virtual DataArray *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const = 0;
188 virtual void rearrange(std::size_t newNbOfCompo) = 0;
189 virtual void circularPermutation(mcIdType nbOfShift=1) = 0;
190 virtual void circularPermutationPerTuple(mcIdType nbOfShift=1) = 0;
191 virtual void reversePerTuple() = 0;
192 void checkNbOfTuples(mcIdType nbOfTuples, const std::string& msg) const;
193 void checkNbOfComps(std::size_t nbOfCompo, const std::string& msg) const;
194 void checkNbOfTuplesAndComp(const DataArray& other, const std::string& msg) const;
195 void checkNbOfTuplesAndComp(mcIdType nbOfTuples, std::size_t nbOfCompo, const std::string& msg) const;
196 void checkNbOfElems(mcIdType nbOfElems, const std::string& msg) const;
197 static void GetSlice(mcIdType start, mcIdType stop, mcIdType step, mcIdType sliceId, mcIdType nbOfSlices, mcIdType& startSlice, mcIdType& stopSlice);
198 static mcIdType GetNumberOfItemGivenBES(mcIdType begin, mcIdType end, mcIdType step, const std::string& msg);
199 static mcIdType GetNumberOfItemGivenBESRelative(mcIdType begin, mcIdType end, mcIdType step, const std::string& msg);
200 static mcIdType GetPosOfItemGivenBESRelativeNoThrow(mcIdType value, mcIdType begin, mcIdType end, mcIdType step);
201 static std::vector<std::string> SplitStringInChuncks(const std::string st, std::size_t sz);
202 static std::string GetVarNameFromInfo(const std::string& info);
203 static std::string GetUnitFromInfo(const std::string& info);
204 static std::string BuildInfoFromVarAndUnit(const std::string& var, const std::string& unit);
205 static std::string GetAxisTypeRepr(MEDCouplingAxisType at);
206 static DataArray *Aggregate(const std::vector<const DataArray *>& arrs);
207 virtual void reprStream(std::ostream& stream) const = 0;
208 virtual void reprZipStream(std::ostream& stream) const = 0;
209 virtual void reprWithoutNameStream(std::ostream& stream) const;
210 virtual void reprZipWithoutNameStream(std::ostream& stream) const = 0;
211 virtual void reprCppStream(const std::string& varName, std::ostream& stream) const = 0;
212 virtual void reprQuickOverview(std::ostream& stream) const = 0;
213 virtual void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const = 0;
218 static void CheckValueInRange(mcIdType ref, mcIdType value, const std::string& msg);
219 static void CheckValueInRangeEx(mcIdType value, mcIdType start, mcIdType end, const std::string& msg);
220 static void CheckClosingParInRange(mcIdType ref, mcIdType value, const std::string& msg);
221 static mcIdType EffectiveCircPerm(mcIdType nbOfShift, mcIdType nbOfTuples);
224 std::vector<std::string> _info_on_compo;
228 namespace MEDCoupling
231 class DataArrayTemplate : public DataArray
236 static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromStdVector(const typename std::vector<T>& v);
237 static MCAuto< typename Traits<T>::ArrayTypeCh > NewFromArray(const T *arrBegin, const T *arrEnd);
238 std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > explodeComponents() const;
240 void printForDebug(std::ostream& oss) const
242 this->checkAllocated();
243 char comma[3] = {'\0',' ','\0'};
244 std::for_each(this->begin(),this->end(),[&comma,&oss](const T& elt) { oss << comma << elt; comma[0]=','; } );
247 std::size_t getHeapMemorySizeWithoutChildren() const;
248 void updateTime() const { }
250 mcIdType getNumberOfTuples() const { return ToIdType(_info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents()); }
251 mcIdType getNbOfElems() const { return ToIdType(_mem.getNbOfElem()); }
253 void *getVoidStarPointer() { return getPointer(); }
254 const T *getConstPointer() const { return _mem.getConstPointer(); }
255 const T *begin() const { return getConstPointer(); }
256 const T *end() const { return getConstPointer()+getNbOfElems(); }
257 T *rwBegin() { return getPointer(); }
258 T *rwEnd() { return getPointer()+getNbOfElems(); }
259 void alloc(std::size_t nbOfTuple, std::size_t nbOfCompo=1);
260 void useArray(const T *array, bool ownership, DeallocType type, std::size_t nbOfTuple, std::size_t nbOfCompo);
261 void useExternalArrayWithRWAccess(const T *array, std::size_t nbOfTuple, std::size_t nbOfCompo);
262 T getIJSafe(std::size_t tupleId, std::size_t compoId) const;
263 T getIJ(std::size_t tupleId, std::size_t compoId) const { return _mem[tupleId*_info_on_compo.size()+compoId]; }
264 void setIJ(std::size_t tupleId, std::size_t compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; declareAsNew(); }
265 void setIJSilent(std::size_t tupleId, std::size_t compoId, T newVal) { _mem[tupleId*_info_on_compo.size()+compoId]=newVal; }
266 T *getPointer() { declareAsNew(); return getPointerSilent(); }
267 T *getPointerSilent() { return _mem.getPointer(); }
269 bool isAllocated() const override;
270 void checkAllocated() const;
272 void reserve(std::size_t nbOfElems);
273 void rearrange(std::size_t newNbOfCompo);
275 void pushBackSilent(T val);
276 void pushBackValsSilent(const T *valsBg, const T *valsEnd);
280 std::size_t getNbOfElemAllocated() const { return _mem.getNbOfElemAllocated(); }
281 void allocIfNecessary(std::size_t nbOfTuple, std::size_t nbOfCompo);
282 void deepCopyFrom(const DataArrayTemplate<T>& other);
284 void fillWithValue(T val);
285 void reAlloc(std::size_t newNbOfTuple);
286 void renumberInPlace(const mcIdType *old2New);
287 void renumberInPlaceR(const mcIdType *new2Old);
288 void sort(bool asc=true);
289 typename Traits<T>::ArrayType *renumber(const mcIdType *old2New) const;
290 typename Traits<T>::ArrayType *renumberR(const mcIdType *new2Old) const;
291 typename Traits<T>::ArrayType *renumberAndReduce(const mcIdType *old2New, mcIdType newNbOfTuple) const;
292 typename Traits<T>::ArrayType *changeNbOfComponents(std::size_t newNbOfComp, T dftValue) const;
293 typename Traits<T>::ArrayType *subArray(mcIdType tupleIdBg, mcIdType tupleIdEnd=-1) const;
294 MCAuto<typename Traits<T>::ArrayTypeCh> selectPartDef(const PartDefinition* pd) const;
295 void circularPermutation(mcIdType nbOfShift=1);
296 void circularPermutationPerTuple(mcIdType nbOfShift=1);
297 void reversePerTuple();
298 void setPartOfValues1(const typename Traits<T>::ArrayType *a, mcIdType bgTuples, mcIdType endTuples, mcIdType stepTuples, mcIdType bgComp, mcIdType endComp, mcIdType stepComp, bool strictCompoCompare=true);
299 void setPartOfValuesSimple1(T a, mcIdType bgTuples, mcIdType endTuples, mcIdType stepTuples, mcIdType bgComp, mcIdType endComp, mcIdType stepComp);
300 void setPartOfValues2(const typename Traits<T>::ArrayType *a, const mcIdType *bgTuples, const mcIdType *endTuples, const mcIdType *bgComp, const mcIdType *endComp, bool strictCompoCompare=true);
301 void setPartOfValuesSimple2(T a, const mcIdType *bgTuples, const mcIdType *endTuples, const mcIdType *bgComp, const mcIdType *endComp);
302 void setPartOfValues3(const typename Traits<T>::ArrayType *a, const mcIdType *bgTuples, const mcIdType *endTuples, mcIdType bgComp, mcIdType endComp, mcIdType stepComp, bool strictCompoCompare=true);
303 void setPartOfValuesSimple3(T a, const mcIdType *bgTuples, const mcIdType *endTuples, mcIdType bgComp, mcIdType endComp, mcIdType stepComp);
304 void setPartOfValues4(const typename Traits<T>::ArrayType *a, mcIdType bgTuples, mcIdType endTuples, mcIdType stepTuples, const mcIdType *bgComp, const mcIdType *endComp, bool strictCompoCompare=true);
305 void setPartOfValuesSimple4(T a, mcIdType bgTuples, mcIdType endTuples, mcIdType stepTuples, const mcIdType *bgComp, const mcIdType *endComp);
306 void setPartOfValuesAdv(const typename Traits<T>::ArrayType *a, const DataArrayIdType *tuplesSelec);
307 void setContigPartOfSelectedValues(mcIdType tupleIdStart, const DataArray *aBase, const DataArrayIdType *tuplesSelec);
308 void setContigPartOfSelectedValuesSlice(mcIdType tupleIdStart, const DataArray *aBase, mcIdType bg, mcIdType end2, mcIdType step);
309 T getMaxValue(mcIdType& tupleId) const;
310 T getMaxValueInArray() const;
311 T getMaxAbsValue(std::size_t& tupleId) const;
312 T getMaxAbsValueInArray() const;
313 T getMinValue(mcIdType& tupleId) const;
314 T getMinValueInArray() const;
315 void getTuple(mcIdType tupleId, T *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
316 template<class InputIterator>
317 void insertAtTheEnd(InputIterator first, InputIterator last);
318 static void SetArrayIn(typename Traits<T>::ArrayType *newArray, typename Traits<T>::ArrayType* &arrayToSet);
319 void writeOnPlace(std::size_t id, T element0, const T *others, mcIdType sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
322 MemArray<T>& accessToMemArray() { return _mem; }
323 const MemArray<T>& accessToMemArray() const { return _mem; }
325 typename Traits<T>::ArrayTypeCh *copySortedImpl(bool asc) const;
326 typename Traits<T>::ArrayType *mySelectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const;
327 typename Traits<T>::ArrayType *mySelectByTupleId(const DataArrayIdType& di) const;
328 typename Traits<T>::ArrayType *mySelectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const;
329 typename Traits<T>::ArrayType *myKeepSelectedComponents(const std::vector<std::size_t>& compoIds) const;
330 typename Traits<T>::ArrayType *mySelectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const;
331 typename Traits<T>::ArrayType *mySelectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const;
337 class DataArrayTemplateClassic : public DataArrayTemplate<T>
340 MCAuto<DataArrayDouble> convertToDblArr() const;
341 MCAuto<DataArrayInt> convertToIntArr() const;
342 MCAuto<DataArrayInt64> convertToInt64Arr() const;
343 MCAuto<DataArrayFloat> convertToFloatArr() const;
344 void applyLin(T a, T b, std::size_t compoId);
345 void applyLin(T a, T b);
346 typename Traits<T>::ArrayType *negate() const;
347 void addEqual(const typename Traits<T>::ArrayType *other);
348 void substractEqual(const typename Traits<T>::ArrayType *other);
349 void multiplyEqual(const typename Traits<T>::ArrayType *other);
350 void divideEqual(const typename Traits<T>::ArrayType *other);
351 static typename Traits<T>::ArrayType *Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
352 static typename Traits<T>::ArrayType *Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
353 static typename Traits<T>::ArrayType *Add(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
354 static typename Traits<T>::ArrayType *Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
355 static typename Traits<T>::ArrayType *Meld(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2);
356 static typename Traits<T>::ArrayType *Meld(const std::vector<const typename Traits<T>::ArrayType *>& arr);
357 MCAuto<DataArrayIdType> findIdsGreaterOrEqualTo(T val) const;
358 MCAuto<DataArrayIdType> findIdsGreaterThan(T val) const;
359 MCAuto<DataArrayIdType> findIdsLowerOrEqualTo(T val) const;
360 MCAuto<DataArrayIdType> findIdsLowerThan(T val) const;
361 DataArrayIdType *findIdsStrictlyNegative() const;
362 typename Traits<T>::ArrayType *fromNoInterlace() const;
363 typename Traits<T>::ArrayType *toNoInterlace() const;
364 void meldWith(const typename Traits<T>::ArrayType *other);
365 typename Traits<T>::ArrayType *duplicateEachTupleNTimes(mcIdType nbTimes) const;
366 void aggregate(const typename Traits<T>::ArrayType *other);
368 typename Traits<T>::ArrayType *computeAbs() const;
369 typename Traits<T>::ArrayType *performCopyOrIncrRef(bool dCpy) const;
370 typename Traits<T>::ArrayType *sumPerTuple() const;
371 void iota(T init=(T)0);
372 void reprStream(std::ostream& stream) const;
373 void reprZipStream(std::ostream& stream) const;
374 void reprNotTooLongStream(std::ostream& stream) const;
375 void reprWithoutNameStream(std::ostream& stream) const;
376 void reprZipWithoutNameStream(std::ostream& stream) const;
377 void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
378 std::string repr() const;
379 std::string reprZip() const;
380 std::string reprNotTooLong() const;
382 MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
384 static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
386 MCAuto<DataArrayIdType> findIdsAdv(const OP& op) const;
389 void somethingEqual(const typename Traits<T>::ArrayType *other);
393 class DataArrayTemplateFP : public DataArrayTemplateClassic<T>
396 bool isUniform(T val, T eps) const;
400 namespace MEDCoupling
402 class DataArrayFloatIterator;
403 class MEDCOUPLING_EXPORT DataArrayFloat : public DataArrayTemplateFP<float>
406 static DataArrayFloat *New();
407 public:// abstract method overload
408 DataArrayFloat *deepCopy() const;
409 DataArrayFloat *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
410 std::string getClassName() const override { return std::string("DataArrayFloat"); }
411 DataArrayFloat *buildNewEmptyInstance() const { return DataArrayFloat::New(); }
412 DataArrayFloat *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return DataArrayTemplateFP<float>::mySelectByTupleRanges(ranges); }
413 DataArrayFloat *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return DataArrayTemplateFP<float>::myKeepSelectedComponents(compoIds); }
414 DataArrayFloat *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
415 DataArrayFloat *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return DataArrayTemplateFP<float>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
416 DataArrayFloat *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return DataArrayTemplateFP<float>::mySelectByTupleIdSafeSlice(bg,end2,step); }
417 void reprCppStream(const std::string& varName, std::ostream& stream) const;
418 void reprQuickOverview(std::ostream& stream) const;
419 void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
420 public:// non abstract but essential
421 bool isEqual(const DataArrayFloat& other, float prec) const;
422 bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const;
423 bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const;
425 DataArrayFloatIterator *iterator();
427 ~DataArrayFloat() { }
432 namespace MEDCoupling
434 class DataArrayDoubleIterator;
435 class MEDCOUPLING_EXPORT DataArrayDouble : public DataArrayTemplateFP<double>
438 static DataArrayDouble *New();
439 double doubleValue() const;
440 DataArrayDouble *deepCopy() const;
441 DataArrayDouble *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
442 std::string getClassName() const override { return std::string("DataArrayDouble"); }
443 DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
444 void checkMonotonic(bool increasing, double eps) const;
445 bool isMonotonic(bool increasing, double eps) const;
446 void writeVTK(std::ostream& ofs, mcIdType indent, const std::string& nameInFile, DataArrayByte *byteArr) const;
447 void reprCppStream(const std::string& varName, std::ostream& stream) const;
448 void reprQuickOverview(std::ostream& stream) const;
449 void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
450 bool isEqual(const DataArrayDouble& other, double prec) const;
451 bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const;
452 bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const;
453 DataArrayDouble *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
454 DataArrayDouble *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
455 DataArrayDouble *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return DataArrayTemplateFP<double>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
456 DataArrayDouble *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return DataArrayTemplateFP<double>::myKeepSelectedComponents(compoIds); }
457 DataArrayDouble *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return DataArrayTemplateFP<double>::mySelectByTupleIdSafeSlice(bg,end2,step); }
458 DataArrayDouble *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return DataArrayTemplateFP<double>::mySelectByTupleRanges(ranges); }
459 bool areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayIdType *&tupleIds) const;
460 void findCommonTuples(double prec, mcIdType limitTupleId, DataArrayIdType *&comm, DataArrayIdType *&commIndex) const;
461 double minimalDistanceTo(const DataArrayDouble *other, mcIdType& thisTupleId, mcIdType& otherTupleId) const;
462 DataArrayDouble *getDifferentValues(double prec, mcIdType limitTupleId=-1) const;
463 DataArrayIdType *findClosestTupleId(const DataArrayDouble *other) const;
464 DataArrayIdType *computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const;
465 void setSelectedComponents(const DataArrayDouble *a, const std::vector<std::size_t>& compoIds);
466 DataArrayDoubleIterator *iterator();
467 void checkNoNullValues() const;
468 void getMinMaxPerComponent(double *bounds) const;
469 DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const;
470 void computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayIdType *& c, DataArrayIdType *& cI) const;
471 void recenterForMaxPrecision(double eps);
472 double getMaxValue2(DataArrayIdType*& tupleIds) const;
473 double getMinValue2(DataArrayIdType*& tupleIds) const;
474 mcIdType count(double value, double eps) const;
475 double getAverageValue() const;
476 double norm2() const;
477 double normMax() const;
478 void normMaxPerComponent(double * res) const;
479 double normMin() const;
480 void accumulate(double *res) const;
481 double accumulate(std::size_t compId) const;
482 DataArrayDouble *accumulatePerChunck(const mcIdType *bgOfIndex, const mcIdType *endOfIndex) const;
483 MCAuto<DataArrayDouble> cumSum() const;
484 double distanceToTuple(const double *tupleBg, const double *tupleEnd, mcIdType& tupleId) const;
485 DataArrayDouble *fromPolarToCart() const;
486 DataArrayDouble *fromCylToCart() const;
487 DataArrayDouble *fromSpherToCart() const;
488 DataArrayDouble *cartesianize(MEDCouplingAxisType atOfThis) const;
489 DataArrayDouble *fromCartToPolar() const;
490 DataArrayDouble *fromCartToCyl() const;
491 DataArrayDouble *fromCartToSpher() const;
492 DataArrayDouble *fromCartToCylGiven(const DataArrayDouble *coords, const double center[3], const double vect[3]) const;
493 DataArrayDouble *doublyContractedProduct() const;
494 DataArrayDouble *determinant() const;
495 DataArrayDouble *eigenValues() const;
496 DataArrayDouble *eigenVectors() const;
497 DataArrayDouble *inverse() const;
498 DataArrayDouble *trace() const;
499 DataArrayDouble *deviator() const;
500 DataArrayDouble *magnitude() const;
501 DataArrayDouble *minPerTuple() const;
502 DataArrayDouble *maxPerTuple() const;
503 DataArrayDouble *maxPerTupleWithCompoId(DataArrayIdType* &compoIdOfMaxPerTuple) const;
504 DataArrayDouble *buildEuclidianDistanceDenseMatrix() const;
505 DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const;
506 void asArcOfCircle(double center[2], double& radius, double& ang) const;
507 void sortPerTuple(bool asc);
508 void applyInv(double numerator);
509 void applyPow(double val);
510 void applyRPow(double val);
511 DataArrayDouble *applyFunc(std::size_t nbOfComp, FunctionToEvaluate func) const;
512 DataArrayDouble *applyFunc(std::size_t nbOfComp, const std::string& func, bool isSafe=true) const;
513 DataArrayDouble *applyFunc(const std::string& func, bool isSafe=true) const;
514 void applyFuncOnThis(const std::string& func, bool isSafe=true);
515 DataArrayDouble *applyFuncCompo(std::size_t nbOfComp, const std::string& func, bool isSafe=true) const;
516 DataArrayDouble *applyFuncNamedCompo(std::size_t nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func, bool isSafe=true) const;
517 void applyFuncFast32(const std::string& func);
518 void applyFuncFast64(const std::string& func);
519 MCAuto<DataArrayDouble> symmetry3DPlane(const double point[3], const double normalVector[3]) const;
520 DataArrayIdType *findIdsInRange(double vmin, double vmax) const;
521 DataArrayIdType *findIdsNotInRange(double vmin, double vmax) const;
522 static DataArrayDouble *Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2);
523 static DataArrayDouble *Aggregate(const std::vector<const DataArrayDouble *>& arr);
524 static DataArrayDouble *Dot(const DataArrayDouble *a1, const DataArrayDouble *a2);
525 static DataArrayDouble *CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2);
526 static DataArrayDouble *Max(const DataArrayDouble *a1, const DataArrayDouble *a2);
527 static DataArrayDouble *Min(const DataArrayDouble *a1, const DataArrayDouble *a2);
528 static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2);
529 void powEqual(const DataArrayDouble *other);
530 std::vector<bool> toVectorOfBool(double eps) const;
531 static void Rotate2DAlg(const double *center, double angle, mcIdType nbNodes, const double *coordsIn, double *coordsOut);
532 static void Rotate3DAlg(const double *center, const double *vect, double angle, mcIdType nbNodes, const double *coordsIn, double *coordsOut);
533 static void Symmetry3DPlane(const double point[3], const double normalVector[3], mcIdType nbNodes, const double *coordsIn, double *coordsOut);
534 static void GiveBaseForPlane(const double normalVector[3], double baseOfPlane[9]);
535 static void ComputeIntegralOfSeg2IntoTri3(const double seg2[4], const double tri3[6], double coeffs[3], double& length);
537 void getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const;
538 void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
539 bool resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI);
540 void finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
542 template<int SPACEDIM>
543 void findCommonTuplesAlg(const double *bbox, mcIdType nbNodes, mcIdType limitNodeId, double prec, DataArrayIdType *c, DataArrayIdType *cI) const;
544 template<int SPACEDIM>
545 static void FindClosestTupleIdAlg(const BBTreePts<SPACEDIM,mcIdType>& myTree, double dist, const double *pos, mcIdType nbOfTuples, const double *thisPt, mcIdType thisNbOfTuples, mcIdType *res);
546 template<int SPACEDIM>
547 static void FindTupleIdsNearTuplesAlg(const BBTreePts<SPACEDIM,mcIdType>& myTree, const double *pos, mcIdType nbOfTuples, double eps,
548 DataArrayIdType *c, DataArrayIdType *cI);
550 DataArrayDouble *operatePerTuple(std::function<double(const double *bg, const double *endd)> func) const;
552 ~DataArrayDouble() { }
553 DataArrayDouble() { }
557 namespace MEDCoupling
560 class DataArrayDiscrete : public DataArrayTemplateClassic<T>
563 using DataArrayType = typename Traits<T>::ArrayType;
565 static DataArrayType *New();
567 bool isEqual(const DataArrayDiscrete<T>& other) const;
568 bool isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const;
569 bool isEqualWithoutConsideringStr(const DataArrayDiscrete<T>& other) const;
570 bool isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const;
571 void switchOnTupleEqualTo(T val, std::vector<bool>& vec) const;
572 void switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const;
573 DataArrayIdType *occurenceRankInThis() const;
574 DataArrayIdType *buildPermutationArr(const DataArrayDiscrete<T>& other) const;
575 DataArrayIdType *indicesOfSubPart(const DataArrayDiscrete<T>& partOfThis) const;
576 void checkMonotonic(bool increasing) const;
577 bool isMonotonic(bool increasing) const;
578 void checkStrictlyMonotonic(bool increasing) const;
579 bool isStrictlyMonotonic(bool increasing) const;
580 mcIdType getHashCode() const;
581 void reprCppStream(const std::string& varName, std::ostream& stream) const;
582 void reprQuickOverview(std::ostream& stream) const;
583 void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
584 void writeVTK(std::ostream& ofs, mcIdType indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const;
585 void transformWithIndArr(const T *indArrBg, const T *indArrEnd);
586 void transformWithIndArr(const MapKeyVal<T, T>& m);
587 DataArrayIdType *findIdsEqual(T val) const;
588 DataArrayIdType *transformWithIndArrR(const T *indArr2Bg, const T *indArrEnd) const;
589 void splitByValueRange(const T *arrBg, const T *arrEnd,
590 DataArrayType *& castArr, DataArrayType *& rankInsideCast, DataArrayType *& castsPresent) const;
591 bool isRange(T& strt, T& sttoopp, T& stteepp) const;
592 DataArrayIdType *invertArrayO2N2N2O(mcIdType newNbOfElem) const;
593 DataArrayIdType *invertArrayN2O2O2N(mcIdType oldNbOfElem) const;
594 DataArrayIdType *invertArrayO2N2N2OBis(mcIdType newNbOfElem) const;
595 MCAuto< MapKeyVal<T, mcIdType> > invertArrayN2O2O2NOptimized() const;
596 MCAuto< MapKeyVal<mcIdType, T> > giveN2OOptimized() const;
597 MCAuto<DataArrayIdType> findIdForEach(const T *valsBg, const T *valsEnd) const;
598 DataArrayIdType *checkAndPreparePermutation() const;
599 void changeSurjectiveFormat(T targetNb, DataArrayIdType *&arr, DataArrayIdType *&arrI) const;
600 DataArrayIdType *buildPermArrPerLevel() const;
601 bool isIota(mcIdType sizeExpected) const;
602 bool isUniform(T val) const;
603 T checkUniformAndGuess() const;
604 bool hasUniqueValues() const;
605 void setSelectedComponents(const DataArrayType *a, const std::vector<std::size_t>& compoIds);
606 DataArrayIdType *findIdsNotEqual(T val) const;
607 DataArrayIdType *findIdsEqualTuple(const T *tupleBg, const T *tupleEnd) const;
608 DataArrayIdType *findIdsEqualList(const T *valsBg, const T *valsEnd) const;
609 DataArrayIdType *findIdsNotEqualList(const T *valsBg, const T *valsEnd) const;
610 mcIdType findIdFirstEqual(T value) const;
611 mcIdType findIdFirstEqual(const std::vector<T>& vals) const;
612 mcIdType findIdFirstEqualTuple(const std::vector<T>& tupl) const;
613 mcIdType findIdSequence(const std::vector<T>& vals) const;
614 mcIdType changeValue(T oldValue, T newValue);
615 mcIdType count(T value) const;
616 bool presenceOfTuple(const std::vector<T>& tupl) const;
617 bool presenceOfValue(T value) const;
618 bool presenceOfValue(const std::vector<T>& vals) const;
619 void accumulate(T *res) const;
620 T accumulate(std::size_t compId) const;
621 DataArrayType *accumulatePerChunck(const mcIdType *bgOfIndex, const mcIdType *endOfIndex) const;
622 void getMinMaxValues(T& minValue, T& maxValue) const;
623 void applyInv(T numerator);
624 void applyDivideBy(T val);
625 void applyModulus(T val);
626 void applyRModulus(T val);
627 void applyPow(T val);
628 void applyRPow(T val);
629 DataArrayIdType *findIdsInRange(T vmin, T vmax) const;
630 DataArrayIdType *findIdsNotInRange(T vmin, T vmax) const;
631 bool checkAllIdsInRange(T vmin, T vmax) const;
632 static DataArrayType *Aggregate(const DataArrayType *a1, const DataArrayType *a2, T offsetA2);
633 static DataArrayType *Aggregate(const std::vector<const DataArrayType *>& arr);
634 static DataArrayType *AggregateIndexes(const std::vector<const DataArrayType *>& arrs);
635 static DataArrayType *BuildUnion(const std::vector<const DataArrayType *>& arr);
636 static DataArrayType *BuildIntersection(const std::vector<const DataArrayType *>& arr);
637 static void PutIntoToSkylineFrmt(const std::vector< std::vector<T> >& v, DataArrayType *& data, DataArrayIdType *& dataIndex);
638 DataArrayIdType *buildComplement(mcIdType nbOfElement) const;
639 DataArrayType *buildSubstraction(const DataArrayType *other) const;
640 DataArrayType *buildSubstractionOptimized(const DataArrayType *other) const;
641 DataArrayType *buildUnion(const DataArrayType *other) const;
642 DataArrayType *buildIntersection(const DataArrayType *other) const;
643 DataArrayIdType *indexOfSameConsecutiveValueGroups() const;
644 DataArrayType *buildUnique() const;
645 DataArrayType *buildUniqueNotSorted() const;
646 DataArrayType *deltaShiftIndex() const;
647 void computeOffsets();
648 void computeOffsetsFull();
649 void findIdsRangesInListOfIds(const DataArrayType *listOfIds, DataArrayIdType *& rangeIdsFetched, DataArrayType *& idsInInputListThatFetch) const;
650 DataArrayType *buildExplicitArrByRanges(const DataArrayType *offsets) const;
651 DataArrayType *buildExplicitArrOfSliceOnScaledArr(T begin, T stop, T step) const;
652 DataArrayIdType *findRangeIdForEachTuple(const DataArrayType *ranges) const;
653 DataArrayType *findIdInRangeForEachTuple(const DataArrayType *ranges) const;
654 void sortEachPairToMakeALinkedList();
655 void sortToHaveConsecutivePairs();
656 MCAuto<DataArrayType> fromLinkedListOfPairToList() const;
657 DataArrayType *getDifferentValues() const;
658 std::vector<DataArrayIdType *> partitionByDifferentValues(std::vector<T>& differentIds) const;
659 std::vector< std::pair<mcIdType,mcIdType> > splitInBalancedSlices(mcIdType nbOfSlices) const;
660 static DataArrayType *Modulus(const DataArrayType *a1, const DataArrayType *a2);
661 void modulusEqual(const DataArrayType *other);
662 static DataArrayType *Pow(const DataArrayType *a1, const DataArrayType *a2);
663 void powEqual(const DataArrayType *other);
664 //MemArray<T>& accessToMemArray() { return _mem; }
665 //const MemArray<T>& accessToMemArray() const { return _mem; }
667 static DataArrayIdType *FindPermutationFromFirstToSecond(const DataArrayType *ids1, const DataArrayType *ids2);
668 static DataArrayIdType *FindPermutationFromFirstToSecondDuplicate(const DataArrayType *ids1, const DataArrayType *ids2);
669 static mcIdType *CheckAndPreparePermutation(const T *start, const T *end);
670 static DataArrayType *BuildListOfSwitchedOn(const std::vector<bool>& v);
671 static DataArrayType *BuildListOfSwitchedOff(const std::vector<bool>& v);
672 static DataArrayIdType *ConvertIndexArrayToO2N(mcIdType nbOfOldTuples, const mcIdType *arr, const mcIdType *arrIBg, const mcIdType *arrIEnd, mcIdType &newNbOfTuples);
673 static DataArrayIdType *MakePartition(const std::vector<const DataArrayType *>& groups, mcIdType newNb, std::vector< std::vector<mcIdType> >& fidsOfGroups);
675 static void ExtractFromIndexedArrays(const mcIdType *idsOfSelectBg, const mcIdType *idsOfSelectEnd,
676 const DataArrayType *arrIn, const DataArrayIdType *arrIndxIn,
677 DataArrayType* &arrOut, DataArrayIdType* &arrIndexOut);
678 static void ExtractFromIndexedArraysSlice(mcIdType idsOfSelectStart, mcIdType idsOfSelectStop, mcIdType idsOfSelectStep,
679 const DataArrayType *arrIn, const DataArrayIdType *arrIndxIn,
680 DataArrayType* &arrOut, DataArrayIdType* &arrIndexOut);
681 static void SetPartOfIndexedArrays(const mcIdType *idsOfSelectBg, const mcIdType *idsOfSelectEnd,
682 const DataArrayType *arrIn, const DataArrayIdType *arrIndxIn,
683 const DataArrayType *srcArr, const DataArrayIdType *srcArrIndex,
684 DataArrayType* &arrOut, DataArrayIdType* &arrIndexOut);
685 static void SetPartOfIndexedArraysSlice(mcIdType start, mcIdType end, mcIdType step,
686 const DataArrayType *arrIn, const DataArrayIdType *arrIndxIn,
687 const DataArrayType *srcArr, const DataArrayIdType *srcArrIndex,
688 DataArrayType* &arrOut, DataArrayIdType* &arrIndexOut);
689 static void SetPartOfIndexedArraysSameIdx(const mcIdType *idsOfSelectBg, const mcIdType *idsOfSelectEnd,
690 DataArrayType *arrInOut, const DataArrayIdType *arrIndxIn,
691 const DataArrayType *srcArr, const DataArrayIdType *srcArrIndex);
692 static void SetPartOfIndexedArraysSameIdxSlice(mcIdType start, mcIdType end, mcIdType step,
693 DataArrayType *arrInOut, const DataArrayIdType *arrIndxIn,
694 const DataArrayType *srcArr, const DataArrayIdType *srcArrIndex);
695 static bool RemoveIdsFromIndexedArrays(const T *idsToRemoveBg, const T *idsToRemoveEnd,
696 DataArrayType *arr, DataArrayIdType *arrIndx, mcIdType offsetForRemoval=0);
697 static DataArrayType *Range(T begin, T end, T step);
699 void getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const;
700 void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
701 bool resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI);
702 void finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
705 void switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const;
707 ~DataArrayDiscrete() { }
711 class DataArrayDiscreteSigned : public DataArrayDiscrete<T>
714 bool isFittingWith(const std::vector<bool>& v) const;
716 ~DataArrayDiscreteSigned() { }
719 class DataArrayInt32Iterator;
721 class MEDCOUPLING_EXPORT DataArrayInt32 : public DataArrayDiscreteSigned<Int32>
723 friend class DataArrayDiscrete<Int32>;
725 DataArrayInt32 *deepCopy() const;
726 DataArrayInt32 *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
727 DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }
728 MCAuto<DataArrayInt64> convertToInt64Arr() const;
730 DataArrayInt32 *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
731 DataArrayInt32 *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
732 DataArrayInt32 *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
733 DataArrayInt32 *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return this->myKeepSelectedComponents(compoIds); }
734 DataArrayInt32 *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return this->mySelectByTupleIdSafeSlice(bg,end2,step); }
735 DataArrayInt32 *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return this->mySelectByTupleRanges(ranges); }
736 std::string getClassName() const override { return std::string("DataArrayInt32"); }
738 DataArrayInt32Iterator *iterator();
740 ~DataArrayInt32() { }
744 class MEDCOUPLING_EXPORT DataArrayInt64 : public DataArrayDiscreteSigned<Int64>
746 friend class DataArrayDiscrete<Int64>;
748 DataArrayInt64 *deepCopy() const;
749 DataArrayInt64 *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
750 DataArrayInt64 *buildNewEmptyInstance() const { return DataArrayInt64::New(); }//ok
751 MCAuto<DataArrayInt32> convertToInt32Arr() const;
753 DataArrayInt64 *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
754 DataArrayInt64 *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
755 DataArrayInt64 *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return DataArrayTemplate<Int64>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
756 DataArrayInt64 *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return DataArrayTemplate<Int64>::myKeepSelectedComponents(compoIds); }
757 DataArrayInt64 *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return DataArrayTemplate<Int64>::mySelectByTupleIdSafeSlice(bg,end2,step); }
758 DataArrayInt64 *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return DataArrayTemplate<Int64>::mySelectByTupleRanges(ranges); }
759 std::string getClassName() const override { return std::string("DataArrayInt64"); }
761 DataArrayInt64Iterator *iterator();
763 ~DataArrayInt64() { }
768 namespace MEDCoupling
773 MCAuto<DataArrayIdType> DataArrayTemplateClassic<T>::findIdsAdv(const OP& op) const
775 this->checkAllocated();
776 if(this->getNumberOfComponents()!=1)
777 throw INTERP_KERNEL::Exception("DataArrayInt::findIdsAdv : this must have exactly one component !");
778 const T *cptr(this->begin());
779 MCAuto<DataArrayIdType> ret(DataArrayIdType::New()); ret->alloc(0,1);
780 mcIdType nbOfTuples=this->getNumberOfTuples();
781 for(mcIdType i=0;i<nbOfTuples;i++,cptr++)
783 ret->pushBackSilent(i);
787 class MEDCOUPLING_EXPORT DataArrayChar : public DataArrayTemplate<char>
790 virtual DataArrayChar *buildEmptySpecializedDAChar() const = 0;
791 mcIdType getHashCode() const;
792 bool isEqual(const DataArrayChar& other) const;
793 virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
794 bool isEqualWithoutConsideringStr(const DataArrayChar& other) const;
795 std::string repr() const;
796 std::string reprZip() const;
797 DataArrayInt *convertToIntArr() const;
798 DataArrayChar *selectByTupleId(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return this->mySelectByTupleId(new2OldBg,new2OldEnd); }
799 DataArrayChar *selectByTupleId(const DataArrayIdType& di) const { return this->mySelectByTupleId(di); }
800 DataArrayChar *selectByTupleIdSafe(const mcIdType *new2OldBg, const mcIdType *new2OldEnd) const { return DataArrayTemplate<char>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
801 DataArrayChar *keepSelectedComponents(const std::vector<std::size_t>& compoIds) const { return DataArrayTemplate<char>::myKeepSelectedComponents(compoIds); }
802 DataArrayChar *selectByTupleIdSafeSlice(mcIdType bg, mcIdType end2, mcIdType step) const { return DataArrayTemplate<char>::mySelectByTupleIdSafeSlice(bg,end2,step); }
803 bool isUniform(char val) const;
804 void meldWith(const DataArrayChar *other);
805 DataArray *selectByTupleRanges(const std::vector<std::pair<mcIdType,mcIdType> >& ranges) const { return DataArrayTemplate<char>::mySelectByTupleRanges(ranges); }
806 DataArrayIdType *findIdsEqual(char val) const;
807 DataArrayIdType *findIdsNotEqual(char val) const;
808 mcIdType findIdSequence(const std::vector<char>& vals) const;
809 mcIdType findIdFirstEqualTuple(const std::vector<char>& tupl) const;
810 mcIdType findIdFirstEqual(char value) const;
811 mcIdType findIdFirstEqual(const std::vector<char>& vals) const;
812 bool presenceOfTuple(const std::vector<char>& tupl) const;
813 bool presenceOfValue(char value) const;
814 bool presenceOfValue(const std::vector<char>& vals) const;
815 DataArrayIdType *findIdsInRange(char vmin, char vmax) const;
816 static DataArrayChar *Aggregate(const DataArrayChar *a1, const DataArrayChar *a2);
817 static DataArrayChar *Aggregate(const std::vector<const DataArrayChar *>& arr);
818 static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2);
819 static DataArrayChar *Meld(const std::vector<const DataArrayChar *>& arr);
820 MemArray<char>& accessToMemArray() { return _mem; }
821 const MemArray<char>& accessToMemArray() const { return _mem; }
823 //void getTinySerializationIntInformation(std::vector<mcIdType>& tinyInfo) const;
824 //void getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const;
825 //bool resizeForUnserialization(const std::vector<mcIdType>& tinyInfoI);
826 //void finishUnserialization(const std::vector<mcIdType>& tinyInfoI, const std::vector<std::string>& tinyInfoS);
831 class DataArrayByteIterator;
833 class MEDCOUPLING_EXPORT DataArrayByte : public DataArrayChar
836 static DataArrayByte *New();
837 DataArrayChar *buildEmptySpecializedDAChar() const;
838 DataArrayByteIterator *iterator();
839 DataArrayByte *deepCopy() const;
840 DataArrayByte *copySorted(bool asc=true) const override { return this->copySortedImpl(asc); }
841 DataArrayByte *performCopyOrIncrRef(bool deepCopy) const;
842 DataArrayByte *buildNewEmptyInstance() const { return DataArrayByte::New(); }
843 char byteValue() const;
844 void reprStream(std::ostream& stream) const;
845 void reprZipStream(std::ostream& stream) const;
846 void reprWithoutNameStream(std::ostream& stream) const;
847 void reprZipWithoutNameStream(std::ostream& stream) const;
848 void reprCppStream(const std::string& varName, std::ostream& stream) const;
849 void reprQuickOverview(std::ostream& stream) const;
850 void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
851 bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
852 std::vector<bool> toVectorOfBool() const;
853 std::string getClassName() const override { return std::string("DataArrayByte"); }
859 class DataArrayAsciiCharIterator;
861 class MEDCOUPLING_EXPORT DataArrayAsciiChar : public DataArrayChar
864 static DataArrayAsciiChar *New();
865 static DataArrayAsciiChar *New(const std::string& st);
866 static DataArrayAsciiChar *New(const std::vector<std::string>& vst, char defaultChar);
867 DataArrayChar *buildEmptySpecializedDAChar() const;
868 DataArrayAsciiCharIterator *iterator();
869 DataArrayAsciiChar *deepCopy() const;
870 DataArrayAsciiChar *copySorted(bool asc=true) const override { (void)asc;throw INTERP_KERNEL::Exception("DataArrayAsciiChar::copySorted : not implemented for DataArrayByte"); }
871 DataArrayAsciiChar *performCopyOrIncrRef(bool deepCopy) const;
872 DataArrayAsciiChar *buildNewEmptyInstance() const { return DataArrayAsciiChar::New(); }
873 char asciiCharValue() const;
874 void reprStream(std::ostream& stream) const;
875 void reprZipStream(std::ostream& stream) const;
876 void reprWithoutNameStream(std::ostream& stream) const;
877 void reprZipWithoutNameStream(std::ostream& stream) const;
878 void reprCppStream(const std::string& varName, std::ostream& stream) const;
879 void reprQuickOverview(std::ostream& stream) const;
880 void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
881 bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
882 std::string getClassName() const override { return std::string("DataArrayAsciiChar"); }
884 ~DataArrayAsciiChar() { }
885 DataArrayAsciiChar() { }
886 DataArrayAsciiChar(const std::string& st);
887 DataArrayAsciiChar(const std::vector<std::string>& vst, char defaultChar);
891 class DataArrayIterator
894 DataArrayIterator(typename Traits<T>::ArrayType *da);
895 ~DataArrayIterator();
896 typename Traits<T>::ArrayTuple *nextt();
898 typename Traits<T>::ArrayType *_da;
901 std::size_t _nb_comp;
909 DataArrayTuple(T *pt, std::size_t nbOfComp);
910 std::string repr() const;
911 std::size_t getNumberOfCompo() const { return _nb_of_compo; }
912 const T *getConstPointer() const { return _pt; }
913 T *getPointer() { return _pt; }
914 typename Traits<T>::ArrayType *buildDA(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
919 std::size_t _nb_of_compo;
922 class DataArrayDoubleTuple;
924 class MEDCOUPLING_EXPORT DataArrayDoubleIterator : public DataArrayIterator<double>
927 DataArrayDoubleIterator(DataArrayDouble *da);
928 ~DataArrayDoubleIterator() { }
931 class MEDCOUPLING_EXPORT DataArrayDoubleTuple : public DataArrayTuple<double>
934 DataArrayDoubleTuple(double *pt, std::size_t nbOfComp);
935 std::string repr() const;
936 double doubleValue() const;
937 DataArrayDouble *buildDADouble(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
940 class DataArrayFloatTuple;
942 class MEDCOUPLING_EXPORT DataArrayFloatIterator : public DataArrayIterator<float>
945 DataArrayFloatIterator(DataArrayFloat *da);
946 ~DataArrayFloatIterator() { }
949 class MEDCOUPLING_EXPORT DataArrayFloatTuple : public DataArrayTuple<float>
952 DataArrayFloatTuple(float *pt, std::size_t nbOfComp);
953 std::string repr() const;
954 float floatValue() const;
955 DataArrayFloat *buildDAFloat(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
958 class MEDCOUPLING_EXPORT DataArrayInt32Iterator : public DataArrayIterator<Int32>
961 DataArrayInt32Iterator(DataArrayInt32 *da);
962 ~DataArrayInt32Iterator() { }
965 class MEDCOUPLING_EXPORT DataArrayInt64Iterator : public DataArrayIterator<Int64>
968 DataArrayInt64Iterator(DataArrayInt64 *da);
969 ~DataArrayInt64Iterator() { }
972 class MEDCOUPLING_EXPORT DataArrayInt32Tuple : public DataArrayTuple<Int32>
975 DataArrayInt32Tuple(Int32 *pt, std::size_t nbOfComp);
976 std::string repr() const;
977 Int32 intValue() const;
978 DataArrayInt32 *buildDAInt(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
981 class MEDCOUPLING_EXPORT DataArrayInt64Tuple : public DataArrayTuple<Int64>
984 DataArrayInt64Tuple(Int64 *pt, std::size_t nbOfComp);
985 std::string repr() const;
986 Int64 intValue() const;
987 DataArrayInt64 *buildDAInt(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
990 typedef DataArrayInt32Tuple DataArrayIntTuple;
992 class DataArrayAsciiCharTuple;
994 class MEDCOUPLING_EXPORT DataArrayAsciiCharIterator
997 DataArrayAsciiCharIterator(DataArrayAsciiChar *da);
998 ~DataArrayAsciiCharIterator();
999 DataArrayAsciiCharTuple *nextt();
1001 DataArrayAsciiChar *_da;
1004 std::size_t _nb_comp;
1008 class MEDCOUPLING_EXPORT DataArrayAsciiCharTuple
1011 DataArrayAsciiCharTuple(char *pt, std::size_t nbOfComp);
1012 std::string repr() const;
1013 std::size_t getNumberOfCompo() const { return _nb_of_compo; }
1014 const char *getConstPointer() const { return _pt; }
1015 char *getPointer() { return _pt; }
1016 char asciiCharValue() const;
1017 DataArrayAsciiChar *buildDAAsciiChar(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
1020 std::size_t _nb_of_compo;
1023 class DataArrayByteTuple;
1025 class MEDCOUPLING_EXPORT DataArrayByteIterator
1028 DataArrayByteIterator(DataArrayByte *da);
1029 ~DataArrayByteIterator();
1030 DataArrayByteTuple *nextt();
1035 std::size_t _nb_comp;
1039 class MEDCOUPLING_EXPORT DataArrayByteTuple
1042 DataArrayByteTuple(char *pt, std::size_t nbOfComp);
1043 std::string repr() const;
1044 std::size_t getNumberOfCompo() const { return _nb_of_compo; }
1045 const char *getConstPointer() const { return _pt; }
1046 char *getPointer() { return _pt; }
1047 char byteValue() const;
1048 DataArrayByte *buildDAByte(std::size_t nbOfTuples, std::size_t nbOfCompo) const;
1051 std::size_t _nb_of_compo;
1055 namespace MEDCoupling
1058 template<class InputIterator>
1059 void MemArray<T>::insertAtTheEnd(InputIterator first, InputIterator last)
1061 T *pointer=_pointer.getPointer();
1064 if(_nb_of_elem>=_nb_of_elem_alloc)
1066 reserve(_nb_of_elem_alloc>0?2*_nb_of_elem_alloc:1);
1067 pointer=_pointer.getPointer();
1069 pointer[_nb_of_elem++]=*first++;
1074 template<class InputIterator>
1075 void DataArrayTemplate<T>::insertAtTheEnd(InputIterator first, InputIterator last)
1077 std::size_t nbCompo(this->getNumberOfComponents());
1079 this->_mem.insertAtTheEnd(first,last);
1082 this->_info_on_compo.resize(1);
1083 this->_mem.insertAtTheEnd(first,last);
1086 throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");