1 // Copyright (C) 2007-2012 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.
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
20 #include "MEDCouplingMemArray.txx"
21 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
23 #include "GenMathFormulae.hxx"
24 #include "InterpKernelExprParser.hxx"
32 typedef double (*MYFUNCPTR)(double);
34 using namespace ParaMEDMEM;
36 template<int SPACEDIM>
37 void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, std::vector<int>& c, std::vector<int>& cI) const
39 const double *coordsPtr=getConstPointer();
40 BBTree<SPACEDIM,int> myTree(bbox,0,0,nbNodes,prec/10);
41 std::vector<bool> isDone(nbNodes);
42 for(int i=0;i<nbNodes;i++)
46 std::vector<int> intersectingElems;
47 myTree.getElementsAroundPoint(coordsPtr+i*SPACEDIM,intersectingElems);
48 if(intersectingElems.size()>1)
50 std::vector<int> commonNodes;
51 for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
55 commonNodes.push_back(*it);
58 if(!commonNodes.empty())
60 cI.push_back(cI.back()+(int)commonNodes.size()+1);
62 c.insert(c.end(),commonNodes.begin(),commonNodes.end());
69 template<int SPACEDIM>
70 void DataArrayDouble::findTupleIdsNearTuplesAlg(const BBTree<SPACEDIM,int>& myTree, const double *pos, int nbOfTuples, double eps,
71 std::vector<int>& c, std::vector<int>& cI) const
73 const double *coordsPtr=getConstPointer();
74 for(int i=0;i<nbOfTuples;i++)
76 std::vector<int> intersectingElems;
77 myTree.getElementsAroundPoint(pos+i*SPACEDIM,intersectingElems);
78 std::vector<int> commonNodes;
79 for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
80 commonNodes.push_back(*it);
81 cI.push_back(cI.back()+(int)commonNodes.size());
82 c.insert(c.end(),commonNodes.begin(),commonNodes.end());
86 void DataArray::setName(const char *name)
91 void DataArray::copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception)
93 if(_info_on_compo.size()!=other._info_on_compo.size())
94 throw INTERP_KERNEL::Exception("Size of arrays mismatches on copyStringInfoFrom !");
96 _info_on_compo=other._info_on_compo;
99 void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
101 int nbOfCompoOth=other.getNumberOfComponents();
102 std::size_t newNbOfCompo=compoIds.size();
103 for(std::size_t i=0;i<newNbOfCompo;i++)
104 if(compoIds[i]>=nbOfCompoOth || compoIds[i]<0)
106 std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")";
107 throw INTERP_KERNEL::Exception(oss.str().c_str());
109 for(std::size_t i=0;i<newNbOfCompo;i++)
110 setInfoOnComponent((int)i,other.getInfoOnComponent(compoIds[i]).c_str());
113 void DataArray::copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception)
115 int nbOfCompo=getNumberOfComponents();
116 std::size_t partOfCompoToSet=compoIds.size();
117 if((int)partOfCompoToSet!=other.getNumberOfComponents())
118 throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !");
119 for(std::size_t i=0;i<partOfCompoToSet;i++)
120 if(compoIds[i]>=nbOfCompo || compoIds[i]<0)
122 std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")";
123 throw INTERP_KERNEL::Exception(oss.str().c_str());
125 for(std::size_t i=0;i<partOfCompoToSet;i++)
126 setInfoOnComponent(compoIds[i],other.getInfoOnComponent((int)i).c_str());
129 bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const
131 std::ostringstream oss;
132 if(_nb_of_tuples!=other._nb_of_tuples)
134 oss << "Number of tuples of DataArray mismatch : this number of tuples=" << _nb_of_tuples << " other number of tuples=" << other._nb_of_tuples;
138 if(_name!=other._name)
140 oss << "Names DataArray mismatch : this name=\"" << _name << " other name=\"" << other._name << "\" !";
144 if(_info_on_compo!=other._info_on_compo)
146 oss << "Components DataArray mismatch : \nThis components=";
147 for(std::vector<std::string>::const_iterator it=_info_on_compo.begin();it!=_info_on_compo.end();it++)
148 oss << "\"" << *it << "\",";
149 oss << "\nOther components=";
150 for(std::vector<std::string>::const_iterator it=other._info_on_compo.begin();it!=other._info_on_compo.end();it++)
151 oss << "\"" << *it << "\",";
158 bool DataArray::areInfoEquals(const DataArray& other) const
161 return areInfoEqualsIfNotWhy(other,tmp);
164 void DataArray::reprWithoutNameStream(std::ostream& stream) const
166 stream << "Number of components : "<< getNumberOfComponents() << "\n";
167 stream << "Info of these components : ";
168 for(std::vector<std::string>::const_iterator iter=_info_on_compo.begin();iter!=_info_on_compo.end();iter++)
169 stream << "\"" << *iter << "\" ";
173 void DataArray::setInfoOnComponents(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
175 if(getNumberOfComponents()!=(int)info.size())
177 std::ostringstream oss; oss << "DataArray::setInfoOnComponents : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " !";
178 throw INTERP_KERNEL::Exception(oss.str().c_str());
183 std::vector<std::string> DataArray::getVarsOnComponent() const
185 int nbOfCompo=(int)_info_on_compo.size();
186 std::vector<std::string> ret(nbOfCompo);
187 for(int i=0;i<nbOfCompo;i++)
188 ret[i]=getVarOnComponent(i);
192 std::vector<std::string> DataArray::getUnitsOnComponent() const
194 int nbOfCompo=(int)_info_on_compo.size();
195 std::vector<std::string> ret(nbOfCompo);
196 for(int i=0;i<nbOfCompo;i++)
197 ret[i]=getUnitOnComponent(i);
201 std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
203 if(i<(int)_info_on_compo.size() && i>=0)
204 return _info_on_compo[i];
207 std::ostringstream oss; oss << "DataArray::getInfoOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
208 throw INTERP_KERNEL::Exception(oss.str().c_str());
213 * In the info part of i_th component this method returns the var part.
214 * For example, if getInfoOnComponent(0) return "SIGXY (N/m^2)", getVarOnComponent(0) will return "SIGXY"
216 std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception)
218 if(i<(int)_info_on_compo.size() && i>=0)
220 return GetVarNameFromInfo(_info_on_compo[i]);
224 std::ostringstream oss; oss << "DataArray::getVarOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
225 throw INTERP_KERNEL::Exception(oss.str().c_str());
230 * In the info part of i_th component this method returns the var part.
231 * For example, if getInfoOnComponent(0) return "SIGXY (N/m^2)", getUnitOnComponent(0) will return "N/m^2"
233 std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception)
235 if(i<(int)_info_on_compo.size() && i>=0)
237 return GetUnitFromInfo(_info_on_compo[i]);
241 std::ostringstream oss; oss << "DataArray::getUnitOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
242 throw INTERP_KERNEL::Exception(oss.str().c_str());
246 std::string DataArray::GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
248 std::size_t p1=info.find_last_of('[');
249 std::size_t p2=info.find_last_of(']');
250 if(p1==std::string::npos || p2==std::string::npos)
255 return std::string();
256 std::size_t p3=info.find_last_not_of(' ',p1-1);
257 return info.substr(0,p3+1);
260 std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
262 std::size_t p1=info.find_last_of('[');
263 std::size_t p2=info.find_last_of(']');
264 if(p1==std::string::npos || p2==std::string::npos)
265 return std::string();
267 return std::string();
268 return info.substr(p1+1,p2-p1-1);
271 void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
273 if(i<(int)_info_on_compo.size() && i>=0)
274 _info_on_compo[i]=info;
277 std::ostringstream oss; oss << "DataArray::setInfoOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
278 throw INTERP_KERNEL::Exception(oss.str().c_str());
282 void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception)
284 if(getNumberOfTuples()!=nbOfTuples)
286 std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " << nbOfTuples << " having " << getNumberOfTuples() << " !";
287 throw INTERP_KERNEL::Exception(oss.str().c_str());
291 void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
293 if(getNumberOfComponents()!=nbOfCompo)
295 std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
296 throw INTERP_KERNEL::Exception(oss.str().c_str());
300 void DataArray::checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception)
302 if(getNbOfElems()!=nbOfElems)
304 std::ostringstream oss; oss << msg << " : mismatch number of elems : Expected " << nbOfElems << " having " << getNbOfElems() << " !";
305 throw INTERP_KERNEL::Exception(oss.str().c_str());
309 void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception)
311 if(getNumberOfTuples()!=other.getNumberOfTuples())
313 std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " << other.getNumberOfTuples() << " having " << getNumberOfTuples() << " !";
314 throw INTERP_KERNEL::Exception(oss.str().c_str());
316 if(getNumberOfComponents()!=other.getNumberOfComponents())
318 std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << other.getNumberOfComponents() << " having " << getNumberOfComponents() << " !";
319 throw INTERP_KERNEL::Exception(oss.str().c_str());
323 void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
325 checkNbOfTuples(nbOfTuples,msg);
326 checkNbOfComps(nbOfCompo,msg);
330 * Simply this method checks that \b value is in [0,\b ref).
332 void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
334 if(value<0 || value>=ref)
336 std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected in range [0," << ref << "[ having " << value << " !";
337 throw INTERP_KERNEL::Exception(oss.str().c_str());
342 * This method checks that [\b start, \b end) is compliant with ref length \b value.
343 * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
345 void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception)
347 if(start<0 || start>=value)
349 if(value!=start || end!=start)
351 std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected start " << start << " of range in [0," << value << "[ !";
352 throw INTERP_KERNEL::Exception(oss.str().c_str());
355 if(end<0 || end>value)
357 std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected start " << end << " of range in [0," << value << "[ !";
358 throw INTERP_KERNEL::Exception(oss.str().c_str());
362 void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
364 if(value<0 || value>ref)
366 std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected a range in [0," << ref << "] having closing open parenthesis " << value << " !";
367 throw INTERP_KERNEL::Exception(oss.str().c_str());
371 int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
375 std::ostringstream oss; oss << msg << " : end before begin !";
376 throw INTERP_KERNEL::Exception(oss.str().c_str());
380 std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
381 throw INTERP_KERNEL::Exception(oss.str().c_str());
383 return (end-1-begin)/step+1;
386 int DataArray::GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
389 throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES : step=0 is not allowed !");
390 if(end<begin && step>0)
392 std::ostringstream oss; oss << msg << " : end before begin whereas step is positive !";
393 throw INTERP_KERNEL::Exception(oss.str().c_str());
395 if(begin<end && step<0)
397 std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
398 throw INTERP_KERNEL::Exception(oss.str().c_str());
401 return (std::max(begin,end)-1-std::min(begin,end))/std::abs(step)+1;
406 int DataArray::GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception)
412 if(begin<=value && value<end)
414 if((value-begin)%step==0)
415 return (value-begin)/step;
424 if(begin>=value && value>end)
426 if((begin-value)%(-step)==0)
427 return (begin-value)/(-step);
439 DataArrayDouble *DataArrayDouble::New()
441 return new DataArrayDouble;
444 bool DataArrayDouble::isAllocated() const
446 return getConstPointer()!=0;
449 void DataArrayDouble::checkAllocated() const throw(INTERP_KERNEL::Exception)
452 throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
456 * This method differs from DataArray::setInfoOnComponents in the sense that if 'this->getNumberOfComponents()!=info.size()'
457 * and if 'this' is not allocated it will change the number of components of 'this'.
458 * If 'this->getNumberOfComponents()==info.size()' the behaviour is the same than DataArray::setInfoOnComponents method.
459 * If 'this->getNumberOfComponents()!=info.size()' and the 'this' is already allocated an exception will be thrown.
461 void DataArrayDouble::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
463 if(getNumberOfComponents()!=(int)info.size())
469 std::ostringstream oss; oss << "DataArrayDouble::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " and this is already allocated !";
470 throw INTERP_KERNEL::Exception(oss.str().c_str());
478 * This method returns the only one value in 'this', if and only if number of elements (nb of tuples * nb of components) is equal to 1, and that 'this' is allocated.
479 * If one or more conditions is not fulfilled an exception will be thrown.
481 double DataArrayDouble::doubleValue() const throw(INTERP_KERNEL::Exception)
485 if(getNbOfElems()==1)
487 return *getConstPointer();
490 throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is allocated but number of elements is not equal to 1 !");
493 throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is not allocated !");
497 * This method should be called on an allocated DataArrayDouble instance. If not an exception will be throw !
498 * This method checks the number of tupes. If it is equal to 0, it returns true, if not false is returned.
500 bool DataArrayDouble::empty() const throw(INTERP_KERNEL::Exception)
503 return getNumberOfTuples()==0;
506 DataArrayDouble *DataArrayDouble::deepCpy() const
508 return new DataArrayDouble(*this);
511 DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const
518 return const_cast<DataArrayDouble *>(this);
522 void DataArrayDouble::cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception)
524 other.checkAllocated();
525 int nbOfTuples=other.getNumberOfTuples();
526 int nbOfComp=other.getNumberOfComponents();
527 allocIfNecessary(nbOfTuples,nbOfComp);
528 int nbOfElems=nbOfTuples*nbOfComp;
529 double *pt=getPointer();
530 const double *ptI=other.getConstPointer();
531 for(int i=0;i<nbOfElems;i++)
533 copyStringInfoFrom(other);
536 void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo)
540 if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
541 alloc(nbOfTuple,nbOfCompo);
544 alloc(nbOfTuple,nbOfCompo);
547 void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
549 if(nbOfTuple<0 || nbOfCompo<0)
550 throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
551 _nb_of_tuples=nbOfTuple;
552 _info_on_compo.resize(nbOfCompo);
553 _mem.alloc(nbOfCompo*_nb_of_tuples);
557 void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception)
560 _mem.fillWithValue(0.);
564 void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception)
567 _mem.fillWithValue(val);
571 void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception)
574 if(getNumberOfComponents()!=1)
575 throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
576 double *ptr=getPointer();
577 int ntuples=getNumberOfTuples();
578 for(int i=0;i<ntuples;i++)
579 ptr[i]=init+double(i);
583 bool DataArrayDouble::isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception)
586 if(getNumberOfComponents()!=1)
587 throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
588 int nbOfTuples=getNumberOfTuples();
589 const double *w=getConstPointer();
590 const double *end2=w+nbOfTuples;
591 const double vmin=val-eps;
592 const double vmax=val+eps;
594 if(*w<vmin || *w>vmax)
599 void DataArrayDouble::sort(bool asc) throw(INTERP_KERNEL::Exception)
602 if(getNumberOfComponents()!=1)
603 throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !");
607 void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception)
610 if(getNumberOfComponents()!=1)
611 throw INTERP_KERNEL::Exception("DataArrayDouble::reverse : only supported with 'this' array with ONE component !");
616 * This method check that (Maths) array consistently INCREASING or DECREASING in value,
617 * with at least absolute difference value of |eps| at each step.
618 * if not an exception will be thrown.
620 void DataArrayDouble::checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
622 if(!isMonotonic(increasing, eps))
626 throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not INCREASING monotonic !");
630 throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not DECREASING monotonic !");
636 * This method check that (Maths) array consistently INCREASING or DECREASING in value,
637 * with at least absolute difference value of |eps| at each step.
639 bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
642 if(getNumberOfComponents()!=1)
643 throw INTERP_KERNEL::Exception("DataArrayDouble::isMonotonic : only supported with 'this' array with ONE component !");
644 int nbOfElements=getNumberOfTuples();
645 const double *ptr=getConstPointer();
649 double absEps=fabs(eps);
652 for(int i=1;i<nbOfElements;i++)
654 if(ptr[i]<(ref+absEps))
662 for(int i=1;i<nbOfElements;i++)
664 if(ptr[i]>(ref-absEps))
672 std::string DataArrayDouble::repr() const
674 std::ostringstream ret;
679 std::string DataArrayDouble::reprZip() const
681 std::ostringstream ret;
686 void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
688 std::string idt(indent,' ');
690 ofs << idt << "<DataArray type=\"Float32\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
691 ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
692 std::copy(begin(),end(),std::ostream_iterator<double>(ofs," "));
693 ofs << std::endl << idt << "</DataArray>\n";
696 void DataArrayDouble::reprStream(std::ostream& stream) const
698 stream << "Name of double array : \"" << _name << "\"\n";
699 reprWithoutNameStream(stream);
702 void DataArrayDouble::reprZipStream(std::ostream& stream) const
704 stream << "Name of double array : \"" << _name << "\"\n";
705 reprZipWithoutNameStream(stream);
708 void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const
710 DataArray::reprWithoutNameStream(stream);
711 stream.precision(15);
712 _mem.repr(getNumberOfComponents(),stream);
715 void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const
717 DataArray::reprWithoutNameStream(stream);
718 stream.precision(15);
719 _mem.reprZip(getNumberOfComponents(),stream);
722 bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const
724 if(!areInfoEqualsIfNotWhy(other,reason))
726 return _mem.isEqual(other._mem,prec,reason);
729 bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const
732 return isEqualIfNotWhy(other,prec,tmp);
735 bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const
738 return _mem.isEqual(other._mem,prec,tmp);
741 void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
744 _mem.reAlloc((int)(_info_on_compo.size())*nbOfTuples);
745 _nb_of_tuples=nbOfTuples;
749 DataArrayInt *DataArrayDouble::convertToIntArr() const
751 DataArrayInt *ret=DataArrayInt::New();
752 ret->alloc(getNumberOfTuples(),getNumberOfComponents());
753 int nbOfVals=getNbOfElems();
754 const double *src=getConstPointer();
755 int *dest=ret->getPointer();
756 std::copy(src,src+nbOfVals,dest);
757 ret->copyStringInfoFrom(*this);
761 DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
764 throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
765 double *tab=_mem.fromNoInterlace(getNumberOfComponents());
766 DataArrayDouble *ret=DataArrayDouble::New();
767 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
771 DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception)
774 throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
775 double *tab=_mem.toNoInterlace(getNumberOfComponents());
776 DataArrayDouble *ret=DataArrayDouble::New();
777 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
782 * This method does \b not change the number of tuples after this call.
783 * Only a permutation is done. If a permutation reduction is needed substr, or selectByTupleId should be used.
785 void DataArrayDouble::renumberInPlace(const int *old2New)
787 int nbTuples=getNumberOfTuples();
788 int nbOfCompo=getNumberOfComponents();
789 double *tmp=new double[nbTuples*nbOfCompo];
790 const double *iptr=getConstPointer();
791 for(int i=0;i<nbTuples;i++)
792 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
793 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
799 * This method does \b not change the number of tuples after this call.
800 * Only a permutation is done.
802 void DataArrayDouble::renumberInPlaceR(const int *new2Old)
804 int nbTuples=getNumberOfTuples();
805 int nbOfCompo=getNumberOfComponents();
806 double *tmp=new double[nbTuples*nbOfCompo];
807 const double *iptr=getConstPointer();
808 for(int i=0;i<nbTuples;i++)
809 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
810 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
816 * This method does \b not change the number of tuples after this call.
817 * Only a permutation is done. If a permutation reduction is needed renumberAndReduce.
819 DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const
821 int nbTuples=getNumberOfTuples();
822 int nbOfCompo=getNumberOfComponents();
823 DataArrayDouble *ret=DataArrayDouble::New();
824 ret->alloc(nbTuples,nbOfCompo);
825 ret->copyStringInfoFrom(*this);
826 const double *iptr=getConstPointer();
827 double *optr=ret->getPointer();
828 for(int i=0;i<nbTuples;i++)
829 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
830 ret->copyStringInfoFrom(*this);
835 * This method does \b not change the number of tuples after this call.
836 * Only a permutation is done. If a permutation reduction is needed substr, or selectByTupleId should be used.
838 DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const
840 int nbTuples=getNumberOfTuples();
841 int nbOfCompo=getNumberOfComponents();
842 DataArrayDouble *ret=DataArrayDouble::New();
843 ret->alloc(nbTuples,nbOfCompo);
844 ret->copyStringInfoFrom(*this);
845 const double *iptr=getConstPointer();
846 double *optr=ret->getPointer();
847 for(int i=0;i<nbTuples;i++)
848 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
849 ret->copyStringInfoFrom(*this);
854 * Idem DataArrayDouble::renumber method except that the number of tuples is reduced.
855 * That is to say that it is expected that newNbOfTuple<this->getNumberOfTuples().
856 * ['old2New','old2New'+getNumberOfTuples()) defines a range containing old to new array. For every negative value in ['old2NewBg','old2New'+getNumberOfTuples()) the corresponding tuple is
859 DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const
861 int nbTuples=getNumberOfTuples();
862 int nbOfCompo=getNumberOfComponents();
863 DataArrayDouble *ret=DataArrayDouble::New();
864 ret->alloc(newNbOfTuple,nbOfCompo);
865 const double *iptr=getConstPointer();
866 double *optr=ret->getPointer();
867 for(int i=0;i<nbTuples;i++)
871 std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
873 ret->copyStringInfoFrom(*this);
878 * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here.
879 * This method is equivalent to DataArrayDouble::renumberAndReduce except that convention in input is new2old and \b not old2new.
881 DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
883 DataArrayDouble *ret=DataArrayDouble::New();
884 int nbComp=getNumberOfComponents();
885 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
886 ret->copyStringInfoFrom(*this);
887 double *pt=ret->getPointer();
888 const double *srcPt=getConstPointer();
890 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
891 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
892 ret->copyStringInfoFrom(*this);
897 * This method is equivalent to DataArrayDouble::selectByTupleId except that an analyze to the content of input range to check that it will not lead to memory corruption !
899 DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
901 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
902 int nbComp=getNumberOfComponents();
903 int oldNbOfTuples=getNumberOfTuples();
904 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
905 ret->copyStringInfoFrom(*this);
906 double *pt=ret->getPointer();
907 const double *srcPt=getConstPointer();
909 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
910 if(*w>=0 && *w<oldNbOfTuples)
911 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
913 throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
914 ret->copyStringInfoFrom(*this);
920 * Idem than DataArrayInt::selectByTupleIdSafe except that the input array is not constructed explicitely.
921 * The convention is as python one. ['bg','end2') with steps of 'step'.
922 * Returns a newly created array.
923 * This method is a generalization of DataArrayDouble::substr.
925 * \sa DataArrayDouble::substr
927 DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
929 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
930 int nbComp=getNumberOfComponents();
931 int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayDouble::selectByTupleId2 : ");
932 ret->alloc(newNbOfTuples,nbComp);
933 double *pt=ret->getPointer();
934 const double *srcPt=getConstPointer()+bg*nbComp;
935 for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
936 std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
937 ret->copyStringInfoFrom(*this);
943 * This method returns a newly allocated array that is the concatenation of all tuples ranges in param 'ranges'.
944 * Each pair in input 'ranges' is in [begin,end) format. If there is a range in 'ranges' so that end is before begin an exception
945 * will be thrown. If there is a range in 'ranges' so that end is greater than number of tuples of 'this', an exception will be thrown too.
947 DataArrayDouble *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
950 int nbOfComp=getNumberOfComponents();
951 int nbOfTuplesThis=getNumberOfTuples();
954 DataArrayDouble *ret=DataArrayDouble::New();
955 ret->alloc(0,nbOfComp);
956 ret->copyStringInfoFrom(*this);
959 int ref=ranges.front().first;
961 bool isIncreasing=true;
962 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
964 if((*it).first<=(*it).second)
966 if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
968 nbOfTuples+=(*it).second-(*it).first;
970 isIncreasing=ref<=(*it).first;
975 std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
976 oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
977 throw INTERP_KERNEL::Exception(oss.str().c_str());
982 std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
983 oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
984 throw INTERP_KERNEL::Exception(oss.str().c_str());
987 if(isIncreasing && nbOfTuplesThis==nbOfTuples)
989 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
990 ret->alloc(nbOfTuples,nbOfComp);
991 ret->copyStringInfoFrom(*this);
992 const double *src=getConstPointer();
993 double *work=ret->getPointer();
994 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
995 work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
1001 * This methods has a similar behaviour than std::string::substr. This method returns a newly created DataArrayInt that is part of this with same number of components.
1002 * The intervall is specified by [tupleIdBg,tupleIdEnd) except if tupleIdEnd ==-1 in this case the [tupleIdBg,this->end()) will be kept.
1003 * This method check that interval is valid regarding this, if not an exception will be thrown.
1004 * This method is a specialization of method DataArrayDouble::selectByTupleId2.
1006 * \sa DataArrayDouble::selectByTupleId2
1008 DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
1010 int nbt=getNumberOfTuples();
1012 throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter must be greater than 0 !");
1014 throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater than number of tuples !");
1015 int trueEnd=tupleIdEnd;
1019 throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
1023 int nbComp=getNumberOfComponents();
1024 DataArrayDouble *ret=DataArrayDouble::New();
1025 ret->alloc(trueEnd-tupleIdBg,nbComp);
1026 ret->copyStringInfoFrom(*this);
1027 std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
1032 * This method builds a new instance of DataArrayDouble (to deal with) that is reduction or an extension of 'this'.
1033 * if 'newNbOfComp' < this->getNumberOfComponents() a reduction is done and for each tuple 'newNbOfComp' first components are kept.
1034 * If 'newNbOfComp' > this->getNumberOfComponents() an extension is done, and for each components i such that i > getNumberOfComponents() 'dftValue' parameter is taken.
1036 DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception)
1039 DataArrayDouble *ret=DataArrayDouble::New();
1040 ret->alloc(getNumberOfTuples(),newNbOfComp);
1041 const double *oldc=getConstPointer();
1042 double *nc=ret->getPointer();
1043 int nbOfTuples=getNumberOfTuples();
1044 int oldNbOfComp=getNumberOfComponents();
1045 int dim=std::min(oldNbOfComp,newNbOfComp);
1046 for(int i=0;i<nbOfTuples;i++)
1050 nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
1051 for(;j<newNbOfComp;j++)
1052 nc[newNbOfComp*i+j]=dftValue;
1054 ret->setName(getName().c_str());
1055 for(int i=0;i<dim;i++)
1056 ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
1057 ret->setName(getName().c_str());
1062 * Contrary to DataArrayDouble::changeNbOfComponents method this method is \b not const. The content
1063 * This method \b do \b not change the content of data but changes the splitting of this data seen by the caller.
1064 * This method makes the assumption that 'this' is already allocated. If not an exception will be thrown.
1065 * This method checks that getNbOfElems()%newNbOfCompo==0. If not an exception will be throw !
1066 * This method erases all components info set before call !
1068 void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
1071 int nbOfElems=getNbOfElems();
1072 if(nbOfElems%newNbOfCompo!=0)
1073 throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !");
1074 _nb_of_tuples=nbOfElems/newNbOfCompo;
1075 _info_on_compo.clear();
1076 _info_on_compo.resize(newNbOfCompo);
1081 * This method makes the assumption that \b this is allocated. If not an INTERP_KERNEL::Exception will be raised.
1082 * This method does not echange the values stored in \b this. Simply, the number of components before the call becomes the number of
1083 * tuples and inversely the number of tuples becomes the number of components. \b WARNING the info on components can be alterated by this method.
1085 void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception)
1088 int nbOfTuples=getNumberOfTuples();
1089 rearrange(nbOfTuples);
1092 DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
1095 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
1096 std::size_t newNbOfCompo=compoIds.size();
1097 int oldNbOfCompo=getNumberOfComponents();
1098 for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
1099 if((*it)<0 || (*it)>=oldNbOfCompo)
1101 std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
1102 throw INTERP_KERNEL::Exception(oss.str().c_str());
1104 int nbOfTuples=getNumberOfTuples();
1105 ret->alloc(nbOfTuples,(int)newNbOfCompo);
1106 ret->copyPartOfStringInfoFrom(*this,compoIds);
1107 const double *oldc=getConstPointer();
1108 double *nc=ret->getPointer();
1109 for(int i=0;i<nbOfTuples;i++)
1110 for(std::size_t j=0;j<newNbOfCompo;j++,nc++)
1111 *nc=oldc[i*oldNbOfCompo+compoIds[j]];
1117 * This method melds the components of 'this' with components of 'other'.
1118 * After this call in case of success, 'this' will contain a number of components equal to the sum of 'this'
1119 * before the call and the number of components of 'other'.
1120 * This method expects that 'this' and 'other' have exactly the same number of tuples. If not an exception is thrown.
1122 void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
1125 other->checkAllocated();
1126 int nbOfTuples=getNumberOfTuples();
1127 if(nbOfTuples!=other->getNumberOfTuples())
1128 throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
1129 int nbOfComp1=getNumberOfComponents();
1130 int nbOfComp2=other->getNumberOfComponents();
1131 double *newArr=new double[nbOfTuples*(nbOfComp1+nbOfComp2)];
1133 const double *inp1=getConstPointer();
1134 const double *inp2=other->getConstPointer();
1135 for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
1137 w=std::copy(inp1,inp1+nbOfComp1,w);
1138 w=std::copy(inp2,inp2+nbOfComp2,w);
1140 useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
1141 std::vector<int> compIds(nbOfComp2);
1142 for(int i=0;i<nbOfComp2;i++)
1143 compIds[i]=nbOfComp1+i;
1144 copyPartOfStringInfoFrom2(compIds,*other);
1148 * This methods searches for each tuple if there are any tuples in 'this' that are less far than 'prec' from n1. if any, these tuples are stored in out params
1149 * comm and commIndex. The distance is computed using norm2. This method expects that 'this' is allocated and that the number of components is in [1,2,3].
1150 * If not an exception will be thrown.
1151 * This method is typically used by MEDCouplingPointSet::findCommonNodes and MEDCouplingUMesh::mergeNodes.
1152 * In case of success, commIndex->getNumberOfTuples()-1 gives the number of tuples groupes that are within distance 'prec'.
1153 * comm->getNumberOfTuples()==commIndex->back()
1154 * The returned pair of DataArrayInt instances ('comm','commIndex') is called Surjectived Format 2 \sa DataArrayInt::BuildNew2OldArrayFromSurjectiveFormat2.
1155 * This format is more compact in surjective format because only all tuple ids not in 'comm' are remain unchanged.
1157 * @param prec is an absolute precision.
1158 * @param limitTupleId is the limit tuple id. All tuples which id is strictly lower than 'limiTupleId' will not be merged each other.
1159 * @param comm out parameter (not inout). Number of components is equal to 1.
1160 * @param commIndex out parameter (not inout). Number of components is equal to 1.
1162 void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
1165 int nbOfCompo=getNumberOfComponents();
1166 if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work
1167 throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3.");
1169 int nbOfTuples=getNumberOfTuples();
1170 comm=DataArrayInt::New();
1171 commIndex=DataArrayInt::New();
1173 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(prec);
1175 std::vector<int> c,cI(1);
1179 findCommonTuplesAlg<3>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1182 findCommonTuplesAlg<2>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1185 findCommonTuplesAlg<1>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1188 throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !");
1190 commIndex->alloc((int)cI.size(),1);
1191 std::copy(cI.begin(),cI.end(),commIndex->getPointer());
1192 comm->alloc(cI.back(),1);
1193 std::copy(c.begin(),c.end(),comm->getPointer());
1198 * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
1199 * \a nbTimes should be at least equal to 1.
1200 * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
1201 * \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.
1203 DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
1206 if(getNumberOfComponents()!=1)
1207 throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
1209 throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
1210 int nbTuples=getNumberOfTuples();
1211 const double *inPtr=getConstPointer();
1212 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1);
1213 double *retPtr=ret->getPointer();
1214 for(int i=0;i<nbTuples;i++,inPtr++)
1217 for(int j=0;j<nbTimes;j++,retPtr++)
1220 ret->copyStringInfoFrom(*this);
1226 * This method returns a newly allocated object the user should deal with.
1227 * This method works for arrays which have number of components into [1,2,3]. If not an exception will be thrown.
1228 * This method returns the different values in 'this' using 'prec'. The different values are kept in the same
1229 * order than 'this'. That is to say that returned DataArrayDouble instance is not systematically sorted.
1231 * @param prec is an absolute precision.
1232 * @param limitTupleId is the limit tuple id. All tuples which id is strictly lower than 'limiTupleId' will not be merged each other.
1234 DataArrayDouble *DataArrayDouble::getDifferentValues(double prec, int limitTupleId) const throw(INTERP_KERNEL::Exception)
1236 DataArrayInt *c0=0,*cI0=0;
1237 findCommonTuples(prec,limitTupleId,c0,cI0);
1238 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(c0),cI(cI0);
1239 int newNbOfTuples=-1;
1240 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0,cI0,newNbOfTuples);
1241 return renumberAndReduce(o2n->getConstPointer(),newNbOfTuples);
1244 void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
1247 throw INTERP_KERNEL::Exception("DataArrayDouble::setSelectedComponents : input DataArrayDouble is NULL !");
1248 copyPartOfStringInfoFrom2(compoIds,*a);
1249 std::size_t partOfCompoSz=compoIds.size();
1250 int nbOfCompo=getNumberOfComponents();
1251 int nbOfTuples=getNumberOfTuples();
1252 const double *ac=a->getConstPointer();
1253 double *nc=getPointer();
1254 for(int i=0;i<nbOfTuples;i++)
1255 for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
1256 nc[nbOfCompo*i+compoIds[j]]=*ac;
1260 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
1261 * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
1263 void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
1266 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues1 : input DataArrayDouble is NULL !");
1267 const char msg[]="DataArrayDouble::setPartOfValues1";
1269 a->checkAllocated();
1270 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
1271 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
1272 int nbComp=getNumberOfComponents();
1273 int nbOfTuples=getNumberOfTuples();
1274 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1275 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1276 a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
1277 if(strictCompoCompare)
1278 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1279 double *pt=getPointer()+bgTuples*nbComp+bgComp;
1280 const double *srcPt=a->getConstPointer();
1281 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1282 for(int j=0;j<newNbOfComp;j++,srcPt++)
1283 pt[j*stepComp]=*srcPt;
1287 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
1289 void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
1291 const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
1293 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
1294 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
1295 int nbComp=getNumberOfComponents();
1296 int nbOfTuples=getNumberOfTuples();
1297 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
1298 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1299 double *pt=getPointer()+bgTuples*nbComp+bgComp;
1300 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
1301 for(int j=0;j<newNbOfComp;j++)
1306 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
1307 * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
1309 void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
1312 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
1313 const char msg[]="DataArrayDouble::setPartOfValues2";
1315 a->checkAllocated();
1316 int nbComp=getNumberOfComponents();
1317 int nbOfTuples=getNumberOfTuples();
1318 for(const int *z=bgComp;z!=endComp;z++)
1319 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1320 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
1321 int newNbOfComp=(int)std::distance(bgComp,endComp);
1322 bool assignTech=true;
1323 if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
1325 if(strictCompoCompare)
1326 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1330 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1333 double *pt=getPointer();
1334 const double *srcPt=a->getConstPointer();
1337 for(const int *w=bgTuples;w!=endTuples;w++)
1339 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1340 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
1342 pt[(*w)*nbComp+(*z)]=*srcPt;
1348 for(const int *w=bgTuples;w!=endTuples;w++)
1350 const double *srcPt2=srcPt;
1351 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1352 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
1354 pt[(*w)*nbComp+(*z)]=*srcPt2;
1361 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
1363 void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
1366 int nbComp=getNumberOfComponents();
1367 int nbOfTuples=getNumberOfTuples();
1368 for(const int *z=bgComp;z!=endComp;z++)
1369 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
1370 double *pt=getPointer();
1371 for(const int *w=bgTuples;w!=endTuples;w++)
1372 for(const int *z=bgComp;z!=endComp;z++)
1374 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1375 pt[(*w)*nbComp+(*z)]=a;
1380 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
1381 * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
1383 void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
1386 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues3 : input DataArrayDouble is NULL !");
1387 const char msg[]="DataArrayDouble::setPartOfValues3";
1389 a->checkAllocated();
1390 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
1391 int nbComp=getNumberOfComponents();
1392 int nbOfTuples=getNumberOfTuples();
1393 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1394 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
1395 bool assignTech=true;
1396 if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
1398 if(strictCompoCompare)
1399 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
1403 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
1406 double *pt=getPointer()+bgComp;
1407 const double *srcPt=a->getConstPointer();
1410 for(const int *w=bgTuples;w!=endTuples;w++)
1411 for(int j=0;j<newNbOfComp;j++,srcPt++)
1413 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1414 pt[(*w)*nbComp+j*stepComp]=*srcPt;
1419 for(const int *w=bgTuples;w!=endTuples;w++)
1421 const double *srcPt2=srcPt;
1422 for(int j=0;j<newNbOfComp;j++,srcPt2++)
1424 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1425 pt[(*w)*nbComp+j*stepComp]=*srcPt2;
1432 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
1434 void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
1436 const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
1438 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
1439 int nbComp=getNumberOfComponents();
1440 int nbOfTuples=getNumberOfTuples();
1441 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
1442 double *pt=getPointer()+bgComp;
1443 for(const int *w=bgTuples;w!=endTuples;w++)
1444 for(int j=0;j<newNbOfComp;j++)
1446 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
1447 pt[(*w)*nbComp+j*stepComp]=a;
1452 * 'this', 'a' and 'tuplesSelec' are expected to be defined. If not an exception will be thrown.
1453 * @param a is an array having exactly the same number of components than 'this'
1454 * @param tuplesSelec is an array having exactly 2 components. The first one refers to the tuple ids of 'this' that will be set. The second one refers to the tuple ids of 'a' that will be used for setting.
1456 void DataArrayDouble::setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
1459 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : input DataArrayDouble is NULL !");
1461 a->checkAllocated();
1462 tuplesSelec->checkAllocated();
1463 int nbOfComp=getNumberOfComponents();
1464 if(nbOfComp!=a->getNumberOfComponents())
1465 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : This and a do not have the same number of components !");
1466 if(tuplesSelec->getNumberOfComponents()!=2)
1467 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
1468 int thisNt=getNumberOfTuples();
1469 int aNt=a->getNumberOfTuples();
1470 double *valsToSet=getPointer();
1471 const double *valsSrc=a->getConstPointer();
1472 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
1474 if(tuple[1]>=0 && tuple[1]<aNt)
1476 if(tuple[0]>=0 && tuple[0]<thisNt)
1477 std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
1480 std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
1481 oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
1482 throw INTERP_KERNEL::Exception(oss.str().c_str());
1487 std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
1488 oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
1489 throw INTERP_KERNEL::Exception(oss.str().c_str());
1495 * 'this', 'a' and 'tuplesSelec' are expected to be defined. If not an exception will be thrown.
1496 * This is a method that is a specialization to DataArrayDouble::setPartOfValuesAdv method, except that here the tuple selection of 'a' is given by a range ('bg','end2' and 'step')
1497 * rather than an explicite array of tuple ids (given by the 2nd component) and the feeding is done in 'this' contiguously starting from 'tupleIdStart'.
1498 * @param a is an array having exactly the same number of components than 'this'
1500 void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
1502 if(!a || !tuplesSelec)
1503 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray is NULL !");
1505 a->checkAllocated();
1506 tuplesSelec->checkAllocated();
1507 int nbOfComp=getNumberOfComponents();
1508 if(nbOfComp!=a->getNumberOfComponents())
1509 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : This and a do not have the same number of components !");
1510 if(tuplesSelec->getNumberOfComponents()!=1)
1511 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
1512 int thisNt=getNumberOfTuples();
1513 int aNt=a->getNumberOfTuples();
1514 int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
1515 double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
1516 if(tupleIdStart+nbOfTupleToWrite>thisNt)
1517 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : invalid number range of values to write !");
1518 const double *valsSrc=a->getConstPointer();
1519 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
1521 if(*tuple>=0 && *tuple<aNt)
1523 std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
1527 std::ostringstream oss; oss << "DataArrayDouble::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
1528 oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
1529 throw INTERP_KERNEL::Exception(oss.str().c_str());
1535 * 'this' and 'a' are expected to be defined. If not an exception will be thrown.
1536 * This is a method that is a specialization to DataArrayDouble::setContigPartOfSelectedValues method, except that here the tuple selection is givenin a is done by a range ('bg','end2' and 'step')
1537 * rather than an explicite array of tuple ids.
1538 * @param a is an array having exactly the same number of components than 'this'
1540 void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
1543 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArrayDouble is NULL !");
1545 a->checkAllocated();
1546 int nbOfComp=getNumberOfComponents();
1547 const char msg[]="DataArrayDouble::setContigPartOfSelectedValues2";
1548 int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
1549 if(nbOfComp!=a->getNumberOfComponents())
1550 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
1551 int thisNt=getNumberOfTuples();
1552 int aNt=a->getNumberOfTuples();
1553 double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
1554 if(tupleIdStart+nbOfTupleToWrite>thisNt)
1555 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid number range of values to write !");
1557 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid range of values to read !");
1558 const double *valsSrc=a->getConstPointer()+bg*nbOfComp;
1559 for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
1561 std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
1566 * This method is equivalent to DataArrayDouble::getIJ except that here \b tupleId is checked to be in [0,this->getNumberOfTuples()) and compoId to be in [0,this->getNumberOfComponents()).
1567 * If one of these check fails an INTERP_KERNEL::Exception will be thrown.
1568 * So this method is safe but expensive if used to go through all data of \b this.
1570 double DataArrayDouble::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
1573 if(tupleId<0 || tupleId>=getNumberOfTuples())
1575 std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
1576 throw INTERP_KERNEL::Exception(oss.str().c_str());
1578 if(compoId<0 || compoId>=getNumberOfComponents())
1580 std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
1581 throw INTERP_KERNEL::Exception(oss.str().c_str());
1583 return _mem[tupleId*((int)_info_on_compo.size())+compoId];
1587 * This method returns the last element in 'this'. So this method makes the hypothesis that 'this' is allocated.
1588 * This method works only for arrays that have exactly number of components equal to 1. If not an exception is thrown.
1589 * And to finish this method works for arrays that have number of tuples >= 1.
1591 double DataArrayDouble::back() const throw(INTERP_KERNEL::Exception)
1594 if(getNumberOfComponents()!=1)
1595 throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of components not equal to one !");
1596 int nbOfTuples=getNumberOfTuples();
1598 throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of tuples must be >= 1 !");
1599 return *(getConstPointer()+nbOfTuples-1);
1602 void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
1604 if(newArray!=arrayToSet)
1607 arrayToSet->decrRef();
1608 arrayToSet=newArray;
1610 arrayToSet->incrRef();
1614 void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
1616 _nb_of_tuples=nbOfTuple;
1617 _info_on_compo.resize(nbOfCompo);
1618 _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
1622 void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception)
1624 const double *tmp=getConstPointer();
1625 int nbOfElems=getNbOfElems();
1626 const double *where=std::find(tmp,tmp+nbOfElems,0.);
1627 if(where!=tmp+nbOfElems)
1628 throw INTERP_KERNEL::Exception("A value 0.0 have been detected !");
1632 * This method assume that \b this is allocated. If not an INTERP_KERNEL::Exception will be thrown.
1633 * This method fills \b bounds params like that : \b bounds[0]=XMin, \b bounds[1]=XMax, \b bounds[2]=YMin, \b bounds[3]=YMax...
1634 * Where X refers to component #0, and Y to component #1...
1635 * This method set 2*this->getNumberOfComponents() elements in \b bounds, so it is up to the caller to allocated enough space before calling this method.
1637 * @param [out] bounds array of size 2*this->getNumberOfComponents().
1639 void DataArrayDouble::getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception)
1642 int dim=getNumberOfComponents();
1643 for (int idim=0; idim<dim; idim++)
1645 bounds[idim*2]=std::numeric_limits<double>::max();
1646 bounds[idim*2+1]=-std::numeric_limits<double>::max();
1648 const double *ptr=getConstPointer();
1649 int nbOfTuples=getNumberOfTuples();
1650 for(int i=0;i<nbOfTuples;i++)
1652 for(int idim=0;idim<dim;idim++)
1654 if(bounds[idim*2]>ptr[i*dim+idim])
1656 bounds[idim*2]=ptr[i*dim+idim];
1658 if(bounds[idim*2+1]<ptr[i*dim+idim])
1660 bounds[idim*2+1]=ptr[i*dim+idim];
1667 * This method retrieves a newly allocated DataArrayDouble instance having same number of tuples than \a this and twice number of components than \a this
1668 * to store both the min and max per component of each tuples.
1669 * \param [in] epsilon the width of the bbox (identical in each direction) - 0.0 by default
1671 * \return a newly created DataArrayDouble instance having \c this->getNumberOfTuples() tuples and 2 * \c this->getNumberOfComponent() components
1673 * \throw If \a this is not allocated yet.
1675 DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon)const throw(INTERP_KERNEL::Exception)
1678 const double *dataPtr=getConstPointer();
1679 int nbOfCompo=getNumberOfComponents();
1680 int nbTuples=getNumberOfTuples();
1681 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=DataArrayDouble::New();
1682 bbox->alloc(nbTuples,2*nbOfCompo);
1683 double *bboxPtr=bbox->getPointer();
1684 for(int i=0;i<nbTuples;i++)
1686 for(int j=0;j<nbOfCompo;j++)
1688 bboxPtr[2*nbOfCompo*i+2*j]=dataPtr[nbOfCompo*i+j]-epsilon;
1689 bboxPtr[2*nbOfCompo*i+2*j+1]=dataPtr[nbOfCompo*i+j]+epsilon;
1697 * For each tuples **t** in \a other, this method retrieves tuples in \a this that are equal to **t**.
1698 * Two tuples are considered equal if the euclidian distance between the two tuples is lower than \a eps.
1700 * \param [in] other a DataArrayDouble having same number of components than \a this.
1701 * \param [in] eps absolute precision representing euclidian distance between 2 tuples behind which 2 tuples are considered equal.
1702 * \param [out] c will contain the set of tuple ids in \a this that are equal to to the tuple ids in \a other contiguously.
1703 * \a cI allows to extract information in \a c.
1704 * \param [out] cI is an indirection array that allows to extract the data contained in \a c.
1706 * \throw In case of:
1707 * - \a this is not allocated
1708 * - \a other is not allocated or null
1709 * - \a this and \a other do not have the same number of components
1710 * - if number of components of \a this is not in [1,2,3]
1712 * \sa MEDCouplingPointSet::getNodeIdsNearPoints, DataArrayDouble::getDifferentValues
1714 void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, std::vector<int>& c, std::vector<int>& cI) const throw(INTERP_KERNEL::Exception)
1717 throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !");
1718 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(eps);
1719 other->checkAllocated();
1720 int nbOfCompo=getNumberOfComponents();
1721 int otherNbOfCompo=other->getNumberOfComponents();
1722 if(nbOfCompo!=otherNbOfCompo)
1723 throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : number of components should be equal between this and other !");
1724 int nbOfTuplesOther=other->getNumberOfTuples();
1725 std::vector<int> ret;
1727 cI.resize(1); cI[0]=0;
1732 BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
1733 findTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI);
1738 BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
1739 findTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI);
1744 BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
1745 findTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI);
1749 throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for computeTupleIdsNearTuples. Must be 1, 2 or 3.");
1754 * This method recenter tuples in \b this in order to be centered at the origin to benefit about the advantages of maximal precision to be around the box
1755 * around origin of 'radius' 1.
1757 * \param [in] eps absolute epsilon. under that value of delta between max and min no scale is performed.
1759 void DataArrayDouble::recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception)
1762 int dim=getNumberOfComponents();
1763 std::vector<double> bounds(2*dim);
1764 getMinMaxPerComponent(&bounds[0]);
1765 for(int i=0;i<dim;i++)
1767 double delta=bounds[2*i+1]-bounds[2*i];
1768 double offset=(bounds[2*i]+bounds[2*i+1])/2.;
1770 applyLin(1./delta,-offset/delta,i);
1772 applyLin(1.,-offset,i);
1776 double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
1778 if(getNumberOfComponents()!=1)
1779 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 !");
1780 int nbOfTuples=getNumberOfTuples();
1782 throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
1783 const double *vals=getConstPointer();
1784 const double *loc=std::max_element(vals,vals+nbOfTuples);
1785 tupleId=(int)std::distance(vals,loc);
1790 * Idem to DataArrayDouble::getMaxValue expect that here number of components can be >=1.
1792 double DataArrayDouble::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
1795 const double *loc=std::max_element(begin(),end());
1799 double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
1803 double ret=getMaxValue(tmp);
1804 tupleIds=getIdsInRange(ret,ret);
1808 double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
1810 if(getNumberOfComponents()!=1)
1811 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
1812 int nbOfTuples=getNumberOfTuples();
1814 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
1815 const double *vals=getConstPointer();
1816 const double *loc=std::min_element(vals,vals+nbOfTuples);
1817 tupleId=(int)std::distance(vals,loc);
1822 * Idem to DataArrayDouble::getMinValue expect that here number of components can be >=1.
1824 double DataArrayDouble::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
1827 const double *loc=std::min_element(begin(),end());
1831 double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
1835 double ret=getMinValue(tmp);
1836 tupleIds=getIdsInRange(ret,ret);
1840 double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
1842 if(getNumberOfComponents()!=1)
1843 throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
1844 int nbOfTuples=getNumberOfTuples();
1846 throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !");
1847 const double *vals=getConstPointer();
1848 double ret=std::accumulate(vals,vals+nbOfTuples,0.);
1849 return ret/nbOfTuples;
1852 double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
1856 int nbOfElems=getNbOfElems();
1857 const double *pt=getConstPointer();
1858 for(int i=0;i<nbOfElems;i++,pt++)
1863 double DataArrayDouble::normMax() const throw(INTERP_KERNEL::Exception)
1867 int nbOfElems=getNbOfElems();
1868 const double *pt=getConstPointer();
1869 for(int i=0;i<nbOfElems;i++,pt++)
1871 double val=std::abs(*pt);
1878 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
1881 const double *ptr=getConstPointer();
1882 int nbTuple=getNumberOfTuples();
1883 int nbComps=getNumberOfComponents();
1884 std::fill(res,res+nbComps,0.);
1885 for(int i=0;i<nbTuple;i++)
1886 std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
1889 double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
1892 const double *ptr=getConstPointer();
1893 int nbTuple=getNumberOfTuples();
1894 int nbComps=getNumberOfComponents();
1896 throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !");
1898 for(int i=0;i<nbTuple;i++)
1899 ret+=ptr[i*nbComps+compId];
1903 DataArrayDouble *DataArrayDouble::fromPolarToCart() const throw(INTERP_KERNEL::Exception)
1905 int nbOfComp=getNumberOfComponents();
1907 throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !");
1908 int nbOfTuple=getNumberOfTuples();
1909 DataArrayDouble *ret=DataArrayDouble::New();
1910 ret->alloc(nbOfTuple,2);
1911 double *w=ret->getPointer();
1912 const double *wIn=getConstPointer();
1913 for(int i=0;i<nbOfTuple;i++,w+=2,wIn+=2)
1915 w[0]=wIn[0]*cos(wIn[1]);
1916 w[1]=wIn[0]*sin(wIn[1]);
1921 DataArrayDouble *DataArrayDouble::fromCylToCart() const throw(INTERP_KERNEL::Exception)
1923 int nbOfComp=getNumberOfComponents();
1925 throw INTERP_KERNEL::Exception("DataArrayDouble::fromCylToCart : must be an array with exactly 3 components !");
1926 int nbOfTuple=getNumberOfTuples();
1927 DataArrayDouble *ret=DataArrayDouble::New();
1928 ret->alloc(getNumberOfTuples(),3);
1929 double *w=ret->getPointer();
1930 const double *wIn=getConstPointer();
1931 for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
1933 w[0]=wIn[0]*cos(wIn[1]);
1934 w[1]=wIn[0]*sin(wIn[1]);
1937 ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str());
1941 DataArrayDouble *DataArrayDouble::fromSpherToCart() const throw(INTERP_KERNEL::Exception)
1943 int nbOfComp=getNumberOfComponents();
1945 throw INTERP_KERNEL::Exception("DataArrayDouble::fromSpherToCart : must be an array with exactly 3 components !");
1946 int nbOfTuple=getNumberOfTuples();
1947 DataArrayDouble *ret=DataArrayDouble::New();
1948 ret->alloc(getNumberOfTuples(),3);
1949 double *w=ret->getPointer();
1950 const double *wIn=getConstPointer();
1951 for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
1953 w[0]=wIn[0]*cos(wIn[2])*sin(wIn[1]);
1954 w[1]=wIn[0]*sin(wIn[2])*sin(wIn[1]);
1955 w[2]=wIn[0]*cos(wIn[1]);
1960 DataArrayDouble *DataArrayDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
1962 int nbOfComp=getNumberOfComponents();
1964 throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !");
1965 DataArrayDouble *ret=DataArrayDouble::New();
1966 int nbOfTuple=getNumberOfTuples();
1967 ret->alloc(nbOfTuple,1);
1968 const double *src=getConstPointer();
1969 double *dest=ret->getPointer();
1970 for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
1971 *dest=src[0]*src[0]+src[1]*src[1]+src[2]*src[2]+2.*src[3]*src[3]+2.*src[4]*src[4]+2.*src[5]*src[5];
1975 DataArrayDouble *DataArrayDouble::determinant() const throw(INTERP_KERNEL::Exception)
1978 DataArrayDouble *ret=DataArrayDouble::New();
1979 int nbOfTuple=getNumberOfTuples();
1980 ret->alloc(nbOfTuple,1);
1981 const double *src=getConstPointer();
1982 double *dest=ret->getPointer();
1983 switch(getNumberOfComponents())
1986 for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
1987 *dest=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
1990 for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
1991 *dest=src[0]*src[3]-src[1]*src[2];
1994 for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
1995 *dest=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
1999 throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
2003 DataArrayDouble *DataArrayDouble::eigenValues() const throw(INTERP_KERNEL::Exception)
2005 int nbOfComp=getNumberOfComponents();
2007 throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !");
2008 DataArrayDouble *ret=DataArrayDouble::New();
2009 int nbOfTuple=getNumberOfTuples();
2010 ret->alloc(nbOfTuple,3);
2011 const double *src=getConstPointer();
2012 double *dest=ret->getPointer();
2013 for(int i=0;i<nbOfTuple;i++,dest+=3,src+=6)
2014 INTERP_KERNEL::computeEigenValues6(src,dest);
2018 DataArrayDouble *DataArrayDouble::eigenVectors() const throw(INTERP_KERNEL::Exception)
2020 int nbOfComp=getNumberOfComponents();
2022 throw INTERP_KERNEL::Exception("DataArrayDouble::eigenVectors : must be an array with exactly 6 components !");
2023 DataArrayDouble *ret=DataArrayDouble::New();
2024 int nbOfTuple=getNumberOfTuples();
2025 ret->alloc(nbOfTuple,9);
2026 const double *src=getConstPointer();
2027 double *dest=ret->getPointer();
2028 for(int i=0;i<nbOfTuple;i++,src+=6)
2031 INTERP_KERNEL::computeEigenValues6(src,tmp);
2032 for(int j=0;j<3;j++,dest+=3)
2033 INTERP_KERNEL::computeEigenVectorForEigenValue6(src,tmp[j],1e-12,dest);
2038 DataArrayDouble *DataArrayDouble::inverse() const throw(INTERP_KERNEL::Exception)
2040 int nbOfComp=getNumberOfComponents();
2041 if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
2042 throw INTERP_KERNEL::Exception("DataArrayDouble::inversion : must be an array with 4,6 or 9 components !");
2043 DataArrayDouble *ret=DataArrayDouble::New();
2044 int nbOfTuple=getNumberOfTuples();
2045 ret->alloc(nbOfTuple,nbOfComp);
2046 const double *src=getConstPointer();
2047 double *dest=ret->getPointer();
2049 for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
2051 double det=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
2052 dest[0]=(src[1]*src[2]-src[4]*src[4])/det;
2053 dest[1]=(src[0]*src[2]-src[5]*src[5])/det;
2054 dest[2]=(src[0]*src[1]-src[3]*src[3])/det;
2055 dest[3]=(src[5]*src[4]-src[3]*src[2])/det;
2056 dest[4]=(src[5]*src[3]-src[0]*src[4])/det;
2057 dest[5]=(src[3]*src[4]-src[1]*src[5])/det;
2059 else if(nbOfComp==4)
2060 for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
2062 double det=src[0]*src[3]-src[1]*src[2];
2064 dest[1]=-src[1]/det;
2065 dest[2]=-src[2]/det;
2069 for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
2071 double det=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
2072 dest[0]=(src[4]*src[8]-src[7]*src[5])/det;
2073 dest[1]=(src[7]*src[2]-src[1]*src[8])/det;
2074 dest[2]=(src[1]*src[5]-src[4]*src[2])/det;
2075 dest[3]=(src[6]*src[5]-src[3]*src[8])/det;
2076 dest[4]=(src[0]*src[8]-src[6]*src[2])/det;
2077 dest[5]=(src[2]*src[3]-src[0]*src[5])/det;
2078 dest[6]=(src[3]*src[7]-src[6]*src[4])/det;
2079 dest[7]=(src[6]*src[1]-src[0]*src[7])/det;
2080 dest[8]=(src[0]*src[4]-src[1]*src[3])/det;
2085 DataArrayDouble *DataArrayDouble::trace() const throw(INTERP_KERNEL::Exception)
2087 int nbOfComp=getNumberOfComponents();
2088 if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
2089 throw INTERP_KERNEL::Exception("DataArrayDouble::trace : must be an array with 4,6 or 9 components !");
2090 DataArrayDouble *ret=DataArrayDouble::New();
2091 int nbOfTuple=getNumberOfTuples();
2092 ret->alloc(nbOfTuple,1);
2093 const double *src=getConstPointer();
2094 double *dest=ret->getPointer();
2096 for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
2097 *dest=src[0]+src[1]+src[2];
2098 else if(nbOfComp==4)
2099 for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
2100 *dest=src[0]+src[3];
2102 for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
2103 *dest=src[0]+src[4]+src[8];
2107 DataArrayDouble *DataArrayDouble::deviator() const throw(INTERP_KERNEL::Exception)
2109 int nbOfComp=getNumberOfComponents();
2111 throw INTERP_KERNEL::Exception("DataArrayDouble::deviator : must be an array with exactly 6 components !");
2112 DataArrayDouble *ret=DataArrayDouble::New();
2113 int nbOfTuple=getNumberOfTuples();
2114 ret->alloc(nbOfTuple,6);
2115 const double *src=getConstPointer();
2116 double *dest=ret->getPointer();
2117 for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
2119 double tr=(src[0]+src[1]+src[2])/3.;
2130 DataArrayDouble *DataArrayDouble::magnitude() const throw(INTERP_KERNEL::Exception)
2133 int nbOfComp=getNumberOfComponents();
2134 DataArrayDouble *ret=DataArrayDouble::New();
2135 int nbOfTuple=getNumberOfTuples();
2136 ret->alloc(nbOfTuple,1);
2137 const double *src=getConstPointer();
2138 double *dest=ret->getPointer();
2139 for(int i=0;i<nbOfTuple;i++,dest++)
2142 for(int j=0;j<nbOfComp;j++,src++)
2149 DataArrayDouble *DataArrayDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
2152 int nbOfComp=getNumberOfComponents();
2153 DataArrayDouble *ret=DataArrayDouble::New();
2154 int nbOfTuple=getNumberOfTuples();
2155 ret->alloc(nbOfTuple,1);
2156 const double *src=getConstPointer();
2157 double *dest=ret->getPointer();
2158 for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
2159 *dest=*std::max_element(src,src+nbOfComp);
2164 * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c this->getNumberOfTuples() tuples.
2165 * \n This returned array contains the euclidian distance for each tuple in \a this.
2166 * \n So the returned array can be seen as a dense symmetrical matrix whose diagonal elements are equal to 0.
2167 * \n The returned array has only one component (and **not** \c this->getNumberOfTuples() components to avoid the useless memory consumption due to components info in returned DataArrayDouble)
2169 * \warning use this method with care because it can leads to big amount of consumed memory !
2171 * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
2173 * \throw If \a this is not allocated.
2175 * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrixWith
2177 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception)
2180 int nbOfComp=getNumberOfComponents();
2181 int nbOfTuples=getNumberOfTuples();
2182 const double *inData=getConstPointer();
2183 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2184 ret->alloc(nbOfTuples*nbOfTuples,1);
2185 double *outData=ret->getPointer();
2186 for(int i=0;i<nbOfTuples;i++)
2188 outData[i*nbOfTuples+i]=0.;
2189 for(int j=i+1;j<nbOfTuples;j++)
2192 for(int k=0;k<nbOfComp;k++)
2193 { double delta=inData[i*nbOfComp+k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
2195 outData[i*nbOfTuples+j]=dist;
2196 outData[j*nbOfTuples+i]=dist;
2204 * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c other->getNumberOfTuples() tuples.
2205 * \n This returned array contains the euclidian distance for each tuple in \a other with each tuple in \a this.
2206 * \n So the returned array can be seen as a dense rectangular matrix with \c other->getNumberOfTuples() rows and \c this->getNumberOfTuples() columns.
2207 * \n Output rectangular matrix is sorted along rows.
2208 * \n The returned array has only one component (and **not** \c this->getNumberOfTuples() components to avoid the useless memory consumption due to components info in returned DataArrayDouble)
2210 * \warning use this method with care because it can leads to big amount of consumed memory !
2212 * \param [in] other DataArrayDouble instance having same number of components than \a this.
2213 * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
2215 * \throw If \a this is not allocated, or if \a other is null or if \a other is not allocated, or if number of components of \a other and \a this differs.
2217 * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrix
2219 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
2222 throw INTERP_KERNEL::Exception("DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : input parameter is null !");
2224 other->checkAllocated();
2225 int nbOfComp=getNumberOfComponents();
2226 int otherNbOfComp=other->getNumberOfComponents();
2227 if(nbOfComp!=otherNbOfComp)
2229 std::ostringstream oss; oss << "DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : this nb of compo=" << nbOfComp << " and other nb of compo=" << otherNbOfComp << ". It should match !";
2230 throw INTERP_KERNEL::Exception(oss.str().c_str());
2232 int nbOfTuples=getNumberOfTuples();
2233 int otherNbOfTuples=other->getNumberOfTuples();
2234 const double *inData=getConstPointer();
2235 const double *inDataOther=other->getConstPointer();
2236 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2237 ret->alloc(otherNbOfTuples*nbOfTuples,1);
2238 double *outData=ret->getPointer();
2239 for(int i=0;i<otherNbOfTuples;i++,inDataOther+=nbOfComp)
2241 for(int j=0;j<nbOfTuples;j++)
2244 for(int k=0;k<nbOfComp;k++)
2245 { double delta=inDataOther[k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
2247 outData[i*nbOfTuples+j]=dist;
2254 void DataArrayDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
2257 double *pt=getPointer();
2258 int nbOfTuple=getNumberOfTuples();
2259 int nbOfComp=getNumberOfComponents();
2261 for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
2262 std::sort(pt,pt+nbOfComp);
2264 for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
2265 std::sort(pt,pt+nbOfComp,std::greater<double>());
2269 void DataArrayDouble::abs() throw(INTERP_KERNEL::Exception)
2272 double *ptr=getPointer();
2273 int nbOfElems=getNbOfElems();
2274 std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
2277 void DataArrayDouble::applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception)
2280 double *ptr=getPointer()+compoId;
2281 int nbOfComp=getNumberOfComponents();
2282 int nbOfTuple=getNumberOfTuples();
2283 for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
2288 void DataArrayDouble::applyLin(double a, double b) throw(INTERP_KERNEL::Exception)
2291 double *ptr=getPointer();
2292 int nbOfElems=getNbOfElems();
2293 for(int i=0;i<nbOfElems;i++,ptr++)
2299 * This method applies the operation 'numerator/x' for each element 'x' in 'this'.
2300 * If there is a value in 'this' exactly equal to 0. an exception is thrown.
2301 * Warning if presence of null this is modified for each values previous than place where exception was thrown !
2303 void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception)
2306 double *ptr=getPointer();
2307 int nbOfElems=getNbOfElems();
2308 for(int i=0;i<nbOfElems;i++,ptr++)
2310 if(std::abs(*ptr)>std::numeric_limits<double>::min())
2312 *ptr=numerator/(*ptr);
2316 std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
2318 throw INTERP_KERNEL::Exception(oss.str().c_str());
2325 * This method returns a newly allocated array containing the application of negate on \b this.
2326 * This method throws an INTERP_KERNEL::Exception if \b this is not allocated.
2328 DataArrayDouble *DataArrayDouble::negate() const throw(INTERP_KERNEL::Exception)
2331 DataArrayDouble *newArr=DataArrayDouble::New();
2332 int nbOfTuples=getNumberOfTuples();
2333 int nbOfComp=getNumberOfComponents();
2334 newArr->alloc(nbOfTuples,nbOfComp);
2335 const double *cptr=getConstPointer();
2336 std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
2337 newArr->copyStringInfoFrom(*this);
2341 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
2344 DataArrayDouble *newArr=DataArrayDouble::New();
2345 int nbOfTuples=getNumberOfTuples();
2346 int oldNbOfComp=getNumberOfComponents();
2347 newArr->alloc(nbOfTuples,nbOfComp);
2348 const double *ptr=getConstPointer();
2349 double *ptrToFill=newArr->getPointer();
2350 for(int i=0;i<nbOfTuples;i++)
2352 if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
2354 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
2355 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
2356 oss << ") : Evaluation of function failed !";
2358 throw INTERP_KERNEL::Exception(oss.str().c_str());
2365 * This method returns a newly allocated array the caller should deal with.
2366 * The returned array will have 'nbOfComp' components (that can be different from this->getNumberOfComponents()) contrary to the other DataArrayDouble::applyFunc overload method.
2368 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
2371 INTERP_KERNEL::ExprParser expr(func);
2373 std::set<std::string> vars;
2374 expr.getTrueSetOfVars(vars);
2375 int oldNbOfComp=getNumberOfComponents();
2376 if((int)vars.size()>oldNbOfComp)
2378 std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
2379 oss << vars.size() << " variables : ";
2380 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
2381 throw INTERP_KERNEL::Exception(oss.str().c_str());
2383 std::vector<std::string> varsV(vars.begin(),vars.end());
2384 expr.prepareExprEvaluation(varsV,oldNbOfComp,nbOfComp);
2386 DataArrayDouble *newArr=DataArrayDouble::New();
2387 int nbOfTuples=getNumberOfTuples();
2388 newArr->alloc(nbOfTuples,nbOfComp);
2389 const double *ptr=getConstPointer();
2390 double *ptrToFill=newArr->getPointer();
2391 for(int i=0;i<nbOfTuples;i++)
2395 expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
2397 catch(INTERP_KERNEL::Exception& e)
2399 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
2400 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
2401 oss << ") : Evaluation of function failed !" << e.what();
2403 throw INTERP_KERNEL::Exception(oss.str().c_str());
2409 DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const throw(INTERP_KERNEL::Exception)
2412 INTERP_KERNEL::ExprParser expr(func);
2414 expr.prepareExprEvaluationVec();
2416 DataArrayDouble *newArr=DataArrayDouble::New();
2417 int nbOfTuples=getNumberOfTuples();
2418 int nbOfComp=getNumberOfComponents();
2419 newArr->alloc(nbOfTuples,nbOfComp);
2420 const double *ptr=getConstPointer();
2421 double *ptrToFill=newArr->getPointer();
2422 for(int i=0;i<nbOfTuples;i++)
2426 expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
2428 catch(INTERP_KERNEL::Exception& e)
2430 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
2431 std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
2432 oss << ") : Evaluation of function failed ! " << e.what();
2434 throw INTERP_KERNEL::Exception(oss.str().c_str());
2441 * This method is equivalent than DataArrayDouble::applyFunc, except that here components names are used to determine vars orders.
2442 * If 'func' contains vars that are not in \c this->getInfoOnComponent() an exception will be thrown.
2444 DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
2447 INTERP_KERNEL::ExprParser expr(func);
2449 std::set<std::string> vars;
2450 expr.getTrueSetOfVars(vars);
2451 int oldNbOfComp=getNumberOfComponents();
2452 if((int)vars.size()>oldNbOfComp)
2454 std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
2455 oss << vars.size() << " variables : ";
2456 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
2457 throw INTERP_KERNEL::Exception(oss.str().c_str());
2459 expr.prepareExprEvaluation(getVarsOnComponent(),oldNbOfComp,nbOfComp);
2461 DataArrayDouble *newArr=DataArrayDouble::New();
2462 int nbOfTuples=getNumberOfTuples();
2463 newArr->alloc(nbOfTuples,nbOfComp);
2464 const double *ptr=getConstPointer();
2465 double *ptrToFill=newArr->getPointer();
2466 for(int i=0;i<nbOfTuples;i++)
2470 expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
2472 catch(INTERP_KERNEL::Exception& e)
2474 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
2475 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
2476 oss << ") : Evaluation of function failed !" << e.what();
2478 throw INTERP_KERNEL::Exception(oss.str().c_str());
2485 * This method is equivalent than DataArrayDouble::applyFunc, except that here order of vars is passed explicitely in parameter.
2486 * In 'func' contains vars not in 'varsOrder' an exception will be thrown.
2488 DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception)
2491 INTERP_KERNEL::ExprParser expr(func);
2493 std::set<std::string> vars;
2494 expr.getTrueSetOfVars(vars);
2495 int oldNbOfComp=getNumberOfComponents();
2496 if((int)vars.size()>oldNbOfComp)
2498 std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
2499 oss << vars.size() << " variables : ";
2500 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
2501 throw INTERP_KERNEL::Exception(oss.str().c_str());
2503 expr.prepareExprEvaluation(varsOrder,oldNbOfComp,nbOfComp);
2505 DataArrayDouble *newArr=DataArrayDouble::New();
2506 int nbOfTuples=getNumberOfTuples();
2507 newArr->alloc(nbOfTuples,nbOfComp);
2508 const double *ptr=getConstPointer();
2509 double *ptrToFill=newArr->getPointer();
2510 for(int i=0;i<nbOfTuples;i++)
2514 expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
2516 catch(INTERP_KERNEL::Exception& e)
2518 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
2519 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
2520 oss << ") : Evaluation of function failed !" << e.what();
2522 throw INTERP_KERNEL::Exception(oss.str().c_str());
2528 void DataArrayDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
2531 INTERP_KERNEL::ExprParser expr(func);
2533 char *funcStr=expr.compileX86();
2535 *((void **)&funcPtr)=funcStr;//he he...
2537 double *ptr=getPointer();
2538 int nbOfComp=getNumberOfComponents();
2539 int nbOfTuples=getNumberOfTuples();
2540 int nbOfElems=nbOfTuples*nbOfComp;
2541 for(int i=0;i<nbOfElems;i++,ptr++)
2546 void DataArrayDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
2549 INTERP_KERNEL::ExprParser expr(func);
2551 char *funcStr=expr.compileX86_64();
2553 *((void **)&funcPtr)=funcStr;//he he...
2555 double *ptr=getPointer();
2556 int nbOfComp=getNumberOfComponents();
2557 int nbOfTuples=getNumberOfTuples();
2558 int nbOfElems=nbOfTuples*nbOfComp;
2559 for(int i=0;i<nbOfElems;i++,ptr++)
2564 DataArrayDoubleIterator *DataArrayDouble::iterator()
2566 return new DataArrayDoubleIterator(this);
2569 DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
2571 if(getNumberOfComponents()!=1)
2572 throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !");
2573 const double *cptr=getConstPointer();
2574 std::vector<int> res;
2575 int nbOfTuples=getNumberOfTuples();
2576 for(int i=0;i<nbOfTuples;i++,cptr++)
2577 if(*cptr>=vmin && *cptr<=vmax)
2579 DataArrayInt *ret=DataArrayInt::New();
2580 ret->alloc((int)res.size(),1);
2581 std::copy(res.begin(),res.end(),ret->getPointer());
2585 DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2587 std::vector<const DataArrayDouble *> tmp(2);
2588 tmp[0]=a1; tmp[1]=a2;
2589 return Aggregate(tmp);
2592 DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
2594 std::vector<const DataArrayDouble *> a;
2595 for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
2599 throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must contain at least one NON EMPTY DataArrayDouble !");
2600 std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
2601 int nbOfComp=(*it)->getNumberOfComponents();
2602 int nbt=(*it++)->getNumberOfTuples();
2603 for(int i=1;it!=a.end();it++,i++)
2605 if((*it)->getNumberOfComponents()!=nbOfComp)
2606 throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
2607 nbt+=(*it)->getNumberOfTuples();
2609 DataArrayDouble *ret=DataArrayDouble::New();
2610 ret->alloc(nbt,nbOfComp);
2611 double *pt=ret->getPointer();
2612 for(it=a.begin();it!=a.end();it++)
2613 pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
2614 ret->copyStringInfoFrom(*(a[0]));
2618 DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2620 std::vector<const DataArrayDouble *> arr(2);
2621 arr[0]=a1; arr[1]=a2;
2625 DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
2627 std::vector<const DataArrayDouble *> a;
2628 for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
2632 throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
2633 std::vector<const DataArrayDouble *>::const_iterator it;
2634 for(it=a.begin();it!=a.end();it++)
2635 (*it)->checkAllocated();
2637 int nbOfTuples=(*it)->getNumberOfTuples();
2638 std::vector<int> nbc(a.size());
2639 std::vector<const double *> pts(a.size());
2640 nbc[0]=(*it)->getNumberOfComponents();
2641 pts[0]=(*it++)->getConstPointer();
2642 for(int i=1;it!=a.end();it++,i++)
2644 if(nbOfTuples!=(*it)->getNumberOfTuples())
2645 throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
2646 nbc[i]=(*it)->getNumberOfComponents();
2647 pts[i]=(*it)->getConstPointer();
2649 int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
2650 DataArrayDouble *ret=DataArrayDouble::New();
2651 ret->alloc(nbOfTuples,totalNbOfComp);
2652 double *retPtr=ret->getPointer();
2653 for(int i=0;i<nbOfTuples;i++)
2654 for(int j=0;j<(int)a.size();j++)
2656 retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
2660 for(int i=0;i<(int)a.size();i++)
2661 for(int j=0;j<nbc[i];j++,k++)
2662 ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
2666 DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2669 throw INTERP_KERNEL::Exception("DataArrayDouble::Dot : input DataArrayDouble instance is NULL !");
2670 a1->checkAllocated();
2671 a2->checkAllocated();
2672 int nbOfComp=a1->getNumberOfComponents();
2673 if(nbOfComp!=a2->getNumberOfComponents())
2674 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
2675 int nbOfTuple=a1->getNumberOfTuples();
2676 if(nbOfTuple!=a2->getNumberOfTuples())
2677 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
2678 DataArrayDouble *ret=DataArrayDouble::New();
2679 ret->alloc(nbOfTuple,1);
2680 double *retPtr=ret->getPointer();
2681 const double *a1Ptr=a1->getConstPointer();
2682 const double *a2Ptr=a2->getConstPointer();
2683 for(int i=0;i<nbOfTuple;i++)
2686 for(int j=0;j<nbOfComp;j++)
2687 sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
2690 ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str());
2691 ret->setName(a1->getName().c_str());
2695 DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2698 throw INTERP_KERNEL::Exception("DataArrayDouble::CrossProduct : input DataArrayDouble instance is NULL !");
2699 int nbOfComp=a1->getNumberOfComponents();
2700 if(nbOfComp!=a2->getNumberOfComponents())
2701 throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
2703 throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
2704 int nbOfTuple=a1->getNumberOfTuples();
2705 if(nbOfTuple!=a2->getNumberOfTuples())
2706 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
2707 DataArrayDouble *ret=DataArrayDouble::New();
2708 ret->alloc(nbOfTuple,3);
2709 double *retPtr=ret->getPointer();
2710 const double *a1Ptr=a1->getConstPointer();
2711 const double *a2Ptr=a2->getConstPointer();
2712 for(int i=0;i<nbOfTuple;i++)
2714 retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
2715 retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
2716 retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
2718 ret->copyStringInfoFrom(*a1);
2722 DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2725 throw INTERP_KERNEL::Exception("DataArrayDouble::Max : input DataArrayDouble instance is NULL !");
2726 int nbOfComp=a1->getNumberOfComponents();
2727 if(nbOfComp!=a2->getNumberOfComponents())
2728 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
2729 int nbOfTuple=a1->getNumberOfTuples();
2730 if(nbOfTuple!=a2->getNumberOfTuples())
2731 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
2732 DataArrayDouble *ret=DataArrayDouble::New();
2733 ret->alloc(nbOfTuple,nbOfComp);
2734 double *retPtr=ret->getPointer();
2735 const double *a1Ptr=a1->getConstPointer();
2736 const double *a2Ptr=a2->getConstPointer();
2737 int nbElem=nbOfTuple*nbOfComp;
2738 for(int i=0;i<nbElem;i++)
2739 retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
2740 ret->copyStringInfoFrom(*a1);
2744 DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2747 throw INTERP_KERNEL::Exception("DataArrayDouble::Min : input DataArrayDouble instance is NULL !");
2748 int nbOfComp=a1->getNumberOfComponents();
2749 if(nbOfComp!=a2->getNumberOfComponents())
2750 throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
2751 int nbOfTuple=a1->getNumberOfTuples();
2752 if(nbOfTuple!=a2->getNumberOfTuples())
2753 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
2754 DataArrayDouble *ret=DataArrayDouble::New();
2755 ret->alloc(nbOfTuple,nbOfComp);
2756 double *retPtr=ret->getPointer();
2757 const double *a1Ptr=a1->getConstPointer();
2758 const double *a2Ptr=a2->getConstPointer();
2759 int nbElem=nbOfTuple*nbOfComp;
2760 for(int i=0;i<nbElem;i++)
2761 retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
2762 ret->copyStringInfoFrom(*a1);
2766 DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2769 throw INTERP_KERNEL::Exception("DataArrayDouble::Add : input DataArrayDouble instance is NULL !");
2770 int nbOfTuple=a1->getNumberOfTuples();
2771 int nbOfTuple2=a2->getNumberOfTuples();
2772 int nbOfComp=a1->getNumberOfComponents();
2773 int nbOfComp2=a2->getNumberOfComponents();
2774 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
2775 if(nbOfTuple==nbOfTuple2)
2777 if(nbOfComp==nbOfComp2)
2779 ret=DataArrayDouble::New();
2780 ret->alloc(nbOfTuple,nbOfComp);
2781 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
2782 ret->copyStringInfoFrom(*a1);
2786 int nbOfCompMin,nbOfCompMax;
2787 const DataArrayDouble *aMin, *aMax;
2788 if(nbOfComp>nbOfComp2)
2790 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
2795 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
2800 ret=DataArrayDouble::New();
2801 ret->alloc(nbOfTuple,nbOfCompMax);
2802 const double *aMinPtr=aMin->getConstPointer();
2803 const double *aMaxPtr=aMax->getConstPointer();
2804 double *res=ret->getPointer();
2805 for(int i=0;i<nbOfTuple;i++)
2806 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
2807 ret->copyStringInfoFrom(*aMax);
2810 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
2813 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
2815 if(nbOfComp==nbOfComp2)
2817 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
2818 const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
2819 const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
2820 const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
2821 ret=DataArrayDouble::New();
2822 ret->alloc(nbOfTupleMax,nbOfComp);
2823 double *res=ret->getPointer();
2824 for(int i=0;i<nbOfTupleMax;i++)
2825 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
2826 ret->copyStringInfoFrom(*aMax);
2829 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
2832 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
2837 void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
2840 throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
2841 const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !";
2842 int nbOfTuple=getNumberOfTuples();
2843 int nbOfTuple2=other->getNumberOfTuples();
2844 int nbOfComp=getNumberOfComponents();
2845 int nbOfComp2=other->getNumberOfComponents();
2846 if(nbOfTuple==nbOfTuple2)
2848 if(nbOfComp==nbOfComp2)
2850 std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
2852 else if(nbOfComp2==1)
2854 double *ptr=getPointer();
2855 const double *ptrc=other->getConstPointer();
2856 for(int i=0;i<nbOfTuple;i++)
2857 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
2860 throw INTERP_KERNEL::Exception(msg);
2862 else if(nbOfTuple2==1)
2864 if(nbOfComp2==nbOfComp)
2866 double *ptr=getPointer();
2867 const double *ptrc=other->getConstPointer();
2868 for(int i=0;i<nbOfTuple;i++)
2869 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
2872 throw INTERP_KERNEL::Exception(msg);
2875 throw INTERP_KERNEL::Exception(msg);
2879 DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2882 throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !");
2883 int nbOfTuple1=a1->getNumberOfTuples();
2884 int nbOfTuple2=a2->getNumberOfTuples();
2885 int nbOfComp1=a1->getNumberOfComponents();
2886 int nbOfComp2=a2->getNumberOfComponents();
2887 if(nbOfTuple2==nbOfTuple1)
2889 if(nbOfComp1==nbOfComp2)
2891 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2892 ret->alloc(nbOfTuple2,nbOfComp1);
2893 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
2894 ret->copyStringInfoFrom(*a1);
2898 else if(nbOfComp2==1)
2900 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2901 ret->alloc(nbOfTuple1,nbOfComp1);
2902 const double *a2Ptr=a2->getConstPointer();
2903 const double *a1Ptr=a1->getConstPointer();
2904 double *res=ret->getPointer();
2905 for(int i=0;i<nbOfTuple1;i++)
2906 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<double>(),a2Ptr[i]));
2907 ret->copyStringInfoFrom(*a1);
2913 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
2917 else if(nbOfTuple2==1)
2919 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
2920 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
2921 ret->alloc(nbOfTuple1,nbOfComp1);
2922 const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
2923 double *pt=ret->getPointer();
2924 for(int i=0;i<nbOfTuple1;i++)
2925 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<double>());
2926 ret->copyStringInfoFrom(*a1);
2932 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
2937 void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
2940 throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !");
2941 const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual !";
2942 int nbOfTuple=getNumberOfTuples();
2943 int nbOfTuple2=other->getNumberOfTuples();
2944 int nbOfComp=getNumberOfComponents();
2945 int nbOfComp2=other->getNumberOfComponents();
2946 if(nbOfTuple==nbOfTuple2)
2948 if(nbOfComp==nbOfComp2)
2950 std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
2952 else if(nbOfComp2==1)
2954 double *ptr=getPointer();
2955 const double *ptrc=other->getConstPointer();
2956 for(int i=0;i<nbOfTuple;i++)
2957 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*ptrc++));
2960 throw INTERP_KERNEL::Exception(msg);
2962 else if(nbOfTuple2==1)
2964 if(nbOfComp2==nbOfComp)
2966 double *ptr=getPointer();
2967 const double *ptrc=other->getConstPointer();
2968 for(int i=0;i<nbOfTuple;i++)
2969 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
2972 throw INTERP_KERNEL::Exception(msg);
2975 throw INTERP_KERNEL::Exception(msg);
2979 DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
2982 throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : input DataArrayDouble instance is NULL !");
2983 int nbOfTuple=a1->getNumberOfTuples();
2984 int nbOfTuple2=a2->getNumberOfTuples();
2985 int nbOfComp=a1->getNumberOfComponents();
2986 int nbOfComp2=a2->getNumberOfComponents();
2987 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
2988 if(nbOfTuple==nbOfTuple2)
2990 if(nbOfComp==nbOfComp2)
2992 ret=DataArrayDouble::New();
2993 ret->alloc(nbOfTuple,nbOfComp);
2994 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<double>());
2995 ret->copyStringInfoFrom(*a1);
2999 int nbOfCompMin,nbOfCompMax;
3000 const DataArrayDouble *aMin, *aMax;
3001 if(nbOfComp>nbOfComp2)
3003 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
3008 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
3013 ret=DataArrayDouble::New();
3014 ret->alloc(nbOfTuple,nbOfCompMax);
3015 const double *aMinPtr=aMin->getConstPointer();
3016 const double *aMaxPtr=aMax->getConstPointer();
3017 double *res=ret->getPointer();
3018 for(int i=0;i<nbOfTuple;i++)
3019 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
3020 ret->copyStringInfoFrom(*aMax);
3023 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
3026 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
3028 if(nbOfComp==nbOfComp2)
3030 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
3031 const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
3032 const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
3033 const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
3034 ret=DataArrayDouble::New();
3035 ret->alloc(nbOfTupleMax,nbOfComp);
3036 double *res=ret->getPointer();
3037 for(int i=0;i<nbOfTupleMax;i++)
3038 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<double>());
3039 ret->copyStringInfoFrom(*aMax);
3042 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
3045 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
3050 void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
3053 throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
3054 const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
3055 int nbOfTuple=getNumberOfTuples();
3056 int nbOfTuple2=other->getNumberOfTuples();
3057 int nbOfComp=getNumberOfComponents();
3058 int nbOfComp2=other->getNumberOfComponents();
3059 if(nbOfTuple==nbOfTuple2)
3061 if(nbOfComp==nbOfComp2)
3063 std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
3065 else if(nbOfComp2==1)
3067 double *ptr=getPointer();
3068 const double *ptrc=other->getConstPointer();
3069 for(int i=0;i<nbOfTuple;i++)
3070 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<double>(),*ptrc++));
3073 throw INTERP_KERNEL::Exception(msg);
3075 else if(nbOfTuple2==1)
3077 if(nbOfComp2==nbOfComp)
3079 double *ptr=getPointer();
3080 const double *ptrc=other->getConstPointer();
3081 for(int i=0;i<nbOfTuple;i++)
3082 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<double>());
3085 throw INTERP_KERNEL::Exception(msg);
3088 throw INTERP_KERNEL::Exception(msg);
3092 DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
3095 throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !");
3096 int nbOfTuple1=a1->getNumberOfTuples();
3097 int nbOfTuple2=a2->getNumberOfTuples();
3098 int nbOfComp1=a1->getNumberOfComponents();
3099 int nbOfComp2=a2->getNumberOfComponents();
3100 if(nbOfTuple2==nbOfTuple1)
3102 if(nbOfComp1==nbOfComp2)
3104 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3105 ret->alloc(nbOfTuple2,nbOfComp1);
3106 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
3107 ret->copyStringInfoFrom(*a1);
3111 else if(nbOfComp2==1)
3113 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3114 ret->alloc(nbOfTuple1,nbOfComp1);
3115 const double *a2Ptr=a2->getConstPointer();
3116 const double *a1Ptr=a1->getConstPointer();
3117 double *res=ret->getPointer();
3118 for(int i=0;i<nbOfTuple1;i++)
3119 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
3120 ret->copyStringInfoFrom(*a1);
3126 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
3130 else if(nbOfTuple2==1)
3132 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
3133 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3134 ret->alloc(nbOfTuple1,nbOfComp1);
3135 const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
3136 double *pt=ret->getPointer();
3137 for(int i=0;i<nbOfTuple1;i++)
3138 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<double>());
3139 ret->copyStringInfoFrom(*a1);
3145 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
3150 void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
3153 throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !");
3154 const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
3155 int nbOfTuple=getNumberOfTuples();
3156 int nbOfTuple2=other->getNumberOfTuples();
3157 int nbOfComp=getNumberOfComponents();
3158 int nbOfComp2=other->getNumberOfComponents();
3159 if(nbOfTuple==nbOfTuple2)
3161 if(nbOfComp==nbOfComp2)
3163 std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
3165 else if(nbOfComp2==1)
3167 double *ptr=getPointer();
3168 const double *ptrc=other->getConstPointer();
3169 for(int i=0;i<nbOfTuple;i++)
3170 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
3173 throw INTERP_KERNEL::Exception(msg);
3175 else if(nbOfTuple2==1)
3177 if(nbOfComp2==nbOfComp)
3179 double *ptr=getPointer();
3180 const double *ptrc=other->getConstPointer();
3181 for(int i=0;i<nbOfTuple;i++)
3182 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
3185 throw INTERP_KERNEL::Exception(msg);
3188 throw INTERP_KERNEL::Exception(msg);
3193 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
3196 void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
3201 tinyInfo[0]=getNumberOfTuples();
3202 tinyInfo[1]=getNumberOfComponents();
3212 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
3215 void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
3219 int nbOfCompo=getNumberOfComponents();
3220 tinyInfo.resize(nbOfCompo+1);
3221 tinyInfo[0]=getName();
3222 for(int i=0;i<nbOfCompo;i++)
3223 tinyInfo[i+1]=getInfoOnComponent(i);
3228 tinyInfo[0]=getName();
3233 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
3234 * This method returns if a feeding is needed.
3236 bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
3238 int nbOfTuple=tinyInfoI[0];
3239 int nbOfComp=tinyInfoI[1];
3240 if(nbOfTuple!=-1 || nbOfComp!=-1)
3242 alloc(nbOfTuple,nbOfComp);
3249 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
3251 void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
3253 setName(tinyInfoS[0].c_str());
3256 int nbOfCompo=getNumberOfComponents();
3257 for(int i=0;i<nbOfCompo;i++)
3258 setInfoOnComponent(i,tinyInfoS[i+1].c_str());
3262 DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
3267 if(_da->isAllocated())
3269 _nb_comp=da->getNumberOfComponents();
3270 _nb_tuple=da->getNumberOfTuples();
3271 _pt=da->getPointer();
3276 DataArrayDoubleIterator::~DataArrayDoubleIterator()
3282 DataArrayDoubleTuple *DataArrayDoubleIterator::nextt()
3284 if(_tuple_id<_nb_tuple)
3287 DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
3295 DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
3300 std::string DataArrayDoubleTuple::repr() const
3302 std::ostringstream oss; oss.precision(15); oss << "(";
3303 for(int i=0;i<_nb_of_compo-1;i++)
3304 oss << _pt[i] << ", ";
3305 oss << _pt[_nb_of_compo-1] << ")";
3309 double DataArrayDoubleTuple::doubleValue() const throw(INTERP_KERNEL::Exception)
3313 throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
3317 * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayDouble::decrRef.
3318 * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayDouble::useArray with ownership set to \b false.
3319 * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or
3320 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
3322 DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
3324 if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
3326 DataArrayDouble *ret=DataArrayDouble::New();
3327 ret->useArray(_pt,false,CPP_DEALLOC,nbOfTuples,nbOfCompo);
3332 std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
3333 oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
3334 throw INTERP_KERNEL::Exception(oss.str().c_str());
3338 DataArrayInt *DataArrayInt::New()
3340 return new DataArrayInt;
3343 bool DataArrayInt::isAllocated() const
3345 return getConstPointer()!=0;
3348 void DataArrayInt::checkAllocated() const throw(INTERP_KERNEL::Exception)
3351 throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
3355 * This method differs from DataArray::setInfoOnComponents in the sense that if 'this->getNumberOfComponents()!=info.size()'
3356 * and if 'this' is not allocated it will change the number of components of 'this'.
3357 * If 'this->getNumberOfComponents()==info.size()' the behaviour is the same than DataArray::setInfoOnComponents method.
3358 * If 'this->getNumberOfComponents()!=info.size()' and the 'this' is already allocated an exception will be thrown.
3360 void DataArrayInt::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
3362 if(getNumberOfComponents()!=(int)info.size())
3365 _info_on_compo=info;
3368 std::ostringstream oss; oss << "DataArrayInt::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " and this is already allocated !";
3369 throw INTERP_KERNEL::Exception(oss.str().c_str());
3373 _info_on_compo=info;
3377 * This method returns the only one value in 'this', if and only if number of elements (nb of tuples * nb of components) is equal to 1, and that 'this' is allocated.
3378 * If one or more conditions is not fulfilled an exception will be thrown.
3380 int DataArrayInt::intValue() const throw(INTERP_KERNEL::Exception)
3384 if(getNbOfElems()==1)
3386 return *getConstPointer();
3389 throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is allocated but number of elements is not equal to 1 !");
3392 throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
3396 * This method expects that \b this is well allocated. If not an INTERP_KERNEL::Exception will be thrown. This method is useful for a quick comparison of many instances of DataArrayInt.
3398 int DataArrayInt::getHashCode() const throw(INTERP_KERNEL::Exception)
3401 int nbOfElems=getNbOfElems();
3402 int ret=nbOfElems*65536;
3407 const int *pt=begin();
3408 for(int i=0;i<nbOfElems;i+=delta)
3409 ret0+=pt[i] & 0x1FFF;
3414 * This method should be called on an allocated DataArrayInt instance. If not an exception will be throw !
3415 * This method checks the number of tupes. If it is equal to 0, it returns true, if not false is returned.
3417 bool DataArrayInt::empty() const throw(INTERP_KERNEL::Exception)
3420 return getNumberOfTuples()==0;
3423 DataArrayInt *DataArrayInt::deepCpy() const
3425 return new DataArrayInt(*this);
3428 DataArrayInt *DataArrayInt::performCpy(bool dCpy) const
3435 return const_cast<DataArrayInt *>(this);
3439 void DataArrayInt::cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception)
3441 other.checkAllocated();
3442 int nbOfTuples=other.getNumberOfTuples();
3443 int nbOfComp=other.getNumberOfComponents();
3444 allocIfNecessary(nbOfTuples,nbOfComp);
3445 int nbOfElems=nbOfTuples*nbOfComp;
3446 int *pt=getPointer();
3447 const int *ptI=other.getConstPointer();
3448 for(int i=0;i<nbOfElems;i++)
3450 copyStringInfoFrom(other);
3453 void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo)
3457 if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
3458 alloc(nbOfTuple,nbOfCompo);
3461 alloc(nbOfTuple,nbOfCompo);
3464 void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
3466 if(nbOfTuple<0 || nbOfCompo<0)
3467 throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
3468 _nb_of_tuples=nbOfTuple;
3469 _info_on_compo.resize(nbOfCompo);
3470 _mem.alloc(nbOfCompo*_nb_of_tuples);
3474 void DataArrayInt::fillWithZero() throw(INTERP_KERNEL::Exception)
3477 _mem.fillWithValue(0);
3481 void DataArrayInt::fillWithValue(int val) throw(INTERP_KERNEL::Exception)
3484 _mem.fillWithValue(val);
3488 void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception)
3491 if(getNumberOfComponents()!=1)
3492 throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
3493 int *ptr=getPointer();
3494 int ntuples=getNumberOfTuples();
3495 for(int i=0;i<ntuples;i++)
3500 std::string DataArrayInt::repr() const
3502 std::ostringstream ret;
3507 std::string DataArrayInt::reprZip() const
3509 std::ostringstream ret;
3514 void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
3516 std::string idt(indent,' ');
3517 ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
3518 ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
3519 std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
3520 ofs << std::endl << idt << "</DataArray>\n";
3523 void DataArrayInt::reprStream(std::ostream& stream) const
3525 stream << "Name of int array : \"" << _name << "\"\n";
3526 reprWithoutNameStream(stream);
3529 void DataArrayInt::reprZipStream(std::ostream& stream) const
3531 stream << "Name of int array : \"" << _name << "\"\n";
3532 reprZipWithoutNameStream(stream);
3535 void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const
3537 DataArray::reprWithoutNameStream(stream);
3538 _mem.repr(getNumberOfComponents(),stream);
3541 void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const
3543 DataArray::reprWithoutNameStream(stream);
3544 _mem.reprZip(getNumberOfComponents(),stream);
3548 * This method expects a number of components equal to 1.
3549 * This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v is replaced by
3550 * indArr[v] where 'indArr' is defined by ['indArrBg','indArrEnd').
3551 * This method is safe that is to say if there is a value in 'this' not in [0,std::distance('indArrBg','indArrEnd')) an exception
3554 void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception)
3556 if(getNumberOfComponents()!=1)
3557 throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
3558 int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
3559 int nbOfTuples=getNumberOfTuples();
3560 int *pt=getPointer();
3561 for(int i=0;i<nbOfTuples;i++,pt++)
3563 if(*pt>=0 && *pt<nbElemsIn)
3567 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
3568 throw INTERP_KERNEL::Exception(oss.str().c_str());
3575 * 'this' should be allocated and with numberOfComponents set to one. If not an exception will be thrown.
3576 * This method takes as input an array defined by ['arrBg','arrEnd'). The size of the array (std::distance(arrBg,arrEnd)) is equal to the number of cast + 1.
3577 * The values contained in ['arrBg','arrEnd') should be sorted ascendently. No check of this will be done. If not the result is not waranted.
3578 * For each cast j the value range that defines the cast is equal to [arrBg[j],arrBg[j+1]).
3579 * This method returns three arrays (to be managed by the caller).
3580 * This method is typically usefull for entity number spliting by types for example.
3581 * Example : If 'this' contains [6,5,0,3,2,7,8,1,4] and if ['arrBg','arrEnd') contains [0,4,9] then the output of this method will be :
3582 * - 'castArr' : [1,1,0,0,0,1,1,0,1]
3583 * - 'rankInsideCast' : [2,1,0,3,2,3,4,1,0]
3584 * - 'return' : [0,1]
3586 * @param castArr is a returned param has the same number of tuples than 'this' and number of components set to one. In case of sucess, this param contains for each tuple in 'this' in which cast it holds.
3587 * @param rankInsideCast is an another returned param has the same number of tuples than 'this' and number of components set to one too. In case of sucess, this param contains for each tuple its rank inside its cast.
3588 * @param castsPresent the casts that 'this' contains.
3589 * @throw if a value in 'this' is greater or equal to the last value of ['arrBg','arrEnd')
3591 void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
3592 DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception)
3594 if(getNumberOfComponents()!=1)
3595 throw INTERP_KERNEL::Exception("Call splitByValueRange method on DataArrayInt with only one component, you can call 'rearrange' method before !");
3596 int nbOfTuples=getNumberOfTuples();
3597 std::size_t nbOfCast=std::distance(arrBg,arrEnd);
3599 throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !");
3601 const int *work=getConstPointer();
3602 typedef std::reverse_iterator<const int *> rintstart;
3603 rintstart bg(arrEnd);//OK no problem because size of 'arr' is greater of equal 2
3604 rintstart end2(arrBg);
3605 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
3606 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=DataArrayInt::New();
3607 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret3=DataArrayInt::New();
3608 ret1->alloc(nbOfTuples,1);
3609 ret2->alloc(nbOfTuples,1);
3610 int *ret1Ptr=ret1->getPointer();
3611 int *ret2Ptr=ret2->getPointer();
3612 std::set<std::size_t> castsDetected;
3613 for(int i=0;i<nbOfTuples;i++)
3615 rintstart res=std::find_if(bg,end2,std::bind2nd(std::less_equal<int>(), work[i]));
3616 std::size_t pos=std::distance(bg,res);
3617 std::size_t pos2=nbOfCast-pos;
3620 ret1Ptr[i]=(int)pos2;
3621 ret2Ptr[i]=work[i]-arrBg[pos2];
3622 castsDetected.insert(pos2);
3626 std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " whereas the last value is " << *bg;
3627 throw INTERP_KERNEL::Exception(oss.str().c_str());
3630 ret3->alloc((int)castsDetected.size(),1);
3631 std::copy(castsDetected.begin(),castsDetected.end(),ret3->getPointer());
3635 rankInsideCast=ret2;
3641 * This method expects a number of components equal to 1.
3642 * This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v on place i, place indArr[v] will have
3644 * indArr[v] where 'indArr' is defined by ['indArrBg','indArrEnd').
3645 * This method is half/safe that is to say if there is location i so that indArr[v] is not in [0,this->getNumberOfTuples()) an exception
3648 DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception)
3650 if(getNumberOfComponents()!=1)
3651 throw INTERP_KERNEL::Exception("Call transformWithIndArrR method on DataArrayInt with only one component, you can call 'rearrange' method before !");
3652 int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
3653 int nbOfTuples=getNumberOfTuples();
3654 const int *pt=getConstPointer();
3655 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
3656 ret->alloc(nbOfTuples,1);
3657 ret->fillWithValue(-1);
3658 int *tmp=ret->getPointer();
3659 for(int i=0;i<nbOfTuples;i++,pt++)
3661 int pos=indArrBg[*pt];
3662 if(pos>=0 && pos<nbElemsIn)
3666 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
3667 throw INTERP_KERNEL::Exception(oss.str().c_str());
3675 * This method invert array 'di' that is a conversion map from Old to New numbering to New to Old numbering.
3677 DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
3679 DataArrayInt *ret=DataArrayInt::New();
3680 ret->alloc(newNbOfElem,1);
3681 int nbOfOldNodes=getNumberOfTuples();
3682 const int *old2New=getConstPointer();
3683 int *pt=ret->getPointer();
3684 for(int i=0;i!=nbOfOldNodes;i++)
3691 * This method invert array 'di' that is a conversion map from New to old numbering to Old to New numbering.
3693 DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
3695 DataArrayInt *ret=DataArrayInt::New();
3696 ret->alloc(oldNbOfElem,1);
3697 const int *new2Old=getConstPointer();
3698 int *pt=ret->getPointer();
3699 std::fill(pt,pt+oldNbOfElem,-1);
3700 int nbOfNewElems=getNumberOfTuples();
3701 for(int i=0;i<nbOfNewElems;i++)
3706 bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const
3708 if(!areInfoEqualsIfNotWhy(other,reason))
3710 return _mem.isEqual(other._mem,0,reason);
3713 bool DataArrayInt::isEqual(const DataArrayInt& other) const
3716 return isEqualIfNotWhy(other,tmp);
3719 bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const
3722 return _mem.isEqual(other._mem,0,tmp);
3725 bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
3727 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a=deepCpy();
3728 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> b=other.deepCpy();
3731 return a->isEqualWithoutConsideringStr(*b);
3734 void DataArrayInt::sort(bool asc) throw(INTERP_KERNEL::Exception)
3737 if(getNumberOfComponents()!=1)
3738 throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !");
3742 void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception)
3745 if(getNumberOfComponents()!=1)
3746 throw INTERP_KERNEL::Exception("DataArrayInt::reverse : only supported with 'this' array with ONE component !");
3751 * This method expects that 'this' and 'other' have the same number of tuples and exactly one component both. If not an exception will be thrown.
3752 * This method retrieves a newly created array with same number of tuples than 'this' and 'other' with one component.
3753 * The returned array 'ret' contains the correspondance from 'this' to 'other' that is to say for every i so that 0<=i<getNumberOfTuples()
3754 * other.getIJ(i,0)==this->getIJ(ret->getIJ(i),0)
3755 * If such permutation is not possible because it exists some elements in 'other' not in 'this', an exception will be thrown.
3757 DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
3759 if(getNumberOfComponents()!=1 || other.getNumberOfComponents()!=1)
3760 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' have to have exactly ONE component !");
3761 int nbTuple=getNumberOfTuples();
3762 if(nbTuple!=other.getNumberOfTuples())
3763 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' must have the same number of tuple !");
3764 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
3765 ret->alloc(nbTuple,1);
3766 ret->fillWithValue(-1);
3767 const int *pt=getConstPointer();
3768 std::map<int,int> mm;
3769 for(int i=0;i<nbTuple;i++)
3771 pt=other.getConstPointer();
3772 int *retToFill=ret->getPointer();
3773 for(int i=0;i<nbTuple;i++)
3775 std::map<int,int>::const_iterator it=mm.find(pt[i]);
3778 std::ostringstream oss; oss << "DataArrayInt::buildPermutationArr : Arrays mismatch : element (" << pt[i] << ") in 'other' not findable in 'this' !";
3779 throw INTERP_KERNEL::Exception(oss.str().c_str());
3781 retToFill[i]=(*it).second;
3787 void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
3789 _nb_of_tuples=nbOfTuple;
3790 _info_on_compo.resize(nbOfCompo);
3791 _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
3795 DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
3798 throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
3799 int *tab=_mem.fromNoInterlace(getNumberOfComponents());
3800 DataArrayInt *ret=DataArrayInt::New();
3801 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
3805 DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception)
3808 throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
3809 int *tab=_mem.toNoInterlace(getNumberOfComponents());
3810 DataArrayInt *ret=DataArrayInt::New();
3811 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
3815 void DataArrayInt::renumberInPlace(const int *old2New)
3817 int nbTuples=getNumberOfTuples();
3818 int nbOfCompo=getNumberOfComponents();
3819 int *tmp=new int[nbTuples*nbOfCompo];
3820 const int *iptr=getConstPointer();
3821 for(int i=0;i<nbTuples;i++)
3822 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
3823 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
3828 void DataArrayInt::renumberInPlaceR(const int *new2Old)
3830 int nbTuples=getNumberOfTuples();
3831 int nbOfCompo=getNumberOfComponents();
3832 int *tmp=new int[nbTuples*nbOfCompo];
3833 const int *iptr=getConstPointer();
3834 for(int i=0;i<nbTuples;i++)
3835 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
3836 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
3842 * This method expects that 'this' is allocated, if not an exception is thrown.
3843 * This method in case of success returns a newly created array the user should deal with.
3844 * In the case of having a renumber array in "old to new" format. More info on renumbering \ref MEDCouplingArrayRenumbering "here".
3846 DataArrayInt *DataArrayInt::renumber(const int *old2New) const
3848 int nbTuples=getNumberOfTuples();
3849 int nbOfCompo=getNumberOfComponents();
3850 DataArrayInt *ret=DataArrayInt::New();
3851 ret->alloc(nbTuples,nbOfCompo);
3852 ret->copyStringInfoFrom(*this);
3853 const int *iptr=getConstPointer();
3854 int *optr=ret->getPointer();
3855 for(int i=0;i<nbTuples;i++)
3856 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
3857 ret->copyStringInfoFrom(*this);
3861 DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const
3863 int nbTuples=getNumberOfTuples();
3864 int nbOfCompo=getNumberOfComponents();
3865 DataArrayInt *ret=DataArrayInt::New();
3866 ret->alloc(nbTuples,nbOfCompo);
3867 ret->copyStringInfoFrom(*this);
3868 const int *iptr=getConstPointer();
3869 int *optr=ret->getPointer();
3870 for(int i=0;i<nbTuples;i++)
3871 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+nbOfCompo*i);
3872 ret->copyStringInfoFrom(*this);
3877 * Idem DataArrayDouble::renumber method except that the number of tuples is reduced.
3878 * That is to say that it is expected that newNbOfTuple<this->getNumberOfTuples().
3879 * ['old2New','old2New'+getNumberOfTuples()) defines a range containing old to new array. For every negative value in ['old2NewBg','old2New'getNumberOfTuples()) the corresponding tuple is
3882 DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const
3884 int nbTuples=getNumberOfTuples();
3885 int nbOfCompo=getNumberOfComponents();
3886 DataArrayInt *ret=DataArrayInt::New();
3887 ret->alloc(newNbOfTuple,nbOfCompo);
3888 const int *iptr=getConstPointer();
3889 int *optr=ret->getPointer();
3890 for(int i=0;i<nbTuples;i++)
3894 std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
3896 ret->copyStringInfoFrom(*this);
3901 * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here.
3902 * This method is equavalent to DataArrayInt::renumberAndReduce except that convention in input is new2old and \b not old2new.
3904 DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
3906 DataArrayInt *ret=DataArrayInt::New();
3907 int nbComp=getNumberOfComponents();
3908 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
3909 ret->copyStringInfoFrom(*this);
3910 int *pt=ret->getPointer();
3911 const int *srcPt=getConstPointer();
3913 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
3914 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
3915 ret->copyStringInfoFrom(*this);
3920 * This method is equivalent to DataArrayInt::selectByTupleId except that an analyze to the content of input range to check that it will not lead to memory corruption !
3922 DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
3924 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
3925 int nbComp=getNumberOfComponents();
3926 int oldNbOfTuples=getNumberOfTuples();
3927 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
3928 ret->copyStringInfoFrom(*this);
3929 int *pt=ret->getPointer();
3930 const int *srcPt=getConstPointer();
3932 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
3933 if(*w>=0 && *w<oldNbOfTuples)
3934 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
3936 throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
3937 ret->copyStringInfoFrom(*this);
3943 * Idem than DataArrayInt::selectByTupleIdSafe except that the input array is not constructed explicitely.
3944 * The convention is as python one. ['bg','end2') with steps of 'step'.
3945 * Returns a newly created array.
3946 * This method is an extension of DataArrayInt::substr method.
3948 * \sa DataArrayInt::substr
3950 DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
3952 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
3953 int nbComp=getNumberOfComponents();
3954 int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : ");
3955 ret->alloc(newNbOfTuples,nbComp);
3956 int *pt=ret->getPointer();
3957 const int *srcPt=getConstPointer()+bg*nbComp;
3958 for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
3959 std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
3960 ret->copyStringInfoFrom(*this);
3966 * This method returns a newly allocated array that is the concatenation of all tuples ranges in param 'ranges'.
3967 * Each pair in input 'ranges' is in [begin,end) format. If there is a range in 'ranges' so that end is before begin an exception
3968 * will be thrown. If there is a range in 'ranges' so that end is greater than number of tuples of 'this', an exception will be thrown too.
3970 DataArrayInt *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
3973 int nbOfComp=getNumberOfComponents();
3974 int nbOfTuplesThis=getNumberOfTuples();
3977 DataArrayInt *ret=DataArrayInt::New();
3978 ret->alloc(0,nbOfComp);
3979 ret->copyStringInfoFrom(*this);
3982 int ref=ranges.front().first;
3984 bool isIncreasing=true;
3985 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
3987 if((*it).first<=(*it).second)
3989 if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
3991 nbOfTuples+=(*it).second-(*it).first;
3993 isIncreasing=ref<=(*it).first;
3998 std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
3999 oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
4000 throw INTERP_KERNEL::Exception(oss.str().c_str());
4005 std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
4006 oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
4007 throw INTERP_KERNEL::Exception(oss.str().c_str());
4010 if(isIncreasing && nbOfTuplesThis==nbOfTuples)
4012 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
4013 ret->alloc(nbOfTuples,nbOfComp);
4014 ret->copyStringInfoFrom(*this);
4015 const int *src=getConstPointer();
4016 int *work=ret->getPointer();
4017 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
4018 work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
4024 * This method works only for arrays having single component.
4025 * If this contains the array a1 containing [9,10,0,6,4,11,3,7] this method returns an array a2 [5,6,0,3,2,7,1,4].
4026 * By doing a1.renumber(a2) the user will obtain array a3 equal to a1 sorted.
4027 * This method is useful for renumbering (in MED file for example). This method is used by MEDCouplingFieldDouble::renumberCells when check is set to true.
4028 * This method throws an exception if more 2 or more elements in 'this' are same.
4030 DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception)
4033 if(getNumberOfComponents()!=1)
4034 throw INTERP_KERNEL::Exception("DataArrayInt::checkAndPreparePermutation : number of components must == 1 !");
4035 int nbTuples=getNumberOfTuples();
4036 const int *pt=getConstPointer();
4037 int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
4038 DataArrayInt *ret=DataArrayInt::New();
4039 ret->useArray(pt2,true,CPP_DEALLOC,nbTuples,1);
4044 * This method makes the assumption that 'this' is correctly set, and has exactly one component. If not an exception will be thrown.
4045 * Given a sujective application defined by 'this' from a set of size this->getNumberOfTuples() to a set of size targetNb.
4046 * 'targetNb'<this->getNumberOfTuples(). 'this' should be surjective that is to say for each id in [0,'targetNb') it exists at least one tupleId tid
4047 * so that this->getIJ(tid,0)==id.
4048 * If not an exception will be thrown.
4049 * This method returns 2 newly allocated arrays 'arr' and 'arrI', corresponding respectively to array and its corresponding index.
4050 * This method is usefull for methods that returns old2New numbering concecutive to a reduction ( MEDCouplingUMesh::zipConnectivityTraducer, MEDCouplingUMesh::zipConnectivityTraducer for example)
4051 * Example : if 'this' equals [0,3,2,3,2,2,1,2] this method will return arrI=[0,1,2,6,8] arr=[0, 6, 2,4,5,7, 1,3]
4052 * That is to say elt id 2 has arrI[2+1]-arrI[2]=4 places in 'this'. The corresponding tuple ids are [2,4,5,7].
4054 void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception)
4057 if(getNumberOfComponents()!=1)
4058 throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : number of components must == 1 !");
4059 int nbOfTuples=getNumberOfTuples();
4060 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
4061 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retI(DataArrayInt::New());
4062 retI->alloc(targetNb+1,1);
4063 const int *input=getConstPointer();
4064 std::vector< std::vector<int> > tmp(targetNb);
4065 for(int i=0;i<nbOfTuples;i++)
4069 tmp[tmp2].push_back(i);
4072 std::ostringstream oss; oss << "DataArrayInt::changeSurjectiveFormat : At pos " << i << " presence of element " << tmp2 << " higher than " << targetNb;
4073 throw INTERP_KERNEL::Exception(oss.str().c_str());
4076 int *retIPtr=retI->getPointer();
4078 for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++,retIPtr++)
4079 retIPtr[1]=retIPtr[0]+(int)((*it1).size());
4080 if(nbOfTuples!=retI->getIJ(targetNb,0))
4081 throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : big problem should never happen !");
4082 ret->alloc(nbOfTuples,1);
4083 int *retPtr=ret->getPointer();
4084 for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++)
4085 retPtr=std::copy((*it1).begin(),(*it1).end(),retPtr);
4093 * This static method computes a old 2 new format DataArrayInt instance from a zip representation of a surjective format (retrived by DataArrayDouble::findCommonTuples for example)
4094 * The retrieved array minimizes the permutation.
4095 * Let's take an example :
4096 * If 'nbOfOldTuples'==10 and 'arr'==[0,3, 5,7,9] and 'arrI'==[0,2,5] it returns the following array [0,1,2,0,3,4,5,4,6,4] and newNbOfTuples==7.
4098 * @param nbOfOldTuples is the number of tuples in initial array.
4099 * @param arr is the list of tuples ids grouped by 'arrI' array
4100 * @param arrI is the entry point of 'arr' array. arrI->getNumberOfTuples()-1 is the number of common groups > 1 tuple.
4101 * @param newNbOfTuples output parameter that retrieves the new number of tuples after surjection application
4103 DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const DataArrayInt *arr, const DataArrayInt *arrI, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
4106 throw INTERP_KERNEL::Exception("DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : presence of NULL ref of DataArrayInt in input !");
4107 DataArrayInt *ret=DataArrayInt::New();
4108 ret->alloc(nbOfOldTuples,1);
4109 int *pt=ret->getPointer();
4110 std::fill(pt,pt+nbOfOldTuples,-1);
4111 int nbOfGrps=arrI->getNumberOfTuples()-1;
4112 const int *cIPtr=arrI->getConstPointer();
4113 const int *cPtr=arr->getConstPointer();
4114 for(int i=0;i<nbOfGrps;i++)
4115 pt[cPtr[cIPtr[i]]]=-(i+2);
4117 for(int iNode=0;iNode<nbOfOldTuples;iNode++)
4125 int grpId=-(pt[iNode]+2);
4126 for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
4132 newNbOfTuples=newNb;
4137 * This method expects that 'this' is allocated and with only one component. If not an exception will be thrown.
4138 * This method returns a newly created array with 'this->getNumberOfTuples()' tuples and 1 component.
4139 * This methods returns an 'old2New' corresponding array that allows to follow the following rules :
4140 * - Lower a value in tuple in 'this' is, higher is its priority.
4141 * - If two tuples i and j have same value if i<j then ret[i]<ret[j]
4142 * - The first tuple with the lowest value will have the value 0, inversely the last tuple with highest value will have value 'this->getNumberOfTuples()-1'
4144 * Example if 'this' contains the following array : [2,0,1,1,0,1,2,0,1,1,0,0] this method returns [10,0,5,6,1,7,11,2,8,9,3,4]
4146 DataArrayInt *DataArrayInt::buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception)
4149 if(getNumberOfComponents()!=1)
4150 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermArrPerLevel : number of components must == 1 !");
4151 int nbOfTuples=getNumberOfTuples();
4152 const int *pt=getConstPointer();
4153 std::map<int,int> m;
4154 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
4155 ret->alloc(nbOfTuples,1);
4156 int *opt=ret->getPointer();
4157 for(int i=0;i<nbOfTuples;i++,pt++,opt++)
4160 std::map<int,int>::iterator it=m.find(val);
4169 m.insert(std::pair<int,int>(val,1));
4173 for(std::map<int,int>::iterator it=m.begin();it!=m.end();it++)
4175 int vt=(*it).second;
4179 pt=getConstPointer();
4180 opt=ret->getPointer();
4181 for(int i=0;i<nbOfTuples;i++,pt++,opt++)
4189 * This method checks that 'this' is with numberofcomponents == 1 and that it is equal to
4190 * stdext::iota() of size getNumberOfTuples. This method is particalary usefull for DataArrayInt instances
4191 * that represents a renumbering array to check the real need in renumbering.
4193 bool DataArrayInt::isIdentity() const throw(INTERP_KERNEL::Exception)
4196 if(getNumberOfComponents()!=1)
4198 int nbOfTuples=getNumberOfTuples();
4199 const int *pt=getConstPointer();
4200 for(int i=0;i<nbOfTuples;i++,pt++)
4206 bool DataArrayInt::isUniform(int val) const throw(INTERP_KERNEL::Exception)
4209 if(getNumberOfComponents()!=1)
4210 throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
4211 int nbOfTuples=getNumberOfTuples();
4212 const int *w=getConstPointer();
4213 const int *end2=w+nbOfTuples;
4220 DataArrayDouble *DataArrayInt::convertToDblArr() const
4223 DataArrayDouble *ret=DataArrayDouble::New();
4224 ret->alloc(getNumberOfTuples(),getNumberOfComponents());
4225 int nbOfVals=getNbOfElems();
4226 const int *src=getConstPointer();
4227 double *dest=ret->getPointer();
4228 std::copy(src,src+nbOfVals,dest);
4229 ret->copyStringInfoFrom(*this);
4234 * This methods has a similar behaviour than std::string::substr. This method returns a newly created DataArrayInt that is part of this with same number of components.
4235 * The intervall is specified by [tupleIdBg,tupleIdEnd) except if tupleIdEnd ==-1 in this case the [tupleIdBg,this->end()) will be kept.
4236 * This method check that interval is valid regarding this, if not an exception will be thrown.
4237 * This method is a specialization of method DataArrayInt::selectByTupleId2.
4239 * \sa DataArrayInt::selectByTupleId2
4241 DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
4243 int nbt=getNumberOfTuples();
4245 throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
4247 throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
4248 int trueEnd=tupleIdEnd;
4252 throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
4256 int nbComp=getNumberOfComponents();
4257 DataArrayInt *ret=DataArrayInt::New();
4258 ret->alloc(trueEnd-tupleIdBg,nbComp);
4259 ret->copyStringInfoFrom(*this);
4260 std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
4265 * Contrary to DataArrayInt::changeNbOfComponents method this method is \b not const. The content
4266 * This method \b do \b not change the content of data but changes the splitting of this data seen by the caller.
4267 * This method makes the assumption that 'this' is already allocated. If not an exception will be thrown.
4268 * This method checks that getNbOfElems()%newNbOfCompo==0. If not an exception will be throw !
4269 * This method erases all components info set before call !
4271 void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
4274 int nbOfElems=getNbOfElems();
4275 if(nbOfElems%newNbOfCompo!=0)
4276 throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
4277 _nb_of_tuples=nbOfElems/newNbOfCompo;
4278 _info_on_compo.clear();
4279 _info_on_compo.resize(newNbOfCompo);
4284 * This method makes the assumption that \b this is allocated. If not an INTERP_KERNEL::Exception will be raised.
4285 * This method does not echange the values stored in \b this. Simply, the number of components before the call becomes the number of
4286 * tuples and inversely the number of tuples becomes the number of components. \b WARNING the info on components can be alterated by this method.
4288 void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception)
4291 int nbOfTuples=getNumberOfTuples();
4292 rearrange(nbOfTuples);
4296 * This method builds a new instance of DataArrayInt (to deal with) that is reduction or an extension of 'this'.
4297 * if 'newNbOfComp' < this->getNumberOfComponents() a reduction is done and for each tuple 'newNbOfComp' first components are kept.
4298 * If 'newNbOfComp' > this->getNumberOfComponents() an extension is done, and for each components i such that i > getNumberOfComponents() 'dftValue' parameter is taken.
4300 DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception)
4303 DataArrayInt *ret=DataArrayInt::New();
4304 ret->alloc(getNumberOfTuples(),newNbOfComp);
4305 const int *oldc=getConstPointer();
4306 int *nc=ret->getPointer();
4307 int nbOfTuples=getNumberOfTuples();
4308 int oldNbOfComp=getNumberOfComponents();
4309 int dim=std::min(oldNbOfComp,newNbOfComp);
4310 for(int i=0;i<nbOfTuples;i++)
4314 nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
4315 for(;j<newNbOfComp;j++)
4316 nc[newNbOfComp*i+j]=dftValue;
4318 ret->setName(getName().c_str());
4319 for(int i=0;i<dim;i++)
4320 ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
4321 ret->setName(getName().c_str());
4325 void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
4328 _mem.reAlloc((int)_info_on_compo.size()*nbOfTuples);
4329 _nb_of_tuples=nbOfTuples;
4333 DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
4336 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
4337 int newNbOfCompo=(int)compoIds.size();
4338 int oldNbOfCompo=getNumberOfComponents();
4339 for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
4340 DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
4341 int nbOfTuples=getNumberOfTuples();
4342 ret->alloc(nbOfTuples,newNbOfCompo);
4343 ret->copyPartOfStringInfoFrom(*this,compoIds);
4344 const int *oldc=getConstPointer();
4345 int *nc=ret->getPointer();
4346 for(int i=0;i<nbOfTuples;i++)
4347 for(int j=0;j<newNbOfCompo;j++,nc++)
4348 *nc=oldc[i*oldNbOfCompo+compoIds[j]];
4354 * This method melds the components of 'this' with components of 'other'.
4355 * After this call in case of success, 'this' will contain a number of components equal to the sum of 'this'
4356 * before the call and the number of components of 'other'.
4357 * This method expects that 'this' and 'other' have exactly the same number of tuples. If not an exception is thrown.
4359 void DataArrayInt::meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
4362 throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
4364 other->checkAllocated();
4365 int nbOfTuples=getNumberOfTuples();
4366 if(nbOfTuples!=other->getNumberOfTuples())
4367 throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
4368 int nbOfComp1=getNumberOfComponents();
4369 int nbOfComp2=other->getNumberOfComponents();
4370 int *newArr=new int[nbOfTuples*(nbOfComp1+nbOfComp2)];
4372 const int *inp1=getConstPointer();
4373 const int *inp2=other->getConstPointer();
4374 for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
4376 w=std::copy(inp1,inp1+nbOfComp1,w);
4377 w=std::copy(inp2,inp2+nbOfComp2,w);
4379 useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
4380 std::vector<int> compIds(nbOfComp2);
4381 for(int i=0;i<nbOfComp2;i++)
4382 compIds[i]=nbOfComp1+i;
4383 copyPartOfStringInfoFrom2(compIds,*other);
4386 void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
4388 copyPartOfStringInfoFrom2(compoIds,*a);
4389 std::size_t partOfCompoSz=compoIds.size();
4390 int nbOfCompo=getNumberOfComponents();
4391 int nbOfTuples=getNumberOfTuples();
4392 const int *ac=a->getConstPointer();
4393 int *nc=getPointer();
4394 for(int i=0;i<nbOfTuples;i++)
4395 for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
4396 nc[nbOfCompo*i+compoIds[j]]=*ac;
4400 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
4401 * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
4403 void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
4406 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues1 : DataArrayInt pointer in input is NULL !");
4407 const char msg[]="DataArrayInt::setPartOfValues1";
4409 a->checkAllocated();
4410 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
4411 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
4412 int nbComp=getNumberOfComponents();
4413 int nbOfTuples=getNumberOfTuples();
4414 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
4415 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
4416 a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
4417 if(strictCompoCompare)
4418 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
4419 int *pt=getPointer()+bgTuples*nbComp+bgComp;
4420 const int *srcPt=a->getConstPointer();
4421 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
4422 for(int j=0;j<newNbOfComp;j++,srcPt++)
4423 pt[j*stepComp]=*srcPt;
4427 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
4429 void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
4431 const char msg[]="DataArrayInt::setPartOfValuesSimple1";
4433 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
4434 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
4435 int nbComp=getNumberOfComponents();
4436 int nbOfTuples=getNumberOfTuples();
4437 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
4438 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
4439 int *pt=getPointer()+bgTuples*nbComp+bgComp;
4440 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
4441 for(int j=0;j<newNbOfComp;j++)
4446 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
4447 * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
4449 void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
4452 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues2 : DataArrayInt pointer in input is NULL !");
4453 const char msg[]="DataArrayInt::setPartOfValues2";
4455 a->checkAllocated();
4456 int nbComp=getNumberOfComponents();
4457 int nbOfTuples=getNumberOfTuples();
4458 for(const int *z=bgComp;z!=endComp;z++)
4459 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
4460 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
4461 int newNbOfComp=(int)std::distance(bgComp,endComp);
4462 bool assignTech=true;
4463 if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
4465 if(strictCompoCompare)
4466 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
4470 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
4473 int *pt=getPointer();
4474 const int *srcPt=a->getConstPointer();
4477 for(const int *w=bgTuples;w!=endTuples;w++)
4479 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
4480 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
4482 pt[(*w)*nbComp+(*z)]=*srcPt;
4488 for(const int *w=bgTuples;w!=endTuples;w++)
4490 const int *srcPt2=srcPt;
4491 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
4492 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
4494 pt[(*w)*nbComp+(*z)]=*srcPt2;
4501 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
4503 void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
4506 int nbComp=getNumberOfComponents();
4507 int nbOfTuples=getNumberOfTuples();
4508 for(const int *z=bgComp;z!=endComp;z++)
4509 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
4510 int *pt=getPointer();
4511 for(const int *w=bgTuples;w!=endTuples;w++)
4512 for(const int *z=bgComp;z!=endComp;z++)
4514 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
4515 pt[(*w)*nbComp+(*z)]=a;
4520 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
4521 * 'strictCompoCompare' specifies if DataArray 'a' should have exactly same number of components and tuples than 'this' (true) or not (false). By default set to true with maximal test.
4523 void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
4526 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues3 : DataArrayInt pointer in input is NULL !");
4527 const char msg[]="DataArrayInt::setPartOfValues3";
4529 a->checkAllocated();
4530 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
4531 int nbComp=getNumberOfComponents();
4532 int nbOfTuples=getNumberOfTuples();
4533 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
4534 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
4535 bool assignTech=true;
4536 if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
4538 if(strictCompoCompare)
4539 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
4543 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
4546 int *pt=getPointer()+bgComp;
4547 const int *srcPt=a->getConstPointer();
4550 for(const int *w=bgTuples;w!=endTuples;w++)
4551 for(int j=0;j<newNbOfComp;j++,srcPt++)
4553 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
4554 pt[(*w)*nbComp+j*stepComp]=*srcPt;
4559 for(const int *w=bgTuples;w!=endTuples;w++)
4561 const int *srcPt2=srcPt;
4562 for(int j=0;j<newNbOfComp;j++,srcPt2++)
4564 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
4565 pt[(*w)*nbComp+j*stepComp]=*srcPt2;
4572 * This method performs a partial assignment of 'this' using 'a' as input. Other input parameters specifies the subpart being considered by the assignment.
4574 void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
4576 const char msg[]="DataArrayInt::setPartOfValuesSimple3";
4578 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
4579 int nbComp=getNumberOfComponents();
4580 int nbOfTuples=getNumberOfTuples();
4581 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
4582 int *pt=getPointer()+bgComp;
4583 for(const int *w=bgTuples;w!=endTuples;w++)
4584 for(int j=0;j<newNbOfComp;j++)
4586 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
4587 pt[(*w)*nbComp+j*stepComp]=a;
4592 * 'this', 'a' and 'tuplesSelec' are expected to be defined. If not an exception will be thrown.
4593 * @param a is an array having exactly the same number of components than 'this'
4594 * @param tuplesSelec is an array having exactly 2 components. The first one refers to the tuple ids of 'this' that will be set. The second one refers to the tuple ids of 'a' that will be used for setting.
4596 void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
4599 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : DataArrayInt pointer in input is NULL !");
4601 a->checkAllocated();
4602 tuplesSelec->checkAllocated();
4603 int nbOfComp=getNumberOfComponents();
4604 if(nbOfComp!=a->getNumberOfComponents())
4605 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : This and a do not have the same number of components !");
4606 if(tuplesSelec->getNumberOfComponents()!=2)
4607 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
4608 int thisNt=getNumberOfTuples();
4609 int aNt=a->getNumberOfTuples();
4610 int *valsToSet=getPointer();
4611 const int *valsSrc=a->getConstPointer();
4612 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
4614 if(tuple[1]>=0 && tuple[1]<aNt)
4616 if(tuple[0]>=0 && tuple[0]<thisNt)
4617 std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
4620 std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
4621 oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
4622 throw INTERP_KERNEL::Exception(oss.str().c_str());
4627 std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
4628 oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
4629 throw INTERP_KERNEL::Exception(oss.str().c_str());
4635 * 'this', 'a' and 'tuplesSelec' are expected to be defined. If not an exception will be thrown.
4636 * This is a method that is a specialization to DataArrayInt::setPartOfValuesAdv method, except that here the tuple selection of 'a' is given by a range ('bg','end2' and 'step')
4637 * rather than an explicite array of tuple ids (given by the 2nd component) and the feeding is done in 'this' contiguously starting from 'tupleIdStart'.
4638 * @param a is an array having exactly the same number of components than 'this'
4640 void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
4643 a->checkAllocated();
4644 tuplesSelec->checkAllocated();
4645 int nbOfComp=getNumberOfComponents();
4646 if(nbOfComp!=a->getNumberOfComponents())
4647 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : This and a do not have the same number of components !");
4648 if(tuplesSelec->getNumberOfComponents()!=1)
4649 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
4650 int thisNt=getNumberOfTuples();
4651 int aNt=a->getNumberOfTuples();
4652 int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
4653 int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
4654 if(tupleIdStart+nbOfTupleToWrite>thisNt)
4655 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : invalid number range of values to write !");
4656 const int *valsSrc=a->getConstPointer();
4657 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
4659 if(*tuple>=0 && *tuple<aNt)
4661 std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
4665 std::ostringstream oss; oss << "DataArrayInt::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
4666 oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
4667 throw INTERP_KERNEL::Exception(oss.str().c_str());
4673 * 'this' and 'a' are expected to be defined. If not an exception will be thrown.
4674 * This is a method that is a specialization to DataArrayInt::setContigPartOfSelectedValues method, except that here the tuple selection is givenin a is done by a range ('bg','end2' and 'step')
4675 * rather than an explicite array of tuple ids.
4676 * @param a is an array having exactly the same number of components than 'this'
4678 void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
4681 a->checkAllocated();
4682 int nbOfComp=getNumberOfComponents();
4683 const char msg[]="DataArrayInt::setContigPartOfSelectedValues2";
4684 int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
4685 if(nbOfComp!=a->getNumberOfComponents())
4686 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
4687 int thisNt=getNumberOfTuples();
4688 int aNt=a->getNumberOfTuples();
4689 int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
4690 if(tupleIdStart+nbOfTupleToWrite>thisNt)
4691 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid number range of values to write !");
4693 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid range of values to read !");
4694 const int *valsSrc=a->getConstPointer()+bg*nbOfComp;
4695 for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
4697 std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
4702 * This method is equivalent to DataArrayInt::getIJ except that here \b tupleId is checked to be in [0,this->getNumberOfTuples()) and compoId to be in [0,this->getNumberOfComponents()).
4703 * If one of these check fails an INTERP_KERNEL::Exception will be thrown.
4704 * So this method is safe but expensive if used to go through all data of \b this.
4706 int DataArrayInt::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
4709 if(tupleId<0 || tupleId>=getNumberOfTuples())
4711 std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
4712 throw INTERP_KERNEL::Exception(oss.str().c_str());
4714 if(compoId<0 || compoId>=getNumberOfComponents())
4716 std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
4717 throw INTERP_KERNEL::Exception(oss.str().c_str());
4719 return _mem[tupleId*((int)_info_on_compo.size())+compoId];
4723 * This method returns the last element in 'this'. So this method makes the hypothesis that 'this' is allocated.
4724 * This method works only for arrays that have exactly number of components equal to 1. If not an exception is thrown.
4725 * And to finish this method works for arrays that have number of tuples >= 1.
4727 int DataArrayInt::back() const throw(INTERP_KERNEL::Exception)
4730 if(getNumberOfComponents()!=1)
4731 throw INTERP_KERNEL::Exception("DataArrayInt::back : number of components not equal to one !");
4732 int nbOfTuples=getNumberOfTuples();
4734 throw INTERP_KERNEL::Exception("DataArrayInt::back : number of tuples must be >= 1 !");
4735 return *(getConstPointer()+nbOfTuples-1);
4738 void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
4740 if(newArray!=arrayToSet)
4743 arrayToSet->decrRef();
4744 arrayToSet=newArray;
4746 arrayToSet->incrRef();
4750 DataArrayIntIterator *DataArrayInt::iterator()
4752 return new DataArrayIntIterator(this);
4755 DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception)
4757 if(getNumberOfComponents()!=1)
4758 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
4759 const int *cptr=getConstPointer();
4760 std::vector<int> res;
4761 int nbOfTuples=getNumberOfTuples();
4762 for(int i=0;i<nbOfTuples;i++,cptr++)
4765 DataArrayInt *ret=DataArrayInt::New();
4766 ret->alloc((int)res.size(),1);
4767 std::copy(res.begin(),res.end(),ret->getPointer());
4771 DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception)
4773 if(getNumberOfComponents()!=1)
4774 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !");
4775 const int *cptr=getConstPointer();
4776 std::vector<int> res;
4777 int nbOfTuples=getNumberOfTuples();
4778 for(int i=0;i<nbOfTuples;i++,cptr++)
4781 DataArrayInt *ret=DataArrayInt::New();
4782 ret->alloc((int)res.size(),1);
4783 std::copy(res.begin(),res.end(),ret->getPointer());
4788 * This method expects that 'this' is allocated. If not an exception will be thrown.
4789 * This method expect that the number of components is exactly equal to 1. If not an exception will be thrown.
4790 * For each element in 'this' equal to 'oldValue' will take the value 'newValue'.
4791 * @return number of elements impacted by the modification.
4793 int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception)
4795 if(getNumberOfComponents()!=1)
4796 throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !");
4798 int *start=getPointer();
4799 int *end2=start+getNbOfElems();
4801 for(int *val=start;val!=end2;val++)
4812 DataArrayInt *DataArrayInt::getIdsEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
4814 if(getNumberOfComponents()!=1)
4815 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component, you can call 'rearrange' method before !");
4816 std::set<int> vals2(valsBg,valsEnd);
4817 const int *cptr=getConstPointer();
4818 std::vector<int> res;
4819 int nbOfTuples=getNumberOfTuples();
4820 for(int i=0;i<nbOfTuples;i++,cptr++)
4821 if(vals2.find(*cptr)!=vals2.end())
4823 DataArrayInt *ret=DataArrayInt::New();
4824 ret->alloc((int)res.size(),1);
4825 std::copy(res.begin(),res.end(),ret->getPointer());
4829 DataArrayInt *DataArrayInt::getIdsNotEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
4831 if(getNumberOfComponents()!=1)
4832 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : the array must have only one component, you can call 'rearrange' method before !");
4833 std::set<int> vals2(valsBg,valsEnd);
4834 const int *cptr=getConstPointer();
4835 std::vector<int> res;
4836 int nbOfTuples=getNumberOfTuples();
4837 for(int i=0;i<nbOfTuples;i++,cptr++)
4838 if(vals2.find(*cptr)==vals2.end())
4840 DataArrayInt *ret=DataArrayInt::New();
4841 ret->alloc((int)res.size(),1);
4842 std::copy(res.begin(),res.end(),ret->getPointer());
4847 * This method is an extension of DataArrayInt::locateValue method because this method works for DataArrayInt with
4848 * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
4849 * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
4850 * If any the tuple id is returned. If not -1 is returned.
4852 * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
4853 * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
4855 * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this.
4856 * \sa DataArrayInt::search, DataArrayInt::presenceOfTuple.
4858 int DataArrayInt::locateTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
4860 int nbOfCompo=getNumberOfComponents();
4862 throw INTERP_KERNEL::Exception("DataArrayInt::locateTuple : 0 components in 'this' !");
4863 if(nbOfCompo!=(int)tupl.size())
4865 std::ostringstream oss; oss << "DataArrayInt::locateTuple : 'this' contains " << nbOfCompo << " components and searching for a tuple of length " << tupl.size() << " !";
4866 throw INTERP_KERNEL::Exception(oss.str().c_str());
4868 const int *cptr=getConstPointer();
4869 int nbOfVals=getNbOfElems();
4870 for(const int *work=cptr;work!=cptr+nbOfVals;)
4872 work=std::search(work,cptr+nbOfVals,tupl.begin(),tupl.end());
4873 if(work!=cptr+nbOfVals)
4875 if(std::distance(cptr,work)%nbOfCompo!=0)
4878 return std::distance(cptr,work)/nbOfCompo;
4885 * This method searches the sequence specified in input parameter \b vals in \b this.
4886 * This works only for DataArrayInt having number of components equal to one (if not an INTERP_KERNEL::Exception will be thrown).
4887 * This method differs from DataArrayInt::locateTuple in that the position is internal raw data is not considered here contrary to DataArrayInt::locateTuple.
4888 * \sa DataArrayInt::locateTuple
4890 int DataArrayInt::search(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
4892 int nbOfCompo=getNumberOfComponents();
4894 throw INTERP_KERNEL::Exception("DataArrayInt::search : works only for DataArrayInt instance with one component !");
4895 const int *cptr=getConstPointer();
4896 int nbOfVals=getNbOfElems();
4897 const int *loc=std::search(cptr,cptr+nbOfVals,vals.begin(),vals.end());
4898 if(loc!=cptr+nbOfVals)
4899 return std::distance(cptr,loc);
4904 * This method expects to be called when number of components of this is equal to one.
4905 * This method returns the tuple id, if it exists, of the first tuple equal to \b value.
4906 * If not any tuple contains \b value -1 is returned.
4907 * \sa DataArrayInt::presenceOfValue
4909 int DataArrayInt::locateValue(int value) const throw(INTERP_KERNEL::Exception)
4911 if(getNumberOfComponents()!=1)
4912 throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
4913 const int *cptr=getConstPointer();
4914 int nbOfTuples=getNumberOfTuples();
4915 const int *ret=std::find(cptr,cptr+nbOfTuples,value);
4916 if(ret!=cptr+nbOfTuples)
4917 return std::distance(cptr,ret);
4922 * This method expects to be called when number of components of this is equal to one.
4923 * This method returns the tuple id, if it exists, of the first tuple so that the value is contained in \b vals.
4924 * If not any tuple contains one of the values contained in 'vals' false is returned.
4925 * \sa DataArrayInt::presenceOfValue
4927 int DataArrayInt::locateValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
4929 if(getNumberOfComponents()!=1)
4930 throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
4931 std::set<int> vals2(vals.begin(),vals.end());
4932 const int *cptr=getConstPointer();
4933 int nbOfTuples=getNumberOfTuples();
4934 for(const int *w=cptr;w!=cptr+nbOfTuples;w++)
4935 if(vals2.find(*w)!=vals2.end())
4936 return std::distance(cptr,w);
4941 * This method is an extension of DataArrayInt::presenceOfValue method because this method works for DataArrayInt with
4942 * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
4943 * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
4944 * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
4945 * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
4946 * \sa DataArrayInt::locateTuple
4948 bool DataArrayInt::presenceOfTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
4950 return locateTuple(tupl)!=-1;
4954 * This method expects to be called when number of components of this is equal to one.
4955 * This method returns true if it exists a tuple equal to \b value.
4956 * If not any tuple contains \b value false is returned.
4957 * \sa DataArrayInt::locateValue
4959 bool DataArrayInt::presenceOfValue(int value) const throw(INTERP_KERNEL::Exception)
4961 return locateValue(value)!=-1;
4965 * This method expects to be called when number of components of this is equal to one.
4966 * This method returns true if it exists a tuple so that the value is contained in \b vals.
4967 * If not any tuple contains one of the values contained in 'vals' false is returned.
4968 * \sa DataArrayInt::locateValue
4970 bool DataArrayInt::presenceOfValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
4972 return locateValue(vals)!=-1;
4975 DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
4978 throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input DataArrayInt instance is NULL !");
4979 int nbOfComp=a1->getNumberOfComponents();
4980 if(nbOfComp!=a2->getNumberOfComponents())
4981 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
4982 int nbOfTuple1=a1->getNumberOfTuples();
4983 int nbOfTuple2=a2->getNumberOfTuples();
4984 DataArrayInt *ret=DataArrayInt::New();
4985 ret->alloc(nbOfTuple1+nbOfTuple2-offsetA2,nbOfComp);
4986 int *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer());
4987 std::copy(a2->getConstPointer()+offsetA2*nbOfComp,a2->getConstPointer()+nbOfTuple2*nbOfComp,pt);
4988 ret->copyStringInfoFrom(*a1);
4992 DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
4994 std::vector<const DataArrayInt *> a;
4995 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4999 throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
5000 std::vector<const DataArrayInt *>::const_iterator it=a.begin();
5001 int nbOfComp=(*it)->getNumberOfComponents();
5002 int nbt=(*it++)->getNumberOfTuples();
5003 for(int i=1;it!=a.end();it++,i++)
5005 if((*it)->getNumberOfComponents()!=nbOfComp)
5006 throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !");
5007 nbt+=(*it)->getNumberOfTuples();
5009 DataArrayInt *ret=DataArrayInt::New();
5010 ret->alloc(nbt,nbOfComp);
5011 int *pt=ret->getPointer();
5012 for(it=a.begin();it!=a.end();it++)
5013 pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
5014 ret->copyStringInfoFrom(*(a[0]));
5018 int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
5020 if(getNumberOfComponents()!=1)
5021 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
5022 int nbOfTuples=getNumberOfTuples();
5024 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
5025 const int *vals=getConstPointer();
5026 const int *loc=std::max_element(vals,vals+nbOfTuples);
5027 tupleId=(int)std::distance(vals,loc);
5032 * Idem to DataArrayInt::getMaxValue expect that here number of components can be >=1.
5034 int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
5037 const int *loc=std::max_element(begin(),end());
5041 int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
5043 if(getNumberOfComponents()!=1)
5044 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
5045 int nbOfTuples=getNumberOfTuples();
5047 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
5048 const int *vals=getConstPointer();
5049 const int *loc=std::min_element(vals,vals+nbOfTuples);
5050 tupleId=(int)std::distance(vals,loc);
5055 * Idem to DataArrayInt::getMinValue expect that here number of components can be >=1.
5057 int DataArrayInt::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
5060 const int *loc=std::min_element(begin(),end());
5064 void DataArrayInt::abs() throw(INTERP_KERNEL::Exception)
5067 int *ptr=getPointer();
5068 int nbOfElems=getNbOfElems();
5069 std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
5072 void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception)
5075 int *ptr=getPointer()+compoId;
5076 int nbOfComp=getNumberOfComponents();
5077 int nbOfTuple=getNumberOfTuples();
5078 for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
5083 void DataArrayInt::applyLin(int a, int b) throw(INTERP_KERNEL::Exception)
5086 int *ptr=getPointer();
5087 int nbOfElems=getNbOfElems();
5088 for(int i=0;i<nbOfElems;i++,ptr++)
5094 * This method returns a newly allocated array containing the application of negate on \b this.
5095 * This method throws an INTERP_KERNEL::Exception if \b this is not allocated.
5097 DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception)
5100 DataArrayInt *newArr=DataArrayInt::New();
5101 int nbOfTuples=getNumberOfTuples();
5102 int nbOfComp=getNumberOfComponents();
5103 newArr->alloc(nbOfTuples,nbOfComp);
5104 const int *cptr=getConstPointer();
5105 std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
5106 newArr->copyStringInfoFrom(*this);
5111 * This method applies the operation 'numerator/x' for each element 'x' in 'this'.
5112 * If there is a value in 'this' exactly equal to 0. an exception is thrown.
5113 * Warning if presence of null this is modified for each values previous than place where exception was thrown !
5115 void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception)
5118 int *ptr=getPointer();
5119 int nbOfElems=getNbOfElems();
5120 for(int i=0;i<nbOfElems;i++,ptr++)
5124 *ptr=numerator/(*ptr);
5128 std::ostringstream oss; oss << "DataArrayInt::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
5130 throw INTERP_KERNEL::Exception(oss.str().c_str());
5136 void DataArrayInt::applyDivideBy(int val) throw(INTERP_KERNEL::Exception)
5139 throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to divide by 0 !");
5141 int *ptr=getPointer();
5142 int nbOfElems=getNbOfElems();
5143 std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides<int>(),val));
5147 void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception)
5150 throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !");
5152 int *ptr=getPointer();
5153 int nbOfElems=getNbOfElems();
5154 std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus<int>(),val));
5159 * This method works only on data array with one component.
5160 * This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that
5161 * this[*id] in [\b vmin,\b vmax)
5163 * \param [in] vmin begin of range. This value is included in range.
5164 * \param [out] vmax end of range. This value is \b not included in range.
5165 * \return a newly allocated data array that the caller should deal with.
5167 DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
5169 if(getNumberOfComponents()!=1)
5170 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsInRange : this must have exactly one component !");
5171 const int *cptr=getConstPointer();
5172 std::vector<int> res;
5173 int nbOfTuples=getNumberOfTuples();
5174 for(int i=0;i<nbOfTuples;i++,cptr++)
5175 if(*cptr>=vmin && *cptr<vmax)
5177 DataArrayInt *ret=DataArrayInt::New();
5178 ret->alloc((int)res.size(),1);
5179 std::copy(res.begin(),res.end(),ret->getPointer());
5184 * This method applies the operation 'numerator%x' for each element 'x' in 'this'.
5185 * If there is a value in 'this' exactly equals or lower than 0. an exception is thrown.
5186 * Warning if presence of null this is modified for each values previous than place where exception was thrown !
5188 void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception)
5191 int *ptr=getPointer();
5192 int nbOfElems=getNbOfElems();
5193 for(int i=0;i<nbOfElems;i++,ptr++)
5201 std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
5203 throw INTERP_KERNEL::Exception(oss.str().c_str());
5209 DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
5211 std::vector<const DataArrayInt *> arr(2);
5212 arr[0]=a1; arr[1]=a2;
5216 DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
5218 std::vector<const DataArrayInt *> a;
5219 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
5223 throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !");
5224 std::vector<const DataArrayInt *>::const_iterator it;
5225 for(it=a.begin();it!=a.end();it++)
5226 (*it)->checkAllocated();
5228 int nbOfTuples=(*it)->getNumberOfTuples();
5229 std::vector<int> nbc(a.size());
5230 std::vector<const int *> pts(a.size());
5231 nbc[0]=(*it)->getNumberOfComponents();
5232 pts[0]=(*it++)->getConstPointer();
5233 for(int i=1;it!=a.end();it++,i++)
5235 if(nbOfTuples!=(*it)->getNumberOfTuples())
5236 throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !");
5237 nbc[i]=(*it)->getNumberOfComponents();
5238 pts[i]=(*it)->getConstPointer();
5240 int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
5241 DataArrayInt *ret=DataArrayInt::New();
5242 ret->alloc(nbOfTuples,totalNbOfComp);
5243 int *retPtr=ret->getPointer();
5244 for(int i=0;i<nbOfTuples;i++)
5245 for(int j=0;j<(int)a.size();j++)
5247 retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
5251 for(int i=0;i<(int)a.size();i++)
5252 for(int j=0;j<nbc[i];j++,k++)
5253 ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
5258 * This method create a minimal partition of groups 'groups' the std::iota array of size 'newNb'.
5259 * This method returns an array of size 'newNb' that specifies for each item at which familyId it owns to, and this method returns
5260 * for each group the familyId it contains. If an id so that id<newNb and that appears in no groups will appears with 0 in return array.
5262 * @param groups in arrays specifying ids of each groups.
5263 * @param newNb specifies size of whole set. Must be at least equal to max eltid in 'groups'.
5264 * @return an array of size newNb specifying fid of each item.
5266 DataArrayInt *DataArrayInt::MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups) throw(INTERP_KERNEL::Exception)
5268 std::vector<const DataArrayInt *> groups2;
5269 for(std::vector<const DataArrayInt *>::const_iterator it4=groups.begin();it4!=groups.end();it4++)
5271 groups2.push_back(*it4);
5272 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5273 ret->alloc(newNb,1);
5274 int *retPtr=ret->getPointer();
5275 std::fill(retPtr,retPtr+newNb,0);
5277 for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++)
5279 const int *ptr=(*iter)->getConstPointer();
5280 int nbOfElem=(*iter)->getNbOfElems();
5282 for(int j=0;j<sfid;j++)
5285 for(int i=0;i<nbOfElem;i++)
5287 if(ptr[i]>=0 && ptr[i]<newNb)
5289 if(retPtr[ptr[i]]==j)
5297 std::ostringstream oss; oss << "DataArrayInt::MakePartition : In group \"" << (*iter)->getName() << "\" in tuple #" << i << " value = " << ptr[i] << " ! Should be in [0," << newNb;
5299 throw INTERP_KERNEL::Exception(oss.str().c_str());
5306 fidsOfGroups.clear();
5307 fidsOfGroups.resize(groups2.size());
5309 for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++,grId++)
5312 const int *ptr=(*iter)->getConstPointer();
5313 int nbOfElem=(*iter)->getNbOfElems();
5314 for(const int *p=ptr;p!=ptr+nbOfElem;p++)
5315 tmp.insert(retPtr[*p]);
5316 fidsOfGroups[grId].insert(fidsOfGroups[grId].end(),tmp.begin(),tmp.end());
5322 DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
5324 std::vector<const DataArrayInt *> a;
5325 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
5328 int valm=std::numeric_limits<int>::max();
5329 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
5331 (*it)->checkAllocated();
5332 if((*it)->getNumberOfComponents()!=1)
5333 throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
5335 valm=std::min((*it)->getMinValue(tmp1),valm);
5338 throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
5341 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
5343 const int *pt=(*it)->getConstPointer();
5344 int nbOfTuples=(*it)->getNumberOfTuples();
5345 r.insert(pt,pt+nbOfTuples);
5347 DataArrayInt *ret=DataArrayInt::New();
5348 ret->alloc((int)r.size(),1);
5349 std::copy(r.begin(),r.end(),ret->getPointer());
5353 DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
5355 std::vector<const DataArrayInt *> a;
5356 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
5359 int valm=std::numeric_limits<int>::max();
5360 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
5362 (*it)->checkAllocated();
5363 if((*it)->getNumberOfComponents()!=1)
5364 throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
5366 valm=std::min((*it)->getMinValue(tmp1),valm);
5369 throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
5372 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
5374 const int *pt=(*it)->getConstPointer();
5375 int nbOfTuples=(*it)->getNumberOfTuples();
5376 std::set<int> s1(pt,pt+nbOfTuples);
5380 std::set_intersection(r.begin(),r.end(),s1.begin(),s1.end(),inserter(r2,r2.end()));
5386 DataArrayInt *ret=DataArrayInt::New();
5387 ret->alloc((int)r.size(),1);
5388 std::copy(r.begin(),r.end(),ret->getPointer());
5392 DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception)
5395 if(getNumberOfComponents()!=1)
5396 throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : only single component allowed !");
5397 std::vector<bool> tmp(nbOfElement);
5398 const int *pt=getConstPointer();
5399 int nbOfTuples=getNumberOfTuples();
5400 for(const int *w=pt;w!=pt+nbOfTuples;w++)
5401 if(*w>=0 && *w<nbOfElement)
5404 throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : an element is not in valid range : [0,nbOfElement) !");
5405 int nbOfRetVal=(int)std::count(tmp.begin(),tmp.end(),false);
5406 DataArrayInt *ret=DataArrayInt::New();
5407 ret->alloc(nbOfRetVal,1);
5409 int *retPtr=ret->getPointer();
5410 for(int i=0;i<nbOfElement;i++)
5416 DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
5419 throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : DataArrayInt pointer in input is NULL !");
5421 other->checkAllocated();
5422 if(getNumberOfComponents()!=1)
5423 throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !");
5424 if(other->getNumberOfComponents()!=1)
5425 throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !");
5426 const int *pt=getConstPointer();
5427 int nbOfTuples=getNumberOfTuples();
5428 std::set<int> s1(pt,pt+nbOfTuples);
5429 pt=other->getConstPointer();
5430 nbOfTuples=other->getNumberOfTuples();
5431 std::set<int> s2(pt,pt+nbOfTuples);
5433 std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<int> >(r));
5434 DataArrayInt *ret=DataArrayInt::New();
5435 ret->alloc((int)r.size(),1);
5436 std::copy(r.begin(),r.end(),ret->getPointer());
5440 DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
5442 std::vector<const DataArrayInt *>arrs(2);
5443 arrs[0]=this; arrs[1]=other;
5444 return BuildUnion(arrs);
5447 DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
5449 std::vector<const DataArrayInt *>arrs(2);
5450 arrs[0]=this; arrs[1]=other;
5451 return BuildIntersection(arrs);
5455 * This method could be usefull for returned DataArrayInt marked as index. Some methods that generate such DataArrayInt instances:
5456 * - ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity
5457 * - ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex
5458 * This method makes the assumption that 'this' is allocated and has exactly one component and 2 or more tuples. If not an exception is thrown.
5459 * This method retrives a newly created DataArrayInt instance with 1 component and this->getNumberOfTuples()-1 tuples.
5460 * If this contains [1,3,6,7,7,9,15] -> returned array will contain [2,3,1,0,2,6].
5462 DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
5465 if(getNumberOfComponents()!=1)
5466 throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
5467 int nbOfTuples=getNumberOfTuples();
5469 throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
5470 const int *ptr=getConstPointer();
5471 DataArrayInt *ret=DataArrayInt::New();
5472 ret->alloc(nbOfTuples-1,1);
5473 int *out=ret->getPointer();
5474 std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
5479 * This method performs the work on itself. This method works on array with number of component equal to one and allocated. If not an exception is thrown.
5480 * This method conserves the number of tuples and number of components (1). No reallocation is done.
5481 * For an array [3,5,1,2,0,8] it becomes [0,3,8,9,11,11]. For each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0.
5482 * This could be usefull for allToAllV in MPI with contiguous policy.
5484 void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception)
5487 if(getNumberOfComponents()!=1)
5488 throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
5489 int nbOfTuples=getNumberOfTuples();
5492 int *work=getPointer();
5495 for(int i=1;i<nbOfTuples;i++)
5498 work[i]=work[i-1]+tmp;
5505 * Idem DataArrayInt::computeOffsets method execpt that 'this' changes its number of tuples.
5506 * After the call in case of success new number of tuples is equal to old number of tuples +1.
5507 * The content in 'this' for the first old number of tuples is exactly the same than those given by
5508 * DataArrayInt::computeOffsets method.
5509 * For an array [3,5,1,2,0,8] it becomes [0,3,8,9,11,11,19].
5511 void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
5514 if(getNumberOfComponents()!=1)
5515 throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !");
5516 int nbOfTuples=getNumberOfTuples();
5517 int *ret=new int[nbOfTuples+1];
5520 const int *work=getConstPointer();
5522 for(int i=0;i<nbOfTuples;i++)
5523 ret[i+1]=work[i]+ret[i];
5524 useArray(ret,true,CPP_DEALLOC,nbOfTuples+1,1);
5529 * This method works on array with number of component equal to one and allocated. If not an exception is thrown.
5530 * 'offsets' should be monotic ascendently. If not, an exception will be thrown.
5531 * This method retrives a newly created DataArrayInt instance with 1 component and this->getNumberOfTuples()-1 tuples.
5532 * If 'this' contains [0,2,3] and 'offsets' [0,3,6,10,14,20] the returned array will contain [0,1,2,6,7,8,9,10,11,12,13]
5534 DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception)
5537 throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : DataArrayInt pointer in input is NULL !");
5539 if(getNumberOfComponents()!=1)
5540 throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
5541 offsets->checkAllocated();
5542 if(offsets->getNumberOfComponents()!=1)
5543 throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
5544 int othNbTuples=offsets->getNumberOfTuples()-1;
5545 int nbOfTuples=getNumberOfTuples();
5546 int retNbOftuples=0;
5547 const int *work=getConstPointer();
5548 const int *offPtr=offsets->getConstPointer();
5549 for(int i=0;i<nbOfTuples;i++)
5552 if(val>=0 && val<othNbTuples)
5554 int delta=offPtr[val+1]-offPtr[val];
5556 retNbOftuples+=delta;
5559 std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
5560 throw INTERP_KERNEL::Exception(oss.str().c_str());
5565 std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
5566 oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
5567 throw INTERP_KERNEL::Exception(oss.str().c_str());
5570 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5571 ret->alloc(retNbOftuples,1);
5572 int *retPtr=ret->getPointer();
5573 for(int i=0;i<nbOfTuples;i++)
5576 int start=offPtr[val];
5577 int off=offPtr[val+1]-start;
5578 for(int j=0;j<off;j++,retPtr++)
5586 * Given in input ranges \a ranges, it returns a newly allocated DataArrayInt instance having one component and the same number of tuples than \a this.
5587 * For each tuple at place **i** in \a this it tells which is the first range in \a ranges that contains value \c this->getIJ(i,0) and put the result
5588 * in tuple **i** of returned DataArrayInt.
5589 * If ranges overlapped (in theory it should not) this method do not detect it and always returns the first range.
5591 * For example if \a this contains : [1,24,7,8,10,17] and \a ranges contains [(0,3),(3,8),(8,15),(15,22),(22,30)]
5592 * The return DataArrayInt will contain : **[0,4,1,2,2,3]**
5594 * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
5595 * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
5596 * \throw If offsets is a null pointer or does not have 2 components or if \a this is not allocated or \a this do not have exactly one component. To finish an exception
5597 * is thrown if no ranges in \a ranges contains value in \a this.
5599 * \sa DataArrayInt::findIdInRangeForEachTuple
5601 DataArrayInt *DataArrayInt::findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
5604 throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : null input pointer !");
5605 if(ranges->getNumberOfComponents()!=2)
5606 throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : input DataArrayInt instance should have 2 components !");
5608 if(getNumberOfComponents()!=1)
5609 throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : this should have only one component !");
5610 int nbTuples=getNumberOfTuples();
5611 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
5612 int nbOfRanges=ranges->getNumberOfTuples();
5613 const int *rangesPtr=ranges->getConstPointer();
5614 int *retPtr=ret->getPointer();
5615 const int *inPtr=getConstPointer();
5616 for(int i=0;i<nbTuples;i++,retPtr++)
5620 for(int j=0;j<nbOfRanges && !found;j++)
5621 if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
5622 { *retPtr=j; found=true; }
5627 std::ostringstream oss; oss << "DataArrayInt::findRangeIdForEachTuple : tuple #" << i << " not found by any ranges !";
5628 throw INTERP_KERNEL::Exception(oss.str().c_str());
5636 * Given in input ranges \a ranges, it returns a newly allocated DataArrayInt instance having one component and the same number of tuples than \a this.
5637 * For each tuple at place **i** in \a this it tells which is the sub position of the first range in \a ranges that contains value \c this->getIJ(i,0) and put the result
5638 * in tuple **i** of returned DataArrayInt.
5639 * If ranges overlapped (in theory it should not) this method do not detect it and always returns the sub position of the first range.
5641 * For example if \a this contains : [1,24,7,8,10,17] and \a ranges contains [(0,3),(3,8),(8,15),(15,22),(22,30)]
5642 * The return DataArrayInt will contain : **[1,2,4,0,2,2]**
5643 * This method is often called in pair with DataArrayInt::findRangeIdForEachTuple method.
5645 * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
5646 * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
5647 * \throw If offsets is a null pointer or does not have 2 components or if \a this is not allocated or \a this do not have exactly one component. To finish an exception
5648 * is thrown if no ranges in \a ranges contains value in \a this.
5649 * \sa DataArrayInt::findRangeIdForEachTuple
5651 DataArrayInt *DataArrayInt::findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
5654 throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : null input pointer !");
5655 if(ranges->getNumberOfComponents()!=2)
5656 throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : input DataArrayInt instance should have 2 components !");
5658 if(getNumberOfComponents()!=1)
5659 throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : this should have only one component !");
5660 int nbTuples=getNumberOfTuples();
5661 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
5662 int nbOfRanges=ranges->getNumberOfTuples();
5663 const int *rangesPtr=ranges->getConstPointer();
5664 int *retPtr=ret->getPointer();
5665 const int *inPtr=getConstPointer();
5666 for(int i=0;i<nbTuples;i++,retPtr++)
5670 for(int j=0;j<nbOfRanges && !found;j++)
5671 if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
5672 { *retPtr=val-rangesPtr[2*j]; found=true; }
5677 std::ostringstream oss; oss << "DataArrayInt::findIdInRangeForEachTuple : tuple #" << i << " not found by any ranges !";
5678 throw INTERP_KERNEL::Exception(oss.str().c_str());
5687 * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
5688 * \a nbTimes should be at least equal to 1.
5689 * \return a newly allocated DataArrayInt having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
5690 * \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.
5692 DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
5695 if(getNumberOfComponents()!=1)
5696 throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !");
5698 throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : nb times should be >= 1 !");
5699 int nbTuples=getNumberOfTuples();
5700 const int *inPtr=getConstPointer();
5701 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTimes*nbTuples,1);
5702 int *retPtr=ret->getPointer();
5703 for(int i=0;i<nbTuples;i++,inPtr++)
5706 for(int j=0;j<nbTimes;j++,retPtr++)
5709 ret->copyStringInfoFrom(*this);
5715 * This method returns all different values found in 'this'.
5717 std::set<int> DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception)
5721 ret.insert(getConstPointer(),getConstPointer()+getNbOfElems());
5725 DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
5728 throw INTERP_KERNEL::Exception("DataArrayInt::Add : input DataArrayInt instance is NULL !");
5729 int nbOfTuple=a1->getNumberOfTuples();
5730 int nbOfTuple2=a2->getNumberOfTuples();
5731 int nbOfComp=a1->getNumberOfComponents();
5732 int nbOfComp2=a2->getNumberOfComponents();
5733 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=0;
5734 if(nbOfTuple==nbOfTuple2)
5736 if(nbOfComp==nbOfComp2)
5738 ret=DataArrayInt::New();
5739 ret->alloc(nbOfTuple,nbOfComp);
5740 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<int>());
5741 ret->copyStringInfoFrom(*a1);
5745 int nbOfCompMin,nbOfCompMax;
5746 const DataArrayInt *aMin, *aMax;
5747 if(nbOfComp>nbOfComp2)
5749 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
5754 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
5759 ret=DataArrayInt::New();
5760 ret->alloc(nbOfTuple,nbOfCompMax);
5761 const int *aMinPtr=aMin->getConstPointer();
5762 const int *aMaxPtr=aMax->getConstPointer();
5763 int *res=ret->getPointer();
5764 for(int i=0;i<nbOfTuple;i++)
5765 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<int>(),aMinPtr[i]));
5766 ret->copyStringInfoFrom(*aMax);
5769 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
5772 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
5774 if(nbOfComp==nbOfComp2)
5776 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
5777 const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
5778 const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
5779 const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
5780 ret=DataArrayInt::New();
5781 ret->alloc(nbOfTupleMax,nbOfComp);
5782 int *res=ret->getPointer();
5783 for(int i=0;i<nbOfTupleMax;i++)
5784 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<int>());
5785 ret->copyStringInfoFrom(*aMax);
5788 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
5791 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
5796 void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
5799 throw INTERP_KERNEL::Exception("DataArrayInt::addEqual : input DataArrayInt instance is NULL !");
5800 const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual !";
5801 int nbOfTuple=getNumberOfTuples();
5802 int nbOfTuple2=other->getNumberOfTuples();
5803 int nbOfComp=getNumberOfComponents();
5804 int nbOfComp2=other->getNumberOfComponents();
5805 if(nbOfTuple==nbOfTuple2)
5807 if(nbOfComp==nbOfComp2)
5809 std::transform(begin(),end(),other->begin(),getPointer(),std::plus<int>());
5811 else if(nbOfComp2==1)
5813 int *ptr=getPointer();
5814 const int *ptrc=other->getConstPointer();
5815 for(int i=0;i<nbOfTuple;i++)
5816 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<int>(),*ptrc++));
5819 throw INTERP_KERNEL::Exception(msg);
5821 else if(nbOfTuple2==1)
5823 if(nbOfComp2==nbOfComp)
5825 int *ptr=getPointer();
5826 const int *ptrc=other->getConstPointer();
5827 for(int i=0;i<nbOfTuple;i++)
5828 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<int>());
5831 throw INTERP_KERNEL::Exception(msg);
5834 throw INTERP_KERNEL::Exception(msg);
5838 DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
5841 throw INTERP_KERNEL::Exception("DataArrayInt::Substract : input DataArrayInt instance is NULL !");
5842 int nbOfTuple1=a1->getNumberOfTuples();
5843 int nbOfTuple2=a2->getNumberOfTuples();
5844 int nbOfComp1=a1->getNumberOfComponents();
5845 int nbOfComp2=a2->getNumberOfComponents();
5846 if(nbOfTuple2==nbOfTuple1)
5848 if(nbOfComp1==nbOfComp2)
5850 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5851 ret->alloc(nbOfTuple2,nbOfComp1);
5852 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<int>());
5853 ret->copyStringInfoFrom(*a1);
5857 else if(nbOfComp2==1)
5859 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5860 ret->alloc(nbOfTuple1,nbOfComp1);
5861 const int *a2Ptr=a2->getConstPointer();
5862 const int *a1Ptr=a1->getConstPointer();
5863 int *res=ret->getPointer();
5864 for(int i=0;i<nbOfTuple1;i++)
5865 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<int>(),a2Ptr[i]));
5866 ret->copyStringInfoFrom(*a1);
5872 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
5876 else if(nbOfTuple2==1)
5878 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
5879 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5880 ret->alloc(nbOfTuple1,nbOfComp1);
5881 const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
5882 int *pt=ret->getPointer();
5883 for(int i=0;i<nbOfTuple1;i++)
5884 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<int>());
5885 ret->copyStringInfoFrom(*a1);
5891 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
5896 void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
5899 throw INTERP_KERNEL::Exception("DataArrayInt::substractEqual : input DataArrayInt instance is NULL !");
5900 const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual !";
5901 int nbOfTuple=getNumberOfTuples();
5902 int nbOfTuple2=other->getNumberOfTuples();
5903 int nbOfComp=getNumberOfComponents();
5904 int nbOfComp2=other->getNumberOfComponents();
5905 if(nbOfTuple==nbOfTuple2)
5907 if(nbOfComp==nbOfComp2)
5909 std::transform(begin(),end(),other->begin(),getPointer(),std::minus<int>());
5911 else if(nbOfComp2==1)
5913 int *ptr=getPointer();
5914 const int *ptrc=other->getConstPointer();
5915 for(int i=0;i<nbOfTuple;i++)
5916 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<int>(),*ptrc++));
5919 throw INTERP_KERNEL::Exception(msg);
5921 else if(nbOfTuple2==1)
5923 int *ptr=getPointer();
5924 const int *ptrc=other->getConstPointer();
5925 for(int i=0;i<nbOfTuple;i++)
5926 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<int>());
5929 throw INTERP_KERNEL::Exception(msg);
5933 DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
5936 throw INTERP_KERNEL::Exception("DataArrayInt::Multiply : input DataArrayInt instance is NULL !");
5937 int nbOfTuple=a1->getNumberOfTuples();
5938 int nbOfTuple2=a2->getNumberOfTuples();
5939 int nbOfComp=a1->getNumberOfComponents();
5940 int nbOfComp2=a2->getNumberOfComponents();
5941 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=0;
5942 if(nbOfTuple==nbOfTuple2)
5944 if(nbOfComp==nbOfComp2)
5946 ret=DataArrayInt::New();
5947 ret->alloc(nbOfTuple,nbOfComp);
5948 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<int>());
5949 ret->copyStringInfoFrom(*a1);
5953 int nbOfCompMin,nbOfCompMax;
5954 const DataArrayInt *aMin, *aMax;
5955 if(nbOfComp>nbOfComp2)
5957 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
5962 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
5967 ret=DataArrayInt::New();
5968 ret->alloc(nbOfTuple,nbOfCompMax);
5969 const int *aMinPtr=aMin->getConstPointer();
5970 const int *aMaxPtr=aMax->getConstPointer();
5971 int *res=ret->getPointer();
5972 for(int i=0;i<nbOfTuple;i++)
5973 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<int>(),aMinPtr[i]));
5974 ret->copyStringInfoFrom(*aMax);
5977 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
5980 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
5982 if(nbOfComp==nbOfComp2)
5984 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
5985 const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
5986 const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
5987 const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
5988 ret=DataArrayInt::New();
5989 ret->alloc(nbOfTupleMax,nbOfComp);
5990 int *res=ret->getPointer();
5991 for(int i=0;i<nbOfTupleMax;i++)
5992 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<int>());
5993 ret->copyStringInfoFrom(*aMax);
5996 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
5999 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
6004 void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
6007 throw INTERP_KERNEL::Exception("DataArrayInt::multiplyEqual : input DataArrayInt instance is NULL !");
6008 const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !";
6009 int nbOfTuple=getNumberOfTuples();
6010 int nbOfTuple2=other->getNumberOfTuples();
6011 int nbOfComp=getNumberOfComponents();
6012 int nbOfComp2=other->getNumberOfComponents();
6013 if(nbOfTuple==nbOfTuple2)
6015 if(nbOfComp==nbOfComp2)
6017 std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<int>());
6019 else if(nbOfComp2==1)
6021 int *ptr=getPointer();
6022 const int *ptrc=other->getConstPointer();
6023 for(int i=0;i<nbOfTuple;i++)
6024 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<int>(),*ptrc++));
6027 throw INTERP_KERNEL::Exception(msg);
6029 else if(nbOfTuple2==1)
6031 if(nbOfComp2==nbOfComp)
6033 int *ptr=getPointer();
6034 const int *ptrc=other->getConstPointer();
6035 for(int i=0;i<nbOfTuple;i++)
6036 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<int>());
6039 throw INTERP_KERNEL::Exception(msg);
6042 throw INTERP_KERNEL::Exception(msg);
6046 DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
6049 throw INTERP_KERNEL::Exception("DataArrayInt::Divide : input DataArrayInt instance is NULL !");
6050 int nbOfTuple1=a1->getNumberOfTuples();
6051 int nbOfTuple2=a2->getNumberOfTuples();
6052 int nbOfComp1=a1->getNumberOfComponents();
6053 int nbOfComp2=a2->getNumberOfComponents();
6054 if(nbOfTuple2==nbOfTuple1)
6056 if(nbOfComp1==nbOfComp2)
6058 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6059 ret->alloc(nbOfTuple2,nbOfComp1);
6060 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<int>());
6061 ret->copyStringInfoFrom(*a1);
6065 else if(nbOfComp2==1)
6067 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6068 ret->alloc(nbOfTuple1,nbOfComp1);
6069 const int *a2Ptr=a2->getConstPointer();
6070 const int *a1Ptr=a1->getConstPointer();
6071 int *res=ret->getPointer();
6072 for(int i=0;i<nbOfTuple1;i++)
6073 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<int>(),a2Ptr[i]));
6074 ret->copyStringInfoFrom(*a1);
6080 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
6084 else if(nbOfTuple2==1)
6086 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
6087 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6088 ret->alloc(nbOfTuple1,nbOfComp1);
6089 const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
6090 int *pt=ret->getPointer();
6091 for(int i=0;i<nbOfTuple1;i++)
6092 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<int>());
6093 ret->copyStringInfoFrom(*a1);
6099 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
6104 void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
6107 throw INTERP_KERNEL::Exception("DataArrayInt::divideEqual : input DataArrayInt instance is NULL !");
6108 const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !";
6109 int nbOfTuple=getNumberOfTuples();
6110 int nbOfTuple2=other->getNumberOfTuples();
6111 int nbOfComp=getNumberOfComponents();
6112 int nbOfComp2=other->getNumberOfComponents();
6113 if(nbOfTuple==nbOfTuple2)
6115 if(nbOfComp==nbOfComp2)
6117 std::transform(begin(),end(),other->begin(),getPointer(),std::divides<int>());
6119 else if(nbOfComp2==1)
6121 int *ptr=getPointer();
6122 const int *ptrc=other->getConstPointer();
6123 for(int i=0;i<nbOfTuple;i++)
6124 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<int>(),*ptrc++));
6127 throw INTERP_KERNEL::Exception(msg);
6129 else if(nbOfTuple2==1)
6131 if(nbOfComp2==nbOfComp)
6133 int *ptr=getPointer();
6134 const int *ptrc=other->getConstPointer();
6135 for(int i=0;i<nbOfTuple;i++)
6136 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<int>());
6139 throw INTERP_KERNEL::Exception(msg);
6142 throw INTERP_KERNEL::Exception(msg);
6146 DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
6149 throw INTERP_KERNEL::Exception("DataArrayInt::Modulus : input DataArrayInt instance is NULL !");
6150 int nbOfTuple1=a1->getNumberOfTuples();
6151 int nbOfTuple2=a2->getNumberOfTuples();
6152 int nbOfComp1=a1->getNumberOfComponents();
6153 int nbOfComp2=a2->getNumberOfComponents();
6154 if(nbOfTuple2==nbOfTuple1)
6156 if(nbOfComp1==nbOfComp2)
6158 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6159 ret->alloc(nbOfTuple2,nbOfComp1);
6160 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::modulus<int>());
6161 ret->copyStringInfoFrom(*a1);
6165 else if(nbOfComp2==1)
6167 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6168 ret->alloc(nbOfTuple1,nbOfComp1);
6169 const int *a2Ptr=a2->getConstPointer();
6170 const int *a1Ptr=a1->getConstPointer();
6171 int *res=ret->getPointer();
6172 for(int i=0;i<nbOfTuple1;i++)
6173 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::modulus<int>(),a2Ptr[i]));
6174 ret->copyStringInfoFrom(*a1);
6180 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
6184 else if(nbOfTuple2==1)
6186 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
6187 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6188 ret->alloc(nbOfTuple1,nbOfComp1);
6189 const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
6190 int *pt=ret->getPointer();
6191 for(int i=0;i<nbOfTuple1;i++)
6192 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::modulus<int>());
6193 ret->copyStringInfoFrom(*a1);
6199 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Modulus !");//will always throw an exception
6204 void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
6207 throw INTERP_KERNEL::Exception("DataArrayInt::modulusEqual : input DataArrayInt instance is NULL !");
6208 const char *msg="Nb of tuples mismatch for DataArrayInt::modulusEqual !";
6209 int nbOfTuple=getNumberOfTuples();
6210 int nbOfTuple2=other->getNumberOfTuples();
6211 int nbOfComp=getNumberOfComponents();
6212 int nbOfComp2=other->getNumberOfComponents();
6213 if(nbOfTuple==nbOfTuple2)
6215 if(nbOfComp==nbOfComp2)
6217 std::transform(begin(),end(),other->begin(),getPointer(),std::modulus<int>());
6219 else if(nbOfComp2==1)
6221 if(nbOfComp2==nbOfComp)
6223 int *ptr=getPointer();
6224 const int *ptrc=other->getConstPointer();
6225 for(int i=0;i<nbOfTuple;i++)
6226 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::modulus<int>(),*ptrc++));
6229 throw INTERP_KERNEL::Exception(msg);
6232 throw INTERP_KERNEL::Exception(msg);
6234 else if(nbOfTuple2==1)
6236 int *ptr=getPointer();
6237 const int *ptrc=other->getConstPointer();
6238 for(int i=0;i<nbOfTuple;i++)
6239 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::modulus<int>());
6242 throw INTERP_KERNEL::Exception(msg);
6246 int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end)
6248 std::size_t sz=std::distance(start,end);
6249 int *ret=new int[sz];
6250 int *work=new int[sz];
6251 std::copy(start,end,work);
6252 std::sort(work,work+sz);
6253 if(std::unique(work,work+sz)!=work+sz)
6257 throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
6260 for(const int *iter=start;iter!=end;iter++,iter2++)
6261 *iter2=(int)std::distance(work,std::find(work,work+sz,*iter));
6266 DataArrayInt *DataArrayInt::Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception)
6268 int nbOfTuples=GetNumberOfItemGivenBESRelative(begin,end,step,"DataArrayInt::Range");
6269 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6270 ret->alloc(nbOfTuples,1);
6271 int *ptr=ret->getPointer();
6274 for(int i=begin;i<end;i+=step,ptr++)
6279 for(int i=begin;i>end;i+=step,ptr++)
6287 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
6290 void DataArrayInt::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
6295 tinyInfo[0]=getNumberOfTuples();
6296 tinyInfo[1]=getNumberOfComponents();
6306 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
6309 void DataArrayInt::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
6313 int nbOfCompo=getNumberOfComponents();
6314 tinyInfo.resize(nbOfCompo+1);
6315 tinyInfo[0]=getName();
6316 for(int i=0;i<nbOfCompo;i++)
6317 tinyInfo[i+1]=getInfoOnComponent(i);
6322 tinyInfo[0]=getName();
6327 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
6328 * This method returns if a feeding is needed.
6330 bool DataArrayInt::resizeForUnserialization(const std::vector<int>& tinyInfoI)
6332 int nbOfTuple=tinyInfoI[0];
6333 int nbOfComp=tinyInfoI[1];
6334 if(nbOfTuple!=-1 || nbOfComp!=-1)
6336 alloc(nbOfTuple,nbOfComp);
6343 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
6344 * This method returns if a feeding is needed.
6346 void DataArrayInt::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
6348 setName(tinyInfoS[0].c_str());
6351 int nbOfCompo=getNumberOfComponents();
6352 for(int i=0;i<nbOfCompo;i++)
6353 setInfoOnComponent(i,tinyInfoS[i+1].c_str());
6357 DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
6362 if(_da->isAllocated())
6364 _nb_comp=da->getNumberOfComponents();
6365 _nb_tuple=da->getNumberOfTuples();
6366 _pt=da->getPointer();
6371 DataArrayIntIterator::~DataArrayIntIterator()
6377 DataArrayIntTuple *DataArrayIntIterator::nextt()
6379 if(_tuple_id<_nb_tuple)
6382 DataArrayIntTuple *ret=new DataArrayIntTuple(_pt,_nb_comp);
6390 DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
6394 std::string DataArrayIntTuple::repr() const
6396 std::ostringstream oss; oss << "(";
6397 for(int i=0;i<_nb_of_compo-1;i++)
6398 oss << _pt[i] << ", ";
6399 oss << _pt[_nb_of_compo-1] << ")";
6403 int DataArrayIntTuple::intValue() const throw(INTERP_KERNEL::Exception)
6407 throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
6411 * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayInt::decrRef.
6412 * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayInt::useArray with ownership set to \b false.
6413 * This method throws an INTERP_KERNEL::Exception is it is impossible to match sizes of \b this that is too say \b nbOfCompo=this->_nb_of_elem and \bnbOfTuples==1 or
6414 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
6416 DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
6418 if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
6420 DataArrayInt *ret=DataArrayInt::New();
6421 ret->useArray(_pt,false,CPP_DEALLOC,nbOfTuples,nbOfCompo);
6426 std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
6427 oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
6428 throw INTERP_KERNEL::Exception(oss.str().c_str());