1 // Copyright (C) 2007-2016 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)
21 #ifndef __PARAMEDMEM_MEDCOUPLINGMEMARRAY_TXX__
22 #define __PARAMEDMEM_MEDCOUPLINGMEMARRAY_TXX__
24 #include "MEDCouplingMemArray.hxx"
25 #include "NormalizedUnstructuredMesh.hxx"
26 #include "InterpKernelException.hxx"
27 #include "InterpolationUtils.hxx"
28 #include "MEDCouplingPartDefinition.hxx"
29 #include "InterpKernelAutoPtr.hxx"
40 void MEDCouplingPointer<T>::setInternal(T *pointer)
47 void MEDCouplingPointer<T>::setExternal(const T *pointer)
54 MemArray<T>::MemArray(const MemArray<T>& other):_nb_of_elem(0),_nb_of_elem_alloc(0),_ownership(false),_dealloc(0),_param_for_deallocator(0)
56 if(!other._pointer.isNull())
58 _nb_of_elem_alloc=other._nb_of_elem;
59 T *pointer=(T*)malloc(_nb_of_elem_alloc*sizeof(T));
60 std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+other._nb_of_elem,pointer);
61 useArray(pointer,true,DeallocType::C_DEALLOC,other._nb_of_elem);
66 void MemArray<T>::useArray(const T *array, bool ownership, DeallocType type, std::size_t nbOfElem)
70 _nb_of_elem_alloc=nbOfElem;
72 _pointer.setInternal(const_cast<T *>(array));
74 _pointer.setExternal(array);
76 _dealloc=BuildFromType(type);
80 void MemArray<T>::useExternalArrayWithRWAccess(const T *array, std::size_t nbOfElem)
84 _nb_of_elem_alloc=nbOfElem;
85 _pointer.setInternal(const_cast<T *>(array));
87 _dealloc=CPPDeallocator;
91 void MemArray<T>::writeOnPlace(std::size_t id, T element0, const T *others, std::size_t sizeOfOthers)
93 if(id+sizeOfOthers>=_nb_of_elem_alloc)
94 reserve(2*_nb_of_elem+sizeOfOthers+1);
95 T *pointer=_pointer.getPointer();
97 std::copy(others,others+sizeOfOthers,pointer+id+1);
98 _nb_of_elem=std::max<std::size_t>(_nb_of_elem,id+sizeOfOthers+1);
102 void MemArray<T>::pushBack(T elem)
104 if(_nb_of_elem>=_nb_of_elem_alloc)
105 reserve(_nb_of_elem_alloc>0?2*_nb_of_elem_alloc:1);
107 pt[_nb_of_elem++]=elem;
111 T MemArray<T>::popBack()
115 const T *pt=getConstPointer();
116 return pt[--_nb_of_elem];
118 throw INTERP_KERNEL::Exception("MemArray::popBack : nothing to pop in array !");
122 void MemArray<T>::pack() const
124 (const_cast<MemArray<T> * >(this))->reserve(_nb_of_elem);
128 bool MemArray<T>::isEqual(const MemArray<T>& other, T prec, std::string& reason) const
130 std::ostringstream oss; oss.precision(15);
131 if(_nb_of_elem!=other._nb_of_elem)
133 oss << "Number of elements in coarse data of DataArray mismatch : this=" << _nb_of_elem << " other=" << other._nb_of_elem;
137 const T *pt1=_pointer.getConstPointer();
138 const T *pt2=other._pointer.getConstPointer();
143 oss << "coarse data pointer is defined for only one DataArray instance !";
149 for(std::size_t i=0;i<_nb_of_elem;i++)
150 if(pt1[i]-pt2[i]<-prec || (pt1[i]-pt2[i])>prec)
152 oss << "The content of data differs at pos #" << i << " of coarse data ! this[i]=" << pt1[i] << " other[i]=" << pt2[i];
160 * \param [in] sl is typically the number of components
161 * \return True if a not null pointer is present, False if not.
164 bool MemArray<T>::reprHeader(int sl, std::ostream& stream) const
166 stream << "Number of tuples : ";
167 if(!_pointer.isNull())
170 stream << _nb_of_elem/sl << std::endl << "Internal memory facts : " << _nb_of_elem << "/" << _nb_of_elem_alloc;
172 stream << "Empty Data";
177 stream << "Data content :\n";
178 bool ret=!_pointer.isNull();
180 stream << "No data !\n";
185 * \param [in] sl is typically the number of components
188 void MemArray<T>::repr(int sl, std::ostream& stream) const
190 if(reprHeader(sl,stream))
192 const T *data=getConstPointer();
193 if(_nb_of_elem!=0 && sl!=0)
195 std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
196 for(std::size_t i=0;i<nbOfTuples;i++)
198 stream << "Tuple #" << i << " : ";
199 std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
205 stream << "Empty Data\n";
210 * \param [in] sl is typically the number of components
213 void MemArray<T>::reprZip(int sl, std::ostream& stream) const
215 stream << "Number of tuples : ";
216 if(!_pointer.isNull())
219 stream << _nb_of_elem/sl;
221 stream << "Empty Data";
226 stream << "Data content : ";
227 const T *data=getConstPointer();
228 if(!_pointer.isNull())
230 if(_nb_of_elem!=0 && sl!=0)
232 std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
233 for(std::size_t i=0;i<nbOfTuples;i++)
236 std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
243 stream << "Empty Data\n";
246 stream << "No data !\n";
250 * \param [in] sl is typically the number of components
253 void MemArray<T>::reprNotTooLong(int sl, std::ostream& stream) const
255 if(reprHeader(sl,stream))
257 const T *data=getConstPointer();
258 if(_nb_of_elem!=0 && sl!=0)
260 std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
263 for(std::size_t i=0;i<nbOfTuples;i++)
265 stream << "Tuple #" << i << " : ";
266 std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
272 {// too much tuples -> print the 3 first tuples and 3 last.
273 stream << "Tuple #0 : ";
274 std::copy(data,data+sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
275 stream << "Tuple #1 : ";
276 std::copy(data+sl,data+2*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
277 stream << "Tuple #2 : ";
278 std::copy(data+2*sl,data+3*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
280 stream << "Tuple #" << nbOfTuples-3 << " : ";
281 std::copy(data+(nbOfTuples-3)*sl,data+(nbOfTuples-2)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
282 stream << "Tuple #" << nbOfTuples-2 << " : ";
283 std::copy(data+(nbOfTuples-2)*sl,data+(nbOfTuples-1)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
284 stream << "Tuple #" << nbOfTuples-1 << " : ";
285 std::copy(data+(nbOfTuples-1)*sl,data+nbOfTuples*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
289 stream << "Empty Data\n";
294 void MemArray<T>::fillWithValue(const T& val)
296 T *pt=_pointer.getPointer();
297 std::fill(pt,pt+_nb_of_elem,val);
301 T *MemArray<T>::fromNoInterlace(int nbOfComp) const
304 throw INTERP_KERNEL::Exception("MemArray<T>::fromNoInterlace : number of components must be > 0 !");
305 const T *pt=_pointer.getConstPointer();
306 std::size_t nbOfTuples=_nb_of_elem/nbOfComp;
307 T *ret=(T*)malloc(_nb_of_elem*sizeof(T));
309 for(std::size_t i=0;i<nbOfTuples;i++)
310 for(int j=0;j<nbOfComp;j++,w++)
311 *w=pt[j*nbOfTuples+i];
316 T *MemArray<T>::toNoInterlace(int nbOfComp) const
319 throw INTERP_KERNEL::Exception("MemArray<T>::toNoInterlace : number of components must be > 0 !");
320 const T *pt=_pointer.getConstPointer();
321 std::size_t nbOfTuples=_nb_of_elem/nbOfComp;
322 T *ret=(T*)malloc(_nb_of_elem*sizeof(T));
324 for(int i=0;i<nbOfComp;i++)
325 for(std::size_t j=0;j<nbOfTuples;j++,w++)
331 void MemArray<T>::sort(bool asc)
333 T *pt=_pointer.getPointer();
335 std::sort(pt,pt+_nb_of_elem);
338 typename std::reverse_iterator<T *> it1(pt+_nb_of_elem);
339 typename std::reverse_iterator<T *> it2(pt);
345 void MemArray<T>::reverse(int nbOfComp)
348 throw INTERP_KERNEL::Exception("MemArray<T>::reverse : only supported with 'this' array with ONE or more than ONE component !");
349 T *pt=_pointer.getPointer();
352 std::reverse(pt,pt+_nb_of_elem);
357 T *pt2=pt+_nb_of_elem-nbOfComp;
358 std::size_t nbOfTuples=_nb_of_elem/nbOfComp;
359 for(std::size_t i=0;i<nbOfTuples/2;i++,pt+=nbOfComp,pt2-=nbOfComp)
361 for(int j=0;j<nbOfComp;j++)
362 std::swap(pt[j],pt2[j]);
368 void MemArray<T>::alloc(std::size_t nbOfElements)
371 _nb_of_elem=nbOfElements;
372 _nb_of_elem_alloc=nbOfElements;
373 _pointer.setInternal((T*)malloc(_nb_of_elem_alloc*sizeof(T)));
375 _dealloc=CDeallocator;
379 * This method performs systematically an allocation of \a newNbOfElements elements in \a this.
380 * \a _nb_of_elem and \a _nb_of_elem_alloc will \b NOT be systematically equal (contrary to MemArray<T>::reAlloc method.
381 * So after the call of this method \a _nb_of_elem will be equal tostd::min<std::size_t>(_nb_of_elem,newNbOfElements) and \a _nb_of_elem_alloc equal to
382 * \a newNbOfElements. This method is typically used to perform a pushBack to avoid systematic allocations-copy-deallocation.
383 * So after the call of this method the accessible content is perfectly set.
385 * So this method should not be confused with MemArray<T>::reserve that is close to MemArray<T>::reAlloc but not same.
388 void MemArray<T>::reserve(std::size_t newNbOfElements)
390 if(_nb_of_elem_alloc==newNbOfElements)
392 T *pointer=(T*)malloc(newNbOfElements*sizeof(T));
393 std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<std::size_t>(_nb_of_elem,newNbOfElements),pointer);
395 DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
396 _pointer.setInternal(pointer);
397 _nb_of_elem=std::min<std::size_t>(_nb_of_elem,newNbOfElements);
398 _nb_of_elem_alloc=newNbOfElements;
400 _dealloc=CDeallocator;
401 _param_for_deallocator=0;
405 * This method performs systematically an allocation of \a newNbOfElements elements in \a this.
406 * \a _nb_of_elem and \a _nb_of_elem_alloc will be equal even if only std::min<std::size_t>(_nb_of_elem,newNbOfElements) come from the .
407 * The remaining part of the new allocated chunk are available but not set previously !
409 * So this method should not be confused with MemArray<T>::reserve that is close to MemArray<T>::reAlloc but not same.
412 void MemArray<T>::reAlloc(std::size_t newNbOfElements)
414 if(_nb_of_elem==newNbOfElements)
416 T *pointer=(T*)malloc(newNbOfElements*sizeof(T));
417 std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<std::size_t>(_nb_of_elem,newNbOfElements),pointer);
419 DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
420 _pointer.setInternal(pointer);
421 _nb_of_elem=newNbOfElements;
422 _nb_of_elem_alloc=newNbOfElements;
424 _dealloc=CDeallocator;
425 _param_for_deallocator=0;
429 void MemArray<T>::CPPDeallocator(void *pt, void *param)
431 delete [] reinterpret_cast<T*>(pt);
435 void MemArray<T>::CDeallocator(void *pt, void *param)
441 void MemArray<T>::COffsetDeallocator(void *pt, void *param)
443 int64_t *offset(reinterpret_cast<int64_t *>(param));
444 char *ptcast(reinterpret_cast<char *>(pt));
445 free(ptcast+*offset);
449 typename MemArray<T>::Deallocator MemArray<T>::BuildFromType(DeallocType type)
453 case DeallocType::CPP_DEALLOC:
454 return CPPDeallocator;
455 case DeallocType::C_DEALLOC:
457 case DeallocType::C_DEALLOC_WITH_OFFSET:
458 return COffsetDeallocator;
460 throw INTERP_KERNEL::Exception("Invalid deallocation requested ! Unrecognized enum DeallocType !");
465 void MemArray<T>::DestroyPointer(T *pt, typename MemArray<T>::Deallocator dealloc, void *param)
472 void MemArray<T>::destroy()
475 DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
479 _param_for_deallocator=NULL;
485 MemArray<T> &MemArray<T>::operator=(const MemArray<T>& other)
487 alloc(other._nb_of_elem);
488 std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+_nb_of_elem,_pointer.getPointer());
492 //////////////////////////////////
495 DataArrayIterator<T>::DataArrayIterator(typename Traits<T>::ArrayType *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
500 if(_da->isAllocated())
502 _nb_comp=da->getNumberOfComponents();
503 _nb_tuple=da->getNumberOfTuples();
504 _pt=da->getPointer();
510 DataArrayIterator<T>::~DataArrayIterator()
517 typename Traits<T>::ArrayTuple *DataArrayIterator<T>::nextt()
519 if(_tuple_id<_nb_tuple)
522 typename Traits<T>::ArrayTuple *ret=new typename Traits<T>::ArrayTuple(_pt,_nb_comp);
530 //////////////////////////////////
533 DataArrayTuple<T>::DataArrayTuple(T *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
538 T DataArrayTuple<T>::zeValue() const
542 throw INTERP_KERNEL::Exception("DataArrayTuple<T>::zeValue : DataArrayTuple instance has not exactly 1 component -> Not possible to convert it into a single value !");
546 typename Traits<T>::ArrayType *DataArrayTuple<T>::buildDA(int nbOfTuples, int nbOfCompo) const
548 if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
550 typename Traits<T>::ArrayType *ret=Traits<T>::ArrayType::New();
551 ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
556 std::ostringstream oss; oss << "DataArrayTuple<T>::buildDA : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
557 oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
558 throw INTERP_KERNEL::Exception(oss.str().c_str());
562 //////////////////////////////////
565 MCAuto< typename Traits<T>::ArrayTypeCh > DataArrayTemplate<T>::NewFromStdVector(const typename std::vector<T>& v)
567 std::size_t sz(v.size());
568 MCAuto< typename Traits<T>::ArrayTypeCh > ret(Traits<T>::ArrayTypeCh::New());
570 T *pt(ret->getPointer());
571 std::copy(v.begin(),v.end(),pt);
576 std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > DataArrayTemplate<T>::explodeComponents() const
579 std::size_t sz(getNumberOfComponents());
580 int nbTuples(getNumberOfTuples());
581 std::string name(getName());
582 std::vector<std::string> compNames(getInfoOnComponents());
583 std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > ret(sz);
584 const T *thisPt(begin());
585 for(std::size_t i=0;i<sz;i++)
587 MCAuto< typename Traits<T>::ArrayTypeCh > part(Traits<T>::ArrayTypeCh::New());
588 part->alloc(nbTuples,1);
590 part->setInfoOnComponent(0,compNames[i]);
591 T *otherPt(part->getPointer());
592 for(int j=0;j<nbTuples;j++)
593 otherPt[j]=thisPt[sz*j+i];
600 std::size_t DataArrayTemplate<T>::getHeapMemorySizeWithoutChildren() const
602 std::size_t sz(_mem.getNbOfElemAllocated());
604 return DataArray::getHeapMemorySizeWithoutChildren()+sz;
608 * Allocates the raw data in memory. If the memory was already allocated, then it is
609 * freed and re-allocated. See an example of this method use
610 * \ref MEDCouplingArraySteps1WC "here".
611 * \param [in] nbOfTuple - number of tuples of data to allocate.
612 * \param [in] nbOfCompo - number of components of data to allocate.
613 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
616 void DataArrayTemplate<T>::alloc(std::size_t nbOfTuple, std::size_t nbOfCompo)
618 _info_on_compo.resize(nbOfCompo);
619 _mem.alloc(nbOfCompo*nbOfTuple);
624 * Sets a C array to be used as raw data of \a this. The previously set info
625 * of components is retained and re-sized.
626 * For more info see \ref MEDCouplingArraySteps1.
627 * \param [in] array - the C array to be used as raw data of \a this.
628 * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
629 * \param [in] type - specifies how to deallocate \a array. If \a type == MEDCoupling::CPP_DEALLOC,
630 * \c delete [] \c array; will be called. If \a type == MEDCoupling::C_DEALLOC,
631 * \c free(\c array ) will be called.
632 * \param [in] nbOfTuple - new number of tuples in \a this.
633 * \param [in] nbOfCompo - new number of components in \a this.
636 void DataArrayTemplate<T>::useArray(const T *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
638 _info_on_compo.resize(nbOfCompo);
639 _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo);
644 void DataArrayTemplate<T>::useExternalArrayWithRWAccess(const T *array, int nbOfTuple, int nbOfCompo)
646 _info_on_compo.resize(nbOfCompo);
647 _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo);
652 * Returns a value located at specified tuple and component.
653 * This method is equivalent to DataArrayTemplate<T>::getIJ() except that validity of
654 * parameters is checked. So this method is safe but expensive if used to go through
655 * all values of \a this.
656 * \param [in] tupleId - index of tuple of interest.
657 * \param [in] compoId - index of component of interest.
658 * \return double - value located by \a tupleId and \a compoId.
659 * \throw If \a this is not allocated.
660 * \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
661 * \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
664 T DataArrayTemplate<T>::getIJSafe(int tupleId, int compoId) const
667 if(tupleId<0 || tupleId>=getNumberOfTuples())
669 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
670 throw INTERP_KERNEL::Exception(oss.str().c_str());
672 if(compoId<0 || compoId>=(int)getNumberOfComponents())
674 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
675 throw INTERP_KERNEL::Exception(oss.str().c_str());
677 return _mem[tupleId*_info_on_compo.size()+compoId];
681 * This method \b do \b not modify content of \a this. It only modify its memory footprint if the allocated memory is to high regarding real data to store.
683 * \sa DataArray::getHeapMemorySizeWithoutChildren, DataArrayTemplate<T>::reserve
686 void DataArrayTemplate<T>::pack() const
692 * Checks if raw data is allocated. Read more on the raw data
693 * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information.
694 * \return bool - \a true if the raw data is allocated, \a false else.
697 bool DataArrayTemplate<T>::isAllocated() const
699 return getConstPointer()!=0;
703 * Checks if raw data is allocated and throws an exception if it is not the case.
704 * \throw If the raw data is not allocated.
707 void DataArrayTemplate<T>::checkAllocated() const
711 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !";
712 throw INTERP_KERNEL::Exception(oss.str().c_str());
717 * This method deallocated \a this without modification of information relative to the components.
718 * After call of this method, DataArrayDouble::isAllocated will return false.
719 * If \a this is already not allocated, \a this is let unchanged.
722 void DataArrayTemplate<T>::desallocate()
728 * This method reserve nbOfElems elements in memory ( nbOfElems*8 bytes ) \b without impacting the number of tuples in \a this.
729 * If \a this has already been allocated, this method checks that \a this has only one component. If not an INTERP_KERNEL::Exception will be thrown.
730 * If \a this has not already been allocated, number of components is set to one.
731 * This method allows to reduce number of reallocations on invocation of DataArrayDouble::pushBackSilent and DataArrayDouble::pushBackValsSilent on \a this.
733 * \sa DataArrayDouble::pack, DataArrayDouble::pushBackSilent, DataArrayDouble::pushBackValsSilent
736 void DataArrayTemplate<T>::reserve(std::size_t nbOfElems)
738 int nbCompo(getNumberOfComponents());
741 _mem.reserve(nbOfElems);
745 _mem.reserve(nbOfElems);
746 _info_on_compo.resize(1);
750 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::reserve : not available for DataArrayDouble with number of components different than 1 !";
751 throw INTERP_KERNEL::Exception(oss.str().c_str());
756 * This method adds at the end of \a this the single value \a val. This method do \b not update its time label to avoid useless incrementation
757 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
759 * \param [in] val the value to be added in \a this
760 * \throw If \a this has already been allocated with number of components different from one.
761 * \sa DataArrayDouble::pushBackValsSilent
764 void DataArrayTemplate<T>::pushBackSilent(T val)
766 int nbCompo(getNumberOfComponents());
771 _info_on_compo.resize(1);
776 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !";
777 throw INTERP_KERNEL::Exception(oss.str().c_str());
782 * This method adds at the end of \a this a series of values [\c valsBg,\c valsEnd). This method do \b not update its time label to avoid useless incrementation
783 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
785 * \param [in] valsBg - an array of values to push at the end of \c this.
786 * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
787 * the last value of \a valsBg is \a valsEnd[ -1 ].
788 * \throw If \a this has already been allocated with number of components different from one.
789 * \sa DataArrayDouble::pushBackSilent
792 void DataArrayTemplate<T>::pushBackValsSilent(const T *valsBg, const T *valsEnd)
794 int nbCompo(getNumberOfComponents());
796 _mem.insertAtTheEnd(valsBg,valsEnd);
799 _info_on_compo.resize(1);
800 _mem.insertAtTheEnd(valsBg,valsEnd);
804 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::pushBackValsSilent : not available for DataArrayDouble with number of components different than 1 !";
805 throw INTERP_KERNEL::Exception(oss.str().c_str());
810 * This method returns silently ( without updating time label in \a this ) the last value, if any and suppress it.
811 * \throw If \a this is already empty.
812 * \throw If \a this has number of components different from one.
815 T DataArrayTemplate<T>::popBackSilent()
817 if(getNumberOfComponents()==1)
818 return _mem.popBack();
821 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::popBackSilent : not available for DataArrayDouble with number of components different than 1 !";
822 throw INTERP_KERNEL::Exception(oss.str().c_str());
827 * Allocates the raw data in memory. If exactly same memory as needed already
828 * allocated, it is not re-allocated.
829 * \param [in] nbOfTuple - number of tuples of data to allocate.
830 * \param [in] nbOfCompo - number of components of data to allocate.
831 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
834 void DataArrayTemplate<T>::allocIfNecessary(int nbOfTuple, int nbOfCompo)
838 if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=(int)getNumberOfComponents())
839 alloc(nbOfTuple,nbOfCompo);
842 alloc(nbOfTuple,nbOfCompo);
846 * Checks the number of tuples.
847 * \return bool - \a true if getNumberOfTuples() == 0, \a false else.
848 * \throw If \a this is not allocated.
851 bool DataArrayTemplate<T>::empty() const
854 return getNumberOfTuples()==0;
858 * Copies all the data from another DataArrayDouble. For more info see
859 * \ref MEDCouplingArrayBasicsCopyDeepAssign.
860 * \param [in] other - another instance of DataArrayDouble to copy data from.
861 * \throw If the \a other is not allocated.
864 void DataArrayTemplate<T>::deepCopyFrom(const DataArrayTemplate<T>& other)
866 other.checkAllocated();
867 int nbOfTuples(other.getNumberOfTuples()),nbOfComp(other.getNumberOfComponents());
868 allocIfNecessary(nbOfTuples,nbOfComp);
869 std::size_t nbOfElems((std::size_t)nbOfTuples*nbOfComp);
871 const T *ptI(other.begin());
872 for(std::size_t i=0;i<nbOfElems;i++)
874 copyStringInfoFrom(other);
878 * Reverse the array values.
879 * \throw If \a this->getNumberOfComponents() < 1.
880 * \throw If \a this is not allocated.
883 void DataArrayTemplate<T>::reverse()
886 _mem.reverse(getNumberOfComponents());
891 * Assign \a val to all values in \a this array. To know more on filling arrays see
892 * \ref MEDCouplingArrayFill.
893 * \param [in] val - the value to fill with.
894 * \throw If \a this is not allocated.
897 void DataArrayTemplate<T>::fillWithValue(T val)
900 _mem.fillWithValue(val);
905 * Changes number of tuples in the array. If the new number of tuples is smaller
906 * than the current number the array is truncated, otherwise the array is extended.
907 * \param [in] nbOfTuples - new number of tuples.
908 * \throw If \a this is not allocated.
909 * \throw If \a nbOfTuples is negative.
912 void DataArrayTemplate<T>::reAlloc(std::size_t nbOfTuples)
915 _mem.reAlloc(getNumberOfComponents()*nbOfTuples);
920 * Permutes values of \a this array as required by \a old2New array. The values are
921 * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains
922 * the same as in \c this one.
923 * If a permutation reduction is needed, subArray() or selectByTupleId() should be used.
924 * For more info on renumbering see \ref numbering.
925 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
926 * giving a new position for i-th old value.
929 void DataArrayTemplate<T>::renumberInPlace(const int *old2New)
932 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
933 T *tmp(new T[nbTuples*nbOfCompo]);
934 const T *iptr(begin());
935 for(int i=0;i<nbTuples;i++)
938 if(v>=0 && v<nbTuples)
939 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*v);
942 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::renumberInPlace : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
943 throw INTERP_KERNEL::Exception(oss.str().c_str());
946 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
953 * Permutes values of \a this array as required by \a new2Old array. The values are
954 * permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of tuples remains
955 * the same as in \c this one.
956 * For more info on renumbering see \ref numbering.
957 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
958 * giving a previous position of i-th new value.
959 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
960 * is to delete using decrRef() as it is no more needed.
963 void DataArrayTemplate<T>::renumberInPlaceR(const int *new2Old)
966 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
967 T *tmp(new T[nbTuples*nbOfCompo]);
968 const T *iptr(begin());
969 for(int i=0;i<nbTuples;i++)
972 if(v>=0 && v<nbTuples)
973 std::copy(iptr+nbOfCompo*v,iptr+nbOfCompo*(v+1),tmp+nbOfCompo*i);
976 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::renumberInPlaceR : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
977 throw INTERP_KERNEL::Exception(oss.str().c_str());
980 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
986 * Sorts values of the array.
987 * \param [in] asc - \a true means ascending order, \a false, descending.
988 * \throw If \a this is not allocated.
989 * \throw If \a this->getNumberOfComponents() != 1.
992 void DataArrayTemplate<T>::sort(bool asc)
995 if(getNumberOfComponents()!=1)
997 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::sort : only supported with 'this' array with ONE component !";
998 throw INTERP_KERNEL::Exception(oss.str().c_str());
1005 * Returns a copy of \a this array with values permuted as required by \a old2New array.
1006 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ].
1007 * Number of tuples in the result array remains the same as in \c this one.
1008 * If a permutation reduction is needed, renumberAndReduce() should be used.
1009 * For more info on renumbering see \ref numbering.
1010 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1011 * giving a new position for i-th old value.
1012 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1013 * is to delete using decrRef() as it is no more needed.
1014 * \throw If \a this is not allocated.
1017 typename Traits<T>::ArrayType *DataArrayTemplate<T>::renumber(const int *old2New) const
1020 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
1021 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1022 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1023 ret->alloc(nbTuples,nbOfCompo);
1024 ret->copyStringInfoFrom(*this);
1025 const T *iptr(begin());
1026 T *optr(ret->getPointer());
1027 for(int i=0;i<nbTuples;i++)
1028 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
1029 ret->copyStringInfoFrom(*this);
1034 * Returns a copy of \a this array with values permuted as required by \a new2Old array.
1035 * The values are permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
1036 * tuples in the result array remains the same as in \c this one.
1037 * If a permutation reduction is needed, subArray() or selectByTupleId() should be used.
1038 * For more info on renumbering see \ref numbering.
1039 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
1040 * giving a previous position of i-th new value.
1041 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1042 * is to delete using decrRef() as it is no more needed.
1045 typename Traits<T>::ArrayType *DataArrayTemplate<T>::renumberR(const int *new2Old) const
1048 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
1049 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1050 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1051 ret->alloc(nbTuples,nbOfCompo);
1052 ret->copyStringInfoFrom(*this);
1053 const T *iptr(getConstPointer());
1054 T *optr(ret->getPointer());
1055 for(int i=0;i<nbTuples;i++)
1056 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
1057 ret->copyStringInfoFrom(*this);
1062 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1063 * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
1064 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ] for all
1065 * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which
1066 * \a old2New[ i ] is negative, is missing from the result array.
1067 * For more info on renumbering see \ref numbering.
1068 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1069 * giving a new position for i-th old tuple and giving negative position for
1070 * for i-th old tuple that should be omitted.
1071 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1072 * is to delete using decrRef() as it is no more needed.
1075 typename Traits<T>::ArrayType *DataArrayTemplate<T>::renumberAndReduce(const int *old2New, int newNbOfTuple) const
1078 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
1079 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1080 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1081 ret->alloc(newNbOfTuple,nbOfCompo);
1082 const T *iptr=getConstPointer();
1083 T *optr=ret->getPointer();
1084 for(int i=0;i<nbTuples;i++)
1088 std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
1090 ret->copyStringInfoFrom(*this);
1095 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1096 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1097 * \a new2OldBg array.
1098 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1099 * This method is equivalent to renumberAndReduce() except that convention in input is
1100 * \c new2old and \b not \c old2new.
1101 * For more info on renumbering see \ref numbering.
1102 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1103 * tuple index in \a this array to fill the i-th tuple in the new array.
1104 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1105 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1106 * \a new2OldBg <= \a pi < \a new2OldEnd.
1107 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1108 * is to delete using decrRef() as it is no more needed.
1111 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
1114 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1115 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1116 int nbComp(getNumberOfComponents());
1117 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1118 ret->copyStringInfoFrom(*this);
1119 T *pt(ret->getPointer());
1120 const T *srcPt(getConstPointer());
1122 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1123 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1124 ret->copyStringInfoFrom(*this);
1129 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleId(const DataArrayInt& di) const
1131 return this->mySelectByTupleId(di.begin(),di.end());
1135 MCAuto<typename Traits<T>::ArrayTypeCh> DataArrayTemplate<T>::selectPartDef(const PartDefinition *pd) const
1138 throw INTERP_KERNEL::Exception("DataArrayTemplate<T>::selectPartDef : null input pointer !");
1139 MCAuto<typename Traits<T>::ArrayTypeCh> ret(Traits<T>::ArrayTypeCh::New());
1140 const SlicePartDefinition *spd(dynamic_cast<const SlicePartDefinition *>(pd));
1144 spd->getSlice(a,b,c);
1145 if(a==0 && b==(int)getNumberOfTuples() && c==1)
1147 DataArrayTemplate<T> *directRet(const_cast<DataArrayTemplate<T> *>(this));
1148 directRet->incrRef();
1149 MCAuto<DataArrayTemplate<T> > ret2(directRet);
1150 return DynamicCastSafe<DataArrayTemplate<T>,typename Traits<T>::ArrayTypeCh>(ret2);
1154 MCAuto<DataArray> ret2(selectByTupleIdSafeSlice(a,b,c));
1155 return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret2);
1158 const DataArrayPartDefinition *dpd(dynamic_cast<const DataArrayPartDefinition *>(pd));
1161 MCAuto<DataArrayInt> arr(dpd->toDAI());
1162 MCAuto<DataArray> ret2(selectByTupleIdSafe(arr->begin(),arr->end()));
1163 return DynamicCastSafe<DataArray,typename Traits<T>::ArrayTypeCh>(ret2);
1166 throw INTERP_KERNEL::Exception("DataArrayTemplate<T>::selectPartDef : unrecognized part def !");
1170 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1171 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1172 * \a new2OldBg array.
1173 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1174 * This method is equivalent to renumberAndReduce() except that convention in input is
1175 * \c new2old and \b not \c old2new.
1176 * This method is equivalent to selectByTupleId() except that it prevents coping data
1177 * from behind the end of \a this array.
1178 * For more info on renumbering see \ref numbering.
1179 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1180 * tuple index in \a this array to fill the i-th tuple in the new array.
1181 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1182 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1183 * \a new2OldBg <= \a pi < \a new2OldEnd.
1184 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1185 * is to delete using decrRef() as it is no more needed.
1186 * \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
1189 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const
1192 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1193 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1194 int nbComp(getNumberOfComponents()),oldNbOfTuples(getNumberOfTuples());
1195 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1196 ret->copyStringInfoFrom(*this);
1197 T *pt(ret->getPointer());
1198 const T *srcPt(getConstPointer());
1200 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1201 if(*w>=0 && *w<oldNbOfTuples)
1202 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1205 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !";
1206 throw INTERP_KERNEL::Exception(oss.str().c_str());
1208 ret->copyStringInfoFrom(*this);
1213 * Changes the number of components within \a this array so that its raw data **does
1214 * not** change, instead splitting this data into tuples changes.
1215 * \warning This method erases all (name and unit) component info set before!
1216 * \param [in] newNbOfComp - number of components for \a this array to have.
1217 * \throw If \a this is not allocated
1218 * \throw If getNbOfElems() % \a newNbOfCompo != 0.
1219 * \throw If \a newNbOfCompo is lower than 1.
1220 * \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
1221 * \warning This method erases all (name and unit) component info set before!
1224 void DataArrayTemplate<T>::rearrange(int newNbOfCompo)
1229 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::rearrange : input newNbOfCompo must be > 0 !";
1230 throw INTERP_KERNEL::Exception(oss.str().c_str());
1232 std::size_t nbOfElems=getNbOfElems();
1233 if(nbOfElems%newNbOfCompo!=0)
1235 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::rearrange : nbOfElems%newNbOfCompo!=0 !";
1236 throw INTERP_KERNEL::Exception(oss.str().c_str());
1238 if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
1240 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !";
1241 throw INTERP_KERNEL::Exception(oss.str().c_str());
1243 _info_on_compo.clear();
1244 _info_on_compo.resize(newNbOfCompo);
1249 * Changes the number of components within \a this array to be equal to its number
1250 * of tuples, and inversely its number of tuples to become equal to its number of
1251 * components. So that its raw data **does not** change, instead splitting this
1252 * data into tuples changes.
1253 * \warning This method erases all (name and unit) component info set before!
1254 * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
1255 * \throw If \a this is not allocated.
1259 void DataArrayTemplate<T>::transpose()
1262 int nbOfTuples(getNumberOfTuples());
1263 rearrange(nbOfTuples);
1267 * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
1268 * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
1269 * is truncated to have \a newNbOfComp components, keeping first components. If \a
1270 * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
1271 * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
1273 * \param [in] newNbOfComp - number of components for the new array to have.
1274 * \param [in] dftValue - value assigned to new values added to the new array.
1275 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1276 * is to delete using decrRef() as it is no more needed.
1277 * \throw If \a this is not allocated.
1280 typename Traits<T>::ArrayType *DataArrayTemplate<T>::changeNbOfComponents(int newNbOfComp, T dftValue) const
1283 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1284 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1285 ret->alloc(getNumberOfTuples(),newNbOfComp);
1286 const T *oldc(getConstPointer());
1287 T *nc(ret->getPointer());
1288 int nbOfTuples(getNumberOfTuples()),oldNbOfComp(getNumberOfComponents());
1289 int dim(std::min(oldNbOfComp,newNbOfComp));
1290 for(int i=0;i<nbOfTuples;i++)
1294 nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
1295 for(;j<newNbOfComp;j++)
1296 nc[newNbOfComp*i+j]=dftValue;
1298 ret->setName(getName());
1299 for(int i=0;i<dim;i++)
1300 ret->setInfoOnComponent(i,getInfoOnComponent(i));
1301 ret->setName(getName());
1306 * Returns a copy of \a this array composed of selected components.
1307 * The new DataArrayDouble has the same number of tuples but includes components
1308 * specified by \a compoIds parameter. So that getNbOfElems() of the result array
1309 * can be either less, same or more than \a this->getNbOfElems().
1310 * \param [in] compoIds - sequence of zero based indices of components to include
1311 * into the new array.
1312 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1313 * is to delete using decrRef() as it is no more needed.
1314 * \throw If \a this is not allocated.
1315 * \throw If a component index (\a i) is not valid:
1316 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
1318 * \if ENABLE_EXAMPLES
1319 * \ref py_mcdataarraydouble_KeepSelectedComponents "Here is a Python example".
1323 typename Traits<T>::ArrayType *DataArrayTemplate<T>::myKeepSelectedComponents(const std::vector<int>& compoIds) const
1326 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1327 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1328 std::size_t newNbOfCompo(compoIds.size());
1329 int oldNbOfCompo(getNumberOfComponents());
1330 for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
1331 if((*it)<0 || (*it)>=oldNbOfCompo)
1333 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
1334 throw INTERP_KERNEL::Exception(oss.str().c_str());
1336 int nbOfTuples(getNumberOfTuples());
1337 ret->alloc(nbOfTuples,(int)newNbOfCompo);
1338 ret->copyPartOfStringInfoFrom(*this,compoIds);
1339 const T *oldc(getConstPointer());
1340 T *nc(ret->getPointer());
1341 for(int i=0;i<nbOfTuples;i++)
1342 for(std::size_t j=0;j<newNbOfCompo;j++,nc++)
1343 *nc=oldc[i*oldNbOfCompo+compoIds[j]];
1348 * Returns a shorten copy of \a this array. The new DataArrayDouble contains all
1349 * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
1350 * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
1351 * This method is a specialization of selectByTupleIdSafeSlice().
1352 * \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
1353 * \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
1354 * If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
1355 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1356 * is to delete using decrRef() as it is no more needed.
1357 * \throw If \a tupleIdBg < 0.
1358 * \throw If \a tupleIdBg > \a this->getNumberOfTuples().
1359 * \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
1360 * \sa DataArrayDouble::selectByTupleIdSafeSlice
1363 typename Traits<T>::ArrayType *DataArrayTemplate<T>::subArray(int tupleIdBg, int tupleIdEnd) const
1366 int nbt(getNumberOfTuples());
1369 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::subArray : The tupleIdBg parameter must be greater than 0 !";
1370 throw INTERP_KERNEL::Exception(oss.str().c_str());
1374 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << ":subArray : The tupleIdBg parameter is greater than number of tuples !";
1375 throw INTERP_KERNEL::Exception(oss.str().c_str());
1377 int trueEnd=tupleIdEnd;
1382 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << ":subArray : The tupleIdBg parameter is greater than number of tuples !";
1383 throw INTERP_KERNEL::Exception(oss.str().c_str());
1388 int nbComp(getNumberOfComponents());
1389 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1390 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1391 ret->alloc(trueEnd-tupleIdBg,nbComp);
1392 ret->copyStringInfoFrom(*this);
1393 std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
1398 * Returns a shorten copy of \a this array. The new DataArrayDouble contains every
1399 * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
1400 * tuple. Indices of the selected tuples are the same as ones returned by the Python
1401 * command \c range( \a bg, \a end2, \a step ).
1402 * This method is equivalent to selectByTupleIdSafe() except that the input array is
1403 * not constructed explicitly.
1404 * For more info on renumbering see \ref numbering.
1405 * \param [in] bg - index of the first tuple to copy from \a this array.
1406 * \param [in] end2 - index of the tuple before which the tuples to copy are located.
1407 * \param [in] step - index increment to get index of the next tuple to copy.
1408 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1409 * is to delete using decrRef() as it is no more needed.
1410 * \sa DataArrayDouble::subArray.
1413 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleIdSafeSlice(int bg, int end2, int step) const
1416 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1417 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1418 int nbComp(getNumberOfComponents());
1419 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::selectByTupleIdSafeSlice : ";
1420 int newNbOfTuples(GetNumberOfItemGivenBESRelative(bg,end2,step,oss.str()));
1421 ret->alloc(newNbOfTuples,nbComp);
1422 T *pt(ret->getPointer());
1423 const T *srcPt(getConstPointer()+bg*nbComp);
1424 for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
1425 std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
1426 ret->copyStringInfoFrom(*this);
1431 * Copy all values from another DataArrayDouble into specified tuples and components
1432 * of \a this array. Textual data is not copied.
1433 * The tree parameters defining set of indices of tuples and components are similar to
1434 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
1435 * \param [in] a - the array to copy values from.
1436 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
1437 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1439 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1440 * \param [in] bgComp - index of the first component of \a this array to assign values to.
1441 * \param [in] endComp - index of the component before which the components to assign
1443 * \param [in] stepComp - index increment to get index of the next component to assign to.
1444 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
1445 * must be equal to the number of columns to assign to, else an
1446 * exception is thrown; if \a false, then it is only required that \a
1447 * a->getNbOfElems() equals to number of values to assign to (this condition
1448 * must be respected even if \a strictCompoCompare is \a true). The number of
1449 * values to assign to is given by following Python expression:
1450 * \a nbTargetValues =
1451 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
1452 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1453 * \throw If \a a is NULL.
1454 * \throw If \a a is not allocated.
1455 * \throw If \a this is not allocated.
1456 * \throw If parameters specifying tuples and components to assign to do not give a
1457 * non-empty range of increasing indices.
1458 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
1459 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
1460 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1462 * \if ENABLE_EXAMPLES
1463 * \ref py_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
1467 void DataArrayTemplate<T>::setPartOfValues1(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
1471 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::setPartOfValues1 : input DataArrayDouble is NULL !";
1472 throw INTERP_KERNEL::Exception(oss.str().c_str());
1474 const char msg[]="DataArrayTemplate::setPartOfValues1";
1476 a->checkAllocated();
1477 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1478 int newNbOfComp(DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg));
1479 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1480 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1481 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1482 bool assignTech(true);
1483 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1485 if(strictCompoCompare)
1486 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1490 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1493 const T *srcPt(a->getConstPointer());
1494 T *pt(getPointer()+bgTuples*nbComp+bgComp);
1497 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1498 for(int j=0;j<newNbOfComp;j++,srcPt++)
1499 pt[j*stepComp]=*srcPt;
1503 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1505 const T*srcPt2=srcPt;
1506 for(int j=0;j<newNbOfComp;j++,srcPt2++)
1507 pt[j*stepComp]=*srcPt2;
1513 * Assign a given value to values at specified tuples and components of \a this array.
1514 * The tree parameters defining set of indices of tuples and components are similar to
1515 * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
1516 * \param [in] a - the value to assign.
1517 * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
1518 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1520 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1521 * \param [in] bgComp - index of the first component of \a this array to assign to.
1522 * \param [in] endComp - index of the component before which the components to assign
1524 * \param [in] stepComp - index increment to get index of the next component to assign to.
1525 * \throw If \a this is not allocated.
1526 * \throw If parameters specifying tuples and components to assign to, do not give a
1527 * non-empty range of increasing indices or indices are out of a valid range
1528 * for \c this array.
1530 * \if ENABLE_EXAMPLES
1531 * \ref py_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
1535 void DataArrayTemplate<T>::setPartOfValuesSimple1(T a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp)
1537 const char msg[]="DataArrayTemplate::setPartOfValuesSimple1";
1539 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1540 int newNbOfComp(DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg));
1541 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1542 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1543 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1544 T *pt=getPointer()+bgTuples*nbComp+bgComp;
1545 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1546 for(int j=0;j<newNbOfComp;j++)
1551 * Copy all values from another DataArrayDouble (\a a) into specified tuples and
1552 * components of \a this array. Textual data is not copied.
1553 * The tuples and components to assign to are defined by C arrays of indices.
1554 * There are two *modes of usage*:
1555 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
1556 * of \a a is assigned to its own location within \a this array.
1557 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
1558 * components of every specified tuple of \a this array. In this mode it is required
1559 * that \a a->getNumberOfComponents() equals to the number of specified components.
1561 * \param [in] a - the array to copy values from.
1562 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1563 * assign values of \a a to.
1564 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1565 * pointer to a tuple index <em>(pi)</em> varies as this:
1566 * \a bgTuples <= \a pi < \a endTuples.
1567 * \param [in] bgComp - pointer to an array of component indices of \a this array to
1568 * assign values of \a a to.
1569 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
1570 * pointer to a component index <em>(pi)</em> varies as this:
1571 * \a bgComp <= \a pi < \a endComp.
1572 * \param [in] strictCompoCompare - this parameter is checked only if the
1573 * *mode of usage* is the first; if it is \a true (default),
1574 * then \a a->getNumberOfComponents() must be equal
1575 * to the number of specified columns, else this is not required.
1576 * \throw If \a a is NULL.
1577 * \throw If \a a is not allocated.
1578 * \throw If \a this is not allocated.
1579 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
1580 * out of a valid range for \a this array.
1581 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
1582 * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
1583 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
1584 * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
1586 * \if ENABLE_EXAMPLES
1587 * \ref py_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
1591 void DataArrayTemplate<T>::setPartOfValues2(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
1594 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
1595 const char msg[]="DataArrayTemplate::setPartOfValues2";
1597 a->checkAllocated();
1598 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1599 for(const int *z=bgComp;z!=endComp;z++)
1600 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1601 int newNbOfTuples((int)std::distance(bgTuples,endTuples));
1602 int newNbOfComp((int)std::distance(bgComp,endComp));
1603 bool assignTech(true);
1604 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1606 if(strictCompoCompare)
1607 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1611 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1614 T *pt(getPointer());
1615 const T *srcPt(a->getConstPointer());
1618 for(const int *w=bgTuples;w!=endTuples;w++)
1620 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1621 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
1623 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
1629 for(const int *w=bgTuples;w!=endTuples;w++)
1631 const T *srcPt2=srcPt;
1632 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1633 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
1635 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
1642 * Assign a given value to values at specified tuples and components of \a this array.
1643 * The tuples and components to assign to are defined by C arrays of indices.
1644 * \param [in] a - the value to assign.
1645 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1647 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1648 * pointer to a tuple index (\a pi) varies as this:
1649 * \a bgTuples <= \a pi < \a endTuples.
1650 * \param [in] bgComp - pointer to an array of component indices of \a this array to
1652 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
1653 * pointer to a component index (\a pi) varies as this:
1654 * \a bgComp <= \a pi < \a endComp.
1655 * \throw If \a this is not allocated.
1656 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
1657 * out of a valid range for \a this array.
1659 * \if ENABLE_EXAMPLES
1660 * \ref py_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
1664 void DataArrayTemplate<T>::setPartOfValuesSimple2(T a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp)
1667 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1668 for(const int *z=bgComp;z!=endComp;z++)
1669 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1670 T *pt(getPointer());
1671 for(const int *w=bgTuples;w!=endTuples;w++)
1672 for(const int *z=bgComp;z!=endComp;z++)
1674 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1675 pt[(std::size_t)(*w)*nbComp+(*z)]=a;
1680 * Copy all values from another DataArrayDouble (\a a) into specified tuples and
1681 * components of \a this array. Textual data is not copied.
1682 * The tuples to assign to are defined by a C array of indices.
1683 * The components to assign to are defined by three values similar to parameters of
1684 * the Python function \c range(\c start,\c stop,\c step).
1685 * There are two *modes of usage*:
1686 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
1687 * of \a a is assigned to its own location within \a this array.
1688 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
1689 * components of every specified tuple of \a this array. In this mode it is required
1690 * that \a a->getNumberOfComponents() equals to the number of specified components.
1692 * \param [in] a - the array to copy values from.
1693 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1694 * assign values of \a a to.
1695 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1696 * pointer to a tuple index <em>(pi)</em> varies as this:
1697 * \a bgTuples <= \a pi < \a endTuples.
1698 * \param [in] bgComp - index of the first component of \a this array to assign to.
1699 * \param [in] endComp - index of the component before which the components to assign
1701 * \param [in] stepComp - index increment to get index of the next component to assign to.
1702 * \param [in] strictCompoCompare - this parameter is checked only in the first
1703 * *mode of usage*; if \a strictCompoCompare is \a true (default),
1704 * then \a a->getNumberOfComponents() must be equal
1705 * to the number of specified columns, else this is not required.
1706 * \throw If \a a is NULL.
1707 * \throw If \a a is not allocated.
1708 * \throw If \a this is not allocated.
1709 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
1711 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
1712 * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
1713 * defined by <em>(bgComp,endComp,stepComp)</em>.
1714 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
1715 * <em> a->getNumberOfComponents()</em> is unequal to the number of components
1716 * defined by <em>(bgComp,endComp,stepComp)</em>.
1717 * \throw If parameters specifying components to assign to, do not give a
1718 * non-empty range of increasing indices or indices are out of a valid range
1719 * for \c this array.
1721 * \if ENABLE_EXAMPLES
1722 * \ref py_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
1726 void DataArrayTemplate<T>::setPartOfValues3(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
1729 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValues3 : input DataArrayDouble is NULL !");
1730 const char msg[]="DataArrayTemplate::setPartOfValues3";
1732 a->checkAllocated();
1733 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
1734 int nbComp=getNumberOfComponents();
1735 int nbOfTuples=getNumberOfTuples();
1736 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1737 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
1738 bool assignTech=true;
1739 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1741 if(strictCompoCompare)
1742 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1746 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1749 T *pt(getPointer()+bgComp);
1750 const T *srcPt(a->getConstPointer());
1753 for(const int *w=bgTuples;w!=endTuples;w++)
1754 for(int j=0;j<newNbOfComp;j++,srcPt++)
1756 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1757 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
1762 for(const int *w=bgTuples;w!=endTuples;w++)
1764 const T *srcPt2=srcPt;
1765 for(int j=0;j<newNbOfComp;j++,srcPt2++)
1767 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1768 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
1775 * Assign a given value to values at specified tuples and components of \a this array.
1776 * The tuples to assign to are defined by a C array of indices.
1777 * The components to assign to are defined by three values similar to parameters of
1778 * the Python function \c range(\c start,\c stop,\c step).
1779 * \param [in] a - the value to assign.
1780 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1782 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1783 * pointer to a tuple index <em>(pi)</em> varies as this:
1784 * \a bgTuples <= \a pi < \a endTuples.
1785 * \param [in] bgComp - index of the first component of \a this array to assign to.
1786 * \param [in] endComp - index of the component before which the components to assign
1788 * \param [in] stepComp - index increment to get index of the next component to assign to.
1789 * \throw If \a this is not allocated.
1790 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
1792 * \throw If parameters specifying components to assign to, do not give a
1793 * non-empty range of increasing indices or indices are out of a valid range
1794 * for \c this array.
1796 * \if ENABLE_EXAMPLES
1797 * \ref py_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
1801 void DataArrayTemplate<T>::setPartOfValuesSimple3(T a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp)
1803 const char msg[]="DataArrayTemplate::setPartOfValuesSimple3";
1805 int newNbOfComp(DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg));
1806 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1807 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1808 T *pt(getPointer()+bgComp);
1809 for(const int *w=bgTuples;w!=endTuples;w++)
1810 for(int j=0;j<newNbOfComp;j++)
1812 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1813 pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
1818 * Copy all values from another DataArrayDouble into specified tuples and components
1819 * of \a this array. Textual data is not copied.
1820 * The tree parameters defining set of indices of tuples and components are similar to
1821 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
1822 * \param [in] a - the array to copy values from.
1823 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
1824 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1826 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1827 * \param [in] bgComp - pointer to an array of component indices of \a this array to
1829 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
1830 * pointer to a component index (\a pi) varies as this:
1831 * \a bgComp <= \a pi < \a endComp.
1832 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
1833 * must be equal to the number of columns to assign to, else an
1834 * exception is thrown; if \a false, then it is only required that \a
1835 * a->getNbOfElems() equals to number of values to assign to (this condition
1836 * must be respected even if \a strictCompoCompare is \a true). The number of
1837 * values to assign to is given by following Python expression:
1838 * \a nbTargetValues =
1839 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
1840 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1841 * \throw If \a a is NULL.
1842 * \throw If \a a is not allocated.
1843 * \throw If \a this is not allocated.
1844 * \throw If parameters specifying tuples and components to assign to do not give a
1845 * non-empty range of increasing indices.
1846 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
1847 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
1848 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1852 void DataArrayTemplate<T>::setPartOfValues4(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
1854 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValues4 : input DataArrayTemplate is NULL !");
1855 const char msg[]="DataArrayTemplate::setPartOfValues4";
1857 a->checkAllocated();
1858 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1859 int newNbOfComp((int)std::distance(bgComp,endComp));
1860 int nbComp(getNumberOfComponents());
1861 for(const int *z=bgComp;z!=endComp;z++)
1862 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1863 int nbOfTuples(getNumberOfTuples());
1864 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1865 bool assignTech(true);
1866 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1868 if(strictCompoCompare)
1869 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1873 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1876 const T *srcPt(a->getConstPointer());
1877 T *pt(getPointer()+bgTuples*nbComp);
1880 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1881 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
1886 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1888 const T *srcPt2(srcPt);
1889 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
1896 void DataArrayTemplate<T>::setPartOfValuesSimple4(T a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp)
1898 const char msg[]="DataArrayTemplate::setPartOfValuesSimple4";
1900 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1901 int nbComp(getNumberOfComponents());
1902 for(const int *z=bgComp;z!=endComp;z++)
1903 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1904 int nbOfTuples(getNumberOfTuples());
1905 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1906 T *pt=getPointer()+bgTuples*nbComp;
1907 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1908 for(const int *z=bgComp;z!=endComp;z++)
1913 * Copy some tuples from another DataArrayDouble into specified tuples
1914 * of \a this array. Textual data is not copied. Both arrays must have equal number of
1916 * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
1917 * All components of selected tuples are copied.
1918 * \param [in] a - the array to copy values from.
1919 * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
1920 * target tuples of \a this. \a tuplesSelec has two components, and the
1921 * first component specifies index of the source tuple and the second
1922 * one specifies index of the target tuple.
1923 * \throw If \a this is not allocated.
1924 * \throw If \a a is NULL.
1925 * \throw If \a a is not allocated.
1926 * \throw If \a tuplesSelec is NULL.
1927 * \throw If \a tuplesSelec is not allocated.
1928 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
1929 * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
1930 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
1931 * the corresponding (\a this or \a a) array.
1934 void DataArrayTemplate<T>::setPartOfValuesAdv(const typename Traits<T>::ArrayType *a, const DataArrayInt *tuplesSelec)
1936 if(!a || !tuplesSelec)
1937 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : input DataArrayTemplate is NULL !");
1939 a->checkAllocated();
1940 tuplesSelec->checkAllocated();
1941 std::size_t nbOfComp(getNumberOfComponents());
1942 if(nbOfComp!=a->getNumberOfComponents())
1943 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : This and a do not have the same number of components !");
1944 if(tuplesSelec->getNumberOfComponents()!=2)
1945 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
1946 int thisNt(getNumberOfTuples());
1947 int aNt(a->getNumberOfTuples());
1948 T *valsToSet(getPointer());
1949 const T *valsSrc(a->getConstPointer());
1950 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
1952 if(tuple[1]>=0 && tuple[1]<aNt)
1954 if(tuple[0]>=0 && tuple[0]<thisNt)
1955 std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
1958 std::ostringstream oss; oss << "DataArrayTemplate::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
1959 oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
1960 throw INTERP_KERNEL::Exception(oss.str().c_str());
1965 std::ostringstream oss; oss << "DataArrayTemplate::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
1966 oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
1967 throw INTERP_KERNEL::Exception(oss.str().c_str());
1973 * Copy some tuples from another DataArrayDouble (\a aBase) into contiguous tuples
1974 * of \a this array. Textual data is not copied. Both arrays must have equal number of
1976 * The tuples to assign to are defined by index of the first tuple, and
1977 * their number is defined by \a tuplesSelec->getNumberOfTuples().
1978 * The tuples to copy are defined by values of a DataArrayInt.
1979 * All components of selected tuples are copied.
1980 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
1982 * \param [in] aBase - the array to copy values from.
1983 * \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
1984 * \throw If \a this is not allocated.
1985 * \throw If \a aBase is NULL.
1986 * \throw If \a aBase is not allocated.
1987 * \throw If \a tuplesSelec is NULL.
1988 * \throw If \a tuplesSelec is not allocated.
1989 * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
1990 * \throw If \a tuplesSelec->getNumberOfComponents() != 1.
1991 * \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
1992 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
1996 void DataArrayTemplate<T>::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec)
1998 if(!aBase || !tuplesSelec)
1999 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : input DataArray is NULL !");
2000 const typename Traits<T>::ArrayType *a(dynamic_cast<const typename Traits<T>::ArrayType *>(aBase));
2002 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayDouble !");
2004 a->checkAllocated();
2005 tuplesSelec->checkAllocated();
2006 std::size_t nbOfComp(getNumberOfComponents());
2007 if(nbOfComp!=a->getNumberOfComponents())
2008 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : This and a do not have the same number of components !");
2009 if(tuplesSelec->getNumberOfComponents()!=1)
2010 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
2011 int thisNt(getNumberOfTuples());
2012 int aNt(a->getNumberOfTuples());
2013 int nbOfTupleToWrite(tuplesSelec->getNumberOfTuples());
2014 T *valsToSet(getPointer()+tupleIdStart*nbOfComp);
2015 if(tupleIdStart+nbOfTupleToWrite>thisNt)
2016 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : invalid number range of values to write !");
2017 const T *valsSrc=a->getConstPointer();
2018 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
2020 if(*tuple>=0 && *tuple<aNt)
2022 std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
2026 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
2027 oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
2028 throw INTERP_KERNEL::Exception(oss.str().c_str());
2034 * Copy some tuples from another DataArrayDouble (\a aBase) into contiguous tuples
2035 * of \a this array. Textual data is not copied. Both arrays must have equal number of
2037 * The tuples to copy are defined by three values similar to parameters of
2038 * the Python function \c range(\c start,\c stop,\c step).
2039 * The tuples to assign to are defined by index of the first tuple, and
2040 * their number is defined by number of tuples to copy.
2041 * All components of selected tuples are copied.
2042 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
2044 * \param [in] aBase - the array to copy values from.
2045 * \param [in] bg - index of the first tuple to copy of the array \a aBase.
2046 * \param [in] end2 - index of the tuple of \a aBase before which the tuples to copy
2048 * \param [in] step - index increment to get index of the next tuple to copy.
2049 * \throw If \a this is not allocated.
2050 * \throw If \a aBase is NULL.
2051 * \throw If \a aBase is not allocated.
2052 * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
2053 * \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
2054 * \throw If parameters specifying tuples to copy, do not give a
2055 * non-empty range of increasing indices or indices are out of a valid range
2056 * for the array \a aBase.
2059 void DataArrayTemplate<T>::setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step)
2063 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::setContigPartOfSelectedValuesSlice : input DataArray is NULL !";
2064 throw INTERP_KERNEL::Exception(oss.str().c_str());
2066 const typename Traits<T>::ArrayType *a(dynamic_cast<const typename Traits<T>::ArrayType *>(aBase));
2068 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : input DataArray aBase is not a DataArrayDouble !");
2070 a->checkAllocated();
2071 std::size_t nbOfComp(getNumberOfComponents());
2072 const char msg[]="DataArrayDouble::setContigPartOfSelectedValuesSlice";
2073 int nbOfTupleToWrite(DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg));
2074 if(nbOfComp!=a->getNumberOfComponents())
2075 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : This and a do not have the same number of components !");
2076 int thisNt(getNumberOfTuples()),aNt(a->getNumberOfTuples());
2077 T *valsToSet(getPointer()+tupleIdStart*nbOfComp);
2078 if(tupleIdStart+nbOfTupleToWrite>thisNt)
2079 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : invalid number range of values to write !");
2081 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : invalid range of values to read !");
2082 const T *valsSrc(a->getConstPointer()+bg*nbOfComp);
2083 for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
2085 std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
2090 * Returns a shorten copy of \a this array. The new DataArrayDouble contains ranges
2091 * of tuples specified by \a ranges parameter.
2092 * For more info on renumbering see \ref numbering.
2093 * \param [in] ranges - std::vector of std::pair's each of which defines a range
2094 * of tuples in [\c begin,\c end) format.
2095 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
2096 * is to delete using decrRef() as it is no more needed.
2097 * \throw If \a end < \a begin.
2098 * \throw If \a end > \a this->getNumberOfTuples().
2099 * \throw If \a this is not allocated.
2102 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const
2105 int nbOfComp(getNumberOfComponents()),nbOfTuplesThis(getNumberOfTuples());
2108 MCAuto<DataArray> ret0(buildNewEmptyInstance());
2109 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
2110 ret->alloc(0,nbOfComp);
2111 ret->copyStringInfoFrom(*this);
2114 int ref(ranges.front().first),nbOfTuples(0);
2115 bool isIncreasing(true);
2116 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
2118 if((*it).first<=(*it).second)
2120 if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
2122 nbOfTuples+=(*it).second-(*it).first;
2124 isIncreasing=ref<=(*it).first;
2129 std::ostringstream oss; oss << "DataArrayTemplate::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
2130 oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
2131 throw INTERP_KERNEL::Exception(oss.str().c_str());
2136 std::ostringstream oss; oss << "DataArrayTemplate::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
2137 oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
2138 throw INTERP_KERNEL::Exception(oss.str().c_str());
2141 if(isIncreasing && nbOfTuplesThis==nbOfTuples)
2142 return static_cast<typename Traits<T>::ArrayType *>(deepCopy());
2143 MCAuto<DataArray> ret0(buildNewEmptyInstance());
2144 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
2145 ret->alloc(nbOfTuples,nbOfComp);
2146 ret->copyStringInfoFrom(*this);
2147 const T *src(getConstPointer());
2148 T *work(ret->getPointer());
2149 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
2150 work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
2155 * Returns the first value of \a this.
2156 * \return double - the last value of \a this array.
2157 * \throw If \a this is not allocated.
2158 * \throw If \a this->getNumberOfComponents() != 1.
2159 * \throw If \a this->getNumberOfTuples() < 1.
2162 T DataArrayTemplate<T>::front() const
2165 if(getNumberOfComponents()!=1)
2166 throw INTERP_KERNEL::Exception("DataArrayTemplate::front : number of components not equal to one !");
2167 int nbOfTuples(getNumberOfTuples());
2169 throw INTERP_KERNEL::Exception("DataArrayTemplate::front : number of tuples must be >= 1 !");
2170 return *(getConstPointer());
2174 * Returns the last value of \a this.
2175 * \return double - the last value of \a this array.
2176 * \throw If \a this is not allocated.
2177 * \throw If \a this->getNumberOfComponents() != 1.
2178 * \throw If \a this->getNumberOfTuples() < 1.
2181 T DataArrayTemplate<T>::back() const
2184 if(getNumberOfComponents()!=1)
2185 throw INTERP_KERNEL::Exception("DataArrayTemplate::back : number of components not equal to one !");
2186 int nbOfTuples(getNumberOfTuples());
2188 throw INTERP_KERNEL::Exception("DataArrayTemplate::back : number of tuples must be >= 1 !");
2189 return *(getConstPointer()+nbOfTuples-1);
2193 * Returns the maximal value and its location within \a this one-dimensional array.
2194 * \param [out] tupleId - index of the tuple holding the maximal value.
2195 * \return double - the maximal value among all values of \a this array.
2196 * \throw If \a this->getNumberOfComponents() != 1
2197 * \throw If \a this->getNumberOfTuples() < 1
2198 * \sa getMaxAbsValue, getMinValue
2201 T DataArrayTemplate<T>::getMaxValue(int& tupleId) const
2204 if(getNumberOfComponents()!=1)
2205 throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before or call 'getMaxValueInArray' method !");
2206 int nbOfTuples(getNumberOfTuples());
2208 throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
2209 const T *vals(getConstPointer());
2210 const T *loc(std::max_element(vals,vals+nbOfTuples));
2211 tupleId=(int)std::distance(vals,loc);
2216 * Returns the maximal value within \a this array that is allowed to have more than
2218 * \return double - the maximal value among all values of \a this array.
2219 * \throw If \a this is not allocated.
2220 * \sa getMaxAbsValueInArray, getMinValueInArray
2223 T DataArrayTemplate<T>::getMaxValueInArray() const
2226 const T *loc(std::max_element(begin(),end()));
2231 * Returns the maximal absolute value in \a this and the first occurrence location associated to it.
2232 * \return the element in this (positive or negative) having the max abs value in \a this.
2233 * \throw If \a this is not allocated.
2234 * \throw If \a this is non one component array.
2235 * \throw If \a this is empty.
2238 T DataArrayTemplate<T>::getMaxAbsValue(std::size_t& tupleId) const
2241 if(getNumberOfComponents()!=1)
2242 throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxAbsValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before or call 'getMaxValueInArray' method !");
2243 std::size_t nbTuples(this->getNumberOfTuples());
2245 throw INTERP_KERNEL::Exception("DataArrayTemplate<T>::getMaxAbsValue : empty array !");
2248 const T *pt(begin());
2249 for(std::size_t i=0;i<nbTuples;i++,pt++)
2251 T cand(std::abs(*pt));
2258 return this->getIJ(tupleId,0);
2262 * Returns the maximal absolute value in \a this.
2263 * \throw If \a this is not allocated.
2264 * \throw If \a this is non one component array.
2265 * \throw If \a this is empty.
2268 T DataArrayTemplate<T>::getMaxAbsValueInArray() const
2271 return getMaxAbsValue(dummy);
2275 * Returns the minimal value and its location within \a this one-dimensional array.
2276 * \param [out] tupleId - index of the tuple holding the minimal value.
2277 * \return double - the minimal value among all values of \a this array.
2278 * \throw If \a this->getNumberOfComponents() != 1
2279 * \throw If \a this->getNumberOfTuples() < 1
2282 T DataArrayTemplate<T>::getMinValue(int& tupleId) const
2285 if(getNumberOfComponents()!=1)
2286 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
2287 int nbOfTuples(getNumberOfTuples());
2289 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
2290 const T *vals(getConstPointer());
2291 const T *loc(std::min_element(vals,vals+nbOfTuples));
2292 tupleId=(int)std::distance(vals,loc);
2297 * Returns the minimal value within \a this array that is allowed to have more than
2299 * \return double - the minimal value among all values of \a this array.
2300 * \throw If \a this is not allocated.
2303 T DataArrayTemplate<T>::getMinValueInArray() const
2306 const T *loc=std::min_element(begin(),end());
2311 void DataArrayTemplate<T>::circularPermutation(int nbOfShift)
2314 int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
2315 int effNbSh(EffectiveCircPerm(nbOfShift,nbTuples));
2318 T *work(getPointer());
2319 if(effNbSh<nbTuples-effNbSh)
2321 typename INTERP_KERNEL::AutoPtr<T> buf(new T[effNbSh*nbOfCompo]);
2322 std::copy(work,work+effNbSh*nbOfCompo,(T *)buf);
2323 std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,work);// ze big shift
2324 std::copy((T *)buf,(T *)buf+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);
2328 typename INTERP_KERNEL::AutoPtr<T> buf(new T[(nbTuples-effNbSh)*nbOfCompo]);
2329 std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,(T *)buf);
2330 std::copy(work,work+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);// ze big shift
2331 std::copy((T*)buf,(T *)buf+(nbTuples-effNbSh)*nbOfCompo,work);
2336 void DataArrayTemplate<T>::circularPermutationPerTuple(int nbOfShift)
2339 int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
2340 int effNbSh(EffectiveCircPerm(nbOfShift,nbOfCompo));
2343 T *work(getPointer());
2344 if(effNbSh<nbOfCompo-effNbSh)
2346 typename INTERP_KERNEL::AutoPtr<T> buf(new T[effNbSh]);
2347 for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
2349 std::copy(work,work+effNbSh,(T *)buf);
2350 std::copy(work+effNbSh,work+nbOfCompo,work);// ze big shift
2351 std::copy((T *)buf,(T *)buf+effNbSh,work+(nbOfCompo-effNbSh));
2356 typename INTERP_KERNEL::AutoPtr<T> buf(new T[nbOfCompo-effNbSh]);
2357 for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
2359 std::copy(work+effNbSh,work+nbOfCompo,(T *)buf);
2360 std::copy(work,work+effNbSh,work+(nbOfCompo-effNbSh));// ze big shift
2361 std::copy((T*)buf,(T *)buf+(nbOfCompo-effNbSh),work);
2364 std::vector<std::string> sts(nbOfCompo);
2365 for(int i=0;i<nbOfCompo;i++)
2366 sts[i]=_info_on_compo[(i+effNbSh)%nbOfCompo];
2367 setInfoOnComponents(sts);
2371 void DataArrayTemplate<T>::reversePerTuple()
2374 int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
2377 T *work(getPointer());
2378 for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
2379 std::reverse(work,work+nbOfCompo);
2380 std::reverse(_info_on_compo.begin(),_info_on_compo.end());
2384 * Assign pointer to one array to a pointer to another appay. Reference counter of
2385 * \a arrayToSet is incremented / decremented.
2386 * \param [in] newArray - the pointer to array to assign to \a arrayToSet.
2387 * \param [in,out] arrayToSet - the pointer to array to assign to.
2390 void DataArrayTemplate<T>::SetArrayIn(typename Traits<T>::ArrayType *newArray, typename Traits<T>::ArrayType* &arrayToSet)
2392 if(newArray!=arrayToSet)
2395 arrayToSet->decrRef();
2396 arrayToSet=newArray;
2398 arrayToSet->incrRef();
2403 * Assign zero to all values in \a this array. To know more on filling arrays see
2404 * \ref MEDCouplingArrayFill.
2405 * \throw If \a this is not allocated.
2408 void DataArrayTemplate<T>::fillWithZero()
2410 fillWithValue((T)0);
2413 //////////////////////////////
2417 MCAuto< typename Traits<U>::ArrayType > DataArrayTemplateClassic<T>::convertToOtherTypeOfArr() const
2419 this->checkAllocated();
2420 MCAuto<typename Traits<U>::ArrayType> ret(Traits<U>::ArrayType::New());
2421 ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents());
2422 std::size_t nbOfVals(this->getNbOfElems());
2423 const T *src(this->begin());
2424 U *dest(ret->getPointer());
2425 // to make Visual C++ happy : instead of std::size_t nbOfVals=getNbOfElems(); std::copy(src,src+nbOfVals,dest);
2426 //for(const T *src=this->begin();src!=this->end();src++,dest++)
2428 std::copy(src,src+nbOfVals,dest);
2429 ret->copyStringInfoFrom(*this);
2434 * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
2435 * array to the new one.
2436 * \return DataArrayDouble * - the new instance of DataArrayInt.
2439 MCAuto<DataArrayDouble> DataArrayTemplateClassic<T>::convertToDblArr() const
2441 return convertToOtherTypeOfArr<double>();
2445 * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
2446 * array to the new one.
2447 * \return DataArrayInt * - the new instance of DataArrayInt.
2450 MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::convertToIntArr() const
2452 return convertToOtherTypeOfArr<int>();
2456 * Creates a new DataArrayFloat and assigns all (textual and numerical) data of \a this
2457 * array to the new one.
2458 * \return DataArrayFloat * - the new instance of DataArrayInt.
2461 MCAuto<DataArrayFloat> DataArrayTemplateClassic<T>::convertToFloatArr() const
2463 return convertToOtherTypeOfArr<float>();
2467 * Apply a linear function to a given component of \a this array, so that
2468 * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
2469 * \param [in] a - the first coefficient of the function.
2470 * \param [in] b - the second coefficient of the function.
2471 * \param [in] compoId - the index of component to modify.
2472 * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ).
2475 void DataArrayTemplateClassic<T>::applyLin(T a, T b, int compoId)
2477 this->checkAllocated();
2478 T *ptr(this->getPointer()+compoId);
2479 int nbOfComp(this->getNumberOfComponents()),nbOfTuple(this->getNumberOfTuples());
2480 if(compoId<0 || compoId>=nbOfComp)
2482 std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !";
2483 throw INTERP_KERNEL::Exception(oss.str().c_str());
2485 for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
2487 this->declareAsNew();
2491 * Apply a linear function to all elements of \a this array, so that
2492 * an element _x_ becomes \f$ a * x + b \f$.
2493 * \param [in] a - the first coefficient of the function.
2494 * \param [in] b - the second coefficient of the function.
2495 * \throw If \a this is not allocated.
2498 void DataArrayTemplateClassic<T>::applyLin(T a, T b)
2500 this->checkAllocated();
2501 T *ptr(this->getPointer());
2502 std::size_t nbOfElems(this->getNbOfElems());
2503 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
2505 this->declareAsNew();
2509 * Returns a full copy of \a this array except that sign of all elements is reversed.
2510 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
2511 * same number of tuples and component as \a this array.
2512 * The caller is to delete this result array using decrRef() as it is no more
2514 * \throw If \a this is not allocated.
2517 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::negate() const
2519 this->checkAllocated();
2520 MCAuto<typename Traits<T>::ArrayType> newArr(Traits<T>::ArrayType::New());
2521 int nbOfTuples(this->getNumberOfTuples()),nbOfComp(this->getNumberOfComponents());
2522 newArr->alloc(nbOfTuples,nbOfComp);
2523 const T *cptr(this->begin());
2524 std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<T>());
2525 newArr->copyStringInfoFrom(*this);
2526 return newArr.retn();
2531 void DataArrayTemplateClassic<T>::somethingEqual(const typename Traits<T>::ArrayType *other)
2534 throw INTERP_KERNEL::Exception("DataArray<T>::SomethingEqual : input DataArray<T> instance is NULL !");
2535 const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
2536 this->checkAllocated();
2537 other->checkAllocated();
2538 int nbOfTuple(this->getNumberOfTuples()),nbOfTuple2(other->getNumberOfTuples());
2539 int nbOfComp(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents());
2540 if(nbOfTuple==nbOfTuple2)
2542 if(nbOfComp==nbOfComp2)
2544 std::transform(this->begin(),this->end(),other->begin(),this->getPointer(),FCT());
2546 else if(nbOfComp2==1)
2548 T *ptr(this->getPointer());
2549 const T *ptrc(other->begin());
2550 for(int i=0;i<nbOfTuple;i++)
2551 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(FCT(),*ptrc++));
2554 throw INTERP_KERNEL::Exception(msg);
2556 else if(nbOfTuple2==1)
2558 if(nbOfComp2==nbOfComp)
2560 T *ptr(this->getPointer());
2561 const T *ptrc(other->begin());
2562 for(int i=0;i<nbOfTuple;i++)
2563 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,FCT());
2566 throw INTERP_KERNEL::Exception(msg);
2569 throw INTERP_KERNEL::Exception(msg);
2570 this->declareAsNew();
2574 * Adds values of another DataArrayDouble to values of \a this one. There are 3
2576 * 1. The arrays have same number of tuples and components. Then each value of
2577 * \a other array is added to the corresponding value of \a this array, i.e.:
2578 * _a_ [ i, j ] += _other_ [ i, j ].
2579 * 2. The arrays have same number of tuples and \a other array has one component. Then
2580 * _a_ [ i, j ] += _other_ [ i, 0 ].
2581 * 3. The arrays have same number of components and \a other array has one tuple. Then
2582 * _a_ [ i, j ] += _a2_ [ 0, j ].
2584 * \param [in] other - an array to add to \a this one.
2585 * \throw If \a other is NULL.
2586 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
2587 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
2588 * \a other has number of both tuples and components not equal to 1.
2591 void DataArrayTemplateClassic<T>::addEqual(const typename Traits<T>::ArrayType *other)
2593 this->somethingEqual< std::plus<T> >(other);
2597 * Subtract values of another DataArrayDouble from values of \a this one. There are 3
2599 * 1. The arrays have same number of tuples and components. Then each value of
2600 * \a other array is subtracted from the corresponding value of \a this array, i.e.:
2601 * _a_ [ i, j ] -= _other_ [ i, j ].
2602 * 2. The arrays have same number of tuples and \a other array has one component. Then
2603 * _a_ [ i, j ] -= _other_ [ i, 0 ].
2604 * 3. The arrays have same number of components and \a other array has one tuple. Then
2605 * _a_ [ i, j ] -= _a2_ [ 0, j ].
2607 * \param [in] other - an array to subtract from \a this one.
2608 * \throw If \a other is NULL.
2609 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
2610 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
2611 * \a other has number of both tuples and components not equal to 1.
2614 void DataArrayTemplateClassic<T>::substractEqual(const typename Traits<T>::ArrayType *other)
2616 this->somethingEqual< std::minus<T> >(other);
2620 * Multiply values of another DataArrayDouble to values of \a this one. There are 3
2622 * 1. The arrays have same number of tuples and components. Then each value of
2623 * \a other array is multiplied to the corresponding value of \a this array, i.e.
2624 * _this_ [ i, j ] *= _other_ [ i, j ].
2625 * 2. The arrays have same number of tuples and \a other array has one component. Then
2626 * _this_ [ i, j ] *= _other_ [ i, 0 ].
2627 * 3. The arrays have same number of components and \a other array has one tuple. Then
2628 * _this_ [ i, j ] *= _a2_ [ 0, j ].
2630 * \param [in] other - an array to multiply to \a this one.
2631 * \throw If \a other is NULL.
2632 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
2633 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
2634 * \a other has number of both tuples and components not equal to 1.
2637 void DataArrayTemplateClassic<T>::multiplyEqual(const typename Traits<T>::ArrayType *other)
2639 this->somethingEqual< std::multiplies<T> >(other);
2643 * Divide values of \a this array by values of another DataArrayDouble. There are 3
2645 * 1. The arrays have same number of tuples and components. Then each value of
2646 * \a this array is divided by the corresponding value of \a other one, i.e.:
2647 * _a_ [ i, j ] /= _other_ [ i, j ].
2648 * 2. The arrays have same number of tuples and \a other array has one component. Then
2649 * _a_ [ i, j ] /= _other_ [ i, 0 ].
2650 * 3. The arrays have same number of components and \a other array has one tuple. Then
2651 * _a_ [ i, j ] /= _a2_ [ 0, j ].
2653 * \warning No check of division by zero is performed!
2654 * \param [in] other - an array to divide \a this one by.
2655 * \throw If \a other is NULL.
2656 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
2657 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
2658 * \a other has number of both tuples and components not equal to 1.
2661 void DataArrayTemplateClassic<T>::divideEqual(const typename Traits<T>::ArrayType *other)
2663 this->somethingEqual< std::divides<T> >(other);
2666 template<class T, class FCT>
2667 typename Traits<T>::ArrayType *DivSub(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
2670 throw INTERP_KERNEL::Exception("DivSub : input DataArrayDouble instance is NULL !");
2671 int nbOfTuple1(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples());
2672 int nbOfComp1(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents());
2673 if(nbOfTuple2==nbOfTuple1)
2675 if(nbOfComp1==nbOfComp2)
2677 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
2678 ret->alloc(nbOfTuple2,nbOfComp1);
2679 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT());
2680 ret->copyStringInfoFrom(*a1);
2683 else if(nbOfComp2==1)
2685 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
2686 ret->alloc(nbOfTuple1,nbOfComp1);
2687 const T *a2Ptr(a2->begin()),*a1Ptr(a1->begin());
2688 T *res(ret->getPointer());
2689 for(int i=0;i<nbOfTuple1;i++)
2690 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(FCT(),a2Ptr[i]));
2691 ret->copyStringInfoFrom(*a1);
2696 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
2700 else if(nbOfTuple2==1)
2702 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
2703 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
2704 ret->alloc(nbOfTuple1,nbOfComp1);
2705 const T *a1ptr=a1->begin(),*a2ptr(a2->begin());
2706 T *pt(ret->getPointer());
2707 for(int i=0;i<nbOfTuple1;i++)
2708 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,FCT());
2709 ret->copyStringInfoFrom(*a1);
2714 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
2720 * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
2722 * 1. The arrays have same number of tuples and components. Then each value of
2723 * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
2724 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
2725 * 2. The arrays have same number of tuples and one array, say _a2_, has one
2727 * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
2728 * 3. The arrays have same number of components and one array, say _a2_, has one
2730 * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
2732 * Info on components is copied either from the first array (in the first case) or from
2733 * the array with maximal number of elements (getNbOfElems()).
2734 * \param [in] a1 - an array to subtract from.
2735 * \param [in] a2 - an array to subtract.
2736 * \return DataArrayDouble * - the new instance of DataArrayDouble.
2737 * The caller is to delete this result array using decrRef() as it is no more
2739 * \throw If either \a a1 or \a a2 is NULL.
2740 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
2741 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
2742 * none of them has number of tuples or components equal to 1.
2745 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Substract(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
2747 return DivSub< T,std::minus<T> >(a1,a2);
2751 * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
2753 * 1. The arrays have same number of tuples and components. Then each value of
2754 * the result array (_a_) is a division of the corresponding values of \a a1 and
2755 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
2756 * 2. The arrays have same number of tuples and one array, say _a2_, has one
2758 * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
2759 * 3. The arrays have same number of components and one array, say _a2_, has one
2761 * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
2763 * Info on components is copied either from the first array (in the first case) or from
2764 * the array with maximal number of elements (getNbOfElems()).
2765 * \warning No check of division by zero is performed!
2766 * \param [in] a1 - a numerator array.
2767 * \param [in] a2 - a denominator array.
2768 * \return DataArrayDouble * - the new instance of DataArrayDouble.
2769 * The caller is to delete this result array using decrRef() as it is no more
2771 * \throw If either \a a1 or \a a2 is NULL.
2772 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
2773 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
2774 * none of them has number of tuples or components equal to 1.
2777 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Divide(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
2779 return DivSub< T,std::divides<T> >(a1,a2);
2782 template<class T, class FCT>
2783 typename Traits<T>::ArrayType *MulAdd(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
2786 throw INTERP_KERNEL::Exception("DataArrayDouble::MulAdd : input DataArrayDouble instance is NULL !");
2787 int nbOfTuple(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples());
2788 int nbOfComp(a1->getNumberOfComponents()),nbOfComp2(a2->getNumberOfComponents());
2789 MCAuto<typename Traits<T>::ArrayType> ret=0;
2790 if(nbOfTuple==nbOfTuple2)
2792 if(nbOfComp==nbOfComp2)
2794 ret=Traits<T>::ArrayType::New();
2795 ret->alloc(nbOfTuple,nbOfComp);
2796 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),FCT());
2797 ret->copyStringInfoFrom(*a1);
2801 int nbOfCompMin,nbOfCompMax;
2802 const typename Traits<T>::ArrayType *aMin, *aMax;
2803 if(nbOfComp>nbOfComp2)
2805 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
2810 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
2815 ret=Traits<T>::ArrayType::New();
2816 ret->alloc(nbOfTuple,nbOfCompMax);
2817 const T *aMinPtr(aMin->begin());
2818 const T *aMaxPtr(aMax->begin());
2819 T *res=ret->getPointer();
2820 for(int i=0;i<nbOfTuple;i++)
2821 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(FCT(),aMinPtr[i]));
2822 ret->copyStringInfoFrom(*aMax);
2825 throw INTERP_KERNEL::Exception("Nb of components mismatch for array MulAdd !");
2828 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
2830 if(nbOfComp==nbOfComp2)
2832 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
2833 const typename Traits<T>::ArrayType *aMin(nbOfTuple>nbOfTuple2?a2:a1);
2834 const typename Traits<T>::ArrayType *aMax(nbOfTuple>nbOfTuple2?a1:a2);
2835 const T *aMinPtr(aMin->begin()),*aMaxPtr(aMax->begin());
2836 ret=Traits<T>::ArrayType::New();
2837 ret->alloc(nbOfTupleMax,nbOfComp);
2838 T *res(ret->getPointer());
2839 for(int i=0;i<nbOfTupleMax;i++)
2840 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,FCT());
2841 ret->copyStringInfoFrom(*aMax);
2844 throw INTERP_KERNEL::Exception("Nb of components mismatch for array MulAdd !");
2847 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array MulAdd !");
2852 * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
2854 * 1. The arrays have same number of tuples and components. Then each value of
2855 * the result array (_a_) is a product of the corresponding values of \a a1 and
2856 * \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
2857 * 2. The arrays have same number of tuples and one array, say _a2_, has one
2859 * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
2860 * 3. The arrays have same number of components and one array, say _a2_, has one
2862 * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
2864 * Info on components is copied either from the first array (in the first case) or from
2865 * the array with maximal number of elements (getNbOfElems()).
2866 * \param [in] a1 - a factor array.
2867 * \param [in] a2 - another factor array.
2868 * \return DataArrayDouble * - the new instance of DataArrayDouble.
2869 * The caller is to delete this result array using decrRef() as it is no more
2871 * \throw If either \a a1 or \a a2 is NULL.
2872 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
2873 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
2874 * none of them has number of tuples or components equal to 1.
2877 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Multiply(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
2879 return MulAdd< T , std::multiplies<T> >(a1,a2);
2883 * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
2885 * 1. The arrays have same number of tuples and components. Then each value of
2886 * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
2887 * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
2888 * 2. The arrays have same number of tuples and one array, say _a2_, has one
2890 * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
2891 * 3. The arrays have same number of components and one array, say _a2_, has one
2893 * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
2895 * Info on components is copied either from the first array (in the first case) or from
2896 * the array with maximal number of elements (getNbOfElems()).
2897 * \param [in] a1 - an array to sum up.
2898 * \param [in] a2 - another array to sum up.
2899 * \return DataArrayDouble * - the new instance of DataArrayDouble.
2900 * The caller is to delete this result array using decrRef() as it is no more
2902 * \throw If either \a a1 or \a a2 is NULL.
2903 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
2904 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
2905 * none of them has number of tuples or components equal to 1.
2908 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Add(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
2910 return MulAdd< T , std::plus<T> >(a1,a2);
2914 * Returns either a \a deep or \a shallow copy of this array. For more info see
2915 * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
2916 * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
2917 * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
2918 * == \a true) or \a this instance (if \a dCpy == \a false).
2921 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self)
2924 return self.deepCopy();
2928 return const_cast<typename Traits<T>::ArrayType *>(&self);
2935 GreatEqual(T v):_v(v) { }
2936 bool operator()(T v) const { return v>=_v; }
2943 GreaterThan(T v):_v(v) { }
2944 bool operator()(T v) const { return v>_v; }
2951 LowerEqual(T v):_v(v) { }
2952 bool operator()(T v) const { return v<=_v; }
2959 LowerThan(T v):_v(v) { }
2960 bool operator()(T v) const { return v<_v; }
2967 InRange(T a, T b):_a(a),_b(b) { }
2968 bool operator()(T v) const { return v>=_a && v<_b; }
2975 NotInRange(T a, T b):_a(a),_b(b) { }
2976 bool operator()(T v) const { return v<_a || v>=_b; }
2981 * This method works only on data array with one component. This method returns a newly allocated array storing stored ascendantly of tuple ids in \a this so that this[id]<0.
2983 * \return a newly allocated data array that the caller should deal with.
2984 * \sa DataArrayInt::findIdsInRange
2987 DataArrayInt *DataArrayTemplateClassic<T>::findIdsStrictlyNegative() const
2989 LowerThan<T> lt((T)0);
2990 MCAuto<DataArrayInt> ret(findIdsAdv(lt));
2995 MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsGreaterOrEqualTo(T val) const
2997 GreatEqual<T> ge(val);
2998 return findIdsAdv(ge);
3002 MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsGreaterThan(T val) const
3004 GreaterThan<T> gt(val);
3005 return findIdsAdv(gt);
3009 MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsLowerOrEqualTo(T val) const
3011 LowerEqual<T> le(val);
3012 return findIdsAdv(le);
3016 MCAuto<DataArrayInt> DataArrayTemplateClassic<T>::findIdsLowerThan(T val) const
3018 LowerThan<T> lt(val);
3019 return findIdsAdv(lt);
3023 * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
3024 * of components in the result array is a sum of the number of components of given arrays
3025 * and (2) the number of tuples in the result array is same as that of each of given
3026 * arrays. In other words the i-th tuple of result array includes all components of
3027 * i-th tuples of all given arrays.
3028 * Number of tuples in the given arrays must be the same.
3029 * \param [in] a1 - an array to include in the result array.
3030 * \param [in] a2 - another array to include in the result array.
3031 * \return DataArrayDouble * - the new instance of DataArrayDouble.
3032 * The caller is to delete this result array using decrRef() as it is no more
3034 * \throw If both \a a1 and \a a2 are NULL.
3035 * \throw If any given array is not allocated.
3036 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
3039 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Meld(const typename Traits<T>::ArrayType *a1, const typename Traits<T>::ArrayType *a2)
3041 std::vector<const typename Traits<T>::ArrayType *> arr(2);
3042 arr[0]=a1; arr[1]=a2;
3047 * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
3048 * of components in the result array is a sum of the number of components of given arrays
3049 * and (2) the number of tuples in the result array is same as that of each of given
3050 * arrays. In other words the i-th tuple of result array includes all components of
3051 * i-th tuples of all given arrays.
3052 * Number of tuples in the given arrays must be the same.
3053 * \param [in] arr - a sequence of arrays to include in the result array.
3054 * \return DataArrayDouble * - the new instance of DataArrayDouble.
3055 * The caller is to delete this result array using decrRef() as it is no more
3057 * \throw If all arrays within \a arr are NULL.
3058 * \throw If any given array is not allocated.
3059 * \throw If getNumberOfTuples() of arrays within \a arr is different.
3062 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::Meld(const std::vector<const typename Traits<T>::ArrayType *>& arr)
3064 std::vector<const typename Traits<T>::ArrayType *> a;
3065 for(typename std::vector<const typename Traits<T>::ArrayType *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
3069 throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
3070 typename std::vector<const typename Traits<T>::ArrayType *>::const_iterator it;
3071 for(it=a.begin();it!=a.end();it++)
3072 (*it)->checkAllocated();
3074 std::size_t nbOfTuples((*it)->getNumberOfTuples());
3075 std::vector<int> nbc(a.size());
3076 std::vector<const T *> pts(a.size());
3077 nbc[0]=(*it)->getNumberOfComponents();
3078 pts[0]=(*it++)->getConstPointer();
3079 for(int i=1;it!=a.end();it++,i++)
3081 if(nbOfTuples!=(*it)->getNumberOfTuples())
3082 throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
3083 nbc[i]=(*it)->getNumberOfComponents();
3084 pts[i]=(*it)->getConstPointer();
3086 int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
3087 typename Traits<T>::ArrayType *ret(Traits<T>::ArrayType::New());
3088 ret->alloc(nbOfTuples,totalNbOfComp);
3089 T *retPtr(ret->getPointer());
3090 for(std::size_t i=0;i<nbOfTuples;i++)
3091 for(std::size_t j=0;j<a.size();j++)
3093 retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
3097 for(int i=0;i<(int)a.size();i++)
3098 for(int j=0;j<nbc[i];j++,k++)
3099 ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
3104 * Returns a new DataArrayDouble holding the same values as \a this array but differently
3105 * arranged in memory. If \a this array holds 2 components of 3 values:
3106 * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
3107 * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
3108 * \warning Do not confuse this method with transpose()!
3109 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
3110 * is to delete using decrRef() as it is no more needed.
3111 * \throw If \a this is not allocated.
3114 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::fromNoInterlace() const
3116 if(this->_mem.isNull())
3117 throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
3118 T *tab(this->_mem.fromNoInterlace(this->getNumberOfComponents()));
3119 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
3120 ret->useArray(tab,true,DeallocType::C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents());
3125 * Returns a new DataArrayDouble holding the same values as \a this array but differently
3126 * arranged in memory. If \a this array holds 2 components of 3 values:
3127 * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
3128 * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
3129 * \warning Do not confuse this method with transpose()!
3130 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
3131 * is to delete using decrRef() as it is no more needed.
3132 * \throw If \a this is not allocated.
3135 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::toNoInterlace() const
3137 if(this->_mem.isNull())
3138 throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
3139 T *tab(this->_mem.toNoInterlace(this->getNumberOfComponents()));
3140 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
3141 ret->useArray(tab,true,DeallocType::C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents());
3146 * Appends components of another array to components of \a this one, tuple by tuple.
3147 * So that the number of tuples of \a this array remains the same and the number of
3148 * components increases.
3149 * \param [in] other - the DataArrayDouble to append to \a this one.
3150 * \throw If \a this is not allocated.
3151 * \throw If \a this and \a other arrays have different number of tuples.
3153 * \if ENABLE_EXAMPLES
3154 * \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
3156 * \ref py_mcdataarraydouble_meldwith "Here is a Python example".
3160 void DataArrayTemplateClassic<T>::meldWith(const typename Traits<T>::ArrayType *other)
3162 this->checkAllocated();
3163 other->checkAllocated();
3164 std::size_t nbOfTuples(this->getNumberOfTuples());
3165 if(nbOfTuples!=other->getNumberOfTuples())
3166 throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
3167 int nbOfComp1(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents());
3168 T *newArr=(T *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(T));
3170 const T *inp1(this->begin()),*inp2(other->begin());
3171 for(std::size_t i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
3173 w=std::copy(inp1,inp1+nbOfComp1,w);
3174 w=std::copy(inp2,inp2+nbOfComp2,w);
3176 this->useArray(newArr,true,DeallocType::C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
3177 std::vector<int> compIds(nbOfComp2);
3178 for(int i=0;i<nbOfComp2;i++)
3179 compIds[i]=nbOfComp1+i;
3180 this->copyPartOfStringInfoFrom2(compIds,*other);
3185 * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
3186 * \a nbTimes should be at least equal to 1.
3187 * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
3188 * \throw if \a this is not allocated or if \a this has not number of components set to one or if \a nbTimes is lower than 1.
3191 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::duplicateEachTupleNTimes(int nbTimes) const
3193 this->checkAllocated();
3194 if(this->getNumberOfComponents()!=1)
3195 throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
3197 throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
3198 int nbTuples(this->getNumberOfTuples());
3199 const T *inPtr(this->begin());
3200 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New()); ret->alloc(nbTimes*nbTuples,1);
3201 T *retPtr(ret->getPointer());
3202 for(int i=0;i<nbTuples;i++,inPtr++)
3205 for(int j=0;j<nbTimes;j++,retPtr++)
3208 ret->copyStringInfoFrom(*this);
3213 void DataArrayTemplateClassic<T>::aggregate(const typename Traits<T>::ArrayType *other)
3216 throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !");
3217 if(this->getNumberOfComponents()!=other->getNumberOfComponents())
3218 throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !");
3219 this->_mem.insertAtTheEnd(other->begin(),other->end());
3223 * Converts every value of \a this array to its absolute value.
3224 * \b WARNING this method is non const. If a new DataArrayDouble instance should be built containing the result of abs DataArrayDouble::computeAbs
3225 * should be called instead.
3227 * \throw If \a this is not allocated.
3228 * \sa DataArrayDouble::computeAbs
3231 void DataArrayTemplateClassic<T>::abs()
3233 this->checkAllocated();
3234 T *ptr(this->getPointer());
3235 std::size_t nbOfElems(this->getNbOfElems());
3236 std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<T,T>(std::abs));
3237 this->declareAsNew();
3241 * This method builds a new instance of \a this object containing the result of std::abs applied of all elements in \a this.
3242 * This method is a const method (that do not change any values in \a this) contrary to DataArrayDouble::abs method.
3244 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3245 * same number of tuples and component as \a this array.
3246 * The caller is to delete this result array using decrRef() as it is no more
3248 * \throw If \a this is not allocated.
3249 * \sa DataArrayDouble::abs
3252 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::computeAbs() const
3254 this->checkAllocated();
3255 MCAuto<typename Traits<T>::ArrayType> newArr(Traits<T>::ArrayType::New());
3256 int nbOfTuples(this->getNumberOfTuples());
3257 int nbOfComp(this->getNumberOfComponents());
3258 newArr->alloc(nbOfTuples,nbOfComp);
3259 std::transform(this->begin(),this->end(),newArr->getPointer(),std::ptr_fun<T,T>(std::abs));
3260 newArr->copyStringInfoFrom(*this);
3261 return newArr.retn();
3265 * Returns either a \a deep or \a shallow copy of this array. For more info see
3266 * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
3267 * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
3268 * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
3269 * == \a true) or \a this instance (if \a dCpy == \a false).
3272 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::performCopyOrIncrRef(bool dCpy) const
3274 const typename Traits<T>::ArrayType *thisC(static_cast<const typename Traits<T>::ArrayType *>(this));
3275 return DataArrayTemplateClassic<T>::PerformCopyOrIncrRef(dCpy,*thisC);
3279 * Computes for each tuple the sum of number of components values in the tuple and return it.
3281 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3282 * same number of tuples as \a this array and one component.
3283 * The caller is to delete this result array using decrRef() as it is no more
3285 * \throw If \a this is not allocated.
3288 typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::sumPerTuple() const
3290 this->checkAllocated();
3291 std::size_t nbOfComp(this->getNumberOfComponents()),nbOfTuple(this->getNumberOfTuples());
3292 MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
3293 ret->alloc(nbOfTuple,1);
3294 const T *src(this->begin());
3295 T *dest(ret->getPointer());
3296 for(std::size_t i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
3297 *dest=std::accumulate(src,src+nbOfComp,(T)0);
3302 * Set all values in \a this array so that the i-th element equals to \a init + i
3303 * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
3304 * \param [in] init - value to assign to the first element of array.
3305 * \throw If \a this->getNumberOfComponents() != 1
3306 * \throw If \a this is not allocated.
3309 void DataArrayTemplateClassic<T>::iota(T init)
3311 this->checkAllocated();
3312 if(this->getNumberOfComponents()!=1)
3313 throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
3314 T *ptr(this->getPointer());
3315 std::size_t ntuples(this->getNumberOfTuples());
3316 for(std::size_t i=0;i<ntuples;i++)
3318 this->declareAsNew();
3322 struct ImplReprTraits { static void SetPrecision(std::ostream& oss) { } };
3325 struct ImplReprTraits<double> { static void SetPrecision(std::ostream& oss) { oss.precision(17); } };
3328 struct ImplReprTraits<float> { static void SetPrecision(std::ostream& oss) { oss.precision(7); } };
3331 void DataArrayTemplateClassic<T>::reprStream(std::ostream& stream) const
3333 stream << "Name of " << Traits<T>::ReprStr << " array : \"" << this->_name << "\"\n";
3334 reprWithoutNameStream(stream);
3338 void DataArrayTemplateClassic<T>::reprZipStream(std::ostream& stream) const
3340 stream << "Name of " << Traits<T>::ReprStr << " array : \"" << this->_name << "\"\n";
3341 reprZipWithoutNameStream(stream);
3345 void DataArrayTemplateClassic<T>::reprNotTooLongStream(std::ostream& stream) const
3347 stream << "Name of "<< Traits<T>::ReprStr << " array : \"" << this->_name << "\"\n";
3348 reprNotTooLongWithoutNameStream(stream);
3352 void DataArrayTemplateClassic<T>::reprWithoutNameStream(std::ostream& stream) const
3354 DataArray::reprWithoutNameStream(stream);
3355 ImplReprTraits<T>::SetPrecision(stream);
3356 this->_mem.repr(this->getNumberOfComponents(),stream);
3360 void DataArrayTemplateClassic<T>::reprZipWithoutNameStream(std::ostream& stream) const
3362 DataArray::reprWithoutNameStream(stream);
3363 ImplReprTraits<T>::SetPrecision(stream);
3364 this->_mem.reprZip(this->getNumberOfComponents(),stream);
3368 void DataArrayTemplateClassic<T>::reprNotTooLongWithoutNameStream(std::ostream& stream) const
3370 DataArray::reprWithoutNameStream(stream);
3371 ImplReprTraits<T>::SetPrecision(stream);
3372 this->_mem.reprNotTooLong(this->getNumberOfComponents(),stream);
3376 * This method is close to repr method except that when \a this has more than 1000 tuples, all tuples are not
3377 * printed out to avoid to consume too much space in interpretor.
3381 std::string DataArrayTemplateClassic<T>::reprNotTooLong() const
3383 std::ostringstream ret;
3384 reprNotTooLongStream(ret);
3389 * Returns a textual and human readable representation of \a this instance of
3390 * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
3391 * \return std::string - text describing \a this DataArrayInt.
3393 * \sa reprNotTooLong, reprZip
3396 std::string DataArrayTemplateClassic<T>::repr() const
3398 std::ostringstream ret;
3399 DataArrayTemplateClassic<T>::reprStream(ret);
3404 std::string DataArrayTemplateClassic<T>::reprZip() const
3406 std::ostringstream ret;
3407 DataArrayTemplateClassic<T>::reprZipStream(ret);
3411 /////////////////////////////////
3414 * Checks if all values in \a this array are equal to \a val at precision \a eps.
3415 * \param [in] val - value to check equality of array values to.
3416 * \param [in] eps - precision to check the equality.
3417 * \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
3419 * \throw If \a this->getNumberOfComponents() != 1
3420 * \throw If \a this is not allocated.
3423 bool DataArrayTemplateFP<T>::isUniform(T val, T eps) const
3425 this->checkAllocated();
3426 if(this->getNumberOfComponents()!=1)
3427 throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
3428 const T *w(this->begin()),*end2(this->end());
3429 const T vmin(val-eps),vmax(val+eps);
3431 if(*w<vmin || *w>vmax)
3437 * Equivalent to DataArrayInt::isEqual except that if false the reason of
3438 * mismatch is given.
3440 * \param [in] other the instance to be compared with \a this
3441 * \param [out] reason In case of inequality returns the reason.
3442 * \sa DataArrayInt::isEqual
3445 bool DataArrayDiscrete<T>::isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const
3447 if(!this->areInfoEqualsIfNotWhy(other,reason))
3449 return this->_mem.isEqual(other._mem,0,reason);
3453 * Checks if \a this and another DataArrayInt are fully equal. For more info see
3454 * \ref MEDCouplingArrayBasicsCompare.
3455 * \param [in] other - an instance of DataArrayInt to compare with \a this one.
3456 * \return bool - \a true if the two arrays are equal, \a false else.
3459 bool DataArrayDiscrete<T>::isEqual(const DataArrayDiscrete<T>& other) const
3462 return isEqualIfNotWhy(other,tmp);
3466 * Returns a new instance of DataArrayInt. The caller is to delete this array
3467 * using decrRef() as it is no more needed.
3470 typename Traits<T>::ArrayType *DataArrayDiscrete<T>::New()
3472 return new typename Traits<T>::ArrayType;
3476 * Checks if values of \a this and another DataArrayInt are equal. For more info see
3477 * \ref MEDCouplingArrayBasicsCompare.
3478 * \param [in] other - an instance of DataArrayInt to compare with \a this one.
3479 * \return bool - \a true if the values of two arrays are equal, \a false else.
3482 bool DataArrayDiscrete<T>::isEqualWithoutConsideringStr(const DataArrayDiscrete<T>& other) const
3485 return this->_mem.isEqual(other._mem,0,tmp);
3489 * Checks if values of \a this and another DataArrayInt are equal. Comparison is
3490 * performed on sorted value sequences.
3491 * For more info see\ref MEDCouplingArrayBasicsCompare.
3492 * \param [in] other - an instance of DataArrayInt to compare with \a this one.
3493 * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
3496 bool DataArrayDiscrete<T>::isEqualWithoutConsideringStrAndOrder(const typename Traits<T>::ArrayType& other) const
3498 MCAuto<typename Traits<T>::ArrayType> a((static_cast<const typename Traits<T>::ArrayType *>(this))->deepCopy());
3499 MCAuto<typename Traits<T>::ArrayType> b((static_cast<const typename Traits<T>::ArrayType *>(&other))->deepCopy());
3502 return a->isEqualWithoutConsideringStr(*b);
3507 void DataArrayDiscrete<T>::switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const
3509 this->checkAllocated();
3510 if(this->getNumberOfComponents()!=1)
3511 throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of components of this should be equal to one !");
3512 int nbOfTuples(this->getNumberOfTuples());
3513 if(nbOfTuples!=(int)vec.size())
3514 throw INTERP_KERNEL::Exception("DataArrayInt::switchOnTupleEqualTo : number of tuples of this should be equal to size of input vector of bool !");
3515 const T *pt(this->begin());
3516 for(int i=0;i<nbOfTuples;i++)
3522 * 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
3523 * put True to the corresponding entry in \a vec.
3524 * \a vec is expected to be with the same size than the number of tuples of \a this.
3526 * \sa DataArrayInt::switchOnTupleNotEqualTo.
3529 void DataArrayDiscrete<T>::switchOnTupleEqualTo(T val, std::vector<bool>& vec) const
3531 switchOnTupleAlg(val,vec,std::equal_to<T>());
3535 * This method assumes that \a this has one component and is allocated. This method scans all tuples in \a this and for all tuple different from \a val
3536 * put True to the corresponding entry in \a vec.
3537 * \a vec is expected to be with the same size than the number of tuples of \a this.
3539 * \sa DataArrayInt::switchOnTupleEqualTo.
3542 void DataArrayDiscrete<T>::switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const
3544 switchOnTupleAlg(val,vec,std::not_equal_to<T>());
3548 * Creates a new one-dimensional DataArrayInt of the same size as \a this and a given
3549 * one-dimensional arrays that must be of the same length. The result array describes
3550 * correspondence between \a this and \a other arrays, so that
3551 * <em> other.getIJ(i,0) == this->getIJ(ret->getIJ(i),0)</em>. If such a permutation is
3552 * not possible because some element in \a other is not in \a this, an exception is thrown.
3553 * \param [in] other - an array to compute permutation to.
3554 * \return DataArrayInt * - a new instance of DataArrayInt, which is a permutation array
3555 * from \a this to \a other. The caller is to delete this array using decrRef() as it is
3557 * \throw If \a this->getNumberOfComponents() != 1.
3558 * \throw If \a other->getNumberOfComponents() != 1.
3559 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples().
3560 * \throw If \a other includes a value which is not in \a this array.
3562 * \if ENABLE_EXAMPLES
3563 * \ref cpp_mcdataarrayint_buildpermutationarr "Here is a C++ example".
3565 * \ref py_mcdataarrayint_buildpermutationarr "Here is a Python example".
3569 DataArrayIdType *DataArrayDiscrete<T>::buildPermutationArr(const DataArrayDiscrete<T>& other) const
3571 this->checkAllocated();
3572 if(this->getNumberOfComponents()!=1 || other.getNumberOfComponents()!=1)
3573 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' have to have exactly ONE component !");
3574 std::size_t nbTuple(this->getNumberOfTuples());
3575 other.checkAllocated();
3576 if(nbTuple!=other.getNumberOfTuples())
3577 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' must have the same number of tuple !");
3578 MCAuto<DataArrayIdType> ret(DataArrayIdType::New());
3579 ret->alloc(nbTuple,1);
3580 ret->fillWithValue(-1);
3581 const T *pt(this->begin());
3582 std::map<int,mcIdType> mm;
3583 for(std::size_t i=0;i<nbTuple;i++)
3584 mm[pt[i]]=(mcIdType)i;
3586 mcIdType *retToFill(ret->getPointer());
3587 for(std::size_t i=0;i<nbTuple;i++)
3589 std::map<int,int>::const_iterator it=mm.find(pt[i]);
3592 std::ostringstream oss; oss << "DataArrayInt::buildPermutationArr : Arrays mismatch : element (" << pt[i] << ") in 'other' not findable in 'this' !";
3593 throw INTERP_KERNEL::Exception(oss.str().c_str());
3595 retToFill[i]=(*it).second;
3601 * Elements of \a partOfThis are expected to be included in \a this.
3602 * The returned array \a ret is so that this[ret]==partOfThis
3604 * 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]
3605 * the return array will contain [3,2,5,7].
3607 * \a this is expected to be a 1 compo allocated array.
3608 * \param [in] partOfThis - A 1 compo allocated array
3609 * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis.
3610 * \throw if two same element is present twice in \a this
3611 * \throw if an element in \a partOfThis is \b NOT in \a this.
3614 DataArrayIdType *DataArrayDiscrete<T>::indicesOfSubPart(const DataArrayDiscrete<T>& partOfThis) const
3616 if(this->getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1)
3617 throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !");
3618 this->checkAllocated(); partOfThis.checkAllocated();
3619 std::size_t thisNbTuples(this->getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples());
3620 const T *thisPt(this->begin()),*pt(partOfThis.begin());
3621 MCAuto<DataArrayIdType> ret(DataArrayIdType::New());
3622 ret->alloc(nbTuples,1);
3623 mcIdType *retPt(ret->getPointer());
3624 std::map<int,mcIdType> m;
3625 for(std::size_t i=0;i<thisNbTuples;i++,thisPt++)
3626 m[*thisPt]=(mcIdType)i;
3627 if(m.size()!=thisNbTuples)
3628 throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
3629 for(std::size_t i=0;i<nbTuples;i++,retPt++,pt++)
3631 std::map<int,mcIdType>::const_iterator it(m.find(*pt));
3633 *retPt=(*it).second;
3636 std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !";
3637 throw INTERP_KERNEL::Exception(oss.str());
3644 * Checks that \a this array is consistently **increasing** or **decreasing** in value.
3645 * If not an exception is thrown.
3646 * \param [in] increasing - if \a true, the array values should be increasing.
3647 * \throw If sequence of values is not strictly monotonic in agreement with \a
3649 * \throw If \a this->getNumberOfComponents() != 1.
3650 * \throw If \a this is not allocated.
3653 void DataArrayDiscrete<T>::checkMonotonic(bool increasing) const
3655 if(!isMonotonic(increasing))
3658 throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
3660 throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
3665 * Checks that \a this array is consistently **increasing** or **decreasing** in value.
3666 * \param [in] increasing - if \a true, array values should be increasing.
3667 * \return bool - \a true if values change in accordance with \a increasing arg.
3668 * \throw If \a this->getNumberOfComponents() != 1.
3669 * \throw If \a this is not allocated.
3672 bool DataArrayDiscrete<T>::isMonotonic(bool increasing) const
3674 this->checkAllocated();
3675 if(this->getNumberOfComponents()!=1)
3676 throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !");
3677 std::size_t nbOfElements(this->getNumberOfTuples());
3678 const T *ptr(this->begin());
3684 for(std::size_t i=1;i<nbOfElements;i++)
3694 for(std::size_t i=1;i<nbOfElements;i++)
3706 * This method check that array consistently INCREASING or DECREASING in value.
3709 bool DataArrayDiscrete<T>::isStrictlyMonotonic(bool increasing) const
3711 this->checkAllocated();
3712 if(this->getNumberOfComponents()!=1)
3713 throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !");
3714 std::size_t nbOfElements(this->getNumberOfTuples());
3715 const T *ptr(this->begin());
3721 for(std::size_t i=1;i<nbOfElements;i++)
3731 for(std::size_t i=1;i<nbOfElements;i++)
3743 * This method check that array consistently INCREASING or DECREASING in value.
3746 void DataArrayDiscrete<T>::checkStrictlyMonotonic(bool increasing) const
3748 if(!isStrictlyMonotonic(increasing))
3751 throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
3753 throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
3758 * Returns an integer value characterizing \a this array, which is useful for a quick
3759 * comparison of many instances of DataArrayInt.
3760 * \return int - the hash value.
3761 * \throw If \a this is not allocated.
3764 int DataArrayDiscrete<T>::getHashCode() const
3766 this->checkAllocated();
3767 std::size_t nbOfElems(this->getNbOfElems());
3768 int ret=nbOfElems*65536;
3773 const T *pt(this->begin());
3774 for(std::size_t i=0;i<nbOfElems;i+=delta)
3775 ret0+=pt[i] & 0x1FFF;
3780 void DataArrayDiscrete<T>::reprCppStream(const std::string& varName, std::ostream& stream) const
3782 std::size_t nbTuples(this->getNumberOfTuples()),nbComp(this->getNumberOfComponents());
3783 const T *data(this->getConstPointer());
3784 stream << Traits<T>::ArrayTypeName << " *" << varName << "=" << Traits<T>::ArrayTypeName << "::New();" << std::endl;
3785 if(nbTuples*nbComp>=1)
3787 stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
3788 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<int>(stream,","));
3789 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
3790 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
3793 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
3794 stream << varName << "->setName(\"" << this->getName() << "\");" << std::endl;
3798 * Method that gives a quick overvien of \a this for python.
3801 void DataArrayDiscrete<T>::reprQuickOverview(std::ostream& stream) const
3803 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
3804 stream << Traits<T>::ArrayTypeName << " C++ instance at " << this << ". ";
3805 if(this->isAllocated())
3807 std::size_t nbOfCompo(this->getNumberOfComponents());
3810 std::size_t nbOfTuples(this->getNumberOfTuples());
3811 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
3812 reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
3815 stream << "Number of components : 0.";
3818 stream << "*** No data allocated ****";
3822 void DataArrayDiscrete<T>::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
3824 const T *data(this->begin());
3825 std::size_t nbOfTuples(this->getNumberOfTuples()),nbOfCompo(this->getNumberOfComponents());
3826 std::ostringstream oss2; oss2 << "[";
3827 std::string oss2Str(oss2.str());
3828 bool isFinished=true;
3829 for(int i=0;i<nbOfTuples && isFinished;i++)
3834 for(int j=0;j<nbOfCompo;j++,data++)
3837 if(j!=nbOfCompo-1) oss2 << ", ";
3843 if(i!=nbOfTuples-1) oss2 << ", ";
3844 std::string oss3Str(oss2.str());
3845 if(oss3Str.length()<maxNbOfByteInRepr)
3857 void DataArrayDiscrete<T>::writeVTK(std::ostream& ofs, int indent, const std::string& type, const std::string& nameInFile, DataArrayByte *byteArr) const
3859 static const char SPACE[4]={' ',' ',' ',' '};
3860 this->checkAllocated();
3861 std::string idt(indent,' ');
3862 ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << this->getNumberOfComponents() << "\"";
3865 ofs << " format=\"appended\" offset=\"" << byteArr->getNumberOfTuples() << "\">";
3866 if(std::string(type)==Traits<T>::VTKReprStr)
3868 const char *data(reinterpret_cast<const char *>(this->begin()));
3869 std::size_t sz(this->getNbOfElems()*sizeof(T));
3870 byteArr->insertAtTheEnd(data,data+sz);
3871 byteArr->insertAtTheEnd(SPACE,SPACE+4);
3873 else if(std::string(type)=="Int8")
3875 INTERP_KERNEL::AutoPtr<char> tmp(new char[this->getNbOfElems()]);
3876 std::copy(this->begin(),this->end(),(char *)tmp);
3877 byteArr->insertAtTheEnd((char *)tmp,(char *)tmp+this->getNbOfElems());
3878 byteArr->insertAtTheEnd(SPACE,SPACE+4);
3880 else if(std::string(type)=="UInt8")
3882 INTERP_KERNEL::AutoPtr<unsigned char> tmp(new unsigned char[this->getNbOfElems()]);
3883 std::copy(this->begin(),this->end(),(unsigned char *)tmp);
3884 byteArr->insertAtTheEnd((unsigned char *)tmp,(unsigned char *)tmp+this->getNbOfElems());
3885 byteArr->insertAtTheEnd(SPACE,SPACE+4);
3889 std::ostringstream oss;
3890 oss << Traits<T>::ArrayTypeName << "::writeVTK : Only " << Traits<T>::VTKReprStr << ", Int8 and UInt8 supported !";
3891 throw INTERP_KERNEL::Exception(oss.str());
3896 ofs << " RangeMin=\"" << this->getMinValueInArray() << "\" RangeMax=\"" << this->getMaxValueInArray() << "\" format=\"ascii\">\n" << idt;
3897 std::copy(this->begin(),this->end(),std::ostream_iterator<int>(ofs," "));
3899 ofs << std::endl << idt << "</DataArray>\n";
3903 * Modifies in place \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
3904 * i.e. a current value is used as in index to get a new value from \a indArrBg.
3905 * \param [in] indArrBg - pointer to the first element of array of new values to assign
3907 * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
3908 * the last value of \a indArrBg is \a indArrEnd[ -1 ].
3909 * \throw If \a this->getNumberOfComponents() != 1
3910 * \throw If any value of \a this can't be used as a valid index for
3911 * [\a indArrBg, \a indArrEnd).
3913 * \sa changeValue, findIdForEach
3916 void DataArrayDiscrete<T>::transformWithIndArr(const T *indArrBg, const T *indArrEnd)
3918 this->checkAllocated();
3919 if(this->getNumberOfComponents()!=1)
3920 throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
3921 std::size_t nbElemsIn(std::distance(indArrBg,indArrEnd)),nbOfTuples(this->getNumberOfTuples());
3922 T *pt(this->getPointer());
3923 for(std::size_t i=0;i<nbOfTuples;i++,pt++)
3925 if(*pt>=0 && *pt<nbElemsIn)
3929 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
3930 throw INTERP_KERNEL::Exception(oss.str());
3933 this->declareAsNew();
3937 void DataArrayDiscrete<T>::transformWithIndArr(const MapKeyVal<T>& m)
3939 this->checkAllocated();
3940 if(this->getNumberOfComponents()!=1)
3941 throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
3942 const typename std::map<T,T>& dat(m.data());
3943 std::size_t nbOfTuples(this->getNumberOfTuples());
3944 T *pt(this->getPointer());
3945 for(std::size_t i=0;i<nbOfTuples;i++,pt++)
3947 typename std::map<T,T>::const_iterator it(dat.find(*pt));
3952 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !";
3953 throw INTERP_KERNEL::Exception(oss.str());
3956 this->declareAsNew();
3960 * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to a
3961 * given one. The ids are sorted in the ascending order.
3962 * \param [in] val - the value to find within \a this.
3963 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
3964 * array using decrRef() as it is no more needed.
3965 * \throw If \a this is not allocated.
3966 * \throw If \a this->getNumberOfComponents() != 1.
3967 * \sa DataArrayInt::findIdsEqualTuple
3970 DataArrayIdType *DataArrayDiscrete<T>::findIdsEqual(T val) const
3972 this->checkAllocated();
3973 if(this->getNumberOfComponents()!=1)
3974 throw INTERP_KERNEL::Exception("DataArrayInt::findIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
3975 const T *cptr(this->getConstPointer());
3976 MCAuto<DataArrayIdType> ret(DataArrayIdType::New()); ret->alloc(0,1);
3977 std::size_t nbOfTuples(this->getNumberOfTuples());
3978 for(std::size_t i=0;i<nbOfTuples;i++,cptr++)
3980 ret->pushBackSilent(ToIdType(i));
3984 ////////////////////////////////////
3987 * This method compares content of input vector \a v and \a this.
3988 * 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.
3989 * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
3991 * \param [in] v - the vector of 'flags' to be compared with \a this.
3993 * \throw If \a this is not sorted ascendingly.
3994 * \throw If \a this has not exactly one component.
3995 * \throw If \a this is not allocated.
3998 bool DataArrayDiscreteSigned<T>::isFittingWith(const std::vector<bool>& v) const
4000 this->checkAllocated();
4001 if(this->getNumberOfComponents()!=1)
4002 throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
4003 const T *w(this->begin()),*end2(this->end());
4004 T refVal=-std::numeric_limits<T>::max();
4006 std::vector<bool>::const_iterator it(v.begin());
4007 for(;it!=v.end();it++,i++)
4019 std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(this->begin(),w-1) << " this is not sorted ascendingly !";
4020 throw INTERP_KERNEL::Exception(oss.str().c_str());