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 (CEA/DEN)
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 "InterpKernelAutoPtr.hxx"
38 void MEDCouplingPointer<T>::setInternal(T *pointer)
45 void MEDCouplingPointer<T>::setExternal(const T *pointer)
52 MemArray<T>::MemArray(const MemArray<T>& other):_nb_of_elem(0),_nb_of_elem_alloc(0),_ownership(false),_dealloc(0),_param_for_deallocator(0)
54 if(!other._pointer.isNull())
56 _nb_of_elem_alloc=other._nb_of_elem;
57 T *pointer=(T*)malloc(_nb_of_elem_alloc*sizeof(T));
58 std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+other._nb_of_elem,pointer);
59 useArray(pointer,true,C_DEALLOC,other._nb_of_elem);
64 void MemArray<T>::useArray(const T *array, bool ownership, DeallocType type, std::size_t nbOfElem)
68 _nb_of_elem_alloc=nbOfElem;
70 _pointer.setInternal(const_cast<T *>(array));
72 _pointer.setExternal(array);
74 _dealloc=BuildFromType(type);
78 void MemArray<T>::useExternalArrayWithRWAccess(const T *array, std::size_t nbOfElem)
82 _nb_of_elem_alloc=nbOfElem;
83 _pointer.setInternal(const_cast<T *>(array));
85 _dealloc=CPPDeallocator;
89 void MemArray<T>::writeOnPlace(std::size_t id, T element0, const T *others, std::size_t sizeOfOthers)
91 if(id+sizeOfOthers>=_nb_of_elem_alloc)
92 reserve(2*_nb_of_elem+sizeOfOthers+1);
93 T *pointer=_pointer.getPointer();
95 std::copy(others,others+sizeOfOthers,pointer+id+1);
96 _nb_of_elem=std::max<std::size_t>(_nb_of_elem,id+sizeOfOthers+1);
100 void MemArray<T>::pushBack(T elem)
102 if(_nb_of_elem>=_nb_of_elem_alloc)
103 reserve(_nb_of_elem_alloc>0?2*_nb_of_elem_alloc:1);
105 pt[_nb_of_elem++]=elem;
109 T MemArray<T>::popBack()
113 const T *pt=getConstPointer();
114 return pt[--_nb_of_elem];
116 throw INTERP_KERNEL::Exception("MemArray::popBack : nothing to pop in array !");
120 void MemArray<T>::pack() const
122 (const_cast<MemArray<T> * >(this))->reserve(_nb_of_elem);
126 bool MemArray<T>::isEqual(const MemArray<T>& other, T prec, std::string& reason) const
128 std::ostringstream oss; oss.precision(15);
129 if(_nb_of_elem!=other._nb_of_elem)
131 oss << "Number of elements in coarse data of DataArray mismatch : this=" << _nb_of_elem << " other=" << other._nb_of_elem;
135 const T *pt1=_pointer.getConstPointer();
136 const T *pt2=other._pointer.getConstPointer();
141 oss << "coarse data pointer is defined for only one DataArray instance !";
147 for(std::size_t i=0;i<_nb_of_elem;i++)
148 if(pt1[i]-pt2[i]<-prec || (pt1[i]-pt2[i])>prec)
150 oss << "The content of data differs at pos #" << i << " of coarse data ! this[i]=" << pt1[i] << " other[i]=" << pt2[i];
158 * \param [in] sl is typically the number of components
159 * \return True if a not null pointer is present, False if not.
162 bool MemArray<T>::reprHeader(int sl, std::ostream& stream) const
164 stream << "Number of tuples : ";
165 if(!_pointer.isNull())
168 stream << _nb_of_elem/sl << std::endl << "Internal memory facts : " << _nb_of_elem << "/" << _nb_of_elem_alloc;
170 stream << "Empty Data";
175 stream << "Data content :\n";
176 bool ret=!_pointer.isNull();
178 stream << "No data !\n";
183 * \param [in] sl is typically the number of components
186 void MemArray<T>::repr(int sl, std::ostream& stream) const
188 if(reprHeader(sl,stream))
190 const T *data=getConstPointer();
191 if(_nb_of_elem!=0 && sl!=0)
193 std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
194 for(std::size_t i=0;i<nbOfTuples;i++)
196 stream << "Tuple #" << i << " : ";
197 std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
203 stream << "Empty Data\n";
208 * \param [in] sl is typically the number of components
211 void MemArray<T>::reprZip(int sl, std::ostream& stream) const
213 stream << "Number of tuples : ";
214 if(!_pointer.isNull())
217 stream << _nb_of_elem/sl;
219 stream << "Empty Data";
224 stream << "Data content : ";
225 const T *data=getConstPointer();
226 if(!_pointer.isNull())
228 if(_nb_of_elem!=0 && sl!=0)
230 std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
231 for(std::size_t i=0;i<nbOfTuples;i++)
234 std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
241 stream << "Empty Data\n";
244 stream << "No data !\n";
248 * \param [in] sl is typically the number of components
251 void MemArray<T>::reprNotTooLong(int sl, std::ostream& stream) const
253 if(reprHeader(sl,stream))
255 const T *data=getConstPointer();
256 if(_nb_of_elem!=0 && sl!=0)
258 std::size_t nbOfTuples=_nb_of_elem/std::abs(sl);
261 for(std::size_t i=0;i<nbOfTuples;i++)
263 stream << "Tuple #" << i << " : ";
264 std::copy(data,data+sl,std::ostream_iterator<T>(stream," "));
270 {// too much tuples -> print the 3 first tuples and 3 last.
271 stream << "Tuple #0 : ";
272 std::copy(data,data+sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
273 stream << "Tuple #1 : ";
274 std::copy(data+sl,data+2*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
275 stream << "Tuple #2 : ";
276 std::copy(data+2*sl,data+3*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
278 stream << "Tuple #" << nbOfTuples-3 << " : ";
279 std::copy(data+(nbOfTuples-3)*sl,data+(nbOfTuples-2)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
280 stream << "Tuple #" << nbOfTuples-2 << " : ";
281 std::copy(data+(nbOfTuples-2)*sl,data+(nbOfTuples-1)*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
282 stream << "Tuple #" << nbOfTuples-1 << " : ";
283 std::copy(data+(nbOfTuples-1)*sl,data+nbOfTuples*sl,std::ostream_iterator<T>(stream," ")); stream << "\n";
287 stream << "Empty Data\n";
292 void MemArray<T>::fillWithValue(const T& val)
294 T *pt=_pointer.getPointer();
295 std::fill(pt,pt+_nb_of_elem,val);
299 T *MemArray<T>::fromNoInterlace(int nbOfComp) const
302 throw INTERP_KERNEL::Exception("MemArray<T>::fromNoInterlace : number of components must be > 0 !");
303 const T *pt=_pointer.getConstPointer();
304 std::size_t nbOfTuples=_nb_of_elem/nbOfComp;
305 T *ret=(T*)malloc(_nb_of_elem*sizeof(T));
307 for(std::size_t i=0;i<nbOfTuples;i++)
308 for(int j=0;j<nbOfComp;j++,w++)
309 *w=pt[j*nbOfTuples+i];
314 T *MemArray<T>::toNoInterlace(int nbOfComp) const
317 throw INTERP_KERNEL::Exception("MemArray<T>::toNoInterlace : number of components must be > 0 !");
318 const T *pt=_pointer.getConstPointer();
319 std::size_t nbOfTuples=_nb_of_elem/nbOfComp;
320 T *ret=(T*)malloc(_nb_of_elem*sizeof(T));
322 for(int i=0;i<nbOfComp;i++)
323 for(std::size_t j=0;j<nbOfTuples;j++,w++)
329 void MemArray<T>::sort(bool asc)
331 T *pt=_pointer.getPointer();
333 std::sort(pt,pt+_nb_of_elem);
336 typename std::reverse_iterator<T *> it1(pt+_nb_of_elem);
337 typename std::reverse_iterator<T *> it2(pt);
343 void MemArray<T>::reverse(int nbOfComp)
346 throw INTERP_KERNEL::Exception("MemArray<T>::reverse : only supported with 'this' array with ONE or more than ONE component !");
347 T *pt=_pointer.getPointer();
350 std::reverse(pt,pt+_nb_of_elem);
355 T *pt2=pt+_nb_of_elem-nbOfComp;
356 std::size_t nbOfTuples=_nb_of_elem/nbOfComp;
357 for(std::size_t i=0;i<nbOfTuples/2;i++,pt+=nbOfComp,pt2-=nbOfComp)
359 for(int j=0;j<nbOfComp;j++)
360 std::swap(pt[j],pt2[j]);
366 void MemArray<T>::alloc(std::size_t nbOfElements)
369 _nb_of_elem=nbOfElements;
370 _nb_of_elem_alloc=nbOfElements;
371 _pointer.setInternal((T*)malloc(_nb_of_elem_alloc*sizeof(T)));
373 _dealloc=CDeallocator;
377 * This method performs systematically an allocation of \a newNbOfElements elements in \a this.
378 * \a _nb_of_elem and \a _nb_of_elem_alloc will \b NOT be systematically equal (contrary to MemArray<T>::reAlloc method.
379 * 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
380 * \a newNbOfElements. This method is typically used to perform a pushBack to avoid systematic allocations-copy-deallocation.
381 * So after the call of this method the accessible content is perfectly set.
383 * So this method should not be confused with MemArray<T>::reserve that is close to MemArray<T>::reAlloc but not same.
386 void MemArray<T>::reserve(std::size_t newNbOfElements)
388 if(_nb_of_elem_alloc==newNbOfElements)
390 T *pointer=(T*)malloc(newNbOfElements*sizeof(T));
391 std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<std::size_t>(_nb_of_elem,newNbOfElements),pointer);
393 DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
394 _pointer.setInternal(pointer);
395 _nb_of_elem=std::min<std::size_t>(_nb_of_elem,newNbOfElements);
396 _nb_of_elem_alloc=newNbOfElements;
398 _dealloc=CDeallocator;
399 _param_for_deallocator=0;
403 * This method performs systematically an allocation of \a newNbOfElements elements in \a this.
404 * \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 .
405 * The remaing part of the new allocated chunk are available but not set previouly !
407 * So this method should not be confused with MemArray<T>::reserve that is close to MemArray<T>::reAlloc but not same.
410 void MemArray<T>::reAlloc(std::size_t newNbOfElements)
412 if(_nb_of_elem==newNbOfElements)
414 T *pointer=(T*)malloc(newNbOfElements*sizeof(T));
415 std::copy(_pointer.getConstPointer(),_pointer.getConstPointer()+std::min<std::size_t>(_nb_of_elem,newNbOfElements),pointer);
417 DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
418 _pointer.setInternal(pointer);
419 _nb_of_elem=newNbOfElements;
420 _nb_of_elem_alloc=newNbOfElements;
422 _dealloc=CDeallocator;
423 _param_for_deallocator=0;
427 void MemArray<T>::CPPDeallocator(void *pt, void *param)
429 delete [] reinterpret_cast<T*>(pt);
433 void MemArray<T>::CDeallocator(void *pt, void *param)
439 typename MemArray<T>::Deallocator MemArray<T>::BuildFromType(DeallocType type)
444 return CPPDeallocator;
448 throw INTERP_KERNEL::Exception("Invalid deallocation requested ! Unrecognized enum DeallocType !");
453 void MemArray<T>::DestroyPointer(T *pt, typename MemArray<T>::Deallocator dealloc, void *param)
460 void MemArray<T>::destroy()
463 DestroyPointer(const_cast<T *>(_pointer.getConstPointer()),_dealloc,_param_for_deallocator);//Do not use getPointer because in case of _external
467 _param_for_deallocator=NULL;
473 MemArray<T> &MemArray<T>::operator=(const MemArray<T>& other)
475 alloc(other._nb_of_elem);
476 std::copy(other._pointer.getConstPointer(),other._pointer.getConstPointer()+_nb_of_elem,_pointer.getPointer());
480 //////////////////////////////////
483 MCAuto< typename Traits<T>::ArrayTypeCh > DataArrayTemplate<T>::NewFromStdVector(const typename std::vector<T>& v)
485 std::size_t sz(v.size());
486 MCAuto< typename Traits<T>::ArrayTypeCh > ret(Traits<T>::ArrayTypeCh::New());
488 T *pt(ret->getPointer());
489 std::copy(v.begin(),v.end(),pt);
494 std::size_t DataArrayTemplate<T>::getHeapMemorySizeWithoutChildren() const
496 std::size_t sz(_mem.getNbOfElemAllocated());
498 return DataArray::getHeapMemorySizeWithoutChildren()+sz;
502 * Allocates the raw data in memory. If the memory was already allocated, then it is
503 * freed and re-allocated. See an example of this method use
504 * \ref MEDCouplingArraySteps1WC "here".
505 * \param [in] nbOfTuple - number of tuples of data to allocate.
506 * \param [in] nbOfCompo - number of components of data to allocate.
507 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
510 void DataArrayTemplate<T>::alloc(std::size_t nbOfTuple, std::size_t nbOfCompo)
512 _info_on_compo.resize(nbOfCompo);
513 _mem.alloc(nbOfCompo*nbOfTuple);
518 * Sets a C array to be used as raw data of \a this. The previously set info
519 * of components is retained and re-sized.
520 * For more info see \ref MEDCouplingArraySteps1.
521 * \param [in] array - the C array to be used as raw data of \a this.
522 * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
523 * \param [in] type - specifies how to deallocate \a array. If \a type == MEDCoupling::CPP_DEALLOC,
524 * \c delete [] \c array; will be called. If \a type == MEDCoupling::C_DEALLOC,
525 * \c free(\c array ) will be called.
526 * \param [in] nbOfTuple - new number of tuples in \a this.
527 * \param [in] nbOfCompo - new number of components in \a this.
530 void DataArrayTemplate<T>::useArray(const T *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
532 _info_on_compo.resize(nbOfCompo);
533 _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo);
538 void DataArrayTemplate<T>::useExternalArrayWithRWAccess(const T *array, int nbOfTuple, int nbOfCompo)
540 _info_on_compo.resize(nbOfCompo);
541 _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo);
546 * Returns a value located at specified tuple and component.
547 * This method is equivalent to DataArrayTemplate<T>::getIJ() except that validity of
548 * parameters is checked. So this method is safe but expensive if used to go through
549 * all values of \a this.
550 * \param [in] tupleId - index of tuple of interest.
551 * \param [in] compoId - index of component of interest.
552 * \return double - value located by \a tupleId and \a compoId.
553 * \throw If \a this is not allocated.
554 * \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
555 * \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
558 T DataArrayTemplate<T>::getIJSafe(int tupleId, int compoId) const
561 if(tupleId<0 || tupleId>=getNumberOfTuples())
563 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
564 throw INTERP_KERNEL::Exception(oss.str().c_str());
566 if(compoId<0 || compoId>=getNumberOfComponents())
568 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
569 throw INTERP_KERNEL::Exception(oss.str().c_str());
571 return _mem[tupleId*_info_on_compo.size()+compoId];
575 * 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.
577 * \sa DataArray::getHeapMemorySizeWithoutChildren, DataArrayTemplate<T>::reserve
580 void DataArrayTemplate<T>::pack() const
586 * Checks if raw data is allocated. Read more on the raw data
587 * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information.
588 * \return bool - \a true if the raw data is allocated, \a false else.
591 bool DataArrayTemplate<T>::isAllocated() const
593 return getConstPointer()!=0;
597 * Checks if raw data is allocated and throws an exception if it is not the case.
598 * \throw If the raw data is not allocated.
601 void DataArrayTemplate<T>::checkAllocated() const
605 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !";
606 throw INTERP_KERNEL::Exception(oss.str().c_str());
611 * This method desallocated \a this without modification of informations relative to the components.
612 * After call of this method, DataArrayDouble::isAllocated will return false.
613 * If \a this is already not allocated, \a this is let unchanged.
616 void DataArrayTemplate<T>::desallocate()
622 * This method reserve nbOfElems elements in memory ( nbOfElems*8 bytes ) \b without impacting the number of tuples in \a this.
623 * 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.
624 * If \a this has not already been allocated, number of components is set to one.
625 * This method allows to reduce number of reallocations on invokation of DataArrayDouble::pushBackSilent and DataArrayDouble::pushBackValsSilent on \a this.
627 * \sa DataArrayDouble::pack, DataArrayDouble::pushBackSilent, DataArrayDouble::pushBackValsSilent
630 void DataArrayTemplate<T>::reserve(std::size_t nbOfElems)
632 int nbCompo(getNumberOfComponents());
635 _mem.reserve(nbOfElems);
639 _mem.reserve(nbOfElems);
640 _info_on_compo.resize(1);
644 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::reserve : not available for DataArrayDouble with number of components different than 1 !";
645 throw INTERP_KERNEL::Exception(oss.str().c_str());
650 * 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
651 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
653 * \param [in] val the value to be added in \a this
654 * \throw If \a this has already been allocated with number of components different from one.
655 * \sa DataArrayDouble::pushBackValsSilent
658 void DataArrayTemplate<T>::pushBackSilent(T val)
660 int nbCompo(getNumberOfComponents());
665 _info_on_compo.resize(1);
670 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !";
671 throw INTERP_KERNEL::Exception(oss.str().c_str());
676 * This method adds at the end of \a this a serie of values [\c valsBg,\c valsEnd). This method do \b not update its time label to avoid useless incrementation
677 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
679 * \param [in] valsBg - an array of values to push at the end of \c this.
680 * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
681 * the last value of \a valsBg is \a valsEnd[ -1 ].
682 * \throw If \a this has already been allocated with number of components different from one.
683 * \sa DataArrayDouble::pushBackSilent
686 void DataArrayTemplate<T>::pushBackValsSilent(const T *valsBg, const T *valsEnd)
688 int nbCompo(getNumberOfComponents());
690 _mem.insertAtTheEnd(valsBg,valsEnd);
693 _info_on_compo.resize(1);
694 _mem.insertAtTheEnd(valsBg,valsEnd);
698 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::pushBackValsSilent : not available for DataArrayDouble with number of components different than 1 !";
699 throw INTERP_KERNEL::Exception(oss.str().c_str());
704 * This method returns silently ( without updating time label in \a this ) the last value, if any and suppress it.
705 * \throw If \a this is already empty.
706 * \throw If \a this has number of components different from one.
709 T DataArrayTemplate<T>::popBackSilent()
711 if(getNumberOfComponents()==1)
712 return _mem.popBack();
715 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::popBackSilent : not available for DataArrayDouble with number of components different than 1 !";
716 throw INTERP_KERNEL::Exception(oss.str().c_str());
721 * Allocates the raw data in memory. If exactly same memory as needed already
722 * allocated, it is not re-allocated.
723 * \param [in] nbOfTuple - number of tuples of data to allocate.
724 * \param [in] nbOfCompo - number of components of data to allocate.
725 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
728 void DataArrayTemplate<T>::allocIfNecessary(int nbOfTuple, int nbOfCompo)
732 if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
733 alloc(nbOfTuple,nbOfCompo);
736 alloc(nbOfTuple,nbOfCompo);
740 * Checks the number of tuples.
741 * \return bool - \a true if getNumberOfTuples() == 0, \a false else.
742 * \throw If \a this is not allocated.
745 bool DataArrayTemplate<T>::empty() const
748 return getNumberOfTuples()==0;
752 * Copies all the data from another DataArrayDouble. For more info see
753 * \ref MEDCouplingArrayBasicsCopyDeepAssign.
754 * \param [in] other - another instance of DataArrayDouble to copy data from.
755 * \throw If the \a other is not allocated.
758 void DataArrayTemplate<T>::deepCopyFrom(const DataArrayTemplate<T>& other)
760 other.checkAllocated();
761 int nbOfTuples(other.getNumberOfTuples()),nbOfComp(other.getNumberOfComponents());
762 allocIfNecessary(nbOfTuples,nbOfComp);
763 std::size_t nbOfElems((std::size_t)nbOfTuples*nbOfComp);
765 const T *ptI(other.begin());
766 for(std::size_t i=0;i<nbOfElems;i++)
768 copyStringInfoFrom(other);
772 * Reverse the array values.
773 * \throw If \a this->getNumberOfComponents() < 1.
774 * \throw If \a this is not allocated.
777 void DataArrayTemplate<T>::reverse()
780 _mem.reverse(getNumberOfComponents());
785 * Assign \a val to all values in \a this array. To know more on filling arrays see
786 * \ref MEDCouplingArrayFill.
787 * \param [in] val - the value to fill with.
788 * \throw If \a this is not allocated.
791 void DataArrayTemplate<T>::fillWithValue(T val)
794 _mem.fillWithValue(val);
799 * Changes number of tuples in the array. If the new number of tuples is smaller
800 * than the current number the array is truncated, otherwise the array is extended.
801 * \param [in] nbOfTuples - new number of tuples.
802 * \throw If \a this is not allocated.
803 * \throw If \a nbOfTuples is negative.
806 void DataArrayTemplate<T>::reAlloc(std::size_t nbOfTuples)
809 _mem.reAlloc(getNumberOfComponents()*nbOfTuples);
814 * Permutes values of \a this array as required by \a old2New array. The values are
815 * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains
816 * the same as in \c this one.
817 * If a permutation reduction is needed, subArray() or selectByTupleId() should be used.
818 * For more info on renumbering see \ref numbering.
819 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
820 * giving a new position for i-th old value.
823 void DataArrayTemplate<T>::renumberInPlace(const int *old2New)
826 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
827 T *tmp(new T[nbTuples*nbOfCompo]);
828 const T *iptr(begin());
829 for(int i=0;i<nbTuples;i++)
832 if(v>=0 && v<nbTuples)
833 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*v);
836 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::renumberInPlace : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
837 throw INTERP_KERNEL::Exception(oss.str().c_str());
840 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
847 * Permutes values of \a this array as required by \a new2Old array. The values are
848 * permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of tuples remains
849 * the same as in \c this one.
850 * For more info on renumbering see \ref numbering.
851 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
852 * giving a previous position of i-th new value.
853 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
854 * is to delete using decrRef() as it is no more needed.
857 void DataArrayTemplate<T>::renumberInPlaceR(const int *new2Old)
860 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
861 T *tmp(new T[nbTuples*nbOfCompo]);
862 const T *iptr(begin());
863 for(int i=0;i<nbTuples;i++)
866 if(v>=0 && v<nbTuples)
867 std::copy(iptr+nbOfCompo*v,iptr+nbOfCompo*(v+1),tmp+nbOfCompo*i);
870 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::renumberInPlaceR : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
871 throw INTERP_KERNEL::Exception(oss.str().c_str());
874 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
880 * Sorts values of the array.
881 * \param [in] asc - \a true means ascending order, \a false, descending.
882 * \throw If \a this is not allocated.
883 * \throw If \a this->getNumberOfComponents() != 1.
886 void DataArrayTemplate<T>::sort(bool asc)
889 if(getNumberOfComponents()!=1)
891 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::sort : only supported with 'this' array with ONE component !";
892 throw INTERP_KERNEL::Exception(oss.str().c_str());
899 * Returns a copy of \a this array with values permuted as required by \a old2New array.
900 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ].
901 * Number of tuples in the result array remains the same as in \c this one.
902 * If a permutation reduction is needed, renumberAndReduce() should be used.
903 * For more info on renumbering see \ref numbering.
904 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
905 * giving a new position for i-th old value.
906 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
907 * is to delete using decrRef() as it is no more needed.
908 * \throw If \a this is not allocated.
911 typename Traits<T>::ArrayType *DataArrayTemplate<T>::renumber(const int *old2New) const
914 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
915 MCAuto<DataArray> ret0(buildNewEmptyInstance());
916 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
917 ret->alloc(nbTuples,nbOfCompo);
918 ret->copyStringInfoFrom(*this);
919 const T *iptr(begin());
920 T *optr(ret->getPointer());
921 for(int i=0;i<nbTuples;i++)
922 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
923 ret->copyStringInfoFrom(*this);
928 * Returns a copy of \a this array with values permuted as required by \a new2Old array.
929 * The values are permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
930 * tuples in the result array remains the same as in \c this one.
931 * If a permutation reduction is needed, subArray() or selectByTupleId() should be used.
932 * For more info on renumbering see \ref numbering.
933 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
934 * giving a previous position of i-th new value.
935 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
936 * is to delete using decrRef() as it is no more needed.
939 typename Traits<T>::ArrayType *DataArrayTemplate<T>::renumberR(const int *new2Old) const
942 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
943 MCAuto<DataArray> ret0(buildNewEmptyInstance());
944 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
945 ret->alloc(nbTuples,nbOfCompo);
946 ret->copyStringInfoFrom(*this);
947 const T *iptr(getConstPointer());
948 T *optr(ret->getPointer());
949 for(int i=0;i<nbTuples;i++)
950 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
951 ret->copyStringInfoFrom(*this);
956 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
957 * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
958 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ] for all
959 * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which
960 * \a old2New[ i ] is negative, is missing from the result array.
961 * For more info on renumbering see \ref numbering.
962 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
963 * giving a new position for i-th old tuple and giving negative position for
964 * for i-th old tuple that should be omitted.
965 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
966 * is to delete using decrRef() as it is no more needed.
969 typename Traits<T>::ArrayType *DataArrayTemplate<T>::renumberAndReduce(const int *old2New, int newNbOfTuple) const
972 int nbTuples(getNumberOfTuples()),nbOfCompo(getNumberOfComponents());
973 MCAuto<DataArray> ret0(buildNewEmptyInstance());
974 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
975 ret->alloc(newNbOfTuple,nbOfCompo);
976 const T *iptr=getConstPointer();
977 T *optr=ret->getPointer();
978 for(int i=0;i<nbTuples;i++)
982 std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
984 ret->copyStringInfoFrom(*this);
989 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
990 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
991 * \a new2OldBg array.
992 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
993 * This method is equivalent to renumberAndReduce() except that convention in input is
994 * \c new2old and \b not \c old2new.
995 * For more info on renumbering see \ref numbering.
996 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
997 * tuple index in \a this array to fill the i-th tuple in the new array.
998 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
999 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1000 * \a new2OldBg <= \a pi < \a new2OldEnd.
1001 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1002 * is to delete using decrRef() as it is no more needed.
1005 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
1008 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1009 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1010 int nbComp(getNumberOfComponents());
1011 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1012 ret->copyStringInfoFrom(*this);
1013 T *pt(ret->getPointer());
1014 const T *srcPt(getConstPointer());
1016 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1017 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1018 ret->copyStringInfoFrom(*this);
1023 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleId(const DataArrayInt& di) const
1025 return DataArrayTemplate<T>::mySelectByTupleId(di.begin(),di.end());
1029 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1030 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1031 * \a new2OldBg array.
1032 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1033 * This method is equivalent to renumberAndReduce() except that convention in input is
1034 * \c new2old and \b not \c old2new.
1035 * This method is equivalent to selectByTupleId() except that it prevents coping data
1036 * from behind the end of \a this array.
1037 * For more info on renumbering see \ref numbering.
1038 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1039 * tuple index in \a this array to fill the i-th tuple in the new array.
1040 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1041 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1042 * \a new2OldBg <= \a pi < \a new2OldEnd.
1043 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1044 * is to delete using decrRef() as it is no more needed.
1045 * \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
1048 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const
1051 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1052 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1053 int nbComp(getNumberOfComponents()),oldNbOfTuples(getNumberOfTuples());
1054 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1055 ret->copyStringInfoFrom(*this);
1056 T *pt(ret->getPointer());
1057 const T *srcPt(getConstPointer());
1059 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1060 if(*w>=0 && *w<oldNbOfTuples)
1061 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1064 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !";
1065 throw INTERP_KERNEL::Exception(oss.str().c_str());
1067 ret->copyStringInfoFrom(*this);
1072 * Changes the number of components within \a this array so that its raw data **does
1073 * not** change, instead splitting this data into tuples changes.
1074 * \warning This method erases all (name and unit) component info set before!
1075 * \param [in] newNbOfComp - number of components for \a this array to have.
1076 * \throw If \a this is not allocated
1077 * \throw If getNbOfElems() % \a newNbOfCompo != 0.
1078 * \throw If \a newNbOfCompo is lower than 1.
1079 * \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
1080 * \warning This method erases all (name and unit) component info set before!
1083 void DataArrayTemplate<T>::rearrange(int newNbOfCompo)
1088 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::rearrange : input newNbOfCompo must be > 0 !";
1089 throw INTERP_KERNEL::Exception(oss.str().c_str());
1091 std::size_t nbOfElems=getNbOfElems();
1092 if(nbOfElems%newNbOfCompo!=0)
1094 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::rearrange : nbOfElems%newNbOfCompo!=0 !";
1095 throw INTERP_KERNEL::Exception(oss.str().c_str());
1097 if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
1099 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !";
1100 throw INTERP_KERNEL::Exception(oss.str().c_str());
1102 _info_on_compo.clear();
1103 _info_on_compo.resize(newNbOfCompo);
1108 * Changes the number of components within \a this array to be equal to its number
1109 * of tuples, and inversely its number of tuples to become equal to its number of
1110 * components. So that its raw data **does not** change, instead splitting this
1111 * data into tuples changes.
1112 * \warning This method erases all (name and unit) component info set before!
1113 * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
1114 * \throw If \a this is not allocated.
1118 void DataArrayTemplate<T>::transpose()
1121 int nbOfTuples(getNumberOfTuples());
1122 rearrange(nbOfTuples);
1126 * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
1127 * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
1128 * is truncated to have \a newNbOfComp components, keeping first components. If \a
1129 * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
1130 * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
1132 * \param [in] newNbOfComp - number of components for the new array to have.
1133 * \param [in] dftValue - value assigned to new values added to the new array.
1134 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1135 * is to delete using decrRef() as it is no more needed.
1136 * \throw If \a this is not allocated.
1139 typename Traits<T>::ArrayType *DataArrayTemplate<T>::changeNbOfComponents(int newNbOfComp, T dftValue) const
1142 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1143 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1144 ret->alloc(getNumberOfTuples(),newNbOfComp);
1145 const T *oldc(getConstPointer());
1146 T *nc(ret->getPointer());
1147 int nbOfTuples(getNumberOfTuples()),oldNbOfComp(getNumberOfComponents());
1148 int dim(std::min(oldNbOfComp,newNbOfComp));
1149 for(int i=0;i<nbOfTuples;i++)
1153 nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
1154 for(;j<newNbOfComp;j++)
1155 nc[newNbOfComp*i+j]=dftValue;
1157 ret->setName(getName());
1158 for(int i=0;i<dim;i++)
1159 ret->setInfoOnComponent(i,getInfoOnComponent(i));
1160 ret->setName(getName());
1165 * Returns a copy of \a this array composed of selected components.
1166 * The new DataArrayDouble has the same number of tuples but includes components
1167 * specified by \a compoIds parameter. So that getNbOfElems() of the result array
1168 * can be either less, same or more than \a this->getNbOfElems().
1169 * \param [in] compoIds - sequence of zero based indices of components to include
1170 * into the new array.
1171 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1172 * is to delete using decrRef() as it is no more needed.
1173 * \throw If \a this is not allocated.
1174 * \throw If a component index (\a i) is not valid:
1175 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
1177 * \if ENABLE_EXAMPLES
1178 * \ref py_mcdataarraydouble_KeepSelectedComponents "Here is a Python example".
1182 typename Traits<T>::ArrayType *DataArrayTemplate<T>::myKeepSelectedComponents(const std::vector<int>& compoIds) const
1185 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1186 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1187 std::size_t newNbOfCompo(compoIds.size());
1188 int oldNbOfCompo(getNumberOfComponents());
1189 for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
1190 if((*it)<0 || (*it)>=oldNbOfCompo)
1192 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
1193 throw INTERP_KERNEL::Exception(oss.str().c_str());
1195 int nbOfTuples(getNumberOfTuples());
1196 ret->alloc(nbOfTuples,(int)newNbOfCompo);
1197 ret->copyPartOfStringInfoFrom(*this,compoIds);
1198 const T *oldc(getConstPointer());
1199 T *nc(ret->getPointer());
1200 for(int i=0;i<nbOfTuples;i++)
1201 for(std::size_t j=0;j<newNbOfCompo;j++,nc++)
1202 *nc=oldc[i*oldNbOfCompo+compoIds[j]];
1207 * Returns a shorten copy of \a this array. The new DataArrayDouble contains all
1208 * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
1209 * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
1210 * This method is a specialization of selectByTupleIdSafeSlice().
1211 * \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
1212 * \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
1213 * If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
1214 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1215 * is to delete using decrRef() as it is no more needed.
1216 * \throw If \a tupleIdBg < 0.
1217 * \throw If \a tupleIdBg > \a this->getNumberOfTuples().
1218 * \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
1219 * \sa DataArrayDouble::selectByTupleIdSafeSlice
1222 typename Traits<T>::ArrayType *DataArrayTemplate<T>::subArray(int tupleIdBg, int tupleIdEnd) const
1225 int nbt(getNumberOfTuples());
1228 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::subArray : The tupleIdBg parameter must be greater than 0 !";
1229 throw INTERP_KERNEL::Exception(oss.str().c_str());
1233 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << ":subArray : The tupleIdBg parameter is greater than number of tuples !";
1234 throw INTERP_KERNEL::Exception(oss.str().c_str());
1236 int trueEnd=tupleIdEnd;
1241 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << ":subArray : The tupleIdBg parameter is greater than number of tuples !";
1242 throw INTERP_KERNEL::Exception(oss.str().c_str());
1247 int nbComp(getNumberOfComponents());
1248 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1249 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1250 ret->alloc(trueEnd-tupleIdBg,nbComp);
1251 ret->copyStringInfoFrom(*this);
1252 std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
1257 * Returns a shorten copy of \a this array. The new DataArrayDouble contains every
1258 * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
1259 * tuple. Indices of the selected tuples are the same as ones returned by the Python
1260 * command \c range( \a bg, \a end2, \a step ).
1261 * This method is equivalent to selectByTupleIdSafe() except that the input array is
1262 * not constructed explicitly.
1263 * For more info on renumbering see \ref numbering.
1264 * \param [in] bg - index of the first tuple to copy from \a this array.
1265 * \param [in] end2 - index of the tuple before which the tuples to copy are located.
1266 * \param [in] step - index increment to get index of the next tuple to copy.
1267 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1268 * is to delete using decrRef() as it is no more needed.
1269 * \sa DataArrayDouble::subArray.
1272 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleIdSafeSlice(int bg, int end2, int step) const
1275 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1276 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1277 int nbComp(getNumberOfComponents());
1278 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::selectByTupleIdSafeSlice : ";
1279 int newNbOfTuples(GetNumberOfItemGivenBESRelative(bg,end2,step,oss.str()));
1280 ret->alloc(newNbOfTuples,nbComp);
1281 T *pt(ret->getPointer());
1282 const T *srcPt(getConstPointer()+bg*nbComp);
1283 for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
1284 std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
1285 ret->copyStringInfoFrom(*this);
1290 * Copy all values from another DataArrayDouble into specified tuples and components
1291 * of \a this array. Textual data is not copied.
1292 * The tree parameters defining set of indices of tuples and components are similar to
1293 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
1294 * \param [in] a - the array to copy values from.
1295 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
1296 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1298 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1299 * \param [in] bgComp - index of the first component of \a this array to assign values to.
1300 * \param [in] endComp - index of the component before which the components to assign
1302 * \param [in] stepComp - index increment to get index of the next component to assign to.
1303 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
1304 * must be equal to the number of columns to assign to, else an
1305 * exception is thrown; if \a false, then it is only required that \a
1306 * a->getNbOfElems() equals to number of values to assign to (this condition
1307 * must be respected even if \a strictCompoCompare is \a true). The number of
1308 * values to assign to is given by following Python expression:
1309 * \a nbTargetValues =
1310 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
1311 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1312 * \throw If \a a is NULL.
1313 * \throw If \a a is not allocated.
1314 * \throw If \a this is not allocated.
1315 * \throw If parameters specifying tuples and components to assign to do not give a
1316 * non-empty range of increasing indices.
1317 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
1318 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
1319 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1321 * \if ENABLE_EXAMPLES
1322 * \ref py_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
1326 void DataArrayTemplate<T>::setPartOfValues1(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
1330 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::setPartOfValues1 : input DataArrayDouble is NULL !";
1331 throw INTERP_KERNEL::Exception(oss.str().c_str());
1333 const char msg[]="DataArrayTemplate::setPartOfValues1";
1335 a->checkAllocated();
1336 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1337 int newNbOfComp(DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg));
1338 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1339 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1340 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1341 bool assignTech(true);
1342 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1344 if(strictCompoCompare)
1345 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1349 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1352 const T *srcPt(a->getConstPointer());
1353 T *pt(getPointer()+bgTuples*nbComp+bgComp);
1356 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1357 for(int j=0;j<newNbOfComp;j++,srcPt++)
1358 pt[j*stepComp]=*srcPt;
1362 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1364 const T*srcPt2=srcPt;
1365 for(int j=0;j<newNbOfComp;j++,srcPt2++)
1366 pt[j*stepComp]=*srcPt2;
1372 * Assign a given value to values at specified tuples and components of \a this array.
1373 * The tree parameters defining set of indices of tuples and components are similar to
1374 * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
1375 * \param [in] a - the value to assign.
1376 * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
1377 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1379 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1380 * \param [in] bgComp - index of the first component of \a this array to assign to.
1381 * \param [in] endComp - index of the component before which the components to assign
1383 * \param [in] stepComp - index increment to get index of the next component to assign to.
1384 * \throw If \a this is not allocated.
1385 * \throw If parameters specifying tuples and components to assign to, do not give a
1386 * non-empty range of increasing indices or indices are out of a valid range
1387 * for \c this array.
1389 * \if ENABLE_EXAMPLES
1390 * \ref py_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
1394 void DataArrayTemplate<T>::setPartOfValuesSimple1(T a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp)
1396 const char msg[]="DataArrayTemplate::setPartOfValuesSimple1";
1398 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1399 int newNbOfComp(DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg));
1400 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1401 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1402 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1403 T *pt=getPointer()+bgTuples*nbComp+bgComp;
1404 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1405 for(int j=0;j<newNbOfComp;j++)
1410 * Copy all values from another DataArrayDouble (\a a) into specified tuples and
1411 * components of \a this array. Textual data is not copied.
1412 * The tuples and components to assign to are defined by C arrays of indices.
1413 * There are two *modes of usage*:
1414 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
1415 * of \a a is assigned to its own location within \a this array.
1416 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
1417 * components of every specified tuple of \a this array. In this mode it is required
1418 * that \a a->getNumberOfComponents() equals to the number of specified components.
1420 * \param [in] a - the array to copy values from.
1421 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1422 * assign values of \a a to.
1423 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1424 * pointer to a tuple index <em>(pi)</em> varies as this:
1425 * \a bgTuples <= \a pi < \a endTuples.
1426 * \param [in] bgComp - pointer to an array of component indices of \a this array to
1427 * assign values of \a a to.
1428 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
1429 * pointer to a component index <em>(pi)</em> varies as this:
1430 * \a bgComp <= \a pi < \a endComp.
1431 * \param [in] strictCompoCompare - this parameter is checked only if the
1432 * *mode of usage* is the first; if it is \a true (default),
1433 * then \a a->getNumberOfComponents() must be equal
1434 * to the number of specified columns, else this is not required.
1435 * \throw If \a a is NULL.
1436 * \throw If \a a is not allocated.
1437 * \throw If \a this is not allocated.
1438 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
1439 * out of a valid range for \a this array.
1440 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
1441 * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
1442 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
1443 * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
1445 * \if ENABLE_EXAMPLES
1446 * \ref py_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
1450 void DataArrayTemplate<T>::setPartOfValues2(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
1453 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
1454 const char msg[]="DataArrayTemplate::setPartOfValues2";
1456 a->checkAllocated();
1457 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1458 for(const int *z=bgComp;z!=endComp;z++)
1459 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1460 int newNbOfTuples((int)std::distance(bgTuples,endTuples));
1461 int newNbOfComp((int)std::distance(bgComp,endComp));
1462 bool assignTech(true);
1463 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1465 if(strictCompoCompare)
1466 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1470 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1473 T *pt(getPointer());
1474 const T *srcPt(a->getConstPointer());
1477 for(const int *w=bgTuples;w!=endTuples;w++)
1479 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1480 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
1482 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
1488 for(const int *w=bgTuples;w!=endTuples;w++)
1490 const T *srcPt2=srcPt;
1491 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1492 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
1494 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
1501 * Assign a given value to values at specified tuples and components of \a this array.
1502 * The tuples and components to assign to are defined by C arrays of indices.
1503 * \param [in] a - the value to assign.
1504 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1506 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1507 * pointer to a tuple index (\a pi) varies as this:
1508 * \a bgTuples <= \a pi < \a endTuples.
1509 * \param [in] bgComp - pointer to an array of component indices of \a this array to
1511 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
1512 * pointer to a component index (\a pi) varies as this:
1513 * \a bgComp <= \a pi < \a endComp.
1514 * \throw If \a this is not allocated.
1515 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
1516 * out of a valid range for \a this array.
1518 * \if ENABLE_EXAMPLES
1519 * \ref py_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
1523 void DataArrayTemplate<T>::setPartOfValuesSimple2(T a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp)
1526 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1527 for(const int *z=bgComp;z!=endComp;z++)
1528 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1529 T *pt(getPointer());
1530 for(const int *w=bgTuples;w!=endTuples;w++)
1531 for(const int *z=bgComp;z!=endComp;z++)
1533 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1534 pt[(std::size_t)(*w)*nbComp+(*z)]=a;
1539 * Copy all values from another DataArrayDouble (\a a) into specified tuples and
1540 * components of \a this array. Textual data is not copied.
1541 * The tuples to assign to are defined by a C array of indices.
1542 * The components to assign to are defined by three values similar to parameters of
1543 * the Python function \c range(\c start,\c stop,\c step).
1544 * There are two *modes of usage*:
1545 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
1546 * of \a a is assigned to its own location within \a this array.
1547 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
1548 * components of every specified tuple of \a this array. In this mode it is required
1549 * that \a a->getNumberOfComponents() equals to the number of specified components.
1551 * \param [in] a - the array to copy values from.
1552 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1553 * assign values of \a a to.
1554 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1555 * pointer to a tuple index <em>(pi)</em> varies as this:
1556 * \a bgTuples <= \a pi < \a endTuples.
1557 * \param [in] bgComp - index of the first component of \a this array to assign to.
1558 * \param [in] endComp - index of the component before which the components to assign
1560 * \param [in] stepComp - index increment to get index of the next component to assign to.
1561 * \param [in] strictCompoCompare - this parameter is checked only in the first
1562 * *mode of usage*; if \a strictCompoCompare is \a true (default),
1563 * then \a a->getNumberOfComponents() must be equal
1564 * to the number of specified columns, else this is not required.
1565 * \throw If \a a is NULL.
1566 * \throw If \a a is not allocated.
1567 * \throw If \a this is not allocated.
1568 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
1570 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
1571 * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
1572 * defined by <em>(bgComp,endComp,stepComp)</em>.
1573 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
1574 * <em> a->getNumberOfComponents()</em> is unequal to the number of components
1575 * defined by <em>(bgComp,endComp,stepComp)</em>.
1576 * \throw If parameters specifying components to assign to, do not give a
1577 * non-empty range of increasing indices or indices are out of a valid range
1578 * for \c this array.
1580 * \if ENABLE_EXAMPLES
1581 * \ref py_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
1585 void DataArrayTemplate<T>::setPartOfValues3(const typename Traits<T>::ArrayType *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare)
1588 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValues3 : input DataArrayDouble is NULL !");
1589 const char msg[]="DataArrayTemplate::setPartOfValues3";
1591 a->checkAllocated();
1592 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
1593 int nbComp=getNumberOfComponents();
1594 int nbOfTuples=getNumberOfTuples();
1595 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1596 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
1597 bool assignTech=true;
1598 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1600 if(strictCompoCompare)
1601 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1605 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1608 T *pt(getPointer()+bgComp);
1609 const T *srcPt(a->getConstPointer());
1612 for(const int *w=bgTuples;w!=endTuples;w++)
1613 for(int j=0;j<newNbOfComp;j++,srcPt++)
1615 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1616 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
1621 for(const int *w=bgTuples;w!=endTuples;w++)
1623 const T *srcPt2=srcPt;
1624 for(int j=0;j<newNbOfComp;j++,srcPt2++)
1626 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1627 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
1634 * Assign a given value to values at specified tuples and components of \a this array.
1635 * The tuples to assign to are defined by a C array of indices.
1636 * The components to assign to are defined by three values similar to parameters of
1637 * the Python function \c range(\c start,\c stop,\c step).
1638 * \param [in] a - the value to assign.
1639 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
1641 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
1642 * pointer to a tuple index <em>(pi)</em> varies as this:
1643 * \a bgTuples <= \a pi < \a endTuples.
1644 * \param [in] bgComp - index of the first component of \a this array to assign to.
1645 * \param [in] endComp - index of the component before which the components to assign
1647 * \param [in] stepComp - index increment to get index of the next component to assign to.
1648 * \throw If \a this is not allocated.
1649 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
1651 * \throw If parameters specifying components to assign to, do not give a
1652 * non-empty range of increasing indices or indices are out of a valid range
1653 * for \c this array.
1655 * \if ENABLE_EXAMPLES
1656 * \ref py_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
1660 void DataArrayTemplate<T>::setPartOfValuesSimple3(T a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp)
1662 const char msg[]="DataArrayTemplate::setPartOfValuesSimple3";
1664 int newNbOfComp(DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg));
1665 int nbComp(getNumberOfComponents()),nbOfTuples(getNumberOfTuples());
1666 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1667 T *pt(getPointer()+bgComp);
1668 for(const int *w=bgTuples;w!=endTuples;w++)
1669 for(int j=0;j<newNbOfComp;j++)
1671 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1672 pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
1677 * Copy all values from another DataArrayDouble into specified tuples and components
1678 * of \a this array. Textual data is not copied.
1679 * The tree parameters defining set of indices of tuples and components are similar to
1680 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
1681 * \param [in] a - the array to copy values from.
1682 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
1683 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1685 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1686 * \param [in] bgComp - pointer to an array of component indices of \a this array to
1688 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
1689 * pointer to a component index (\a pi) varies as this:
1690 * \a bgComp <= \a pi < \a endComp.
1691 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
1692 * must be equal to the number of columns to assign to, else an
1693 * exception is thrown; if \a false, then it is only required that \a
1694 * a->getNbOfElems() equals to number of values to assign to (this condition
1695 * must be respected even if \a strictCompoCompare is \a true). The number of
1696 * values to assign to is given by following Python expression:
1697 * \a nbTargetValues =
1698 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
1699 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1700 * \throw If \a a is NULL.
1701 * \throw If \a a is not allocated.
1702 * \throw If \a this is not allocated.
1703 * \throw If parameters specifying tuples and components to assign to do not give a
1704 * non-empty range of increasing indices.
1705 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
1706 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
1707 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1711 void DataArrayTemplate<T>::setPartOfValues4(const typename Traits<T>::ArrayType *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare)
1713 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValues4 : input DataArrayTemplate is NULL !");
1714 const char msg[]="DataArrayTemplate::setPartOfValues4";
1716 a->checkAllocated();
1717 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1718 int newNbOfComp((int)std::distance(bgComp,endComp));
1719 int nbComp(getNumberOfComponents());
1720 for(const int *z=bgComp;z!=endComp;z++)
1721 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1722 int nbOfTuples(getNumberOfTuples());
1723 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1724 bool assignTech(true);
1725 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
1727 if(strictCompoCompare)
1728 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1732 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1735 const T *srcPt(a->getConstPointer());
1736 T *pt(getPointer()+bgTuples*nbComp);
1739 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1740 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
1745 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1747 const T *srcPt2(srcPt);
1748 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
1755 void DataArrayTemplate<T>::setPartOfValuesSimple4(T a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp)
1757 const char msg[]="DataArrayTemplate::setPartOfValuesSimple4";
1759 int newNbOfTuples(DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg));
1760 int nbComp(getNumberOfComponents());
1761 for(const int *z=bgComp;z!=endComp;z++)
1762 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1763 int nbOfTuples(getNumberOfTuples());
1764 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1765 T *pt=getPointer()+bgTuples*nbComp;
1766 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1767 for(const int *z=bgComp;z!=endComp;z++)
1772 * Copy some tuples from another DataArrayDouble into specified tuples
1773 * of \a this array. Textual data is not copied. Both arrays must have equal number of
1775 * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
1776 * All components of selected tuples are copied.
1777 * \param [in] a - the array to copy values from.
1778 * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
1779 * target tuples of \a this. \a tuplesSelec has two components, and the
1780 * first component specifies index of the source tuple and the second
1781 * one specifies index of the target tuple.
1782 * \throw If \a this is not allocated.
1783 * \throw If \a a is NULL.
1784 * \throw If \a a is not allocated.
1785 * \throw If \a tuplesSelec is NULL.
1786 * \throw If \a tuplesSelec is not allocated.
1787 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
1788 * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
1789 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
1790 * the corresponding (\a this or \a a) array.
1793 void DataArrayTemplate<T>::setPartOfValuesAdv(const typename Traits<T>::ArrayType *a, const DataArrayInt *tuplesSelec)
1795 if(!a || !tuplesSelec)
1796 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : input DataArrayTemplate is NULL !");
1798 a->checkAllocated();
1799 tuplesSelec->checkAllocated();
1800 int nbOfComp=getNumberOfComponents();
1801 if(nbOfComp!=a->getNumberOfComponents())
1802 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : This and a do not have the same number of components !");
1803 if(tuplesSelec->getNumberOfComponents()!=2)
1804 throw INTERP_KERNEL::Exception("DataArrayTemplate::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
1805 int thisNt(getNumberOfTuples());
1806 int aNt(a->getNumberOfTuples());
1807 T *valsToSet(getPointer());
1808 const T *valsSrc(a->getConstPointer());
1809 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
1811 if(tuple[1]>=0 && tuple[1]<aNt)
1813 if(tuple[0]>=0 && tuple[0]<thisNt)
1814 std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
1817 std::ostringstream oss; oss << "DataArrayTemplate::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
1818 oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
1819 throw INTERP_KERNEL::Exception(oss.str().c_str());
1824 std::ostringstream oss; oss << "DataArrayTemplate::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
1825 oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
1826 throw INTERP_KERNEL::Exception(oss.str().c_str());
1832 * Copy some tuples from another DataArrayDouble (\a aBase) into contiguous tuples
1833 * of \a this array. Textual data is not copied. Both arrays must have equal number of
1835 * The tuples to assign to are defined by index of the first tuple, and
1836 * their number is defined by \a tuplesSelec->getNumberOfTuples().
1837 * The tuples to copy are defined by values of a DataArrayInt.
1838 * All components of selected tuples are copied.
1839 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
1841 * \param [in] aBase - the array to copy values from.
1842 * \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
1843 * \throw If \a this is not allocated.
1844 * \throw If \a aBase is NULL.
1845 * \throw If \a aBase is not allocated.
1846 * \throw If \a tuplesSelec is NULL.
1847 * \throw If \a tuplesSelec is not allocated.
1848 * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
1849 * \throw If \a tuplesSelec->getNumberOfComponents() != 1.
1850 * \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
1851 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
1855 void DataArrayTemplate<T>::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec)
1857 if(!aBase || !tuplesSelec)
1858 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : input DataArray is NULL !");
1859 const typename Traits<T>::ArrayType *a(dynamic_cast<const typename Traits<T>::ArrayType *>(aBase));
1861 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayDouble !");
1863 a->checkAllocated();
1864 tuplesSelec->checkAllocated();
1865 int nbOfComp(getNumberOfComponents());
1866 if(nbOfComp!=a->getNumberOfComponents())
1867 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : This and a do not have the same number of components !");
1868 if(tuplesSelec->getNumberOfComponents()!=1)
1869 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
1870 int thisNt(getNumberOfTuples());
1871 int aNt(a->getNumberOfTuples());
1872 int nbOfTupleToWrite(tuplesSelec->getNumberOfTuples());
1873 T *valsToSet(getPointer()+tupleIdStart*nbOfComp);
1874 if(tupleIdStart+nbOfTupleToWrite>thisNt)
1875 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValues : invalid number range of values to write !");
1876 const T *valsSrc=a->getConstPointer();
1877 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
1879 if(*tuple>=0 && *tuple<aNt)
1881 std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
1885 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
1886 oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
1887 throw INTERP_KERNEL::Exception(oss.str().c_str());
1893 * Copy some tuples from another DataArrayDouble (\a aBase) into contiguous tuples
1894 * of \a this array. Textual data is not copied. Both arrays must have equal number of
1896 * The tuples to copy are defined by three values similar to parameters of
1897 * the Python function \c range(\c start,\c stop,\c step).
1898 * The tuples to assign to are defined by index of the first tuple, and
1899 * their number is defined by number of tuples to copy.
1900 * All components of selected tuples are copied.
1901 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
1903 * \param [in] aBase - the array to copy values from.
1904 * \param [in] bg - index of the first tuple to copy of the array \a aBase.
1905 * \param [in] end2 - index of the tuple of \a aBase before which the tuples to copy
1907 * \param [in] step - index increment to get index of the next tuple to copy.
1908 * \throw If \a this is not allocated.
1909 * \throw If \a aBase is NULL.
1910 * \throw If \a aBase is not allocated.
1911 * \throw If <em>this->getNumberOfComponents() != aBase->getNumberOfComponents()</em>.
1912 * \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
1913 * \throw If parameters specifying tuples to copy, do not give a
1914 * non-empty range of increasing indices or indices are out of a valid range
1915 * for the array \a aBase.
1918 void DataArrayTemplate<T>::setContigPartOfSelectedValuesSlice(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step)
1922 std::ostringstream oss; oss << Traits<T>::ArrayTypeName << "::setContigPartOfSelectedValuesSlice : input DataArray is NULL !";
1923 throw INTERP_KERNEL::Exception(oss.str().c_str());
1925 const typename Traits<T>::ArrayType *a(dynamic_cast<const typename Traits<T>::ArrayType *>(aBase));
1927 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : input DataArray aBase is not a DataArrayDouble !");
1929 a->checkAllocated();
1930 int nbOfComp(getNumberOfComponents());
1931 const char msg[]="DataArrayDouble::setContigPartOfSelectedValuesSlice";
1932 int nbOfTupleToWrite(DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg));
1933 if(nbOfComp!=a->getNumberOfComponents())
1934 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : This and a do not have the same number of components !");
1935 int thisNt(getNumberOfTuples()),aNt(a->getNumberOfTuples());
1936 T *valsToSet(getPointer()+tupleIdStart*nbOfComp);
1937 if(tupleIdStart+nbOfTupleToWrite>thisNt)
1938 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : invalid number range of values to write !");
1940 throw INTERP_KERNEL::Exception("DataArrayTemplate::setContigPartOfSelectedValuesSlice : invalid range of values to read !");
1941 const T *valsSrc(a->getConstPointer()+bg*nbOfComp);
1942 for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
1944 std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
1949 * Returns a shorten copy of \a this array. The new DataArrayDouble contains ranges
1950 * of tuples specified by \a ranges parameter.
1951 * For more info on renumbering see \ref numbering.
1952 * \param [in] ranges - std::vector of std::pair's each of which defines a range
1953 * of tuples in [\c begin,\c end) format.
1954 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1955 * is to delete using decrRef() as it is no more needed.
1956 * \throw If \a end < \a begin.
1957 * \throw If \a end > \a this->getNumberOfTuples().
1958 * \throw If \a this is not allocated.
1961 typename Traits<T>::ArrayType *DataArrayTemplate<T>::mySelectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const
1964 int nbOfComp(getNumberOfComponents()),nbOfTuplesThis(getNumberOfTuples());
1967 MCAuto<DataArray> ret0(buildNewEmptyInstance());
1968 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
1969 ret->alloc(0,nbOfComp);
1970 ret->copyStringInfoFrom(*this);
1973 int ref(ranges.front().first),nbOfTuples(0);
1974 bool isIncreasing(true);
1975 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
1977 if((*it).first<=(*it).second)
1979 if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
1981 nbOfTuples+=(*it).second-(*it).first;
1983 isIncreasing=ref<=(*it).first;
1988 std::ostringstream oss; oss << "DataArrayTemplate::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
1989 oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
1990 throw INTERP_KERNEL::Exception(oss.str().c_str());
1995 std::ostringstream oss; oss << "DataArrayTemplate::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
1996 oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
1997 throw INTERP_KERNEL::Exception(oss.str().c_str());
2000 if(isIncreasing && nbOfTuplesThis==nbOfTuples)
2001 return static_cast<typename Traits<T>::ArrayType *>(deepCopy());
2002 MCAuto<DataArray> ret0(buildNewEmptyInstance());
2003 MCAuto< typename Traits<T>::ArrayType > ret(DynamicCastSafe<DataArray,typename Traits<T>::ArrayType>(ret0));
2004 ret->alloc(nbOfTuples,nbOfComp);
2005 ret->copyStringInfoFrom(*this);
2006 const T *src(getConstPointer());
2007 T *work(ret->getPointer());
2008 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
2009 work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
2014 * Returns the first value of \a this.
2015 * \return double - the last value of \a this array.
2016 * \throw If \a this is not allocated.
2017 * \throw If \a this->getNumberOfComponents() != 1.
2018 * \throw If \a this->getNumberOfTuples() < 1.
2021 T DataArrayTemplate<T>::front() const
2024 if(getNumberOfComponents()!=1)
2025 throw INTERP_KERNEL::Exception("DataArrayTemplate::front : number of components not equal to one !");
2026 int nbOfTuples(getNumberOfTuples());
2028 throw INTERP_KERNEL::Exception("DataArrayTemplate::front : number of tuples must be >= 1 !");
2029 return *(getConstPointer());
2033 * Returns the last value of \a this.
2034 * \return double - the last value of \a this array.
2035 * \throw If \a this is not allocated.
2036 * \throw If \a this->getNumberOfComponents() != 1.
2037 * \throw If \a this->getNumberOfTuples() < 1.
2040 T DataArrayTemplate<T>::back() const
2043 if(getNumberOfComponents()!=1)
2044 throw INTERP_KERNEL::Exception("DataArrayTemplate::back : number of components not equal to one !");
2045 int nbOfTuples(getNumberOfTuples());
2047 throw INTERP_KERNEL::Exception("DataArrayTemplate::back : number of tuples must be >= 1 !");
2048 return *(getConstPointer()+nbOfTuples-1);
2052 * Returns the maximal value and its location within \a this one-dimensional array.
2053 * \param [out] tupleId - index of the tuple holding the maximal value.
2054 * \return double - the maximal value among all values of \a this array.
2055 * \throw If \a this->getNumberOfComponents() != 1
2056 * \throw If \a this->getNumberOfTuples() < 1
2059 T DataArrayTemplate<T>::getMaxValue(int& tupleId) const
2062 if(getNumberOfComponents()!=1)
2063 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 !");
2064 int nbOfTuples(getNumberOfTuples());
2066 throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
2067 const T *vals(getConstPointer());
2068 const T *loc(std::max_element(vals,vals+nbOfTuples));
2069 tupleId=(int)std::distance(vals,loc);
2074 * Returns the maximal value within \a this array that is allowed to have more than
2076 * \return double - the maximal value among all values of \a this array.
2077 * \throw If \a this is not allocated.
2080 T DataArrayTemplate<T>::getMaxValueInArray() const
2083 const T *loc(std::max_element(begin(),end()));
2088 * Returns the minimal value and its location within \a this one-dimensional array.
2089 * \param [out] tupleId - index of the tuple holding the minimal value.
2090 * \return double - the minimal value among all values of \a this array.
2091 * \throw If \a this->getNumberOfComponents() != 1
2092 * \throw If \a this->getNumberOfTuples() < 1
2095 T DataArrayTemplate<T>::getMinValue(int& tupleId) const
2098 if(getNumberOfComponents()!=1)
2099 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
2100 int nbOfTuples(getNumberOfTuples());
2102 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
2103 const T *vals(getConstPointer());
2104 const T *loc(std::min_element(vals,vals+nbOfTuples));
2105 tupleId=(int)std::distance(vals,loc);
2110 * Returns the minimal value within \a this array that is allowed to have more than
2112 * \return double - the minimal value among all values of \a this array.
2113 * \throw If \a this is not allocated.
2116 T DataArrayTemplate<T>::getMinValueInArray() const
2119 const T *loc=std::min_element(begin(),end());
2124 void DataArrayTemplate<T>::circularPermutation(int nbOfShift)
2127 int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
2128 int effNbSh(EffectiveCircPerm(nbOfShift,nbTuples));
2131 T *work(getPointer());
2132 if(effNbSh<nbTuples-effNbSh)
2134 typename INTERP_KERNEL::AutoPtr<T> buf(new T[effNbSh*nbOfCompo]);
2135 std::copy(work,work+effNbSh*nbOfCompo,(T *)buf);
2136 std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,work);// ze big shift
2137 std::copy((T *)buf,(T *)buf+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);
2141 typename INTERP_KERNEL::AutoPtr<T> buf(new T[(nbTuples-effNbSh)*nbOfCompo]);
2142 std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,(T *)buf);
2143 std::copy(work,work+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);// ze big shift
2144 std::copy((T*)buf,(T *)buf+(nbTuples-effNbSh)*nbOfCompo,work);
2149 void DataArrayTemplate<T>::circularPermutationPerTuple(int nbOfShift)
2152 int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
2153 int effNbSh(EffectiveCircPerm(nbOfShift,nbOfCompo));
2156 T *work(getPointer());
2157 if(effNbSh<nbOfCompo-effNbSh)
2159 typename INTERP_KERNEL::AutoPtr<T> buf(new T[effNbSh]);
2160 for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
2162 std::copy(work,work+effNbSh,(T *)buf);
2163 std::copy(work+effNbSh,work+nbOfCompo,work);// ze big shift
2164 std::copy((T *)buf,(T *)buf+effNbSh,work+(nbOfCompo-effNbSh));
2169 typename INTERP_KERNEL::AutoPtr<T> buf(new T[nbOfCompo-effNbSh]);
2170 for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
2172 std::copy(work+effNbSh,work+nbOfCompo,(T *)buf);
2173 std::copy(work,work+effNbSh,work+(nbOfCompo-effNbSh));// ze big shift
2174 std::copy((T*)buf,(T *)buf+(nbOfCompo-effNbSh),work);
2177 std::vector<std::string> sts(nbOfCompo);
2178 for(int i=0;i<nbOfCompo;i++)
2179 sts[i]=_info_on_compo[(i+effNbSh)%nbOfCompo];
2180 setInfoOnComponents(sts);
2184 void DataArrayTemplate<T>::reversePerTuple()
2187 int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples());
2190 T *work(getPointer());
2191 for(int i=0;i<nbTuples;i++,work+=nbOfCompo)
2192 std::reverse(work,work+nbOfCompo);
2193 std::reverse(_info_on_compo.begin(),_info_on_compo.end());