1 // Copyright (C) 2007-2013 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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingMemArray.txx"
22 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
24 #include "GenMathFormulae.hxx"
25 #include "InterpKernelExprParser.hxx"
34 typedef double (*MYFUNCPTR)(double);
36 using namespace ParaMEDMEM;
38 template<int SPACEDIM>
39 void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
41 const double *coordsPtr=getConstPointer();
42 BBTree<SPACEDIM,int> myTree(bbox,0,0,nbNodes,prec/10);
43 std::vector<bool> isDone(nbNodes);
44 for(int i=0;i<nbNodes;i++)
48 std::vector<int> intersectingElems;
49 myTree.getElementsAroundPoint(coordsPtr+i*SPACEDIM,intersectingElems);
50 if(intersectingElems.size()>1)
52 std::vector<int> commonNodes;
53 for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
57 commonNodes.push_back(*it);
60 if(!commonNodes.empty())
62 cI->pushBackSilent(cI->back()+(int)commonNodes.size()+1);
64 c->insertAtTheEnd(commonNodes.begin(),commonNodes.end());
71 template<int SPACEDIM>
72 void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTree<SPACEDIM,int>& myTree, const double *pos, int nbOfTuples, double eps,
73 DataArrayInt *c, DataArrayInt *cI)
75 for(int i=0;i<nbOfTuples;i++)
77 std::vector<int> intersectingElems;
78 myTree.getElementsAroundPoint(pos+i*SPACEDIM,intersectingElems);
79 std::vector<int> commonNodes;
80 for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
81 commonNodes.push_back(*it);
82 cI->pushBackSilent(cI->back()+(int)commonNodes.size());
83 c->insertAtTheEnd(commonNodes.begin(),commonNodes.end());
87 template<int SPACEDIM>
88 void DataArrayDouble::FindClosestTupleIdAlg(const BBTreePts<SPACEDIM,int>& myTree, double dist, const double *pos, int nbOfTuples, const double *thisPt, int thisNbOfTuples, int *res)
93 for(int i=0;i<nbOfTuples;i++,p+=SPACEDIM,r++)
98 double ret=myTree.getElementsAroundPoint2(p,distOpt,elem);
99 if(ret!=std::numeric_limits<double>::max())
101 distOpt=std::max(ret,1e-4);
106 { distOpt=2*distOpt; continue; }
111 std::size_t DataArray::getHeapMemorySize() const
113 std::size_t sz1=_name.capacity();
114 std::size_t sz2=_info_on_compo.capacity();
116 for(std::vector<std::string>::const_iterator it=_info_on_compo.begin();it!=_info_on_compo.end();it++)
117 sz3+=(*it).capacity();
122 * Sets the attribute \a _name of \a this array.
123 * See \ref MEDCouplingArrayBasicsName "DataArrays infos" for more information.
124 * \param [in] name - new array name
126 void DataArray::setName(const char *name)
132 * Copies textual data from an \a other DataArray. The copied data are
133 * - the name attribute,
134 * - the information of components.
136 * For more information on these data see \ref MEDCouplingArrayBasicsName "DataArrays infos".
138 * \param [in] other - another instance of DataArray to copy the textual data from.
139 * \throw If number of components of \a this array differs from that of the \a other.
141 void DataArray::copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception)
143 if(_info_on_compo.size()!=other._info_on_compo.size())
144 throw INTERP_KERNEL::Exception("Size of arrays mismatches on copyStringInfoFrom !");
146 _info_on_compo=other._info_on_compo;
149 void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
151 int nbOfCompoOth=other.getNumberOfComponents();
152 std::size_t newNbOfCompo=compoIds.size();
153 for(std::size_t i=0;i<newNbOfCompo;i++)
154 if(compoIds[i]>=nbOfCompoOth || compoIds[i]<0)
156 std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")";
157 throw INTERP_KERNEL::Exception(oss.str().c_str());
159 for(std::size_t i=0;i<newNbOfCompo;i++)
160 setInfoOnComponent((int)i,other.getInfoOnComponent(compoIds[i]).c_str());
163 void DataArray::copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception)
165 int nbOfCompo=getNumberOfComponents();
166 std::size_t partOfCompoToSet=compoIds.size();
167 if((int)partOfCompoToSet!=other.getNumberOfComponents())
168 throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !");
169 for(std::size_t i=0;i<partOfCompoToSet;i++)
170 if(compoIds[i]>=nbOfCompo || compoIds[i]<0)
172 std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")";
173 throw INTERP_KERNEL::Exception(oss.str().c_str());
175 for(std::size_t i=0;i<partOfCompoToSet;i++)
176 setInfoOnComponent(compoIds[i],other.getInfoOnComponent((int)i).c_str());
179 bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const throw(INTERP_KERNEL::Exception)
181 std::ostringstream oss;
182 if(_name!=other._name)
184 oss << "Names DataArray mismatch : this name=\"" << _name << " other name=\"" << other._name << "\" !";
188 if(_info_on_compo!=other._info_on_compo)
190 oss << "Components DataArray mismatch : \nThis components=";
191 for(std::vector<std::string>::const_iterator it=_info_on_compo.begin();it!=_info_on_compo.end();it++)
192 oss << "\"" << *it << "\",";
193 oss << "\nOther components=";
194 for(std::vector<std::string>::const_iterator it=other._info_on_compo.begin();it!=other._info_on_compo.end();it++)
195 oss << "\"" << *it << "\",";
203 * Compares textual information of \a this DataArray with that of an \a other one.
204 * The compared data are
205 * - the name attribute,
206 * - the information of components.
208 * For more information on these data see \ref MEDCouplingArrayBasicsName "DataArrays infos".
209 * \param [in] other - another instance of DataArray to compare the textual data of.
210 * \return bool - \a true if the textual information is same, \a false else.
212 bool DataArray::areInfoEquals(const DataArray& other) const throw(INTERP_KERNEL::Exception)
215 return areInfoEqualsIfNotWhy(other,tmp);
218 void DataArray::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
220 stream << "Number of components : "<< getNumberOfComponents() << "\n";
221 stream << "Info of these components : ";
222 for(std::vector<std::string>::const_iterator iter=_info_on_compo.begin();iter!=_info_on_compo.end();iter++)
223 stream << "\"" << *iter << "\" ";
227 std::string DataArray::cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception)
229 std::ostringstream ret;
230 reprCppStream(varName,ret);
235 * Sets information on all components. To know more on format of this information
236 * see \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
237 * \param [in] info - a vector of strings.
238 * \throw If size of \a info differs from the number of components of \a this.
240 void DataArray::setInfoOnComponents(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
242 if(getNumberOfComponents()!=(int)info.size())
244 std::ostringstream oss; oss << "DataArray::setInfoOnComponents : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " !";
245 throw INTERP_KERNEL::Exception(oss.str().c_str());
250 std::vector<std::string> DataArray::getVarsOnComponent() const throw(INTERP_KERNEL::Exception)
252 int nbOfCompo=(int)_info_on_compo.size();
253 std::vector<std::string> ret(nbOfCompo);
254 for(int i=0;i<nbOfCompo;i++)
255 ret[i]=getVarOnComponent(i);
259 std::vector<std::string> DataArray::getUnitsOnComponent() const throw(INTERP_KERNEL::Exception)
261 int nbOfCompo=(int)_info_on_compo.size();
262 std::vector<std::string> ret(nbOfCompo);
263 for(int i=0;i<nbOfCompo;i++)
264 ret[i]=getUnitOnComponent(i);
269 * Returns information on a component specified by an index.
270 * To know more on format of this information
271 * see \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
272 * \param [in] i - the index (zero based) of the component of interest.
273 * \return std::string - a string containing the information on \a i-th component.
274 * \throw If \a i is not a valid component index.
276 std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
278 if(i<(int)_info_on_compo.size() && i>=0)
279 return _info_on_compo[i];
282 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();
283 throw INTERP_KERNEL::Exception(oss.str().c_str());
288 * Returns the var part of the full information of the \a i-th component.
289 * For example, if \c getInfoOnComponent(0) returns "SIGXY [N/m^2]", then
290 * \c getVarOnComponent(0) returns "SIGXY".
291 * If a unit part of information is not detected by presence of
292 * two square brackets, then the full information is returned.
293 * To read more about the component information format, see
294 * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
295 * \param [in] i - the index (zero based) of the component of interest.
296 * \return std::string - a string containing the var information, or the full info.
297 * \throw If \a i is not a valid component index.
299 std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception)
301 if(i<(int)_info_on_compo.size() && i>=0)
303 return GetVarNameFromInfo(_info_on_compo[i]);
307 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();
308 throw INTERP_KERNEL::Exception(oss.str().c_str());
313 * Returns the unit part of the full information of the \a i-th component.
314 * For example, if \c getInfoOnComponent(0) returns "SIGXY [ N/m^2]", then
315 * \c getUnitOnComponent(0) returns " N/m^2".
316 * If a unit part of information is not detected by presence of
317 * two square brackets, then an empty string is returned.
318 * To read more about the component information format, see
319 * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
320 * \param [in] i - the index (zero based) of the component of interest.
321 * \return std::string - a string containing the unit information, if any, or "".
322 * \throw If \a i is not a valid component index.
324 std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception)
326 if(i<(int)_info_on_compo.size() && i>=0)
328 return GetUnitFromInfo(_info_on_compo[i]);
332 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();
333 throw INTERP_KERNEL::Exception(oss.str().c_str());
338 * Returns the var part of the full component information.
339 * For example, if \a info == "SIGXY [N/m^2]", then this method returns "SIGXY".
340 * If a unit part of information is not detected by presence of
341 * two square brackets, then the whole \a info is returned.
342 * To read more about the component information format, see
343 * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
344 * \param [in] info - the full component information.
345 * \return std::string - a string containing only var information, or the \a info.
347 std::string DataArray::GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
349 std::size_t p1=info.find_last_of('[');
350 std::size_t p2=info.find_last_of(']');
351 if(p1==std::string::npos || p2==std::string::npos)
356 return std::string();
357 std::size_t p3=info.find_last_not_of(' ',p1-1);
358 return info.substr(0,p3+1);
362 * Returns the unit part of the full component information.
363 * For example, if \a info == "SIGXY [ N/m^2]", then this method returns " N/m^2".
364 * If a unit part of information is not detected by presence of
365 * two square brackets, then an empty string is returned.
366 * To read more about the component information format, see
367 * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
368 * \param [in] info - the full component information.
369 * \return std::string - a string containing only unit information, if any, or "".
371 std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
373 std::size_t p1=info.find_last_of('[');
374 std::size_t p2=info.find_last_of(']');
375 if(p1==std::string::npos || p2==std::string::npos)
376 return std::string();
378 return std::string();
379 return info.substr(p1+1,p2-p1-1);
383 * Sets information on a component specified by an index.
384 * To know more on format of this information
385 * see \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
386 * \param [in] i - the index (zero based) of the component of interest.
387 * \param [in] info - the string containing the information.
388 * \throw If \a i is not a valid component index.
389 * \warning Don't pass NULL as \a info!
391 void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
393 if(i<(int)_info_on_compo.size() && i>=0)
394 _info_on_compo[i]=info;
397 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();
398 throw INTERP_KERNEL::Exception(oss.str().c_str());
402 void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception)
404 if(getNumberOfTuples()!=nbOfTuples)
406 std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " << nbOfTuples << " having " << getNumberOfTuples() << " !";
407 throw INTERP_KERNEL::Exception(oss.str().c_str());
411 void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
413 if(getNumberOfComponents()!=nbOfCompo)
415 std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
416 throw INTERP_KERNEL::Exception(oss.str().c_str());
420 void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception)
422 if(getNbOfElems()!=nbOfElems)
424 std::ostringstream oss; oss << msg << " : mismatch number of elems : Expected " << nbOfElems << " having " << getNbOfElems() << " !";
425 throw INTERP_KERNEL::Exception(oss.str().c_str());
429 void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception)
431 if(getNumberOfTuples()!=other.getNumberOfTuples())
433 std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " << other.getNumberOfTuples() << " having " << getNumberOfTuples() << " !";
434 throw INTERP_KERNEL::Exception(oss.str().c_str());
436 if(getNumberOfComponents()!=other.getNumberOfComponents())
438 std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << other.getNumberOfComponents() << " having " << getNumberOfComponents() << " !";
439 throw INTERP_KERNEL::Exception(oss.str().c_str());
443 void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
445 checkNbOfTuples(nbOfTuples,msg);
446 checkNbOfComps(nbOfCompo,msg);
450 * Simply this method checks that \b value is in [0,\b ref).
452 void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
454 if(value<0 || value>=ref)
456 std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected in range [0," << ref << "[ having " << value << " !";
457 throw INTERP_KERNEL::Exception(oss.str().c_str());
462 * This method checks that [\b start, \b end) is compliant with ref length \b value.
463 * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
465 void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception)
467 if(start<0 || start>=value)
469 if(value!=start || end!=start)
471 std::ostringstream oss; oss << "DataArray::CheckValueInRangeEx : " << msg << " ! Expected start " << start << " of input range, in [0," << value << "[ !";
472 throw INTERP_KERNEL::Exception(oss.str().c_str());
475 if(end<0 || end>value)
477 std::ostringstream oss; oss << "DataArray::CheckValueInRangeEx : " << msg << " ! Expected end " << end << " of input range, in [0," << value << "] !";
478 throw INTERP_KERNEL::Exception(oss.str().c_str());
482 void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
484 if(value<0 || value>ref)
486 std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected input range in [0," << ref << "] having closing open parenthesis " << value << " !";
487 throw INTERP_KERNEL::Exception(oss.str().c_str());
491 int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
495 std::ostringstream oss; oss << msg << " : end before begin !";
496 throw INTERP_KERNEL::Exception(oss.str().c_str());
502 std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
503 throw INTERP_KERNEL::Exception(oss.str().c_str());
505 return (end-1-begin)/step+1;
508 int DataArray::GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
511 throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES : step=0 is not allowed !");
512 if(end<begin && step>0)
514 std::ostringstream oss; oss << msg << " : end before begin whereas step is positive !";
515 throw INTERP_KERNEL::Exception(oss.str().c_str());
517 if(begin<end && step<0)
519 std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
520 throw INTERP_KERNEL::Exception(oss.str().c_str());
523 return (std::max(begin,end)-1-std::min(begin,end))/std::abs(step)+1;
528 int DataArray::GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception)
534 if(begin<=value && value<end)
536 if((value-begin)%step==0)
537 return (value-begin)/step;
546 if(begin>=value && value>end)
548 if((begin-value)%(-step)==0)
549 return (begin-value)/(-step);
562 * Returns a new instance of DataArrayDouble. The caller is to delete this array
563 * using decrRef() as it is no more needed.
565 DataArrayDouble *DataArrayDouble::New()
567 return new DataArrayDouble;
571 * Checks if raw data is allocated. Read more on the raw data
572 * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information.
573 * \return bool - \a true if the raw data is allocated, \a false else.
575 bool DataArrayDouble::isAllocated() const throw(INTERP_KERNEL::Exception)
577 return getConstPointer()!=0;
581 * Checks if raw data is allocated and throws an exception if it is not the case.
582 * \throw If the raw data is not allocated.
584 void DataArrayDouble::checkAllocated() const throw(INTERP_KERNEL::Exception)
587 throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
590 std::size_t DataArrayDouble::getHeapMemorySize() const
592 std::size_t sz=_mem.getNbOfElemAllocated();
594 return DataArray::getHeapMemorySize()+sz;
598 * Sets information on all components. This method can change number of components
599 * at certain conditions; if the conditions are not respected, an exception is thrown.
600 * The number of components can be changed provided that \a this is not allocated.
602 * To know more on format of the component information see
603 * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
604 * \param [in] info - a vector of component infos.
605 * \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated()
607 void DataArrayDouble::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
609 if(getNumberOfComponents()!=(int)info.size())
615 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 !";
616 throw INTERP_KERNEL::Exception(oss.str().c_str());
624 * Returns the only one value in \a this, if and only if number of elements
625 * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated.
626 * \return double - the sole value stored in \a this array.
627 * \throw If at least one of conditions stated above is not fulfilled.
629 double DataArrayDouble::doubleValue() const throw(INTERP_KERNEL::Exception)
633 if(getNbOfElems()==1)
635 return *getConstPointer();
638 throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is allocated but number of elements is not equal to 1 !");
641 throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is not allocated !");
645 * Checks the number of tuples.
646 * \return bool - \a true if getNumberOfTuples() == 0, \a false else.
647 * \throw If \a this is not allocated.
649 bool DataArrayDouble::empty() const throw(INTERP_KERNEL::Exception)
652 return getNumberOfTuples()==0;
656 * Returns a full copy of \a this. For more info on copying data arrays see
657 * \ref MEDCouplingArrayBasicsCopyDeep.
658 * \return DataArrayDouble * - a new instance of DataArrayDouble.
660 DataArrayDouble *DataArrayDouble::deepCpy() const throw(INTERP_KERNEL::Exception)
662 return new DataArrayDouble(*this);
666 * Returns either a \a deep or \a shallow copy of this array. For more info see
667 * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
668 * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
669 * \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
670 * == \a true) or \a this instance (if \a dCpy == \a false).
672 DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception)
679 return const_cast<DataArrayDouble *>(this);
684 * Copies all the data from another DataArrayDouble. For more info see
685 * \ref MEDCouplingArrayBasicsCopyDeepAssign.
686 * \param [in] other - another instance of DataArrayDouble to copy data from.
687 * \throw If the \a other is not allocated.
689 void DataArrayDouble::cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception)
691 other.checkAllocated();
692 int nbOfTuples=other.getNumberOfTuples();
693 int nbOfComp=other.getNumberOfComponents();
694 allocIfNecessary(nbOfTuples,nbOfComp);
695 std::size_t nbOfElems=(std::size_t)nbOfTuples*nbOfComp;
696 double *pt=getPointer();
697 const double *ptI=other.getConstPointer();
698 for(std::size_t i=0;i<nbOfElems;i++)
700 copyStringInfoFrom(other);
704 * This method reserve nbOfElems elements in memory ( nbOfElems*8 bytes ) \b without impacting the number of tuples in \a this.
705 * If \a this has already been allocated, this method checks that \a this has only one component. If not an INTERP_KERNEL::Exception will be thrown.
706 * If \a this has not already been allocated, number of components is set to one.
707 * This method allows to reduce number of reallocations on invokation of DataArrayDouble::pushBackSilent and DataArrayDouble::pushBackValsSilent on \a this.
709 * \sa DataArrayDouble::pack, DataArrayDouble::pushBackSilent, DataArrayDouble::pushBackValsSilent
711 void DataArrayDouble::reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception)
713 int nbCompo=getNumberOfComponents();
716 _mem.reserve(nbOfElems);
720 _mem.reserve(nbOfElems);
721 _info_on_compo.resize(1);
724 throw INTERP_KERNEL::Exception("DataArrayDouble::reserve : not available for DataArrayDouble with number of components different than 1 !");
728 * This method adds at the end of \a this the single value \a val. This method do \b not update its time label to avoid useless incrementation
729 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
731 * \param [in] val the value to be added in \a this
732 * \throw If \a this has already been allocated with number of components different from one.
733 * \sa DataArrayDouble::pushBackValsSilent
735 void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception)
737 int nbCompo=getNumberOfComponents();
742 _info_on_compo.resize(1);
746 throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !");
750 * This method adds at the end of \a this a serie of values [\c valsBg,\c valsEnd). This method do \b not update its time label to avoid useless incrementation
751 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
753 * \param [in] valsBg - an array of values to push at the end of \this.
754 * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
755 * the last value of \a valsBg is \a valsEnd[ -1 ].
756 * \throw If \a this has already been allocated with number of components different from one.
757 * \sa DataArrayDouble::pushBackSilent
759 void DataArrayDouble::pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception)
761 int nbCompo=getNumberOfComponents();
763 _mem.insertAtTheEnd(valsBg,valsEnd);
766 _info_on_compo.resize(1);
767 _mem.insertAtTheEnd(valsBg,valsEnd);
770 throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackValsSilent : not available for DataArrayDouble with number of components different than 1 !");
774 * This method returns silently ( without updating time label in \a this ) the last value, if any and suppress it.
775 * \throw If \a this is already empty.
776 * \throw If \a this has number of components different from one.
778 double DataArrayDouble::popBackSilent() throw(INTERP_KERNEL::Exception)
780 if(getNumberOfComponents()==1)
781 return _mem.popBack();
783 throw INTERP_KERNEL::Exception("DataArrayDouble::popBackSilent : not available for DataArrayDouble with number of components different than 1 !");
787 * This method \b do \b not modify content of \a this. It only modify its memory footprint if the allocated memory is to high regarding real data to store.
789 * \sa DataArrayDouble::getHeapMemorySize, DataArrayDouble::reserve
791 void DataArrayDouble::pack() const throw(INTERP_KERNEL::Exception)
797 * Allocates the raw data in memory. If exactly same memory as needed already
798 * allocated, it is not re-allocated.
799 * \param [in] nbOfTuple - number of tuples of data to allocate.
800 * \param [in] nbOfCompo - number of components of data to allocate.
801 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
803 void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
807 if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
808 alloc(nbOfTuple,nbOfCompo);
811 alloc(nbOfTuple,nbOfCompo);
815 * Allocates the raw data in memory. If the memory was already allocated, then it is
816 * freed and re-allocated. See an example of this method use
817 * \ref MEDCouplingArraySteps1WC "here".
818 * \param [in] nbOfTuple - number of tuples of data to allocate.
819 * \param [in] nbOfCompo - number of components of data to allocate.
820 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
822 void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
824 if(nbOfTuple<0 || nbOfCompo<0)
825 throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
826 _info_on_compo.resize(nbOfCompo);
827 _mem.alloc(nbOfCompo*(std::size_t)nbOfTuple);
832 * Assign zero to all values in \a this array. To know more on filling arrays see
833 * \ref MEDCouplingArrayFill.
834 * \throw If \a this is not allocated.
836 void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception)
839 _mem.fillWithValue(0.);
844 * Assign \a val to all values in \a this array. To know more on filling arrays see
845 * \ref MEDCouplingArrayFill.
846 * \param [in] val - the value to fill with.
847 * \throw If \a this is not allocated.
849 void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception)
852 _mem.fillWithValue(val);
857 * Set all values in \a this array so that the i-th element equals to \a init + i
858 * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
859 * \param [in] init - value to assign to the first element of array.
860 * \throw If \a this->getNumberOfComponents() != 1
861 * \throw If \a this is not allocated.
863 void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception)
866 if(getNumberOfComponents()!=1)
867 throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
868 double *ptr=getPointer();
869 int ntuples=getNumberOfTuples();
870 for(int i=0;i<ntuples;i++)
871 ptr[i]=init+double(i);
876 * Checks if all values in \a this array are equal to \a val at precision \a eps.
877 * \param [in] val - value to check equality of array values to.
878 * \param [in] eps - precision to check the equality.
879 * \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
881 * \throw If \a this->getNumberOfComponents() != 1
882 * \throw If \a this is not allocated.
884 bool DataArrayDouble::isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception)
887 if(getNumberOfComponents()!=1)
888 throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
889 int nbOfTuples=getNumberOfTuples();
890 const double *w=getConstPointer();
891 const double *end2=w+nbOfTuples;
892 const double vmin=val-eps;
893 const double vmax=val+eps;
895 if(*w<vmin || *w>vmax)
901 * Sorts values of the array.
902 * \param [in] asc - \a true means ascending order, \a false, descending.
903 * \throw If \a this is not allocated.
904 * \throw If \a this->getNumberOfComponents() != 1.
906 void DataArrayDouble::sort(bool asc) throw(INTERP_KERNEL::Exception)
909 if(getNumberOfComponents()!=1)
910 throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !");
916 * Reverse the array values.
917 * \throw If \a this->getNumberOfComponents() < 1.
918 * \throw If \a this is not allocated.
920 void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception)
923 _mem.reverse(getNumberOfComponents());
928 * Checks that \a this array is consistently **increasing** or **decreasing** in value,
929 * with at least absolute difference value of |\a eps| at each step.
930 * If not an exception is thrown.
931 * \param [in] increasing - if \a true, the array values should be increasing.
932 * \param [in] eps - minimal absolute difference between the neighbor values at which
933 * the values are considered different.
934 * \throw If sequence of values is not strictly monotonic in agreement with \a
936 * \throw If \a this->getNumberOfComponents() != 1.
937 * \throw If \a this is not allocated.
939 void DataArrayDouble::checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
941 if(!isMonotonic(increasing,eps))
944 throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not INCREASING monotonic !");
946 throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not DECREASING monotonic !");
951 * Checks that \a this array is consistently **increasing** or **decreasing** in value,
952 * with at least absolute difference value of |\a eps| at each step.
953 * \param [in] increasing - if \a true, array values should be increasing.
954 * \param [in] eps - minimal absolute difference between the neighbor values at which
955 * the values are considered different.
956 * \return bool - \a true if values change in accordance with \a increasing arg.
957 * \throw If \a this->getNumberOfComponents() != 1.
958 * \throw If \a this is not allocated.
960 bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
963 if(getNumberOfComponents()!=1)
964 throw INTERP_KERNEL::Exception("DataArrayDouble::isMonotonic : only supported with 'this' array with ONE component !");
965 int nbOfElements=getNumberOfTuples();
966 const double *ptr=getConstPointer();
970 double absEps=fabs(eps);
973 for(int i=1;i<nbOfElements;i++)
975 if(ptr[i]<(ref+absEps))
983 for(int i=1;i<nbOfElements;i++)
985 if(ptr[i]>(ref-absEps))
994 * Returns a textual and human readable representation of \a this instance of
995 * DataArrayDouble. This text is shown when a DataArrayDouble is printed in Python.
996 * \return std::string - text describing \a this DataArrayDouble.
998 std::string DataArrayDouble::repr() const throw(INTERP_KERNEL::Exception)
1000 std::ostringstream ret;
1005 std::string DataArrayDouble::reprZip() const throw(INTERP_KERNEL::Exception)
1007 std::ostringstream ret;
1012 void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
1014 std::string idt(indent,' ');
1016 ofs << idt << "<DataArray type=\"Float32\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
1017 ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
1018 std::copy(begin(),end(),std::ostream_iterator<double>(ofs," "));
1019 ofs << std::endl << idt << "</DataArray>\n";
1022 void DataArrayDouble::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1024 stream << "Name of double array : \"" << _name << "\"\n";
1025 reprWithoutNameStream(stream);
1028 void DataArrayDouble::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1030 stream << "Name of double array : \"" << _name << "\"\n";
1031 reprZipWithoutNameStream(stream);
1034 void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1036 DataArray::reprWithoutNameStream(stream);
1037 stream.precision(17);
1038 _mem.repr(getNumberOfComponents(),stream);
1041 void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1043 DataArray::reprWithoutNameStream(stream);
1044 stream.precision(17);
1045 _mem.reprZip(getNumberOfComponents(),stream);
1048 void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1050 int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
1051 const double *data=getConstPointer();
1052 stream.precision(17);
1053 stream << "DataArrayDouble *" << varName << "=DataArrayDouble::New();" << std::endl;
1054 if(nbTuples*nbComp>=1)
1056 stream << "const double " << varName << "Data[" << nbTuples*nbComp << "]={";
1057 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<double>(stream,","));
1058 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
1059 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
1062 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
1063 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
1067 * Method that gives a quick overvien of \a this for python.
1069 void DataArrayDouble::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1071 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
1072 stream << "DataArrayDouble C++ instance at " << this << ". ";
1075 int nbOfCompo=(int)_info_on_compo.size();
1078 int nbOfTuples=getNumberOfTuples();
1079 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
1080 const double *data=begin();
1081 std::ostringstream oss2; oss2 << "[";
1083 std::string oss2Str(oss2.str());
1084 bool isFinished=true;
1085 for(int i=0;i<nbOfTuples && isFinished;i++)
1090 for(int j=0;j<nbOfCompo;j++,data++)
1093 if(j!=nbOfCompo-1) oss2 << ", ";
1099 if(i!=nbOfTuples-1) oss2 << ", ";
1100 std::string oss3Str(oss2.str());
1101 if(oss3Str.length()<MAX_NB_OF_BYTE_IN_REPR)
1112 stream << "Number of components : 0.";
1115 stream << "*** No data allocated ****";
1119 * Equivalent to DataArrayDouble::isEqual except that if false the reason of
1120 * mismatch is given.
1122 * \param [in] other the instance to be compared with \a this
1123 * \param [in] prec the precision to compare numeric data of the arrays.
1124 * \param [out] reason In case of inequality returns the reason.
1125 * \sa DataArrayDouble::isEqual
1127 bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
1129 if(!areInfoEqualsIfNotWhy(other,reason))
1131 return _mem.isEqual(other._mem,prec,reason);
1135 * Checks if \a this and another DataArrayDouble are fully equal. For more info see
1136 * \ref MEDCouplingArrayBasicsCompare.
1137 * \param [in] other - an instance of DataArrayDouble to compare with \a this one.
1138 * \param [in] prec - precision value to compare numeric data of the arrays.
1139 * \return bool - \a true if the two arrays are equal, \a false else.
1141 bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception)
1144 return isEqualIfNotWhy(other,prec,tmp);
1148 * Checks if values of \a this and another DataArrayDouble are equal. For more info see
1149 * \ref MEDCouplingArrayBasicsCompare.
1150 * \param [in] other - an instance of DataArrayDouble to compare with \a this one.
1151 * \param [in] prec - precision value to compare numeric data of the arrays.
1152 * \return bool - \a true if the values of two arrays are equal, \a false else.
1154 bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception)
1157 return _mem.isEqual(other._mem,prec,tmp);
1161 * Changes number of tuples in the array. If the new number of tuples is smaller
1162 * than the current number the array is truncated, otherwise the array is extended.
1163 * \param [in] nbOfTuples - new number of tuples.
1164 * \throw If \a this is not allocated.
1166 void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
1169 _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
1174 * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
1175 * array to the new one.
1176 * \return DataArrayInt * - the new instance of DataArrayInt.
1178 DataArrayInt *DataArrayDouble::convertToIntArr() const
1180 DataArrayInt *ret=DataArrayInt::New();
1181 ret->alloc(getNumberOfTuples(),getNumberOfComponents());
1182 std::size_t nbOfVals=getNbOfElems();
1183 const double *src=getConstPointer();
1184 int *dest=ret->getPointer();
1185 std::copy(src,src+nbOfVals,dest);
1186 ret->copyStringInfoFrom(*this);
1191 * Returns a new DataArrayDouble holding the same values as \a this array but differently
1192 * arranged in memory. If \a this array holds 2 components of 3 values:
1193 * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
1194 * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
1195 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1196 * is to delete using decrRef() as it is no more needed.
1197 * \throw If \a this is not allocated.
1198 * \warning Do not confuse this method with transpose()!
1200 DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
1203 throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
1204 double *tab=_mem.fromNoInterlace(getNumberOfComponents());
1205 DataArrayDouble *ret=DataArrayDouble::New();
1206 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
1211 * Returns a new DataArrayDouble holding the same values as \a this array but differently
1212 * arranged in memory. If \a this array holds 2 components of 3 values:
1213 * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
1214 * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
1215 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1216 * is to delete using decrRef() as it is no more needed.
1217 * \throw If \a this is not allocated.
1218 * \warning Do not confuse this method with transpose()!
1220 DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception)
1223 throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
1224 double *tab=_mem.toNoInterlace(getNumberOfComponents());
1225 DataArrayDouble *ret=DataArrayDouble::New();
1226 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
1231 * Permutes values of \a this array as required by \a old2New array. The values are
1232 * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains
1233 * the same as in \this one.
1234 * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
1235 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1236 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1237 * giving a new position for i-th old value.
1239 void DataArrayDouble::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception)
1242 int nbTuples=getNumberOfTuples();
1243 int nbOfCompo=getNumberOfComponents();
1244 double *tmp=new double[nbTuples*nbOfCompo];
1245 const double *iptr=getConstPointer();
1246 for(int i=0;i<nbTuples;i++)
1247 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
1248 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
1254 * Permutes values of \a this array as required by \a new2Old array. The values are
1255 * permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of tuples remains
1256 * the same as in \this one.
1257 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1258 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
1259 * giving a previous position of i-th new value.
1260 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1261 * is to delete using decrRef() as it is no more needed.
1263 void DataArrayDouble::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception)
1266 int nbTuples=getNumberOfTuples();
1267 int nbOfCompo=getNumberOfComponents();
1268 double *tmp=new double[nbTuples*nbOfCompo];
1269 const double *iptr=getConstPointer();
1270 for(int i=0;i<nbTuples;i++)
1271 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
1272 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
1278 * Returns a copy of \a this array with values permuted as required by \a old2New array.
1279 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ].
1280 * Number of tuples in the result array remains the same as in \this one.
1281 * If a permutation reduction is needed, renumberAndReduce() should be used.
1282 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1283 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1284 * giving a new position for i-th old value.
1285 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1286 * is to delete using decrRef() as it is no more needed.
1287 * \throw If \a this is not allocated.
1289 DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception)
1292 int nbTuples=getNumberOfTuples();
1293 int nbOfCompo=getNumberOfComponents();
1294 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1295 ret->alloc(nbTuples,nbOfCompo);
1296 ret->copyStringInfoFrom(*this);
1297 const double *iptr=getConstPointer();
1298 double *optr=ret->getPointer();
1299 for(int i=0;i<nbTuples;i++)
1300 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
1301 ret->copyStringInfoFrom(*this);
1306 * Returns a copy of \a this array with values permuted as required by \a new2Old array.
1307 * The values are permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
1308 * tuples in the result array remains the same as in \this one.
1309 * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
1310 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1311 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
1312 * giving a previous position of i-th new value.
1313 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1314 * is to delete using decrRef() as it is no more needed.
1316 DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception)
1319 int nbTuples=getNumberOfTuples();
1320 int nbOfCompo=getNumberOfComponents();
1321 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1322 ret->alloc(nbTuples,nbOfCompo);
1323 ret->copyStringInfoFrom(*this);
1324 const double *iptr=getConstPointer();
1325 double *optr=ret->getPointer();
1326 for(int i=0;i<nbTuples;i++)
1327 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
1328 ret->copyStringInfoFrom(*this);
1333 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1334 * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
1335 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ] for all
1336 * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which
1337 * \a old2New[ i ] is negative, is missing from the result array.
1338 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1339 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1340 * giving a new position for i-th old tuple and giving negative position for
1341 * for i-th old tuple that should be omitted.
1342 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1343 * is to delete using decrRef() as it is no more needed.
1345 DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception)
1348 int nbTuples=getNumberOfTuples();
1349 int nbOfCompo=getNumberOfComponents();
1350 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1351 ret->alloc(newNbOfTuple,nbOfCompo);
1352 const double *iptr=getConstPointer();
1353 double *optr=ret->getPointer();
1354 for(int i=0;i<nbTuples;i++)
1358 std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
1360 ret->copyStringInfoFrom(*this);
1365 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1366 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1367 * \a new2OldBg array.
1368 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1369 * This method is equivalent to renumberAndReduce() except that convention in input is
1370 * \c new2old and \b not \c old2new.
1371 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1372 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1373 * tuple index in \a this array to fill the i-th tuple in the new array.
1374 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1375 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1376 * \a new2OldBg <= \a pi < \a new2OldEnd.
1377 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1378 * is to delete using decrRef() as it is no more needed.
1380 DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
1383 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1384 int nbComp=getNumberOfComponents();
1385 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1386 ret->copyStringInfoFrom(*this);
1387 double *pt=ret->getPointer();
1388 const double *srcPt=getConstPointer();
1390 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1391 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1392 ret->copyStringInfoFrom(*this);
1397 * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1398 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1399 * \a new2OldBg array.
1400 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1401 * This method is equivalent to renumberAndReduce() except that convention in input is
1402 * \c new2old and \b not \c old2new.
1403 * This method is equivalent to selectByTupleId() except that it prevents coping data
1404 * from behind the end of \a this array.
1405 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1406 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1407 * tuple index in \a this array to fill the i-th tuple in the new array.
1408 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1409 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1410 * \a new2OldBg <= \a pi < \a new2OldEnd.
1411 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1412 * is to delete using decrRef() as it is no more needed.
1413 * \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
1415 DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
1418 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1419 int nbComp=getNumberOfComponents();
1420 int oldNbOfTuples=getNumberOfTuples();
1421 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1422 ret->copyStringInfoFrom(*this);
1423 double *pt=ret->getPointer();
1424 const double *srcPt=getConstPointer();
1426 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1427 if(*w>=0 && *w<oldNbOfTuples)
1428 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1430 throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
1431 ret->copyStringInfoFrom(*this);
1436 * Returns a shorten copy of \a this array. The new DataArrayDouble contains every
1437 * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
1438 * tuple. Indices of the selected tuples are the same as ones returned by the Python
1439 * command \c range( \a bg, \a end2, \a step ).
1440 * This method is equivalent to selectByTupleIdSafe() except that the input array is
1441 * not constructed explicitly.
1442 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1443 * \param [in] bg - index of the first tuple to copy from \a this array.
1444 * \param [in] end2 - index of the tuple before which the tuples to copy are located.
1445 * \param [in] step - index increment to get index of the next tuple to copy.
1446 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1447 * is to delete using decrRef() as it is no more needed.
1448 * \throw If (\a end2 < \a bg) or (\a step <= 0).
1449 * \sa DataArrayDouble::substr.
1451 DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
1454 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1455 int nbComp=getNumberOfComponents();
1456 int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayDouble::selectByTupleId2 : ");
1457 ret->alloc(newNbOfTuples,nbComp);
1458 double *pt=ret->getPointer();
1459 const double *srcPt=getConstPointer()+bg*nbComp;
1460 for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
1461 std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
1462 ret->copyStringInfoFrom(*this);
1467 * Returns a shorten copy of \a this array. The new DataArrayDouble contains ranges
1468 * of tuples specified by \a ranges parameter.
1469 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1470 * \param [in] ranges - std::vector of std::pair's each of which defines a range
1471 * of tuples in [\c begin,\c end) format.
1472 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1473 * is to delete using decrRef() as it is no more needed.
1474 * \throw If \a end < \a begin.
1475 * \throw If \a end > \a this->getNumberOfTuples().
1476 * \throw If \a this is not allocated.
1478 DataArrayDouble *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
1481 int nbOfComp=getNumberOfComponents();
1482 int nbOfTuplesThis=getNumberOfTuples();
1485 DataArrayDouble *ret=DataArrayDouble::New();
1486 ret->alloc(0,nbOfComp);
1487 ret->copyStringInfoFrom(*this);
1490 int ref=ranges.front().first;
1492 bool isIncreasing=true;
1493 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
1495 if((*it).first<=(*it).second)
1497 if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
1499 nbOfTuples+=(*it).second-(*it).first;
1501 isIncreasing=ref<=(*it).first;
1506 std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
1507 oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
1508 throw INTERP_KERNEL::Exception(oss.str().c_str());
1513 std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
1514 oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
1515 throw INTERP_KERNEL::Exception(oss.str().c_str());
1518 if(isIncreasing && nbOfTuplesThis==nbOfTuples)
1520 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1521 ret->alloc(nbOfTuples,nbOfComp);
1522 ret->copyStringInfoFrom(*this);
1523 const double *src=getConstPointer();
1524 double *work=ret->getPointer();
1525 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
1526 work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
1531 * Returns a shorten copy of \a this array. The new DataArrayDouble contains all
1532 * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
1533 * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
1534 * This method is a specialization of selectByTupleId2().
1535 * \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
1536 * \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
1537 * If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
1538 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1539 * is to delete using decrRef() as it is no more needed.
1540 * \throw If \a tupleIdBg < 0.
1541 * \throw If \a tupleIdBg > \a this->getNumberOfTuples().
1542 \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
1543 * \sa DataArrayDouble::selectByTupleId2
1545 DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
1548 int nbt=getNumberOfTuples();
1550 throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter must be greater than 0 !");
1552 throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater than number of tuples !");
1553 int trueEnd=tupleIdEnd;
1557 throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
1561 int nbComp=getNumberOfComponents();
1562 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1563 ret->alloc(trueEnd-tupleIdBg,nbComp);
1564 ret->copyStringInfoFrom(*this);
1565 std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
1570 * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
1571 * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
1572 * is truncated to have \a newNbOfComp components, keeping first components. If \a
1573 * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
1574 * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
1576 * \param [in] newNbOfComp - number of components for the new array to have.
1577 * \param [in] dftValue - value assigned to new values added to the new array.
1578 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1579 * is to delete using decrRef() as it is no more needed.
1580 * \throw If \a this is not allocated.
1582 DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception)
1585 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1586 ret->alloc(getNumberOfTuples(),newNbOfComp);
1587 const double *oldc=getConstPointer();
1588 double *nc=ret->getPointer();
1589 int nbOfTuples=getNumberOfTuples();
1590 int oldNbOfComp=getNumberOfComponents();
1591 int dim=std::min(oldNbOfComp,newNbOfComp);
1592 for(int i=0;i<nbOfTuples;i++)
1596 nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
1597 for(;j<newNbOfComp;j++)
1598 nc[newNbOfComp*i+j]=dftValue;
1600 ret->setName(getName().c_str());
1601 for(int i=0;i<dim;i++)
1602 ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
1603 ret->setName(getName().c_str());
1608 * Changes the number of components within \a this array so that its raw data **does
1609 * not** change, instead splitting this data into tuples changes.
1610 * \param [in] newNbOfComp - number of components for \a this array to have.
1611 * \throw If \a this is not allocated
1612 * \throw If getNbOfElems() % \a newNbOfCompo != 0.
1613 * \throw If \a newNbOfCompo is lower than 1.
1614 * \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
1615 * \warning This method erases all (name and unit) component info set before!
1617 void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
1621 throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : input newNbOfCompo must be > 0 !");
1622 std::size_t nbOfElems=getNbOfElems();
1623 if(nbOfElems%newNbOfCompo!=0)
1624 throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !");
1625 if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
1626 throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !");
1627 _info_on_compo.clear();
1628 _info_on_compo.resize(newNbOfCompo);
1633 * Changes the number of components within \a this array to be equal to its number
1634 * of tuples, and inversely its number of tuples to become equal to its number of
1635 * components. So that its raw data **does not** change, instead splitting this
1636 * data into tuples changes.
1637 * \throw If \a this is not allocated.
1638 * \warning This method erases all (name and unit) component info set before!
1639 * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
1642 void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception)
1645 int nbOfTuples=getNumberOfTuples();
1646 rearrange(nbOfTuples);
1650 * Returns a copy of \a this array composed of selected components.
1651 * The new DataArrayDouble has the same number of tuples but includes components
1652 * specified by \a compoIds parameter. So that getNbOfElems() of the result array
1653 * can be either less, same or more than \a this->getNbOfElems().
1654 * \param [in] compoIds - sequence of zero based indices of components to include
1655 * into the new array.
1656 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1657 * is to delete using decrRef() as it is no more needed.
1658 * \throw If \a this is not allocated.
1659 * \throw If a component index (\a i) is not valid:
1660 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
1662 * \ref cpp_mcdataarraydouble_keepselectedcomponents "Here is a Python example".
1664 DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
1667 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
1668 std::size_t newNbOfCompo=compoIds.size();
1669 int oldNbOfCompo=getNumberOfComponents();
1670 for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
1671 if((*it)<0 || (*it)>=oldNbOfCompo)
1673 std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
1674 throw INTERP_KERNEL::Exception(oss.str().c_str());
1676 int nbOfTuples=getNumberOfTuples();
1677 ret->alloc(nbOfTuples,(int)newNbOfCompo);
1678 ret->copyPartOfStringInfoFrom(*this,compoIds);
1679 const double *oldc=getConstPointer();
1680 double *nc=ret->getPointer();
1681 for(int i=0;i<nbOfTuples;i++)
1682 for(std::size_t j=0;j<newNbOfCompo;j++,nc++)
1683 *nc=oldc[i*oldNbOfCompo+compoIds[j]];
1688 * Appends components of another array to components of \a this one, tuple by tuple.
1689 * So that the number of tuples of \a this array remains the same and the number of
1690 * components increases.
1691 * \param [in] other - the DataArrayDouble to append to \a this one.
1692 * \throw If \a this is not allocated.
1693 * \throw If \a this and \a other arrays have different number of tuples.
1695 * \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
1697 * \ref py_mcdataarraydouble_meldwith "Here is a Python example".
1699 void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
1702 other->checkAllocated();
1703 int nbOfTuples=getNumberOfTuples();
1704 if(nbOfTuples!=other->getNumberOfTuples())
1705 throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
1706 int nbOfComp1=getNumberOfComponents();
1707 int nbOfComp2=other->getNumberOfComponents();
1708 double *newArr=new double[nbOfTuples*(nbOfComp1+nbOfComp2)];
1710 const double *inp1=getConstPointer();
1711 const double *inp2=other->getConstPointer();
1712 for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
1714 w=std::copy(inp1,inp1+nbOfComp1,w);
1715 w=std::copy(inp2,inp2+nbOfComp2,w);
1717 useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
1718 std::vector<int> compIds(nbOfComp2);
1719 for(int i=0;i<nbOfComp2;i++)
1720 compIds[i]=nbOfComp1+i;
1721 copyPartOfStringInfoFrom2(compIds,*other);
1725 * Searches for tuples coincident within \a prec tolerance. Each tuple is considered
1726 * as coordinates of a point in getNumberOfComponents()-dimensional space. The
1727 * distance is computed using norm2.
1729 * Indices of coincident tuples are stored in output arrays.
1730 * A pair of arrays (\a comm, \a commIndex) is called "Surjective Format 2".
1732 * This method is typically used by MEDCouplingPointSet::findCommonNodes() and
1733 * MEDCouplingUMesh::mergeNodes().
1734 * \param [in] prec - minimal absolute distance between two tuples at which they are
1735 * considered not coincident.
1736 * \param [in] limitTupleId - limit tuple id. Tuples with id strictly lower than \a
1737 * limitTupleId are not considered.
1738 * \param [out] comm - the array holding ids (== indices) of coincident tuples.
1739 * \a comm->getNumberOfComponents() == 1.
1740 * \a comm->getNumberOfTuples() == \a commIndex->back().
1741 * \param [out] commIndex - the array dividing all indices stored in \a comm into
1742 * groups of (indices of) coincident tuples. Its every value is a tuple
1743 * index where a next group of tuples begins. For example the second
1744 * group of tuples in \a comm is described by following range of indices:
1745 * [ \a commIndex[1], \a commIndex[2] ). \a commIndex->getNumberOfTuples()-1
1746 * gives the number of groups of coincident tuples.
1747 * \throw If \a this is not allocated.
1748 * \throw If the number of components is not in [1,2,3].
1750 * \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example".
1752 * \ref py_mcdataarraydouble_findcommontuples "Here is a Python example".
1753 * \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2().
1755 void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
1758 int nbOfCompo=getNumberOfComponents();
1759 if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work
1760 throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3.");
1762 int nbOfTuples=getNumberOfTuples();
1764 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(prec);
1766 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0);
1770 findCommonTuplesAlg<3>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1773 findCommonTuplesAlg<2>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1776 findCommonTuplesAlg<1>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1779 throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !");
1782 commIndex=cI.retn();
1787 * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
1788 * \a nbTimes should be at least equal to 1.
1789 * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
1790 * \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.
1792 DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
1795 if(getNumberOfComponents()!=1)
1796 throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
1798 throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
1799 int nbTuples=getNumberOfTuples();
1800 const double *inPtr=getConstPointer();
1801 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1);
1802 double *retPtr=ret->getPointer();
1803 for(int i=0;i<nbTuples;i++,inPtr++)
1806 for(int j=0;j<nbTimes;j++,retPtr++)
1809 ret->copyStringInfoFrom(*this);
1814 * This methods returns the minimal distance between the two set of points \a this and \a other.
1815 * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
1816 * This method works only if number of components of \a this (equal to those of \a other) is in 1, 2 or 3.
1818 * \param [out] thisTupleId the tuple id in \a this corresponding to the returned minimal distance
1819 * \param [out] otherTupleId the tuple id in \a other corresponding to the returned minimal distance
1820 * \return the minimal distance between the two set of points \a this and \a other.
1821 * \sa DataArrayDouble::findClosestTupleId
1823 double DataArrayDouble::minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const throw(INTERP_KERNEL::Exception)
1825 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> part1=findClosestTupleId(other);
1826 int nbOfCompo(getNumberOfComponents());
1827 int otherNbTuples(other->getNumberOfTuples());
1828 const double *thisPt(begin()),*otherPt(other->begin());
1829 const int *part1Pt(part1->begin());
1830 double ret=std::numeric_limits<double>::max();
1831 for(int i=0;i<otherNbTuples;i++,part1Pt++,otherPt+=nbOfCompo)
1834 for(int j=0;j<nbOfCompo;j++)
1835 tmp+=(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j])*(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j]);
1837 { ret=tmp; thisTupleId=*part1Pt; otherTupleId=i; }
1843 * This methods returns for each tuple in \a other which tuple in \a this is the closest.
1844 * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
1845 * This method works only if number of components of \a this (equal to those of \a other) is in 1, 2 or 3.
1847 * \return a newly allocated (new object to be dealt by the caller) DataArrayInt having \c other->getNumberOfTuples() tuples and one components.
1848 * \sa DataArrayDouble::minimalDistanceTo
1850 DataArrayInt *DataArrayDouble::findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
1853 throw INTERP_KERNEL::Exception("DataArrayDouble::findClosestTupleId : other instance is NULL !");
1854 checkAllocated(); other->checkAllocated();
1855 int nbOfCompo=getNumberOfComponents();
1856 if(nbOfCompo!=other->getNumberOfComponents())
1858 std::ostringstream oss; oss << "DataArrayDouble::findClosestTupleId : number of components in this is " << nbOfCompo;
1859 oss << ", whereas number of components in other is " << other->getNumberOfComponents() << "! Should be equal !";
1860 throw INTERP_KERNEL::Exception(oss.str().c_str());
1862 int nbOfTuples=other->getNumberOfTuples();
1863 int thisNbOfTuples=getNumberOfTuples();
1864 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
1866 getMinMaxPerComponent(bounds);
1871 double xDelta(fabs(bounds[1]-bounds[0])),yDelta(fabs(bounds[3]-bounds[2])),zDelta(fabs(bounds[5]-bounds[4]));
1872 double delta=std::max(xDelta,yDelta); delta=std::max(delta,zDelta);
1873 double characSize=pow((delta*delta*delta)/((double)thisNbOfTuples),1./3.);
1874 BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
1875 FindClosestTupleIdAlg<3>(myTree,3.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
1880 double xDelta(fabs(bounds[1]-bounds[0])),yDelta(fabs(bounds[3]-bounds[2]));
1881 double delta=std::max(xDelta,yDelta);
1882 double characSize=sqrt(delta/(double)thisNbOfTuples);
1883 BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
1884 FindClosestTupleIdAlg<2>(myTree,2.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
1889 double characSize=fabs(bounds[1]-bounds[0])/thisNbOfTuples;
1890 BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
1891 FindClosestTupleIdAlg<1>(myTree,1.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
1895 throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for findClosestTupleId. Must be 1, 2 or 3.");
1901 * Returns a copy of \a this array by excluding coincident tuples. Each tuple is
1902 * considered as coordinates of a point in getNumberOfComponents()-dimensional
1903 * space. The distance between tuples is computed using norm2. If several tuples are
1904 * not far each from other than \a prec, only one of them remains in the result
1905 * array. The order of tuples in the result array is same as in \a this one except
1906 * that coincident tuples are excluded.
1907 * \param [in] prec - minimal absolute distance between two tuples at which they are
1908 * considered not coincident.
1909 * \param [in] limitTupleId - limit tuple id. Tuples with id strictly lower than \a
1910 * limiTupleId are not considered and thus not excluded.
1911 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1912 * is to delete using decrRef() as it is no more needed.
1913 * \throw If \a this is not allocated.
1914 * \throw If the number of components is not in [1,2,3].
1916 * \ref cpp_mcdataarraydouble_getdifferentvalues "Here is a Python example".
1918 DataArrayDouble *DataArrayDouble::getDifferentValues(double prec, int limitTupleId) const throw(INTERP_KERNEL::Exception)
1921 DataArrayInt *c0=0,*cI0=0;
1922 findCommonTuples(prec,limitTupleId,c0,cI0);
1923 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(c0),cI(cI0);
1924 int newNbOfTuples=-1;
1925 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0->begin(),cI0->begin(),cI0->end(),newNbOfTuples);
1926 return renumberAndReduce(o2n->getConstPointer(),newNbOfTuples);
1930 * Copy all components in a specified order from another DataArrayDouble.
1931 * The specified components become the first ones in \a this array.
1932 * Both numerical and textual data is copied. The number of tuples in \a this and
1933 * the other array can be different.
1934 * \param [in] a - the array to copy data from.
1935 * \param [in] compoIds - sequence of zero based indices of components, data of which is
1937 * \throw If \a a is NULL.
1938 * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
1939 * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
1941 * \ref cpp_mcdataarraydouble_setselectedcomponents "Here is a Python example".
1943 void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
1946 throw INTERP_KERNEL::Exception("DataArrayDouble::setSelectedComponents : input DataArrayDouble is NULL !");
1948 copyPartOfStringInfoFrom2(compoIds,*a);
1949 std::size_t partOfCompoSz=compoIds.size();
1950 int nbOfCompo=getNumberOfComponents();
1951 int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
1952 const double *ac=a->getConstPointer();
1953 double *nc=getPointer();
1954 for(int i=0;i<nbOfTuples;i++)
1955 for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
1956 nc[nbOfCompo*i+compoIds[j]]=*ac;
1960 * Copy all values from another DataArrayDouble into specified tuples and components
1961 * of \a this array. Textual data is not copied.
1962 * The tree parameters defining set of indices of tuples and components are similar to
1963 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
1964 * \param [in] a - the array to copy values from.
1965 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
1966 * \param [in] endTuples - index of the tuple before which the tuples to assign to
1968 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
1969 * \param [in] bgComp - index of the first component of \a this array to assign values to.
1970 * \param [in] endComp - index of the component before which the components to assign
1972 * \param [in] stepComp - index increment to get index of the next component to assign to.
1973 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
1974 * must be equal to the number of columns to assign to, else an
1975 * exception is thrown; if \a false, then it is only required that \a
1976 * a->getNbOfElems() equals to number of values to assign to (this condition
1977 * must be respected even if \a strictCompoCompare is \a true). The number of
1978 * values to assign to is given by following Python expression:
1979 * \a nbTargetValues =
1980 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
1981 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1982 * \throw If \a a is NULL.
1983 * \throw If \a a is not allocated.
1984 * \throw If \a this is not allocated.
1985 * \throw If parameters specifying tuples and components to assign to do not give a
1986 * non-empty range of increasing indices.
1987 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
1988 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
1989 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
1991 * \ref cpp_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
1993 void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
1996 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues1 : input DataArrayDouble is NULL !");
1997 const char msg[]="DataArrayDouble::setPartOfValues1";
1999 a->checkAllocated();
2000 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2001 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2002 int nbComp=getNumberOfComponents();
2003 int nbOfTuples=getNumberOfTuples();
2004 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2005 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2006 bool assignTech=true;
2007 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2009 if(strictCompoCompare)
2010 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2014 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2017 const double *srcPt=a->getConstPointer();
2018 double *pt=getPointer()+bgTuples*nbComp+bgComp;
2021 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2022 for(int j=0;j<newNbOfComp;j++,srcPt++)
2023 pt[j*stepComp]=*srcPt;
2027 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2029 const double *srcPt2=srcPt;
2030 for(int j=0;j<newNbOfComp;j++,srcPt2++)
2031 pt[j*stepComp]=*srcPt2;
2037 * Assign a given value to values at specified tuples and components of \a this array.
2038 * The tree parameters defining set of indices of tuples and components are similar to
2039 * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
2040 * \param [in] a - the value to assign.
2041 * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
2042 * \param [in] endTuples - index of the tuple before which the tuples to assign to
2044 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
2045 * \param [in] bgComp - index of the first component of \a this array to assign to.
2046 * \param [in] endComp - index of the component before which the components to assign
2048 * \param [in] stepComp - index increment to get index of the next component to assign to.
2049 * \throw If \a this is not allocated.
2050 * \throw If parameters specifying tuples and components to assign to, do not give a
2051 * non-empty range of increasing indices or indices are out of a valid range
2054 * \ref cpp_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
2056 void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
2058 const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
2060 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2061 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2062 int nbComp=getNumberOfComponents();
2063 int nbOfTuples=getNumberOfTuples();
2064 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2065 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2066 double *pt=getPointer()+bgTuples*nbComp+bgComp;
2067 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2068 for(int j=0;j<newNbOfComp;j++)
2073 * Copy all values from another DataArrayDouble (\a a) into specified tuples and
2074 * components of \a this array. Textual data is not copied.
2075 * The tuples and components to assign to are defined by C arrays of indices.
2076 * There are two *modes of usage*:
2077 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
2078 * of \a a is assigned to its own location within \a this array.
2079 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
2080 * components of every specified tuple of \a this array. In this mode it is required
2081 * that \a a->getNumberOfComponents() equals to the number of specified components.
2083 * \param [in] a - the array to copy values from.
2084 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2085 * assign values of \a a to.
2086 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2087 * pointer to a tuple index <em>(pi)</em> varies as this:
2088 * \a bgTuples <= \a pi < \a endTuples.
2089 * \param [in] bgComp - pointer to an array of component indices of \a this array to
2090 * assign values of \a a to.
2091 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
2092 * pointer to a component index <em>(pi)</em> varies as this:
2093 * \a bgComp <= \a pi < \a endComp.
2094 * \param [in] strictCompoCompare - this parameter is checked only if the
2095 * *mode of usage* is the first; if it is \a true (default),
2096 * then \a a->getNumberOfComponents() must be equal
2097 * to the number of specified columns, else this is not required.
2098 * \throw If \a a is NULL.
2099 * \throw If \a a is not allocated.
2100 * \throw If \a this is not allocated.
2101 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
2102 * out of a valid range for \a this array.
2103 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
2104 * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
2105 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
2106 * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
2108 * \ref cpp_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
2110 void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2113 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
2114 const char msg[]="DataArrayDouble::setPartOfValues2";
2116 a->checkAllocated();
2117 int nbComp=getNumberOfComponents();
2118 int nbOfTuples=getNumberOfTuples();
2119 for(const int *z=bgComp;z!=endComp;z++)
2120 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2121 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
2122 int newNbOfComp=(int)std::distance(bgComp,endComp);
2123 bool assignTech=true;
2124 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2126 if(strictCompoCompare)
2127 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2131 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2134 double *pt=getPointer();
2135 const double *srcPt=a->getConstPointer();
2138 for(const int *w=bgTuples;w!=endTuples;w++)
2140 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2141 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
2143 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
2149 for(const int *w=bgTuples;w!=endTuples;w++)
2151 const double *srcPt2=srcPt;
2152 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2153 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
2155 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
2162 * Assign a given value to values at specified tuples and components of \a this array.
2163 * The tuples and components to assign to are defined by C arrays of indices.
2164 * \param [in] a - the value to assign.
2165 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2167 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2168 * pointer to a tuple index (\a pi) varies as this:
2169 * \a bgTuples <= \a pi < \a endTuples.
2170 * \param [in] bgComp - pointer to an array of component indices of \a this array to
2172 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
2173 * pointer to a component index (\a pi) varies as this:
2174 * \a bgComp <= \a pi < \a endComp.
2175 * \throw If \a this is not allocated.
2176 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
2177 * out of a valid range for \a this array.
2179 * \ref cpp_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
2181 void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
2184 int nbComp=getNumberOfComponents();
2185 int nbOfTuples=getNumberOfTuples();
2186 for(const int *z=bgComp;z!=endComp;z++)
2187 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2188 double *pt=getPointer();
2189 for(const int *w=bgTuples;w!=endTuples;w++)
2190 for(const int *z=bgComp;z!=endComp;z++)
2192 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2193 pt[(std::size_t)(*w)*nbComp+(*z)]=a;
2198 * Copy all values from another DataArrayDouble (\a a) into specified tuples and
2199 * components of \a this array. Textual data is not copied.
2200 * The tuples to assign to are defined by a C array of indices.
2201 * The components to assign to are defined by three values similar to parameters of
2202 * the Python function \c range(\c start,\c stop,\c step).
2203 * There are two *modes of usage*:
2204 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
2205 * of \a a is assigned to its own location within \a this array.
2206 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
2207 * components of every specified tuple of \a this array. In this mode it is required
2208 * that \a a->getNumberOfComponents() equals to the number of specified components.
2210 * \param [in] a - the array to copy values from.
2211 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2212 * assign values of \a a to.
2213 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2214 * pointer to a tuple index <em>(pi)</em> varies as this:
2215 * \a bgTuples <= \a pi < \a endTuples.
2216 * \param [in] bgComp - index of the first component of \a this array to assign to.
2217 * \param [in] endComp - index of the component before which the components to assign
2219 * \param [in] stepComp - index increment to get index of the next component to assign to.
2220 * \param [in] strictCompoCompare - this parameter is checked only in the first
2221 * *mode of usage*; if \a strictCompoCompare is \a true (default),
2222 * then \a a->getNumberOfComponents() must be equal
2223 * to the number of specified columns, else this is not required.
2224 * \throw If \a a is NULL.
2225 * \throw If \a a is not allocated.
2226 * \throw If \a this is not allocated.
2227 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
2229 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
2230 * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
2231 * defined by <em>(bgComp,endComp,stepComp)</em>.
2232 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
2233 * <em> a->getNumberOfComponents()</em> is unequal to the number of components
2234 * defined by <em>(bgComp,endComp,stepComp)</em>.
2235 * \throw If parameters specifying components to assign to, do not give a
2236 * non-empty range of increasing indices or indices are out of a valid range
2239 * \ref cpp_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
2241 void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2244 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues3 : input DataArrayDouble is NULL !");
2245 const char msg[]="DataArrayDouble::setPartOfValues3";
2247 a->checkAllocated();
2248 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2249 int nbComp=getNumberOfComponents();
2250 int nbOfTuples=getNumberOfTuples();
2251 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2252 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
2253 bool assignTech=true;
2254 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2256 if(strictCompoCompare)
2257 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2261 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2264 double *pt=getPointer()+bgComp;
2265 const double *srcPt=a->getConstPointer();
2268 for(const int *w=bgTuples;w!=endTuples;w++)
2269 for(int j=0;j<newNbOfComp;j++,srcPt++)
2271 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2272 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
2277 for(const int *w=bgTuples;w!=endTuples;w++)
2279 const double *srcPt2=srcPt;
2280 for(int j=0;j<newNbOfComp;j++,srcPt2++)
2282 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2283 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
2290 * Assign a given value to values at specified tuples and components of \a this array.
2291 * The tuples to assign to are defined by a C array of indices.
2292 * The components to assign to are defined by three values similar to parameters of
2293 * the Python function \c range(\c start,\c stop,\c step).
2294 * \param [in] a - the value to assign.
2295 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2297 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2298 * pointer to a tuple index <em>(pi)</em> varies as this:
2299 * \a bgTuples <= \a pi < \a endTuples.
2300 * \param [in] bgComp - index of the first component of \a this array to assign to.
2301 * \param [in] endComp - index of the component before which the components to assign
2303 * \param [in] stepComp - index increment to get index of the next component to assign to.
2304 * \throw If \a this is not allocated.
2305 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
2307 * \throw If parameters specifying components to assign to, do not give a
2308 * non-empty range of increasing indices or indices are out of a valid range
2311 * \ref cpp_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
2313 void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
2315 const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
2317 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2318 int nbComp=getNumberOfComponents();
2319 int nbOfTuples=getNumberOfTuples();
2320 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2321 double *pt=getPointer()+bgComp;
2322 for(const int *w=bgTuples;w!=endTuples;w++)
2323 for(int j=0;j<newNbOfComp;j++)
2325 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2326 pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
2331 * Copy all values from another DataArrayDouble into specified tuples and components
2332 * of \a this array. Textual data is not copied.
2333 * The tree parameters defining set of indices of tuples and components are similar to
2334 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
2335 * \param [in] a - the array to copy values from.
2336 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
2337 * \param [in] endTuples - index of the tuple before which the tuples to assign to
2339 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
2340 * \param [in] bgComp - pointer to an array of component indices of \a this array to
2342 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
2343 * pointer to a component index (\a pi) varies as this:
2344 * \a bgComp <= \a pi < \a endComp.
2345 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
2346 * must be equal to the number of columns to assign to, else an
2347 * exception is thrown; if \a false, then it is only required that \a
2348 * a->getNbOfElems() equals to number of values to assign to (this condition
2349 * must be respected even if \a strictCompoCompare is \a true). The number of
2350 * values to assign to is given by following Python expression:
2351 * \a nbTargetValues =
2352 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
2353 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
2354 * \throw If \a a is NULL.
2355 * \throw If \a a is not allocated.
2356 * \throw If \a this is not allocated.
2357 * \throw If parameters specifying tuples and components to assign to do not give a
2358 * non-empty range of increasing indices.
2359 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
2360 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
2361 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
2364 void DataArrayDouble::setPartOfValues4(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2367 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues4 : input DataArrayDouble is NULL !");
2368 const char msg[]="DataArrayDouble::setPartOfValues4";
2370 a->checkAllocated();
2371 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2372 int newNbOfComp=(int)std::distance(bgComp,endComp);
2373 int nbComp=getNumberOfComponents();
2374 for(const int *z=bgComp;z!=endComp;z++)
2375 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2376 int nbOfTuples=getNumberOfTuples();
2377 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2378 bool assignTech=true;
2379 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2381 if(strictCompoCompare)
2382 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2386 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2389 const double *srcPt=a->getConstPointer();
2390 double *pt=getPointer()+bgTuples*nbComp;
2393 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2394 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
2399 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2401 const double *srcPt2=srcPt;
2402 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
2408 void DataArrayDouble::setPartOfValuesSimple4(double a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
2410 const char msg[]="DataArrayDouble::setPartOfValuesSimple4";
2412 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2413 int nbComp=getNumberOfComponents();
2414 for(const int *z=bgComp;z!=endComp;z++)
2415 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2416 int nbOfTuples=getNumberOfTuples();
2417 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2418 double *pt=getPointer()+bgTuples*nbComp;
2419 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2420 for(const int *z=bgComp;z!=endComp;z++)
2425 * Copy some tuples from another DataArrayDouble into specified tuples
2426 * of \a this array. Textual data is not copied. Both arrays must have equal number of
2428 * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
2429 * All components of selected tuples are copied.
2430 * \param [in] a - the array to copy values from.
2431 * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
2432 * target tuples of \a this. \a tuplesSelec has two components, and the
2433 * first component specifies index of the source tuple and the second
2434 * one specifies index of the target tuple.
2435 * \throw If \a this is not allocated.
2436 * \throw If \a a is NULL.
2437 * \throw If \a a is not allocated.
2438 * \throw If \a tuplesSelec is NULL.
2439 * \throw If \a tuplesSelec is not allocated.
2440 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
2441 * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
2442 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
2443 * the corresponding (\a this or \a a) array.
2445 void DataArrayDouble::setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
2447 if(!a || !tuplesSelec)
2448 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : input DataArrayDouble is NULL !");
2450 a->checkAllocated();
2451 tuplesSelec->checkAllocated();
2452 int nbOfComp=getNumberOfComponents();
2453 if(nbOfComp!=a->getNumberOfComponents())
2454 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : This and a do not have the same number of components !");
2455 if(tuplesSelec->getNumberOfComponents()!=2)
2456 throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
2457 int thisNt=getNumberOfTuples();
2458 int aNt=a->getNumberOfTuples();
2459 double *valsToSet=getPointer();
2460 const double *valsSrc=a->getConstPointer();
2461 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
2463 if(tuple[1]>=0 && tuple[1]<aNt)
2465 if(tuple[0]>=0 && tuple[0]<thisNt)
2466 std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
2469 std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
2470 oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
2471 throw INTERP_KERNEL::Exception(oss.str().c_str());
2476 std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
2477 oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
2478 throw INTERP_KERNEL::Exception(oss.str().c_str());
2484 * Copy some tuples from another DataArrayDouble (\a a) into contiguous tuples
2485 * of \a this array. Textual data is not copied. Both arrays must have equal number of
2487 * The tuples to assign to are defined by index of the first tuple, and
2488 * their number is defined by \a tuplesSelec->getNumberOfTuples().
2489 * The tuples to copy are defined by values of a DataArrayInt.
2490 * All components of selected tuples are copied.
2491 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
2493 * \param [in] a - the array to copy values from.
2494 * \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
2495 * \throw If \a this is not allocated.
2496 * \throw If \a a is NULL.
2497 * \throw If \a a is not allocated.
2498 * \throw If \a tuplesSelec is NULL.
2499 * \throw If \a tuplesSelec is not allocated.
2500 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
2501 * \throw If \a tuplesSelec->getNumberOfComponents() != 1.
2502 * \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
2503 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
2506 void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
2508 if(!a || !tuplesSelec)
2509 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray is NULL !");
2511 a->checkAllocated();
2512 tuplesSelec->checkAllocated();
2513 int nbOfComp=getNumberOfComponents();
2514 if(nbOfComp!=a->getNumberOfComponents())
2515 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : This and a do not have the same number of components !");
2516 if(tuplesSelec->getNumberOfComponents()!=1)
2517 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
2518 int thisNt=getNumberOfTuples();
2519 int aNt=a->getNumberOfTuples();
2520 int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
2521 double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
2522 if(tupleIdStart+nbOfTupleToWrite>thisNt)
2523 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : invalid number range of values to write !");
2524 const double *valsSrc=a->getConstPointer();
2525 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
2527 if(*tuple>=0 && *tuple<aNt)
2529 std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
2533 std::ostringstream oss; oss << "DataArrayDouble::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
2534 oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
2535 throw INTERP_KERNEL::Exception(oss.str().c_str());
2541 * Copy some tuples from another DataArrayDouble (\a a) into contiguous tuples
2542 * of \a this array. Textual data is not copied. Both arrays must have equal number of
2544 * The tuples to copy are defined by three values similar to parameters of
2545 * the Python function \c range(\c start,\c stop,\c step).
2546 * The tuples to assign to are defined by index of the first tuple, and
2547 * their number is defined by number of tuples to copy.
2548 * All components of selected tuples are copied.
2549 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
2551 * \param [in] a - the array to copy values from.
2552 * \param [in] bg - index of the first tuple to copy of the array \a a.
2553 * \param [in] end2 - index of the tuple of \a a before which the tuples to copy
2555 * \param [in] step - index increment to get index of the next tuple to copy.
2556 * \throw If \a this is not allocated.
2557 * \throw If \a a is NULL.
2558 * \throw If \a a is not allocated.
2559 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
2560 * \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
2561 * \throw If parameters specifying tuples to copy, do not give a
2562 * non-empty range of increasing indices or indices are out of a valid range
2563 * for the array \a a.
2565 void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
2568 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArrayDouble is NULL !");
2570 a->checkAllocated();
2571 int nbOfComp=getNumberOfComponents();
2572 const char msg[]="DataArrayDouble::setContigPartOfSelectedValues2";
2573 int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
2574 if(nbOfComp!=a->getNumberOfComponents())
2575 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
2576 int thisNt=getNumberOfTuples();
2577 int aNt=a->getNumberOfTuples();
2578 double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
2579 if(tupleIdStart+nbOfTupleToWrite>thisNt)
2580 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid number range of values to write !");
2582 throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid range of values to read !");
2583 const double *valsSrc=a->getConstPointer()+bg*nbOfComp;
2584 for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
2586 std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
2591 * Returns a value located at specified tuple and component.
2592 * This method is equivalent to DataArrayDouble::getIJ() except that validity of
2593 * parameters is checked. So this method is safe but expensive if used to go through
2594 * all values of \a this.
2595 * \param [in] tupleId - index of tuple of interest.
2596 * \param [in] compoId - index of component of interest.
2597 * \return double - value located by \a tupleId and \a compoId.
2598 * \throw If \a this is not allocated.
2599 * \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
2600 * \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
2602 double DataArrayDouble::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
2605 if(tupleId<0 || tupleId>=getNumberOfTuples())
2607 std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
2608 throw INTERP_KERNEL::Exception(oss.str().c_str());
2610 if(compoId<0 || compoId>=getNumberOfComponents())
2612 std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
2613 throw INTERP_KERNEL::Exception(oss.str().c_str());
2615 return _mem[tupleId*_info_on_compo.size()+compoId];
2619 * Returns the last value of \a this.
2620 * \return double - the last value of \a this array.
2621 * \throw If \a this is not allocated.
2622 * \throw If \a this->getNumberOfComponents() != 1.
2623 * \throw If \a this->getNumberOfTuples() < 1.
2625 double DataArrayDouble::back() const throw(INTERP_KERNEL::Exception)
2628 if(getNumberOfComponents()!=1)
2629 throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of components not equal to one !");
2630 int nbOfTuples=getNumberOfTuples();
2632 throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of tuples must be >= 1 !");
2633 return *(getConstPointer()+nbOfTuples-1);
2636 void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
2638 if(newArray!=arrayToSet)
2641 arrayToSet->decrRef();
2642 arrayToSet=newArray;
2644 arrayToSet->incrRef();
2649 * Sets a C array to be used as raw data of \a this. The previously set info
2650 * of components is retained and re-sized.
2651 * For more info see \ref MEDCouplingArraySteps1.
2652 * \param [in] array - the C array to be used as raw data of \a this.
2653 * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
2654 * \param [in] type - specifies how to deallocate \a array. If \a type == ParaMEDMEM::CPP_DEALLOC,
2655 * \c delete [] \c array; will be called. If \a type == ParaMEDMEM::C_DEALLOC,
2656 * \c free(\c array ) will be called.
2657 * \param [in] nbOfTuple - new number of tuples in \a this.
2658 * \param [in] nbOfCompo - new number of components in \a this.
2660 void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
2662 _info_on_compo.resize(nbOfCompo);
2663 _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo);
2667 void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
2669 _info_on_compo.resize(nbOfCompo);
2670 _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo);
2675 * Checks if 0.0 value is present in \a this array. If it is the case, an exception
2677 * \throw If zero is found in \a this array.
2679 void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception)
2681 const double *tmp=getConstPointer();
2682 std::size_t nbOfElems=getNbOfElems();
2683 const double *where=std::find(tmp,tmp+nbOfElems,0.);
2684 if(where!=tmp+nbOfElems)
2685 throw INTERP_KERNEL::Exception("A value 0.0 have been detected !");
2689 * Computes minimal and maximal value in each component. An output array is filled
2690 * with \c 2 * \a this->getNumberOfComponents() values, so the caller is to allocate
2691 * enough memory before calling this method.
2692 * \param [out] bounds - array of size at least 2 *\a this->getNumberOfComponents().
2693 * It is filled as follows:<br>
2694 * \a bounds[0] = \c min_of_component_0 <br>
2695 * \a bounds[1] = \c max_of_component_0 <br>
2696 * \a bounds[2] = \c min_of_component_1 <br>
2697 * \a bounds[3] = \c max_of_component_1 <br>
2700 void DataArrayDouble::getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception)
2703 int dim=getNumberOfComponents();
2704 for (int idim=0; idim<dim; idim++)
2706 bounds[idim*2]=std::numeric_limits<double>::max();
2707 bounds[idim*2+1]=-std::numeric_limits<double>::max();
2709 const double *ptr=getConstPointer();
2710 int nbOfTuples=getNumberOfTuples();
2711 for(int i=0;i<nbOfTuples;i++)
2713 for(int idim=0;idim<dim;idim++)
2715 if(bounds[idim*2]>ptr[i*dim+idim])
2717 bounds[idim*2]=ptr[i*dim+idim];
2719 if(bounds[idim*2+1]<ptr[i*dim+idim])
2721 bounds[idim*2+1]=ptr[i*dim+idim];
2728 * This method retrieves a newly allocated DataArrayDouble instance having same number of tuples than \a this and twice number of components than \a this
2729 * to store both the min and max per component of each tuples.
2730 * \param [in] epsilon the width of the bbox (identical in each direction) - 0.0 by default
2732 * \return a newly created DataArrayDouble instance having \c this->getNumberOfTuples() tuples and 2 * \c this->getNumberOfComponent() components
2734 * \throw If \a this is not allocated yet.
2736 DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon)const throw(INTERP_KERNEL::Exception)
2739 const double *dataPtr=getConstPointer();
2740 int nbOfCompo=getNumberOfComponents();
2741 int nbTuples=getNumberOfTuples();
2742 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=DataArrayDouble::New();
2743 bbox->alloc(nbTuples,2*nbOfCompo);
2744 double *bboxPtr=bbox->getPointer();
2745 for(int i=0;i<nbTuples;i++)
2747 for(int j=0;j<nbOfCompo;j++)
2749 bboxPtr[2*nbOfCompo*i+2*j]=dataPtr[nbOfCompo*i+j]-epsilon;
2750 bboxPtr[2*nbOfCompo*i+2*j+1]=dataPtr[nbOfCompo*i+j]+epsilon;
2757 * For each tuples **t** in \a other, this method retrieves tuples in \a this that are equal to **t**.
2758 * Two tuples are considered equal if the euclidian distance between the two tuples is lower than \a eps.
2760 * \param [in] other a DataArrayDouble having same number of components than \a this.
2761 * \param [in] eps absolute precision representing euclidian distance between 2 tuples behind which 2 tuples are considered equal.
2762 * \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.
2763 * \a cI allows to extract information in \a c.
2764 * \param [out] cI is an indirection array that allows to extract the data contained in \a c.
2766 * \throw In case of:
2767 * - \a this is not allocated
2768 * - \a other is not allocated or null
2769 * - \a this and \a other do not have the same number of components
2770 * - if number of components of \a this is not in [1,2,3]
2772 * \sa MEDCouplingPointSet::getNodeIdsNearPoints, DataArrayDouble::getDifferentValues
2774 void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception)
2777 throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !");
2779 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(eps);
2780 other->checkAllocated();
2781 int nbOfCompo=getNumberOfComponents();
2782 int otherNbOfCompo=other->getNumberOfComponents();
2783 if(nbOfCompo!=otherNbOfCompo)
2784 throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : number of components should be equal between this and other !");
2785 int nbOfTuplesOther=other->getNumberOfTuples();
2786 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),cIArr(DataArrayInt::New()); cArr->alloc(0,1); cIArr->pushBackSilent(0);
2791 BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
2792 FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2797 BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
2798 FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2803 BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
2804 FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2808 throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for computeTupleIdsNearTuples. Must be 1, 2 or 3.");
2810 c=cArr.retn(); cI=cIArr.retn();
2814 * 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
2815 * around origin of 'radius' 1.
2817 * \param [in] eps absolute epsilon. under that value of delta between max and min no scale is performed.
2819 void DataArrayDouble::recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception)
2822 int dim=getNumberOfComponents();
2823 std::vector<double> bounds(2*dim);
2824 getMinMaxPerComponent(&bounds[0]);
2825 for(int i=0;i<dim;i++)
2827 double delta=bounds[2*i+1]-bounds[2*i];
2828 double offset=(bounds[2*i]+bounds[2*i+1])/2.;
2830 applyLin(1./delta,-offset/delta,i);
2832 applyLin(1.,-offset,i);
2837 * Returns the maximal value and its location within \a this one-dimensional array.
2838 * \param [out] tupleId - index of the tuple holding the maximal value.
2839 * \return double - the maximal value among all values of \a this array.
2840 * \throw If \a this->getNumberOfComponents() != 1
2841 * \throw If \a this->getNumberOfTuples() < 1
2843 double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
2846 if(getNumberOfComponents()!=1)
2847 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 !");
2848 int nbOfTuples=getNumberOfTuples();
2850 throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
2851 const double *vals=getConstPointer();
2852 const double *loc=std::max_element(vals,vals+nbOfTuples);
2853 tupleId=(int)std::distance(vals,loc);
2858 * Returns the maximal value within \a this array that is allowed to have more than
2860 * \return double - the maximal value among all values of \a this array.
2861 * \throw If \a this is not allocated.
2863 double DataArrayDouble::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
2866 const double *loc=std::max_element(begin(),end());
2871 * Returns the maximal value and all its locations within \a this one-dimensional array.
2872 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
2873 * tuples holding the maximal value. The caller is to delete it using
2874 * decrRef() as it is no more needed.
2875 * \return double - the maximal value among all values of \a this array.
2876 * \throw If \a this->getNumberOfComponents() != 1
2877 * \throw If \a this->getNumberOfTuples() < 1
2879 double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
2883 double ret=getMaxValue(tmp);
2884 tupleIds=getIdsInRange(ret,ret);
2889 * Returns the minimal value and its location within \a this one-dimensional array.
2890 * \param [out] tupleId - index of the tuple holding the minimal value.
2891 * \return double - the minimal value among all values of \a this array.
2892 * \throw If \a this->getNumberOfComponents() != 1
2893 * \throw If \a this->getNumberOfTuples() < 1
2895 double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
2898 if(getNumberOfComponents()!=1)
2899 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
2900 int nbOfTuples=getNumberOfTuples();
2902 throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
2903 const double *vals=getConstPointer();
2904 const double *loc=std::min_element(vals,vals+nbOfTuples);
2905 tupleId=(int)std::distance(vals,loc);
2910 * Returns the minimal value within \a this array that is allowed to have more than
2912 * \return double - the minimal value among all values of \a this array.
2913 * \throw If \a this is not allocated.
2915 double DataArrayDouble::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
2918 const double *loc=std::min_element(begin(),end());
2923 * Returns the minimal value and all its locations within \a this one-dimensional array.
2924 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
2925 * tuples holding the minimal value. The caller is to delete it using
2926 * decrRef() as it is no more needed.
2927 * \return double - the minimal value among all values of \a this array.
2928 * \throw If \a this->getNumberOfComponents() != 1
2929 * \throw If \a this->getNumberOfTuples() < 1
2931 double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
2935 double ret=getMinValue(tmp);
2936 tupleIds=getIdsInRange(ret,ret);
2941 * Returns the average value of \a this one-dimensional array.
2942 * \return double - the average value over all values of \a this array.
2943 * \throw If \a this->getNumberOfComponents() != 1
2944 * \throw If \a this->getNumberOfTuples() < 1
2946 double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
2948 if(getNumberOfComponents()!=1)
2949 throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
2950 int nbOfTuples=getNumberOfTuples();
2952 throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !");
2953 const double *vals=getConstPointer();
2954 double ret=std::accumulate(vals,vals+nbOfTuples,0.);
2955 return ret/nbOfTuples;
2959 * Returns the Euclidean norm of the vector defined by \a this array.
2960 * \return double - the value of the Euclidean norm, i.e.
2961 * the square root of the inner product of vector.
2962 * \throw If \a this is not allocated.
2964 double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
2968 std::size_t nbOfElems=getNbOfElems();
2969 const double *pt=getConstPointer();
2970 for(std::size_t i=0;i<nbOfElems;i++,pt++)
2976 * Returns the maximum norm of the vector defined by \a this array.
2977 * \return double - the value of the maximum norm, i.e.
2978 * the maximal absolute value among values of \a this array.
2979 * \throw If \a this is not allocated.
2981 double DataArrayDouble::normMax() const throw(INTERP_KERNEL::Exception)
2985 std::size_t nbOfElems=getNbOfElems();
2986 const double *pt=getConstPointer();
2987 for(std::size_t i=0;i<nbOfElems;i++,pt++)
2989 double val=std::abs(*pt);
2997 * Accumulates values of each component of \a this array.
2998 * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
2999 * by the caller, that is filled by this method with sum value for each
3001 * \throw If \a this is not allocated.
3003 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
3006 const double *ptr=getConstPointer();
3007 int nbTuple=getNumberOfTuples();
3008 int nbComps=getNumberOfComponents();
3009 std::fill(res,res+nbComps,0.);
3010 for(int i=0;i<nbTuple;i++)
3011 std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
3015 * This method returns the min distance from an external tuple defined by [ \a tupleBg , \a tupleEnd ) to \a this and
3016 * the first tuple in \a this that matches the returned distance. If there is no tuples in \a this an exception will be thrown.
3019 * \a this is expected to be allocated and expected to have a number of components equal to the distance from \a tupleBg to
3020 * \a tupleEnd. If not an exception will be thrown.
3022 * \param [in] tupleBg start pointer (included) of input external tuple
3023 * \param [in] tupleEnd end pointer (not included) of input external tuple
3024 * \param [out] tupleId the tuple id in \a this that matches the min of distance between \a this and input external tuple
3025 * \return the min distance.
3026 * \sa MEDCouplingUMesh::distanceToPoint
3028 double DataArrayDouble::distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const throw(INTERP_KERNEL::Exception)
3031 int nbTuple=getNumberOfTuples();
3032 int nbComps=getNumberOfComponents();
3033 if(nbComps!=(int)std::distance(tupleBg,tupleEnd))
3034 { std::ostringstream oss; oss << "DataArrayDouble::distanceToTuple : size of input tuple is " << std::distance(tupleBg,tupleEnd) << " should be equal to the number of components in this : " << nbComps << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); }
3036 throw INTERP_KERNEL::Exception("DataArrayDouble::distanceToTuple : no tuple in this ! No distance to compute !");
3037 double ret0=std::numeric_limits<double>::max();
3039 const double *work=getConstPointer();
3040 for(int i=0;i<nbTuple;i++)
3043 for(int j=0;j<nbComps;j++,work++)
3044 val+=(*work-tupleBg[j])*((*work-tupleBg[j]));
3048 { ret0=val; tupleId=i; }
3054 * Accumulate values of the given component of \a this array.
3055 * \param [in] compId - the index of the component of interest.
3056 * \return double - a sum value of \a compId-th component.
3057 * \throw If \a this is not allocated.
3058 * \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
3061 double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
3064 const double *ptr=getConstPointer();
3065 int nbTuple=getNumberOfTuples();
3066 int nbComps=getNumberOfComponents();
3067 if(compId<0 || compId>=nbComps)
3068 throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !");
3070 for(int i=0;i<nbTuple;i++)
3071 ret+=ptr[i*nbComps+compId];
3076 * Converts each 2D point defined by the tuple of \a this array from the Polar to the
3077 * Cartesian coordinate system. The two components of the tuple of \a this array are
3078 * considered to contain (1) radius and (2) angle of the point in the Polar CS.
3079 * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3080 * contains X and Y coordinates of the point in the Cartesian CS. The caller
3081 * is to delete this array using decrRef() as it is no more needed. The array
3082 * does not contain any textual info on components.
3083 * \throw If \a this->getNumberOfComponents() != 2.
3085 DataArrayDouble *DataArrayDouble::fromPolarToCart() const throw(INTERP_KERNEL::Exception)
3088 int nbOfComp=getNumberOfComponents();
3090 throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !");
3091 int nbOfTuple=getNumberOfTuples();
3092 DataArrayDouble *ret=DataArrayDouble::New();
3093 ret->alloc(nbOfTuple,2);
3094 double *w=ret->getPointer();
3095 const double *wIn=getConstPointer();
3096 for(int i=0;i<nbOfTuple;i++,w+=2,wIn+=2)
3098 w[0]=wIn[0]*cos(wIn[1]);
3099 w[1]=wIn[0]*sin(wIn[1]);
3105 * Converts each 3D point defined by the tuple of \a this array from the Cylindrical to
3106 * the Cartesian coordinate system. The three components of the tuple of \a this array
3107 * are considered to contain (1) radius, (2) azimuth and (3) altitude of the point in
3108 * the Cylindrical CS.
3109 * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3110 * contains X, Y and Z coordinates of the point in the Cartesian CS. The info
3111 * on the third component is copied from \a this array. The caller
3112 * is to delete this array using decrRef() as it is no more needed.
3113 * \throw If \a this->getNumberOfComponents() != 3.
3115 DataArrayDouble *DataArrayDouble::fromCylToCart() const throw(INTERP_KERNEL::Exception)
3118 int nbOfComp=getNumberOfComponents();
3120 throw INTERP_KERNEL::Exception("DataArrayDouble::fromCylToCart : must be an array with exactly 3 components !");
3121 int nbOfTuple=getNumberOfTuples();
3122 DataArrayDouble *ret=DataArrayDouble::New();
3123 ret->alloc(getNumberOfTuples(),3);
3124 double *w=ret->getPointer();
3125 const double *wIn=getConstPointer();
3126 for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
3128 w[0]=wIn[0]*cos(wIn[1]);
3129 w[1]=wIn[0]*sin(wIn[1]);
3132 ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str());
3137 * Converts each 3D point defined by the tuple of \a this array from the Spherical to
3138 * the Cartesian coordinate system. The three components of the tuple of \a this array
3139 * are considered to contain (1) radius, (2) polar angle and (3) azimuthal angle of the
3140 * point in the Cylindrical CS.
3141 * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3142 * contains X, Y and Z coordinates of the point in the Cartesian CS. The info
3143 * on the third component is copied from \a this array. The caller
3144 * is to delete this array using decrRef() as it is no more needed.
3145 * \throw If \a this->getNumberOfComponents() != 3.
3147 DataArrayDouble *DataArrayDouble::fromSpherToCart() const throw(INTERP_KERNEL::Exception)
3150 int nbOfComp=getNumberOfComponents();
3152 throw INTERP_KERNEL::Exception("DataArrayDouble::fromSpherToCart : must be an array with exactly 3 components !");
3153 int nbOfTuple=getNumberOfTuples();
3154 DataArrayDouble *ret=DataArrayDouble::New();
3155 ret->alloc(getNumberOfTuples(),3);
3156 double *w=ret->getPointer();
3157 const double *wIn=getConstPointer();
3158 for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
3160 w[0]=wIn[0]*cos(wIn[2])*sin(wIn[1]);
3161 w[1]=wIn[0]*sin(wIn[2])*sin(wIn[1]);
3162 w[2]=wIn[0]*cos(wIn[1]);
3168 * Computes the doubly contracted product of every tensor defined by the tuple of \a this
3169 * array contating 6 components.
3170 * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3171 * is calculated from the tuple <em>(t)</em> of \a this array as follows:
3172 * \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
3173 * The caller is to delete this result array using decrRef() as it is no more needed.
3174 * \throw If \a this->getNumberOfComponents() != 6.
3176 DataArrayDouble *DataArrayDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
3179 int nbOfComp=getNumberOfComponents();
3181 throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !");
3182 DataArrayDouble *ret=DataArrayDouble::New();
3183 int nbOfTuple=getNumberOfTuples();
3184 ret->alloc(nbOfTuple,1);
3185 const double *src=getConstPointer();
3186 double *dest=ret->getPointer();
3187 for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
3188 *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];
3193 * Computes the determinant of every square matrix defined by the tuple of \a this
3194 * array, which contains either 4, 6 or 9 components. The case of 6 components
3195 * corresponds to that of the upper triangular matrix.
3196 * \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3197 * is the determinant of matrix of the corresponding tuple of \a this array.
3198 * The caller is to delete this result array using decrRef() as it is no more
3200 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3202 DataArrayDouble *DataArrayDouble::determinant() const throw(INTERP_KERNEL::Exception)
3205 DataArrayDouble *ret=DataArrayDouble::New();
3206 int nbOfTuple=getNumberOfTuples();
3207 ret->alloc(nbOfTuple,1);
3208 const double *src=getConstPointer();
3209 double *dest=ret->getPointer();
3210 switch(getNumberOfComponents())
3213 for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
3214 *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];
3217 for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
3218 *dest=src[0]*src[3]-src[1]*src[2];
3221 for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
3222 *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];
3226 throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
3231 * Computes 3 eigenvalues of every upper triangular matrix defined by the tuple of
3232 * \a this array, which contains 6 components.
3233 * \return DataArrayDouble * - the new instance of DataArrayDouble containing 3
3234 * components, whose each tuple contains the eigenvalues of the matrix of
3235 * corresponding tuple of \a this array.
3236 * The caller is to delete this result array using decrRef() as it is no more
3238 * \throw If \a this->getNumberOfComponents() != 6.
3240 DataArrayDouble *DataArrayDouble::eigenValues() const throw(INTERP_KERNEL::Exception)
3243 int nbOfComp=getNumberOfComponents();
3245 throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !");
3246 DataArrayDouble *ret=DataArrayDouble::New();
3247 int nbOfTuple=getNumberOfTuples();
3248 ret->alloc(nbOfTuple,3);
3249 const double *src=getConstPointer();
3250 double *dest=ret->getPointer();
3251 for(int i=0;i<nbOfTuple;i++,dest+=3,src+=6)
3252 INTERP_KERNEL::computeEigenValues6(src,dest);
3257 * Computes 3 eigenvectors of every upper triangular matrix defined by the tuple of
3258 * \a this array, which contains 6 components.
3259 * \return DataArrayDouble * - the new instance of DataArrayDouble containing 9
3260 * components, whose each tuple contains 3 eigenvectors of the matrix of
3261 * corresponding tuple of \a this array.
3262 * The caller is to delete this result array using decrRef() as it is no more
3264 * \throw If \a this->getNumberOfComponents() != 6.
3266 DataArrayDouble *DataArrayDouble::eigenVectors() const throw(INTERP_KERNEL::Exception)
3269 int nbOfComp=getNumberOfComponents();
3271 throw INTERP_KERNEL::Exception("DataArrayDouble::eigenVectors : must be an array with exactly 6 components !");
3272 DataArrayDouble *ret=DataArrayDouble::New();
3273 int nbOfTuple=getNumberOfTuples();
3274 ret->alloc(nbOfTuple,9);
3275 const double *src=getConstPointer();
3276 double *dest=ret->getPointer();
3277 for(int i=0;i<nbOfTuple;i++,src+=6)
3280 INTERP_KERNEL::computeEigenValues6(src,tmp);
3281 for(int j=0;j<3;j++,dest+=3)
3282 INTERP_KERNEL::computeEigenVectorForEigenValue6(src,tmp[j],1e-12,dest);
3288 * Computes the inverse matrix of every matrix defined by the tuple of \a this
3289 * array, which contains either 4, 6 or 9 components. The case of 6 components
3290 * corresponds to that of the upper triangular matrix.
3291 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3292 * same number of components as \a this one, whose each tuple is the inverse
3293 * matrix of the matrix of corresponding tuple of \a this array.
3294 * The caller is to delete this result array using decrRef() as it is no more
3296 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3298 DataArrayDouble *DataArrayDouble::inverse() const throw(INTERP_KERNEL::Exception)
3301 int nbOfComp=getNumberOfComponents();
3302 if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
3303 throw INTERP_KERNEL::Exception("DataArrayDouble::inversion : must be an array with 4,6 or 9 components !");
3304 DataArrayDouble *ret=DataArrayDouble::New();
3305 int nbOfTuple=getNumberOfTuples();
3306 ret->alloc(nbOfTuple,nbOfComp);
3307 const double *src=getConstPointer();
3308 double *dest=ret->getPointer();
3310 for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
3312 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];
3313 dest[0]=(src[1]*src[2]-src[4]*src[4])/det;
3314 dest[1]=(src[0]*src[2]-src[5]*src[5])/det;
3315 dest[2]=(src[0]*src[1]-src[3]*src[3])/det;
3316 dest[3]=(src[5]*src[4]-src[3]*src[2])/det;
3317 dest[4]=(src[5]*src[3]-src[0]*src[4])/det;
3318 dest[5]=(src[3]*src[4]-src[1]*src[5])/det;
3320 else if(nbOfComp==4)
3321 for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
3323 double det=src[0]*src[3]-src[1]*src[2];
3325 dest[1]=-src[1]/det;
3326 dest[2]=-src[2]/det;
3330 for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
3332 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];
3333 dest[0]=(src[4]*src[8]-src[7]*src[5])/det;
3334 dest[1]=(src[7]*src[2]-src[1]*src[8])/det;
3335 dest[2]=(src[1]*src[5]-src[4]*src[2])/det;
3336 dest[3]=(src[6]*src[5]-src[3]*src[8])/det;
3337 dest[4]=(src[0]*src[8]-src[6]*src[2])/det;
3338 dest[5]=(src[2]*src[3]-src[0]*src[5])/det;
3339 dest[6]=(src[3]*src[7]-src[6]*src[4])/det;
3340 dest[7]=(src[6]*src[1]-src[0]*src[7])/det;
3341 dest[8]=(src[0]*src[4]-src[1]*src[3])/det;
3347 * Computes the trace of every matrix defined by the tuple of \a this
3348 * array, which contains either 4, 6 or 9 components. The case of 6 components
3349 * corresponds to that of the upper triangular matrix.
3350 * \return DataArrayDouble * - the new instance of DataArrayDouble containing
3351 * 1 component, whose each tuple is the trace of
3352 * the matrix of corresponding tuple of \a this array.
3353 * The caller is to delete this result array using decrRef() as it is no more
3355 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3357 DataArrayDouble *DataArrayDouble::trace() const throw(INTERP_KERNEL::Exception)
3360 int nbOfComp=getNumberOfComponents();
3361 if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
3362 throw INTERP_KERNEL::Exception("DataArrayDouble::trace : must be an array with 4,6 or 9 components !");
3363 DataArrayDouble *ret=DataArrayDouble::New();
3364 int nbOfTuple=getNumberOfTuples();
3365 ret->alloc(nbOfTuple,1);
3366 const double *src=getConstPointer();
3367 double *dest=ret->getPointer();
3369 for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
3370 *dest=src[0]+src[1]+src[2];
3371 else if(nbOfComp==4)
3372 for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
3373 *dest=src[0]+src[3];
3375 for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
3376 *dest=src[0]+src[4]+src[8];
3381 * Computes the stress deviator tensor of every stress tensor defined by the tuple of
3382 * \a this array, which contains 6 components.
3383 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3384 * same number of components and tuples as \a this array.
3385 * The caller is to delete this result array using decrRef() as it is no more
3387 * \throw If \a this->getNumberOfComponents() != 6.
3389 DataArrayDouble *DataArrayDouble::deviator() const throw(INTERP_KERNEL::Exception)
3392 int nbOfComp=getNumberOfComponents();
3394 throw INTERP_KERNEL::Exception("DataArrayDouble::deviator : must be an array with exactly 6 components !");
3395 DataArrayDouble *ret=DataArrayDouble::New();
3396 int nbOfTuple=getNumberOfTuples();
3397 ret->alloc(nbOfTuple,6);
3398 const double *src=getConstPointer();
3399 double *dest=ret->getPointer();
3400 for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
3402 double tr=(src[0]+src[1]+src[2])/3.;
3414 * Computes the magnitude of every vector defined by the tuple of
3416 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3417 * same number of tuples as \a this array and one component.
3418 * The caller is to delete this result array using decrRef() as it is no more
3420 * \throw If \a this is not allocated.
3422 DataArrayDouble *DataArrayDouble::magnitude() const throw(INTERP_KERNEL::Exception)
3425 int nbOfComp=getNumberOfComponents();
3426 DataArrayDouble *ret=DataArrayDouble::New();
3427 int nbOfTuple=getNumberOfTuples();
3428 ret->alloc(nbOfTuple,1);
3429 const double *src=getConstPointer();
3430 double *dest=ret->getPointer();
3431 for(int i=0;i<nbOfTuple;i++,dest++)
3434 for(int j=0;j<nbOfComp;j++,src++)
3442 * Computes the maximal value within every tuple of \a this array.
3443 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3444 * same number of tuples as \a this array and one component.
3445 * The caller is to delete this result array using decrRef() as it is no more
3447 * \throw If \a this is not allocated.
3449 DataArrayDouble *DataArrayDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
3452 int nbOfComp=getNumberOfComponents();
3453 DataArrayDouble *ret=DataArrayDouble::New();
3454 int nbOfTuple=getNumberOfTuples();
3455 ret->alloc(nbOfTuple,1);
3456 const double *src=getConstPointer();
3457 double *dest=ret->getPointer();
3458 for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
3459 *dest=*std::max_element(src,src+nbOfComp);
3464 * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c this->getNumberOfTuples() tuples.
3465 * \n This returned array contains the euclidian distance for each tuple in \a this.
3466 * \n So the returned array can be seen as a dense symmetrical matrix whose diagonal elements are equal to 0.
3467 * \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)
3469 * \warning use this method with care because it can leads to big amount of consumed memory !
3471 * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
3473 * \throw If \a this is not allocated.
3475 * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrixWith
3477 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception)
3480 int nbOfComp=getNumberOfComponents();
3481 int nbOfTuples=getNumberOfTuples();
3482 const double *inData=getConstPointer();
3483 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3484 ret->alloc(nbOfTuples*nbOfTuples,1);
3485 double *outData=ret->getPointer();
3486 for(int i=0;i<nbOfTuples;i++)
3488 outData[i*nbOfTuples+i]=0.;
3489 for(int j=i+1;j<nbOfTuples;j++)
3492 for(int k=0;k<nbOfComp;k++)
3493 { double delta=inData[i*nbOfComp+k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
3495 outData[i*nbOfTuples+j]=dist;
3496 outData[j*nbOfTuples+i]=dist;
3503 * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c other->getNumberOfTuples() tuples.
3504 * \n This returned array contains the euclidian distance for each tuple in \a other with each tuple in \a this.
3505 * \n So the returned array can be seen as a dense rectangular matrix with \c other->getNumberOfTuples() rows and \c this->getNumberOfTuples() columns.
3506 * \n Output rectangular matrix is sorted along rows.
3507 * \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)
3509 * \warning use this method with care because it can leads to big amount of consumed memory !
3511 * \param [in] other DataArrayDouble instance having same number of components than \a this.
3512 * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
3514 * \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.
3516 * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrix
3518 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
3521 throw INTERP_KERNEL::Exception("DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : input parameter is null !");
3523 other->checkAllocated();
3524 int nbOfComp=getNumberOfComponents();
3525 int otherNbOfComp=other->getNumberOfComponents();
3526 if(nbOfComp!=otherNbOfComp)
3528 std::ostringstream oss; oss << "DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : this nb of compo=" << nbOfComp << " and other nb of compo=" << otherNbOfComp << ". It should match !";
3529 throw INTERP_KERNEL::Exception(oss.str().c_str());
3531 int nbOfTuples=getNumberOfTuples();
3532 int otherNbOfTuples=other->getNumberOfTuples();
3533 const double *inData=getConstPointer();
3534 const double *inDataOther=other->getConstPointer();
3535 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3536 ret->alloc(otherNbOfTuples*nbOfTuples,1);
3537 double *outData=ret->getPointer();
3538 for(int i=0;i<otherNbOfTuples;i++,inDataOther+=nbOfComp)
3540 for(int j=0;j<nbOfTuples;j++)
3543 for(int k=0;k<nbOfComp;k++)
3544 { double delta=inDataOther[k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
3546 outData[i*nbOfTuples+j]=dist;
3553 * Sorts value within every tuple of \a this array.
3554 * \param [in] asc - if \a true, the values are sorted in ascending order, else,
3555 * in descending order.
3556 * \throw If \a this is not allocated.
3558 void DataArrayDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
3561 double *pt=getPointer();
3562 int nbOfTuple=getNumberOfTuples();
3563 int nbOfComp=getNumberOfComponents();
3565 for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
3566 std::sort(pt,pt+nbOfComp);
3568 for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
3569 std::sort(pt,pt+nbOfComp,std::greater<double>());
3574 * Converts every value of \a this array to its absolute value.
3575 * \throw If \a this is not allocated.
3577 void DataArrayDouble::abs() throw(INTERP_KERNEL::Exception)
3580 double *ptr=getPointer();
3581 std::size_t nbOfElems=getNbOfElems();
3582 std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
3587 * Apply a liner function to a given component of \a this array, so that
3588 * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
3589 * \param [in] a - the first coefficient of the function.
3590 * \param [in] b - the second coefficient of the function.
3591 * \param [in] compoId - the index of component to modify.
3592 * \throw If \a this is not allocated.
3594 void DataArrayDouble::applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception)
3597 double *ptr=getPointer()+compoId;
3598 int nbOfComp=getNumberOfComponents();
3599 int nbOfTuple=getNumberOfTuples();
3600 for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
3606 * Apply a liner function to all elements of \a this array, so that
3607 * an element _x_ becomes \f$ a * x + b \f$.
3608 * \param [in] a - the first coefficient of the function.
3609 * \param [in] b - the second coefficient of the function.
3610 * \throw If \a this is not allocated.
3612 void DataArrayDouble::applyLin(double a, double b) throw(INTERP_KERNEL::Exception)
3615 double *ptr=getPointer();
3616 std::size_t nbOfElems=getNbOfElems();
3617 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3623 * Modify all elements of \a this array, so that
3624 * an element _x_ becomes \f$ numerator / x \f$.
3625 * \param [in] numerator - the numerator used to modify array elements.
3626 * \throw If \a this is not allocated.
3627 * \throw If there is an element equal to 0.0 in \a this array.
3628 * \warning If an exception is thrown because of presence of 0.0 element in \a this
3629 * array, all elements processed before detection of the zero element remain
3632 void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception)
3635 double *ptr=getPointer();
3636 std::size_t nbOfElems=getNbOfElems();
3637 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3639 if(std::abs(*ptr)>std::numeric_limits<double>::min())
3641 *ptr=numerator/(*ptr);
3645 std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
3647 throw INTERP_KERNEL::Exception(oss.str().c_str());
3654 * Returns a full copy of \a this array except that sign of all elements is reversed.
3655 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3656 * same number of tuples and component as \a this array.
3657 * The caller is to delete this result array using decrRef() as it is no more
3659 * \throw If \a this is not allocated.
3661 DataArrayDouble *DataArrayDouble::negate() const throw(INTERP_KERNEL::Exception)
3664 DataArrayDouble *newArr=DataArrayDouble::New();
3665 int nbOfTuples=getNumberOfTuples();
3666 int nbOfComp=getNumberOfComponents();
3667 newArr->alloc(nbOfTuples,nbOfComp);
3668 const double *cptr=getConstPointer();
3669 std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
3670 newArr->copyStringInfoFrom(*this);
3675 * Modify all elements of \a this array, so that
3676 * an element _x_ becomes <em> val ^ x </em>. Contrary to DataArrayInt::applyPow
3677 * all values in \a this have to be >= 0 if val is \b not integer.
3678 * \param [in] val - the value used to apply pow on all array elements.
3679 * \throw If \a this is not allocated.
3680 * \warning If an exception is thrown because of presence of 0 element in \a this
3681 * array and \a val is \b not integer, all elements processed before detection of the zero element remain
3684 void DataArrayDouble::applyPow(double val) throw(INTERP_KERNEL::Exception)
3687 double *ptr=getPointer();
3688 std::size_t nbOfElems=getNbOfElems();
3690 bool isInt=((double)val2)==val;
3693 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3699 std::ostringstream oss; oss << "DataArrayDouble::applyPow (double) : At elem # " << i << " value is " << *ptr << " ! must be >=0. !";
3700 throw INTERP_KERNEL::Exception(oss.str().c_str());
3706 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3707 *ptr=pow(*ptr,val2);
3713 * Modify all elements of \a this array, so that
3714 * an element _x_ becomes \f$ val ^ x \f$.
3715 * \param [in] val - the value used to apply pow on all array elements.
3716 * \throw If \a this is not allocated.
3717 * \throw If \a val < 0.
3718 * \warning If an exception is thrown because of presence of 0 element in \a this
3719 * array, all elements processed before detection of the zero element remain
3722 void DataArrayDouble::applyRPow(double val) throw(INTERP_KERNEL::Exception)
3726 throw INTERP_KERNEL::Exception("DataArrayDouble::applyRPow : the input value has to be >= 0 !");
3727 double *ptr=getPointer();
3728 std::size_t nbOfElems=getNbOfElems();
3729 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3735 * Returns a new DataArrayDouble created from \a this one by applying \a
3736 * FunctionToEvaluate to every tuple of \a this array. Textual data is not copied.
3737 * For more info see \ref MEDCouplingArrayApplyFunc
3738 * \param [in] nbOfComp - number of components in the result array.
3739 * \param [in] func - the \a FunctionToEvaluate declared as
3740 * \c bool (*\a func)(\c const \c double *\a pos, \c double *\a res),
3741 * where \a pos points to the first component of a tuple of \a this array
3742 * and \a res points to the first component of a tuple of the result array.
3743 * Note that length (number of components) of \a pos can differ from
3745 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3746 * same number of tuples as \a this array.
3747 * The caller is to delete this result array using decrRef() as it is no more
3749 * \throw If \a this is not allocated.
3750 * \throw If \a func returns \a false.
3752 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
3755 DataArrayDouble *newArr=DataArrayDouble::New();
3756 int nbOfTuples=getNumberOfTuples();
3757 int oldNbOfComp=getNumberOfComponents();
3758 newArr->alloc(nbOfTuples,nbOfComp);
3759 const double *ptr=getConstPointer();
3760 double *ptrToFill=newArr->getPointer();
3761 for(int i=0;i<nbOfTuples;i++)
3763 if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
3765 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
3766 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
3767 oss << ") : Evaluation of function failed !";
3769 throw INTERP_KERNEL::Exception(oss.str().c_str());
3776 * Returns a new DataArrayDouble created from \a this one by applying a function to every
3777 * tuple of \a this array. Textual data is not copied.
3778 * For more info see \ref MEDCouplingArrayApplyFunc1.
3779 * \param [in] nbOfComp - number of components in the result array.
3780 * \param [in] func - the expression defining how to transform a tuple of \a this array.
3781 * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
3782 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3783 * same number of tuples as \a this array and \a nbOfComp components.
3784 * The caller is to delete this result array using decrRef() as it is no more
3786 * \throw If \a this is not allocated.
3787 * \throw If computing \a func fails.
3789 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
3792 INTERP_KERNEL::ExprParser expr(func);
3794 std::set<std::string> vars;
3795 expr.getTrueSetOfVars(vars);
3796 int oldNbOfComp=getNumberOfComponents();
3797 if((int)vars.size()>oldNbOfComp)
3799 std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
3800 oss << vars.size() << " variables : ";
3801 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
3802 throw INTERP_KERNEL::Exception(oss.str().c_str());
3804 std::vector<std::string> varsV(vars.begin(),vars.end());
3805 expr.prepareExprEvaluation(varsV,oldNbOfComp,nbOfComp);
3807 DataArrayDouble *newArr=DataArrayDouble::New();
3808 int nbOfTuples=getNumberOfTuples();
3809 newArr->alloc(nbOfTuples,nbOfComp);
3810 const double *ptr=getConstPointer();
3811 double *ptrToFill=newArr->getPointer();
3812 for(int i=0;i<nbOfTuples;i++)
3816 expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
3818 catch(INTERP_KERNEL::Exception& e)
3820 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
3821 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
3822 oss << ") : Evaluation of function failed !" << e.what();
3824 throw INTERP_KERNEL::Exception(oss.str().c_str());
3831 * Returns a new DataArrayDouble created from \a this one by applying a function to every
3832 * tuple of \a this array. Textual data is not copied.
3833 * For more info see \ref MEDCouplingArrayApplyFunc0.
3834 * \param [in] func - the expression defining how to transform a tuple of \a this array.
3835 * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
3836 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3837 * same number of tuples and components as \a this array.
3838 * The caller is to delete this result array using decrRef() as it is no more
3840 * \throw If \a this is not allocated.
3841 * \throw If computing \a func fails.
3843 DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const throw(INTERP_KERNEL::Exception)
3846 INTERP_KERNEL::ExprParser expr(func);
3848 expr.prepareExprEvaluationVec();
3850 DataArrayDouble *newArr=DataArrayDouble::New();
3851 int nbOfTuples=getNumberOfTuples();
3852 int nbOfComp=getNumberOfComponents();
3853 newArr->alloc(nbOfTuples,nbOfComp);
3854 const double *ptr=getConstPointer();
3855 double *ptrToFill=newArr->getPointer();
3856 for(int i=0;i<nbOfTuples;i++)
3860 expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
3862 catch(INTERP_KERNEL::Exception& e)
3864 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
3865 std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
3866 oss << ") : Evaluation of function failed ! " << e.what();
3868 throw INTERP_KERNEL::Exception(oss.str().c_str());
3875 * Returns a new DataArrayDouble created from \a this one by applying a function to every
3876 * tuple of \a this array. Textual data is not copied.
3877 * For more info see \ref MEDCouplingArrayApplyFunc2.
3878 * \param [in] nbOfComp - number of components in the result array.
3879 * \param [in] func - the expression defining how to transform a tuple of \a this array.
3880 * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
3881 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3882 * same number of tuples as \a this array.
3883 * The caller is to delete this result array using decrRef() as it is no more
3885 * \throw If \a this is not allocated.
3886 * \throw If \a func contains vars that are not in \a this->getInfoOnComponent().
3887 * \throw If computing \a func fails.
3889 DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
3892 INTERP_KERNEL::ExprParser expr(func);
3894 std::set<std::string> vars;
3895 expr.getTrueSetOfVars(vars);
3896 int oldNbOfComp=getNumberOfComponents();
3897 if((int)vars.size()>oldNbOfComp)
3899 std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
3900 oss << vars.size() << " variables : ";
3901 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
3902 throw INTERP_KERNEL::Exception(oss.str().c_str());
3904 expr.prepareExprEvaluation(getVarsOnComponent(),oldNbOfComp,nbOfComp);
3906 DataArrayDouble *newArr=DataArrayDouble::New();
3907 int nbOfTuples=getNumberOfTuples();
3908 newArr->alloc(nbOfTuples,nbOfComp);
3909 const double *ptr=getConstPointer();
3910 double *ptrToFill=newArr->getPointer();
3911 for(int i=0;i<nbOfTuples;i++)
3915 expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
3917 catch(INTERP_KERNEL::Exception& e)
3919 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
3920 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
3921 oss << ") : Evaluation of function failed !" << e.what();
3923 throw INTERP_KERNEL::Exception(oss.str().c_str());
3930 * Returns a new DataArrayDouble created from \a this one by applying a function to every
3931 * tuple of \a this array. Textual data is not copied.
3932 * For more info see \ref MEDCouplingArrayApplyFunc3.
3933 * \param [in] nbOfComp - number of components in the result array.
3934 * \param [in] varsOrder - sequence of vars defining their order.
3935 * \param [in] func - the expression defining how to transform a tuple of \a this array.
3936 * Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
3937 * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3938 * same number of tuples as \a this array.
3939 * The caller is to delete this result array using decrRef() as it is no more
3941 * \throw If \a this is not allocated.
3942 * \throw If \a func contains vars not in \a varsOrder.
3943 * \throw If computing \a func fails.
3945 DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception)
3948 INTERP_KERNEL::ExprParser expr(func);
3950 std::set<std::string> vars;
3951 expr.getTrueSetOfVars(vars);
3952 int oldNbOfComp=getNumberOfComponents();
3953 if((int)vars.size()>oldNbOfComp)
3955 std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
3956 oss << vars.size() << " variables : ";
3957 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
3958 throw INTERP_KERNEL::Exception(oss.str().c_str());
3960 expr.prepareExprEvaluation(varsOrder,oldNbOfComp,nbOfComp);
3962 DataArrayDouble *newArr=DataArrayDouble::New();
3963 int nbOfTuples=getNumberOfTuples();
3964 newArr->alloc(nbOfTuples,nbOfComp);
3965 const double *ptr=getConstPointer();
3966 double *ptrToFill=newArr->getPointer();
3967 for(int i=0;i<nbOfTuples;i++)
3971 expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
3973 catch(INTERP_KERNEL::Exception& e)
3975 std::ostringstream oss; oss << "For tuple # " << i << " with value (";
3976 std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
3977 oss << ") : Evaluation of function failed !" << e.what();
3979 throw INTERP_KERNEL::Exception(oss.str().c_str());
3985 void DataArrayDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
3988 INTERP_KERNEL::ExprParser expr(func);
3990 char *funcStr=expr.compileX86();
3992 *((void **)&funcPtr)=funcStr;//he he...
3994 double *ptr=getPointer();
3995 int nbOfComp=getNumberOfComponents();
3996 int nbOfTuples=getNumberOfTuples();
3997 int nbOfElems=nbOfTuples*nbOfComp;
3998 for(int i=0;i<nbOfElems;i++,ptr++)
4003 void DataArrayDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
4006 INTERP_KERNEL::ExprParser expr(func);
4008 char *funcStr=expr.compileX86_64();
4010 *((void **)&funcPtr)=funcStr;//he he...
4012 double *ptr=getPointer();
4013 int nbOfComp=getNumberOfComponents();
4014 int nbOfTuples=getNumberOfTuples();
4015 int nbOfElems=nbOfTuples*nbOfComp;
4016 for(int i=0;i<nbOfElems;i++,ptr++)
4021 DataArrayDoubleIterator *DataArrayDouble::iterator() throw(INTERP_KERNEL::Exception)
4023 return new DataArrayDoubleIterator(this);
4027 * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
4028 * array whose values are within a given range. Textual data is not copied.
4029 * \param [in] vmin - a lowest acceptable value.
4030 * \param [in] vmax - a greatest acceptable value.
4031 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4032 * The caller is to delete this result array using decrRef() as it is no more
4034 * \throw If \a this->getNumberOfComponents() != 1
4036 * \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".
4038 * \ref py_mcdataarraydouble_getidsinrange "Here is a Python example".
4040 DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
4043 if(getNumberOfComponents()!=1)
4044 throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !");
4045 const double *cptr=getConstPointer();
4046 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
4047 int nbOfTuples=getNumberOfTuples();
4048 for(int i=0;i<nbOfTuples;i++,cptr++)
4049 if(*cptr>=vmin && *cptr<=vmax)
4050 ret->pushBackSilent(i);
4055 * Returns a new DataArrayDouble by concatenating two given arrays, so that (1) the number
4056 * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
4057 * the number of component in the result array is same as that of each of given arrays.
4058 * Info on components is copied from the first of the given arrays. Number of components
4059 * in the given arrays must be the same.
4060 * \param [in] a1 - an array to include in the result array.
4061 * \param [in] a2 - another array to include in the result array.
4062 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4063 * The caller is to delete this result array using decrRef() as it is no more
4065 * \throw If both \a a1 and \a a2 are NULL.
4066 * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
4068 DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4070 std::vector<const DataArrayDouble *> tmp(2);
4071 tmp[0]=a1; tmp[1]=a2;
4072 return Aggregate(tmp);
4076 * Returns a new DataArrayDouble by concatenating all given arrays, so that (1) the number
4077 * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
4078 * the number of component in the result array is same as that of each of given arrays.
4079 * Info on components is copied from the first of the given arrays. Number of components
4080 * in the given arrays must be the same.
4081 * \param [in] arr - a sequence of arrays to include in the result array.
4082 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4083 * The caller is to delete this result array using decrRef() as it is no more
4085 * \throw If all arrays within \a arr are NULL.
4086 * \throw If getNumberOfComponents() of arrays within \a arr.
4088 DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
4090 std::vector<const DataArrayDouble *> a;
4091 for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4095 throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must contain at least one NON EMPTY DataArrayDouble !");
4096 std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
4097 int nbOfComp=(*it)->getNumberOfComponents();
4098 int nbt=(*it++)->getNumberOfTuples();
4099 for(int i=1;it!=a.end();it++,i++)
4101 if((*it)->getNumberOfComponents()!=nbOfComp)
4102 throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
4103 nbt+=(*it)->getNumberOfTuples();
4105 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4106 ret->alloc(nbt,nbOfComp);
4107 double *pt=ret->getPointer();
4108 for(it=a.begin();it!=a.end();it++)
4109 pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
4110 ret->copyStringInfoFrom(*(a[0]));
4115 * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
4116 * of components in the result array is a sum of the number of components of given arrays
4117 * and (2) the number of tuples in the result array is same as that of each of given
4118 * arrays. In other words the i-th tuple of result array includes all components of
4119 * i-th tuples of all given arrays.
4120 * Number of tuples in the given arrays must be the same.
4121 * \param [in] a1 - an array to include in the result array.
4122 * \param [in] a2 - another array to include in the result array.
4123 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4124 * The caller is to delete this result array using decrRef() as it is no more
4126 * \throw If both \a a1 and \a a2 are NULL.
4127 * \throw If any given array is not allocated.
4128 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4130 DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4132 std::vector<const DataArrayDouble *> arr(2);
4133 arr[0]=a1; arr[1]=a2;
4138 * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
4139 * of components in the result array is a sum of the number of components of given arrays
4140 * and (2) the number of tuples in the result array is same as that of each of given
4141 * arrays. In other words the i-th tuple of result array includes all components of
4142 * i-th tuples of all given arrays.
4143 * Number of tuples in the given arrays must be the same.
4144 * \param [in] arr - a sequence of arrays to include in the result array.
4145 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4146 * The caller is to delete this result array using decrRef() as it is no more
4148 * \throw If all arrays within \a arr are NULL.
4149 * \throw If any given array is not allocated.
4150 * \throw If getNumberOfTuples() of arrays within \a arr is different.
4152 DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
4154 std::vector<const DataArrayDouble *> a;
4155 for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4159 throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
4160 std::vector<const DataArrayDouble *>::const_iterator it;
4161 for(it=a.begin();it!=a.end();it++)
4162 (*it)->checkAllocated();
4164 int nbOfTuples=(*it)->getNumberOfTuples();
4165 std::vector<int> nbc(a.size());
4166 std::vector<const double *> pts(a.size());
4167 nbc[0]=(*it)->getNumberOfComponents();
4168 pts[0]=(*it++)->getConstPointer();
4169 for(int i=1;it!=a.end();it++,i++)
4171 if(nbOfTuples!=(*it)->getNumberOfTuples())
4172 throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
4173 nbc[i]=(*it)->getNumberOfComponents();
4174 pts[i]=(*it)->getConstPointer();
4176 int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
4177 DataArrayDouble *ret=DataArrayDouble::New();
4178 ret->alloc(nbOfTuples,totalNbOfComp);
4179 double *retPtr=ret->getPointer();
4180 for(int i=0;i<nbOfTuples;i++)
4181 for(int j=0;j<(int)a.size();j++)
4183 retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
4187 for(int i=0;i<(int)a.size();i++)
4188 for(int j=0;j<nbc[i];j++,k++)
4189 ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
4194 * Returns a new DataArrayDouble containing a dot product of two given arrays, so that
4195 * the i-th tuple of the result array is a sum of products of j-th components of i-th
4196 * tuples of given arrays (\f$ a_i = \sum_{j=1}^n a1_j * a2_j \f$).
4197 * Info on components and name is copied from the first of the given arrays.
4198 * Number of tuples and components in the given arrays must be the same.
4199 * \param [in] a1 - a given array.
4200 * \param [in] a2 - another given array.
4201 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4202 * The caller is to delete this result array using decrRef() as it is no more
4204 * \throw If either \a a1 or \a a2 is NULL.
4205 * \throw If any given array is not allocated.
4206 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4207 * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
4209 DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4212 throw INTERP_KERNEL::Exception("DataArrayDouble::Dot : input DataArrayDouble instance is NULL !");
4213 a1->checkAllocated();
4214 a2->checkAllocated();
4215 int nbOfComp=a1->getNumberOfComponents();
4216 if(nbOfComp!=a2->getNumberOfComponents())
4217 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
4218 int nbOfTuple=a1->getNumberOfTuples();
4219 if(nbOfTuple!=a2->getNumberOfTuples())
4220 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
4221 DataArrayDouble *ret=DataArrayDouble::New();
4222 ret->alloc(nbOfTuple,1);
4223 double *retPtr=ret->getPointer();
4224 const double *a1Ptr=a1->getConstPointer();
4225 const double *a2Ptr=a2->getConstPointer();
4226 for(int i=0;i<nbOfTuple;i++)
4229 for(int j=0;j<nbOfComp;j++)
4230 sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
4233 ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str());
4234 ret->setName(a1->getName().c_str());
4239 * Returns a new DataArrayDouble containing a cross product of two given arrays, so that
4240 * the i-th tuple of the result array contains 3 components of a vector which is a cross
4241 * product of two vectors defined by the i-th tuples of given arrays.
4242 * Info on components is copied from the first of the given arrays.
4243 * Number of tuples in the given arrays must be the same.
4244 * Number of components in the given arrays must be 3.
4245 * \param [in] a1 - a given array.
4246 * \param [in] a2 - another given array.
4247 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4248 * The caller is to delete this result array using decrRef() as it is no more
4250 * \throw If either \a a1 or \a a2 is NULL.
4251 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4252 * \throw If \a a1->getNumberOfComponents() != 3
4253 * \throw If \a a2->getNumberOfComponents() != 3
4255 DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4258 throw INTERP_KERNEL::Exception("DataArrayDouble::CrossProduct : input DataArrayDouble instance is NULL !");
4259 int nbOfComp=a1->getNumberOfComponents();
4260 if(nbOfComp!=a2->getNumberOfComponents())
4261 throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
4263 throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
4264 int nbOfTuple=a1->getNumberOfTuples();
4265 if(nbOfTuple!=a2->getNumberOfTuples())
4266 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
4267 DataArrayDouble *ret=DataArrayDouble::New();
4268 ret->alloc(nbOfTuple,3);
4269 double *retPtr=ret->getPointer();
4270 const double *a1Ptr=a1->getConstPointer();
4271 const double *a2Ptr=a2->getConstPointer();
4272 for(int i=0;i<nbOfTuple;i++)
4274 retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
4275 retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
4276 retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
4278 ret->copyStringInfoFrom(*a1);
4283 * Returns a new DataArrayDouble containing maximal values of two given arrays.
4284 * Info on components is copied from the first of the given arrays.
4285 * Number of tuples and components in the given arrays must be the same.
4286 * \param [in] a1 - an array to compare values with another one.
4287 * \param [in] a2 - another array to compare values with the first one.
4288 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4289 * The caller is to delete this result array using decrRef() as it is no more
4291 * \throw If either \a a1 or \a a2 is NULL.
4292 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4293 * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
4295 DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4298 throw INTERP_KERNEL::Exception("DataArrayDouble::Max : input DataArrayDouble instance is NULL !");
4299 int nbOfComp=a1->getNumberOfComponents();
4300 if(nbOfComp!=a2->getNumberOfComponents())
4301 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
4302 int nbOfTuple=a1->getNumberOfTuples();
4303 if(nbOfTuple!=a2->getNumberOfTuples())
4304 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
4305 DataArrayDouble *ret=DataArrayDouble::New();
4306 ret->alloc(nbOfTuple,nbOfComp);
4307 double *retPtr=ret->getPointer();
4308 const double *a1Ptr=a1->getConstPointer();
4309 const double *a2Ptr=a2->getConstPointer();
4310 int nbElem=nbOfTuple*nbOfComp;
4311 for(int i=0;i<nbElem;i++)
4312 retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
4313 ret->copyStringInfoFrom(*a1);
4318 * Returns a new DataArrayDouble containing minimal values of two given arrays.
4319 * Info on components is copied from the first of the given arrays.
4320 * Number of tuples and components in the given arrays must be the same.
4321 * \param [in] a1 - an array to compare values with another one.
4322 * \param [in] a2 - another array to compare values with the first one.
4323 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4324 * The caller is to delete this result array using decrRef() as it is no more
4326 * \throw If either \a a1 or \a a2 is NULL.
4327 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4328 * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
4330 DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4333 throw INTERP_KERNEL::Exception("DataArrayDouble::Min : input DataArrayDouble instance is NULL !");
4334 int nbOfComp=a1->getNumberOfComponents();
4335 if(nbOfComp!=a2->getNumberOfComponents())
4336 throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
4337 int nbOfTuple=a1->getNumberOfTuples();
4338 if(nbOfTuple!=a2->getNumberOfTuples())
4339 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
4340 DataArrayDouble *ret=DataArrayDouble::New();
4341 ret->alloc(nbOfTuple,nbOfComp);
4342 double *retPtr=ret->getPointer();
4343 const double *a1Ptr=a1->getConstPointer();
4344 const double *a2Ptr=a2->getConstPointer();
4345 int nbElem=nbOfTuple*nbOfComp;
4346 for(int i=0;i<nbElem;i++)
4347 retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
4348 ret->copyStringInfoFrom(*a1);
4353 * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
4355 * 1. The arrays have same number of tuples and components. Then each value of
4356 * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
4357 * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
4358 * 2. The arrays have same number of tuples and one array, say _a2_, has one
4360 * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
4361 * 3. The arrays have same number of components and one array, say _a2_, has one
4363 * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
4365 * Info on components is copied either from the first array (in the first case) or from
4366 * the array with maximal number of elements (getNbOfElems()).
4367 * \param [in] a1 - an array to sum up.
4368 * \param [in] a2 - another array to sum up.
4369 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4370 * The caller is to delete this result array using decrRef() as it is no more
4372 * \throw If either \a a1 or \a a2 is NULL.
4373 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4374 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4375 * none of them has number of tuples or components equal to 1.
4377 DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4380 throw INTERP_KERNEL::Exception("DataArrayDouble::Add : input DataArrayDouble instance is NULL !");
4381 int nbOfTuple=a1->getNumberOfTuples();
4382 int nbOfTuple2=a2->getNumberOfTuples();
4383 int nbOfComp=a1->getNumberOfComponents();
4384 int nbOfComp2=a2->getNumberOfComponents();
4385 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
4386 if(nbOfTuple==nbOfTuple2)
4388 if(nbOfComp==nbOfComp2)
4390 ret=DataArrayDouble::New();
4391 ret->alloc(nbOfTuple,nbOfComp);
4392 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
4393 ret->copyStringInfoFrom(*a1);
4397 int nbOfCompMin,nbOfCompMax;
4398 const DataArrayDouble *aMin, *aMax;
4399 if(nbOfComp>nbOfComp2)
4401 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
4406 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
4411 ret=DataArrayDouble::New();
4412 ret->alloc(nbOfTuple,nbOfCompMax);
4413 const double *aMinPtr=aMin->getConstPointer();
4414 const double *aMaxPtr=aMax->getConstPointer();
4415 double *res=ret->getPointer();
4416 for(int i=0;i<nbOfTuple;i++)
4417 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
4418 ret->copyStringInfoFrom(*aMax);
4421 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
4424 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
4426 if(nbOfComp==nbOfComp2)
4428 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
4429 const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
4430 const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
4431 const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
4432 ret=DataArrayDouble::New();
4433 ret->alloc(nbOfTupleMax,nbOfComp);
4434 double *res=ret->getPointer();
4435 for(int i=0;i<nbOfTupleMax;i++)
4436 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
4437 ret->copyStringInfoFrom(*aMax);
4440 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
4443 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
4448 * Adds values of another DataArrayDouble to values of \a this one. There are 3
4450 * 1. The arrays have same number of tuples and components. Then each value of
4451 * \a other array is added to the corresponding value of \a this array, i.e.:
4452 * _a_ [ i, j ] += _other_ [ i, j ].
4453 * 2. The arrays have same number of tuples and \a other array has one component. Then
4454 * _a_ [ i, j ] += _other_ [ i, 0 ].
4455 * 3. The arrays have same number of components and \a other array has one tuple. Then
4456 * _a_ [ i, j ] += _a2_ [ 0, j ].
4458 * \param [in] other - an array to add to \a this one.
4459 * \throw If \a other is NULL.
4460 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
4461 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
4462 * \a other has number of both tuples and components not equal to 1.
4464 void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4467 throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
4468 const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual !";
4470 other->checkAllocated();
4471 int nbOfTuple=getNumberOfTuples();
4472 int nbOfTuple2=other->getNumberOfTuples();
4473 int nbOfComp=getNumberOfComponents();
4474 int nbOfComp2=other->getNumberOfComponents();
4475 if(nbOfTuple==nbOfTuple2)
4477 if(nbOfComp==nbOfComp2)
4479 std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
4481 else if(nbOfComp2==1)
4483 double *ptr=getPointer();
4484 const double *ptrc=other->getConstPointer();
4485 for(int i=0;i<nbOfTuple;i++)
4486 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
4489 throw INTERP_KERNEL::Exception(msg);
4491 else if(nbOfTuple2==1)
4493 if(nbOfComp2==nbOfComp)
4495 double *ptr=getPointer();
4496 const double *ptrc=other->getConstPointer();
4497 for(int i=0;i<nbOfTuple;i++)
4498 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
4501 throw INTERP_KERNEL::Exception(msg);
4504 throw INTERP_KERNEL::Exception(msg);
4509 * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
4511 * 1. The arrays have same number of tuples and components. Then each value of
4512 * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
4513 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
4514 * 2. The arrays have same number of tuples and one array, say _a2_, has one
4516 * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
4517 * 3. The arrays have same number of components and one array, say _a2_, has one
4519 * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
4521 * Info on components is copied either from the first array (in the first case) or from
4522 * the array with maximal number of elements (getNbOfElems()).
4523 * \param [in] a1 - an array to subtract from.
4524 * \param [in] a2 - an array to subtract.
4525 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4526 * The caller is to delete this result array using decrRef() as it is no more
4528 * \throw If either \a a1 or \a a2 is NULL.
4529 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4530 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4531 * none of them has number of tuples or components equal to 1.
4533 DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4536 throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !");
4537 int nbOfTuple1=a1->getNumberOfTuples();
4538 int nbOfTuple2=a2->getNumberOfTuples();
4539 int nbOfComp1=a1->getNumberOfComponents();
4540 int nbOfComp2=a2->getNumberOfComponents();
4541 if(nbOfTuple2==nbOfTuple1)
4543 if(nbOfComp1==nbOfComp2)
4545 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4546 ret->alloc(nbOfTuple2,nbOfComp1);
4547 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
4548 ret->copyStringInfoFrom(*a1);
4551 else if(nbOfComp2==1)
4553 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4554 ret->alloc(nbOfTuple1,nbOfComp1);
4555 const double *a2Ptr=a2->getConstPointer();
4556 const double *a1Ptr=a1->getConstPointer();
4557 double *res=ret->getPointer();
4558 for(int i=0;i<nbOfTuple1;i++)
4559 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<double>(),a2Ptr[i]));
4560 ret->copyStringInfoFrom(*a1);
4565 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
4569 else if(nbOfTuple2==1)
4571 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
4572 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4573 ret->alloc(nbOfTuple1,nbOfComp1);
4574 const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
4575 double *pt=ret->getPointer();
4576 for(int i=0;i<nbOfTuple1;i++)
4577 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<double>());
4578 ret->copyStringInfoFrom(*a1);
4583 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
4589 * Subtract values of another DataArrayDouble from values of \a this one. There are 3
4591 * 1. The arrays have same number of tuples and components. Then each value of
4592 * \a other array is subtracted from the corresponding value of \a this array, i.e.:
4593 * _a_ [ i, j ] -= _other_ [ i, j ].
4594 * 2. The arrays have same number of tuples and \a other array has one component. Then
4595 * _a_ [ i, j ] -= _other_ [ i, 0 ].
4596 * 3. The arrays have same number of components and \a other array has one tuple. Then
4597 * _a_ [ i, j ] -= _a2_ [ 0, j ].
4599 * \param [in] other - an array to subtract from \a this one.
4600 * \throw If \a other is NULL.
4601 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
4602 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
4603 * \a other has number of both tuples and components not equal to 1.
4605 void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4608 throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !");
4609 const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual !";
4611 other->checkAllocated();
4612 int nbOfTuple=getNumberOfTuples();
4613 int nbOfTuple2=other->getNumberOfTuples();
4614 int nbOfComp=getNumberOfComponents();
4615 int nbOfComp2=other->getNumberOfComponents();
4616 if(nbOfTuple==nbOfTuple2)
4618 if(nbOfComp==nbOfComp2)
4620 std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
4622 else if(nbOfComp2==1)
4624 double *ptr=getPointer();
4625 const double *ptrc=other->getConstPointer();
4626 for(int i=0;i<nbOfTuple;i++)
4627 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*ptrc++));
4630 throw INTERP_KERNEL::Exception(msg);
4632 else if(nbOfTuple2==1)
4634 if(nbOfComp2==nbOfComp)
4636 double *ptr=getPointer();
4637 const double *ptrc=other->getConstPointer();
4638 for(int i=0;i<nbOfTuple;i++)
4639 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
4642 throw INTERP_KERNEL::Exception(msg);
4645 throw INTERP_KERNEL::Exception(msg);
4650 * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
4652 * 1. The arrays have same number of tuples and components. Then each value of
4653 * the result array (_a_) is a product of the corresponding values of \a a1 and
4654 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
4655 * 2. The arrays have same number of tuples and one array, say _a2_, has one
4657 * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
4658 * 3. The arrays have same number of components and one array, say _a2_, has one
4660 * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
4662 * Info on components is copied either from the first array (in the first case) or from
4663 * the array with maximal number of elements (getNbOfElems()).
4664 * \param [in] a1 - a factor array.
4665 * \param [in] a2 - another factor array.
4666 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4667 * The caller is to delete this result array using decrRef() as it is no more
4669 * \throw If either \a a1 or \a a2 is NULL.
4670 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4671 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4672 * none of them has number of tuples or components equal to 1.
4674 DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4677 throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : input DataArrayDouble instance is NULL !");
4678 int nbOfTuple=a1->getNumberOfTuples();
4679 int nbOfTuple2=a2->getNumberOfTuples();
4680 int nbOfComp=a1->getNumberOfComponents();
4681 int nbOfComp2=a2->getNumberOfComponents();
4682 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
4683 if(nbOfTuple==nbOfTuple2)
4685 if(nbOfComp==nbOfComp2)
4687 ret=DataArrayDouble::New();
4688 ret->alloc(nbOfTuple,nbOfComp);
4689 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<double>());
4690 ret->copyStringInfoFrom(*a1);
4694 int nbOfCompMin,nbOfCompMax;
4695 const DataArrayDouble *aMin, *aMax;
4696 if(nbOfComp>nbOfComp2)
4698 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
4703 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
4708 ret=DataArrayDouble::New();
4709 ret->alloc(nbOfTuple,nbOfCompMax);
4710 const double *aMinPtr=aMin->getConstPointer();
4711 const double *aMaxPtr=aMax->getConstPointer();
4712 double *res=ret->getPointer();
4713 for(int i=0;i<nbOfTuple;i++)
4714 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
4715 ret->copyStringInfoFrom(*aMax);
4718 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
4721 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
4723 if(nbOfComp==nbOfComp2)
4725 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
4726 const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
4727 const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
4728 const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
4729 ret=DataArrayDouble::New();
4730 ret->alloc(nbOfTupleMax,nbOfComp);
4731 double *res=ret->getPointer();
4732 for(int i=0;i<nbOfTupleMax;i++)
4733 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<double>());
4734 ret->copyStringInfoFrom(*aMax);
4737 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
4740 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
4745 * Multiply values of another DataArrayDouble to values of \a this one. There are 3
4747 * 1. The arrays have same number of tuples and components. Then each value of
4748 * \a other array is multiplied to the corresponding value of \a this array, i.e.:
4749 * _a_ [ i, j ] *= _other_ [ i, j ].
4750 * 2. The arrays have same number of tuples and \a other array has one component. Then
4751 * _a_ [ i, j ] *= _other_ [ i, 0 ].
4752 * 3. The arrays have same number of components and \a other array has one tuple. Then
4753 * _a_ [ i, j ] *= _a2_ [ 0, j ].
4755 * \param [in] other - an array to multiply to \a this one.
4756 * \throw If \a other is NULL.
4757 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
4758 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
4759 * \a other has number of both tuples and components not equal to 1.
4761 void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4764 throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
4765 const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
4767 other->checkAllocated();
4768 int nbOfTuple=getNumberOfTuples();
4769 int nbOfTuple2=other->getNumberOfTuples();
4770 int nbOfComp=getNumberOfComponents();
4771 int nbOfComp2=other->getNumberOfComponents();
4772 if(nbOfTuple==nbOfTuple2)
4774 if(nbOfComp==nbOfComp2)
4776 std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
4778 else if(nbOfComp2==1)
4780 double *ptr=getPointer();
4781 const double *ptrc=other->getConstPointer();
4782 for(int i=0;i<nbOfTuple;i++)
4783 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<double>(),*ptrc++));
4786 throw INTERP_KERNEL::Exception(msg);
4788 else if(nbOfTuple2==1)
4790 if(nbOfComp2==nbOfComp)
4792 double *ptr=getPointer();
4793 const double *ptrc=other->getConstPointer();
4794 for(int i=0;i<nbOfTuple;i++)
4795 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<double>());
4798 throw INTERP_KERNEL::Exception(msg);
4801 throw INTERP_KERNEL::Exception(msg);
4806 * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
4808 * 1. The arrays have same number of tuples and components. Then each value of
4809 * the result array (_a_) is a division of the corresponding values of \a a1 and
4810 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
4811 * 2. The arrays have same number of tuples and one array, say _a2_, has one
4813 * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
4814 * 3. The arrays have same number of components and one array, say _a2_, has one
4816 * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
4818 * Info on components is copied either from the first array (in the first case) or from
4819 * the array with maximal number of elements (getNbOfElems()).
4820 * \param [in] a1 - a numerator array.
4821 * \param [in] a2 - a denominator array.
4822 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4823 * The caller is to delete this result array using decrRef() as it is no more
4825 * \throw If either \a a1 or \a a2 is NULL.
4826 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4827 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4828 * none of them has number of tuples or components equal to 1.
4829 * \warning No check of division by zero is performed!
4831 DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4834 throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !");
4835 int nbOfTuple1=a1->getNumberOfTuples();
4836 int nbOfTuple2=a2->getNumberOfTuples();
4837 int nbOfComp1=a1->getNumberOfComponents();
4838 int nbOfComp2=a2->getNumberOfComponents();
4839 if(nbOfTuple2==nbOfTuple1)
4841 if(nbOfComp1==nbOfComp2)
4843 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4844 ret->alloc(nbOfTuple2,nbOfComp1);
4845 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
4846 ret->copyStringInfoFrom(*a1);
4849 else if(nbOfComp2==1)
4851 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4852 ret->alloc(nbOfTuple1,nbOfComp1);
4853 const double *a2Ptr=a2->getConstPointer();
4854 const double *a1Ptr=a1->getConstPointer();
4855 double *res=ret->getPointer();
4856 for(int i=0;i<nbOfTuple1;i++)
4857 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
4858 ret->copyStringInfoFrom(*a1);
4863 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
4867 else if(nbOfTuple2==1)
4869 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
4870 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4871 ret->alloc(nbOfTuple1,nbOfComp1);
4872 const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
4873 double *pt=ret->getPointer();
4874 for(int i=0;i<nbOfTuple1;i++)
4875 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<double>());
4876 ret->copyStringInfoFrom(*a1);
4881 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
4887 * Divide values of \a this array by values of another DataArrayDouble. There are 3
4889 * 1. The arrays have same number of tuples and components. Then each value of
4890 * \a this array is divided by the corresponding value of \a other one, i.e.:
4891 * _a_ [ i, j ] /= _other_ [ i, j ].
4892 * 2. The arrays have same number of tuples and \a other array has one component. Then
4893 * _a_ [ i, j ] /= _other_ [ i, 0 ].
4894 * 3. The arrays have same number of components and \a other array has one tuple. Then
4895 * _a_ [ i, j ] /= _a2_ [ 0, j ].
4897 * \param [in] other - an array to divide \a this one by.
4898 * \throw If \a other is NULL.
4899 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
4900 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
4901 * \a other has number of both tuples and components not equal to 1.
4902 * \warning No check of division by zero is performed!
4904 void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4907 throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !");
4908 const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
4910 other->checkAllocated();
4911 int nbOfTuple=getNumberOfTuples();
4912 int nbOfTuple2=other->getNumberOfTuples();
4913 int nbOfComp=getNumberOfComponents();
4914 int nbOfComp2=other->getNumberOfComponents();
4915 if(nbOfTuple==nbOfTuple2)
4917 if(nbOfComp==nbOfComp2)
4919 std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
4921 else if(nbOfComp2==1)
4923 double *ptr=getPointer();
4924 const double *ptrc=other->getConstPointer();
4925 for(int i=0;i<nbOfTuple;i++)
4926 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
4929 throw INTERP_KERNEL::Exception(msg);
4931 else if(nbOfTuple2==1)
4933 if(nbOfComp2==nbOfComp)
4935 double *ptr=getPointer();
4936 const double *ptrc=other->getConstPointer();
4937 for(int i=0;i<nbOfTuple;i++)
4938 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
4941 throw INTERP_KERNEL::Exception(msg);
4944 throw INTERP_KERNEL::Exception(msg);
4949 * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3
4952 * \param [in] a1 - an array to pow up.
4953 * \param [in] a2 - another array to sum up.
4954 * \return DataArrayDouble * - the new instance of DataArrayDouble.
4955 * The caller is to delete this result array using decrRef() as it is no more
4957 * \throw If either \a a1 or \a a2 is NULL.
4958 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4959 * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
4960 * \throw If there is a negative value in \a a1.
4962 DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4965 throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
4966 int nbOfTuple=a1->getNumberOfTuples();
4967 int nbOfTuple2=a2->getNumberOfTuples();
4968 int nbOfComp=a1->getNumberOfComponents();
4969 int nbOfComp2=a2->getNumberOfComponents();
4970 if(nbOfTuple!=nbOfTuple2)
4971 throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
4972 if(nbOfComp!=1 || nbOfComp2!=1)
4973 throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
4974 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
4975 const double *ptr1(a1->begin()),*ptr2(a2->begin());
4976 double *ptr=ret->getPointer();
4977 for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
4981 *ptr=pow(*ptr1,*ptr2);
4985 std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
4986 throw INTERP_KERNEL::Exception(oss.str().c_str());
4993 * Apply pow on values of another DataArrayDouble to values of \a this one.
4995 * \param [in] other - an array to pow to \a this one.
4996 * \throw If \a other is NULL.
4997 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
4998 * \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
4999 * \throw If there is a negative value in \a this.
5001 void DataArrayDouble::powEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
5004 throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : input instance is null !");
5005 int nbOfTuple=getNumberOfTuples();
5006 int nbOfTuple2=other->getNumberOfTuples();
5007 int nbOfComp=getNumberOfComponents();
5008 int nbOfComp2=other->getNumberOfComponents();
5009 if(nbOfTuple!=nbOfTuple2)
5010 throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of tuples mismatches !");
5011 if(nbOfComp!=1 || nbOfComp2!=1)
5012 throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of components of both arrays must be equal to 1 !");
5013 double *ptr=getPointer();
5014 const double *ptrc=other->begin();
5015 for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
5018 *ptr=pow(*ptr,*ptrc);
5021 std::ostringstream oss; oss << "DataArrayDouble::powEqual : on tuple #" << i << " of this value is < 0 (" << *ptr << ") !";
5022 throw INTERP_KERNEL::Exception(oss.str().c_str());
5029 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5032 void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
5037 tinyInfo[0]=getNumberOfTuples();
5038 tinyInfo[1]=getNumberOfComponents();
5048 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5051 void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
5055 int nbOfCompo=getNumberOfComponents();
5056 tinyInfo.resize(nbOfCompo+1);
5057 tinyInfo[0]=getName();
5058 for(int i=0;i<nbOfCompo;i++)
5059 tinyInfo[i+1]=getInfoOnComponent(i);
5064 tinyInfo[0]=getName();
5069 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5070 * This method returns if a feeding is needed.
5072 bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
5074 int nbOfTuple=tinyInfoI[0];
5075 int nbOfComp=tinyInfoI[1];
5076 if(nbOfTuple!=-1 || nbOfComp!=-1)
5078 alloc(nbOfTuple,nbOfComp);
5085 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5087 void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
5089 setName(tinyInfoS[0].c_str());
5092 int nbOfCompo=getNumberOfComponents();
5093 for(int i=0;i<nbOfCompo;i++)
5094 setInfoOnComponent(i,tinyInfoS[i+1].c_str());
5098 DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
5103 if(_da->isAllocated())
5105 _nb_comp=da->getNumberOfComponents();
5106 _nb_tuple=da->getNumberOfTuples();
5107 _pt=da->getPointer();
5112 DataArrayDoubleIterator::~DataArrayDoubleIterator()
5118 DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() throw(INTERP_KERNEL::Exception)
5120 if(_tuple_id<_nb_tuple)
5123 DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
5131 DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
5136 std::string DataArrayDoubleTuple::repr() const throw(INTERP_KERNEL::Exception)
5138 std::ostringstream oss; oss.precision(17); oss << "(";
5139 for(int i=0;i<_nb_of_compo-1;i++)
5140 oss << _pt[i] << ", ";
5141 oss << _pt[_nb_of_compo-1] << ")";
5145 double DataArrayDoubleTuple::doubleValue() const throw(INTERP_KERNEL::Exception)
5149 throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
5153 * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayDouble::decrRef.
5154 * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayDouble::useArray with ownership set to \b false.
5155 * 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
5156 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
5158 DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
5160 if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
5162 DataArrayDouble *ret=DataArrayDouble::New();
5163 ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
5168 std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
5169 oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
5170 throw INTERP_KERNEL::Exception(oss.str().c_str());
5175 * Returns a new instance of DataArrayInt. The caller is to delete this array
5176 * using decrRef() as it is no more needed.
5178 DataArrayInt *DataArrayInt::New()
5180 return new DataArrayInt;
5184 * Checks if raw data is allocated. Read more on the raw data
5185 * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information.
5186 * \return bool - \a true if the raw data is allocated, \a false else.
5188 bool DataArrayInt::isAllocated() const throw(INTERP_KERNEL::Exception)
5190 return getConstPointer()!=0;
5194 * Checks if raw data is allocated and throws an exception if it is not the case.
5195 * \throw If the raw data is not allocated.
5197 void DataArrayInt::checkAllocated() const throw(INTERP_KERNEL::Exception)
5200 throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
5203 std::size_t DataArrayInt::getHeapMemorySize() const
5205 std::size_t sz=_mem.getNbOfElemAllocated();
5207 return DataArray::getHeapMemorySize()+sz;
5211 * Sets information on all components. This method can change number of components
5212 * at certain conditions; if the conditions are not respected, an exception is thrown.
5213 * The number of components can be changed provided that \a this is not allocated.
5215 * To know more on format of the component information see
5216 * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
5217 * \param [in] info - a vector of component infos.
5218 * \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated()
5220 void DataArrayInt::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
5222 if(getNumberOfComponents()!=(int)info.size())
5225 _info_on_compo=info;
5228 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 !";
5229 throw INTERP_KERNEL::Exception(oss.str().c_str());
5233 _info_on_compo=info;
5237 * Returns the only one value in \a this, if and only if number of elements
5238 * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated.
5239 * \return double - the sole value stored in \a this array.
5240 * \throw If at least one of conditions stated above is not fulfilled.
5242 int DataArrayInt::intValue() const throw(INTERP_KERNEL::Exception)
5246 if(getNbOfElems()==1)
5248 return *getConstPointer();
5251 throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is allocated but number of elements is not equal to 1 !");
5254 throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
5258 * Returns an integer value characterizing \a this array, which is useful for a quick
5259 * comparison of many instances of DataArrayInt.
5260 * \return int - the hash value.
5261 * \throw If \a this is not allocated.
5263 int DataArrayInt::getHashCode() const throw(INTERP_KERNEL::Exception)
5266 std::size_t nbOfElems=getNbOfElems();
5267 int ret=nbOfElems*65536;
5272 const int *pt=begin();
5273 for(std::size_t i=0;i<nbOfElems;i+=delta)
5274 ret0+=pt[i] & 0x1FFF;
5279 * Checks the number of tuples.
5280 * \return bool - \a true if getNumberOfTuples() == 0, \a false else.
5281 * \throw If \a this is not allocated.
5283 bool DataArrayInt::empty() const throw(INTERP_KERNEL::Exception)
5286 return getNumberOfTuples()==0;
5290 * Returns a full copy of \a this. For more info on copying data arrays see
5291 * \ref MEDCouplingArrayBasicsCopyDeep.
5292 * \return DataArrayInt * - a new instance of DataArrayInt.
5294 DataArrayInt *DataArrayInt::deepCpy() const throw(INTERP_KERNEL::Exception)
5296 return new DataArrayInt(*this);
5300 * Returns either a \a deep or \a shallow copy of this array. For more info see
5301 * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
5302 * \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
5303 * \return DataArrayInt * - either a new instance of DataArrayInt (if \a dCpy
5304 * == \a true) or \a this instance (if \a dCpy == \a false).
5306 DataArrayInt *DataArrayInt::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception)
5313 return const_cast<DataArrayInt *>(this);
5318 * Copies all the data from another DataArrayInt. For more info see
5319 * \ref MEDCouplingArrayBasicsCopyDeepAssign.
5320 * \param [in] other - another instance of DataArrayInt to copy data from.
5321 * \throw If the \a other is not allocated.
5323 void DataArrayInt::cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception)
5325 other.checkAllocated();
5326 int nbOfTuples=other.getNumberOfTuples();
5327 int nbOfComp=other.getNumberOfComponents();
5328 allocIfNecessary(nbOfTuples,nbOfComp);
5329 std::size_t nbOfElems=(std::size_t)nbOfTuples*nbOfComp;
5330 int *pt=getPointer();
5331 const int *ptI=other.getConstPointer();
5332 for(std::size_t i=0;i<nbOfElems;i++)
5334 copyStringInfoFrom(other);
5338 * This method reserve nbOfElems elements in memory ( nbOfElems*4 bytes ) \b without impacting the number of tuples in \a this.
5339 * If \a this has already been allocated, this method checks that \a this has only one component. If not an INTERP_KERNEL::Exception will be thrown.
5340 * If \a this has not already been allocated, number of components is set to one.
5341 * This method allows to reduce number of reallocations on invokation of DataArrayInt::pushBackSilent and DataArrayInt::pushBackValsSilent on \a this.
5343 * \sa DataArrayInt::pack, DataArrayInt::pushBackSilent, DataArrayInt::pushBackValsSilent
5345 void DataArrayInt::reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception)
5347 int nbCompo=getNumberOfComponents();
5350 _mem.reserve(nbOfElems);
5354 _mem.reserve(nbOfElems);
5355 _info_on_compo.resize(1);
5358 throw INTERP_KERNEL::Exception("DataArrayInt::reserve : not available for DataArrayInt with number of components different than 1 !");
5362 * This method adds at the end of \a this the single value \a val. This method do \b not update its time label to avoid useless incrementation
5363 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
5365 * \param [in] val the value to be added in \a this
5366 * \throw If \a this has already been allocated with number of components different from one.
5367 * \sa DataArrayInt::pushBackValsSilent
5369 void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception)
5371 int nbCompo=getNumberOfComponents();
5376 _info_on_compo.resize(1);
5380 throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !");
5384 * This method adds at the end of \a this a serie of values [\c valsBg,\c valsEnd). This method do \b not update its time label to avoid useless incrementation
5385 * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
5387 * \param [in] valsBg - an array of values to push at the end of \this.
5388 * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
5389 * the last value of \a valsBg is \a valsEnd[ -1 ].
5390 * \throw If \a this has already been allocated with number of components different from one.
5391 * \sa DataArrayInt::pushBackSilent
5393 void DataArrayInt::pushBackValsSilent(const int *valsBg, const int *valsEnd) throw(INTERP_KERNEL::Exception)
5395 int nbCompo=getNumberOfComponents();
5397 _mem.insertAtTheEnd(valsBg,valsEnd);
5400 _info_on_compo.resize(1);
5401 _mem.insertAtTheEnd(valsBg,valsEnd);
5404 throw INTERP_KERNEL::Exception("DataArrayInt::pushBackValsSilent : not available for DataArrayInt with number of components different than 1 !");
5408 * This method returns silently ( without updating time label in \a this ) the last value, if any and suppress it.
5409 * \throw If \a this is already empty.
5410 * \throw If \a this has number of components different from one.
5412 int DataArrayInt::popBackSilent() throw(INTERP_KERNEL::Exception)
5414 if(getNumberOfComponents()==1)
5415 return _mem.popBack();
5417 throw INTERP_KERNEL::Exception("DataArrayInt::popBackSilent : not available for DataArrayInt with number of components different than 1 !");
5421 * This method \b do \b not modify content of \a this. It only modify its memory footprint if the allocated memory is to high regarding real data to store.
5423 * \sa DataArrayInt::getHeapMemorySize, DataArrayInt::reserve
5425 void DataArrayInt::pack() const throw(INTERP_KERNEL::Exception)
5431 * Allocates the raw data in memory. If exactly as same memory as needed already
5432 * allocated, it is not re-allocated.
5433 * \param [in] nbOfTuple - number of tuples of data to allocate.
5434 * \param [in] nbOfCompo - number of components of data to allocate.
5435 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
5437 void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
5441 if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
5442 alloc(nbOfTuple,nbOfCompo);
5445 alloc(nbOfTuple,nbOfCompo);
5449 * Allocates the raw data in memory. If the memory was already allocated, then it is
5450 * freed and re-allocated. See an example of this method use
5451 * \ref MEDCouplingArraySteps1WC "here".
5452 * \param [in] nbOfTuple - number of tuples of data to allocate.
5453 * \param [in] nbOfCompo - number of components of data to allocate.
5454 * \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
5456 void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
5458 if(nbOfTuple<0 || nbOfCompo<0)
5459 throw INTERP_KERNEL::Exception("DataArrayInt::alloc : request for negative length of data !");
5460 _info_on_compo.resize(nbOfCompo);
5461 _mem.alloc(nbOfCompo*(std::size_t)nbOfTuple);
5466 * Assign zero to all values in \a this array. To know more on filling arrays see
5467 * \ref MEDCouplingArrayFill.
5468 * \throw If \a this is not allocated.
5470 void DataArrayInt::fillWithZero() throw(INTERP_KERNEL::Exception)
5473 _mem.fillWithValue(0);
5478 * Assign \a val to all values in \a this array. To know more on filling arrays see
5479 * \ref MEDCouplingArrayFill.
5480 * \param [in] val - the value to fill with.
5481 * \throw If \a this is not allocated.
5483 void DataArrayInt::fillWithValue(int val) throw(INTERP_KERNEL::Exception)
5486 _mem.fillWithValue(val);
5491 * Set all values in \a this array so that the i-th element equals to \a init + i
5492 * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
5493 * \param [in] init - value to assign to the first element of array.
5494 * \throw If \a this->getNumberOfComponents() != 1
5495 * \throw If \a this is not allocated.
5497 void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception)
5500 if(getNumberOfComponents()!=1)
5501 throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
5502 int *ptr=getPointer();
5503 int ntuples=getNumberOfTuples();
5504 for(int i=0;i<ntuples;i++)
5510 * Returns a textual and human readable representation of \a this instance of
5511 * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
5512 * \return std::string - text describing \a this DataArrayInt.
5514 std::string DataArrayInt::repr() const throw(INTERP_KERNEL::Exception)
5516 std::ostringstream ret;
5521 std::string DataArrayInt::reprZip() const throw(INTERP_KERNEL::Exception)
5523 std::ostringstream ret;
5528 void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
5531 std::string idt(indent,' ');
5532 ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
5533 ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
5534 std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
5535 ofs << std::endl << idt << "</DataArray>\n";
5538 void DataArrayInt::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5540 stream << "Name of int array : \"" << _name << "\"\n";
5541 reprWithoutNameStream(stream);
5544 void DataArrayInt::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5546 stream << "Name of int array : \"" << _name << "\"\n";
5547 reprZipWithoutNameStream(stream);
5550 void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5552 DataArray::reprWithoutNameStream(stream);
5553 _mem.repr(getNumberOfComponents(),stream);
5556 void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5558 DataArray::reprWithoutNameStream(stream);
5559 _mem.reprZip(getNumberOfComponents(),stream);
5562 void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5564 int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
5565 const int *data=getConstPointer();
5566 stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl;
5567 if(nbTuples*nbComp>=1)
5569 stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
5570 std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<int>(stream,","));
5571 stream << data[nbTuples*nbComp-1] << "};" << std::endl;
5572 stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
5575 stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
5576 stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
5580 * Method that gives a quick overvien of \a this for python.
5582 void DataArrayInt::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5584 static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
5585 stream << "DataArrayInt C++ instance at " << this << ". ";
5588 int nbOfCompo=(int)_info_on_compo.size();
5591 int nbOfTuples=getNumberOfTuples();
5592 stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
5593 const int *data=begin();
5594 std::ostringstream oss2; oss2 << "[";
5595 std::string oss2Str(oss2.str());
5596 bool isFinished=true;
5597 for(int i=0;i<nbOfTuples && isFinished;i++)
5602 for(int j=0;j<nbOfCompo;j++,data++)
5605 if(j!=nbOfCompo-1) oss2 << ", ";
5611 if(i!=nbOfTuples-1) oss2 << ", ";
5612 std::string oss3Str(oss2.str());
5613 if(oss3Str.length()<MAX_NB_OF_BYTE_IN_REPR)
5624 stream << "Number of components : 0.";
5627 stream << "*** No data allocated ****";
5631 * Modifies \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
5632 * i.e. a current value is used as in index to get a new value from \a indArrBg.
5633 * \param [in] indArrBg - pointer to the first element of array of new values to assign
5635 * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
5636 * the last value of \a indArrBg is \a indArrEnd[ -1 ].
5637 * \throw If \a this->getNumberOfComponents() != 1
5638 * \throw If any value of \a this can't be used as a valid index for
5639 * [\a indArrBg, \a indArrEnd).
5641 void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception)
5644 if(getNumberOfComponents()!=1)
5645 throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
5646 int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
5647 int nbOfTuples=getNumberOfTuples();
5648 int *pt=getPointer();
5649 for(int i=0;i<nbOfTuples;i++,pt++)
5651 if(*pt>=0 && *pt<nbElemsIn)
5655 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
5656 throw INTERP_KERNEL::Exception(oss.str().c_str());
5663 * Computes distribution of values of \a this one-dimensional array between given value
5664 * ranges (casts). This method is typically useful for entity number spliting by types,
5666 * \param [in] arrBg - the array of ascending values defining the value ranges. The i-th
5667 * value of \a arrBg (\a arrBg[ i ]) gives the lowest value of the i-th range,
5668 * and the greatest value of the i-th range equals to \a arrBg[ i+1 ] - 1. \a
5669 * arrBg containing \a n values defines \a n-1 ranges. The last value of \a arrBg
5670 * should be more than every value in \a this array.
5671 * \param [in] arrEnd - specifies the end of the array \a arrBg, so that
5672 * the last value of \a arrBg is \a arrEnd[ -1 ].
5673 * \param [out] castArr - a new instance of DataArrayInt, of same size as \a this array
5674 * (same number of tuples and components), the caller is to delete
5675 * using decrRef() as it is no more needed.
5676 * This array contains indices of ranges for every value of \a this array. I.e.
5677 * the i-th value of \a castArr gives the index of range the i-th value of \a this
5678 * belongs to. Or, in other words, this parameter contains for each tuple in \a
5679 * this in which cast it holds.
5680 * \param [out] rankInsideCast - a new instance of DataArrayInt, of same size as \a this
5681 * array, the caller is to delete using decrRef() as it is no more needed.
5682 * This array contains ranks of values of \a this array within ranges
5683 * they belongs to. I.e. the i-th value of \a rankInsideCast gives the rank of
5684 * the i-th value of \a this array within the \a castArr[ i ]-th range, to which
5685 * the i-th value of \a this belongs to. Or, in other words, this param contains
5686 * for each tuple its rank inside its cast. The rank is computed as difference
5687 * between the value and the lowest value of range.
5688 * \param [out] castsPresent - a new instance of DataArrayInt, containing indices of
5689 * ranges (casts) to which at least one value of \a this array belongs.
5690 * Or, in other words, this param contains the casts that \a this contains.
5691 * The caller is to delete this array using decrRef() as it is no more needed.
5693 * \b Example: If \a this contains [6,5,0,3,2,7,8,1,4] and \a arrBg contains [0,4,9] then
5694 * the output of this method will be :
5695 * - \a castArr : [1,1,0,0,0,1,1,0,1]
5696 * - \a rankInsideCast: [2,1,0,3,2,3,4,1,0]
5697 * - \a castsPresent : [0,1]
5699 * I.e. values of \a this array belong to 2 ranges: #0 and #1. Value 6 belongs to the
5700 * range #1 and its rank within this range is 2; etc.
5702 * \throw If \a this->getNumberOfComponents() != 1.
5703 * \throw If \a arrEnd - arrBg < 2.
5704 * \throw If any value of \a this is not less than \a arrEnd[-1].
5705 * \warning The values contained in \a arrBg should be sorted ascendently. No
5706 * check of this is be done. If not, the result is not warranted.
5709 void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
5710 DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception)
5713 if(getNumberOfComponents()!=1)
5714 throw INTERP_KERNEL::Exception("Call splitByValueRange method on DataArrayInt with only one component, you can call 'rearrange' method before !");
5715 int nbOfTuples=getNumberOfTuples();
5716 std::size_t nbOfCast=std::distance(arrBg,arrEnd);
5718 throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !");
5720 const int *work=getConstPointer();
5721 typedef std::reverse_iterator<const int *> rintstart;
5722 rintstart bg(arrEnd);//OK no problem because size of 'arr' is greater or equal 2
5723 rintstart end2(arrBg);
5724 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
5725 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=DataArrayInt::New();
5726 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret3=DataArrayInt::New();
5727 ret1->alloc(nbOfTuples,1);
5728 ret2->alloc(nbOfTuples,1);
5729 int *ret1Ptr=ret1->getPointer();
5730 int *ret2Ptr=ret2->getPointer();
5731 std::set<std::size_t> castsDetected;
5732 for(int i=0;i<nbOfTuples;i++)
5734 rintstart res=std::find_if(bg,end2,std::bind2nd(std::less_equal<int>(), work[i]));
5735 std::size_t pos=std::distance(bg,res);
5736 std::size_t pos2=nbOfCast-pos;
5739 ret1Ptr[i]=(int)pos2;
5740 ret2Ptr[i]=work[i]-arrBg[pos2];
5741 castsDetected.insert(pos2);
5745 std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " whereas the last value is " << *bg;
5746 throw INTERP_KERNEL::Exception(oss.str().c_str());
5749 ret3->alloc((int)castsDetected.size(),1);
5750 std::copy(castsDetected.begin(),castsDetected.end(),ret3->getPointer());
5751 castArr=ret1.retn();
5752 rankInsideCast=ret2.retn();
5753 castsPresent=ret3.retn();
5757 * Creates a one-dimensional DataArrayInt (\a res) whose contents are computed from
5758 * values of \a this (\a a) and the given (\a indArr) arrays as follows:
5759 * \a res[ \a indArr[ \a a[ i ]]] = i. I.e. for each value in place i \a v = \a a[ i ],
5760 * new value in place \a indArr[ \a v ] is i.
5761 * \param [in] indArrBg - the array holding indices within the result array to assign
5762 * indices of values of \a this array pointing to values of \a indArrBg.
5763 * \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
5764 * the last value of \a indArrBg is \a indArrEnd[ -1 ].
5765 * \return DataArrayInt * - the new instance of DataArrayInt.
5766 * The caller is to delete this result array using decrRef() as it is no more
5768 * \throw If \a this->getNumberOfComponents() != 1.
5769 * \throw If any value of \a this array is not a valid index for \a indArrBg array.
5770 * \throw If any value of \a indArrBg is not a valid index for \a this array.
5772 DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception)
5775 if(getNumberOfComponents()!=1)
5776 throw INTERP_KERNEL::Exception("Call transformWithIndArrR method on DataArrayInt with only one component, you can call 'rearrange' method before !");
5777 int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
5778 int nbOfTuples=getNumberOfTuples();
5779 const int *pt=getConstPointer();
5780 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5781 ret->alloc(nbOfTuples,1);
5782 ret->fillWithValue(-1);
5783 int *tmp=ret->getPointer();
5784 for(int i=0;i<nbOfTuples;i++,pt++)
5786 if(*pt>=0 && *pt<nbElemsIn)
5788 int pos=indArrBg[*pt];
5789 if(pos>=0 && pos<nbOfTuples)
5793 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value of new pos is " << pos << " ( indArrBg[" << *pt << "]) ! Should be in [0," << nbOfTuples << ") !";
5794 throw INTERP_KERNEL::Exception(oss.str().c_str());
5799 std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn << " !";
5800 throw INTERP_KERNEL::Exception(oss.str().c_str());
5807 * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
5808 * from values of \a this array, which is supposed to contain a renumbering map in
5809 * "Old to New" mode. The result array contains a renumbering map in "New to Old" mode.
5810 * To know how to use the renumbering maps see \ref MEDCouplingArrayRenumbering.
5811 * \param [in] newNbOfElem - the number of tuples in the result array.
5812 * \return DataArrayInt * - the new instance of DataArrayInt.
5813 * The caller is to delete this result array using decrRef() as it is no more
5816 * \ref cpp_mcdataarrayint_invertarrayo2n2n2o "Here is a C++ example".<br>
5817 * \ref py_mcdataarrayint_invertarrayo2n2n2o "Here is a Python example".
5819 DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
5821 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5822 ret->alloc(newNbOfElem,1);
5823 int nbOfOldNodes=getNumberOfTuples();
5824 const int *old2New=getConstPointer();
5825 int *pt=ret->getPointer();
5826 for(int i=0;i!=nbOfOldNodes;i++)
5833 * This method is similar to DataArrayInt::invertArrayO2N2N2O except that
5834 * Example : If \a this contains [0,1,2,0,3,4,5,4,6,4] this method will return [0,1,2,4,5,6,8] whereas DataArrayInt::invertArrayO2N2N2O returns [3,1,2,4,9,6,8]
5836 DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception)
5838 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5839 ret->alloc(newNbOfElem,1);
5840 int nbOfOldNodes=getNumberOfTuples();
5841 const int *old2New=getConstPointer();
5842 int *pt=ret->getPointer();
5843 for(int i=nbOfOldNodes-1;i>=0;i--)
5850 * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
5851 * from values of \a this array, which is supposed to contain a renumbering map in
5852 * "New to Old" mode. The result array contains a renumbering map in "Old to New" mode.
5853 * To know how to use the renumbering maps see \ref MEDCouplingArrayRenumbering.
5854 * \param [in] newNbOfElem - the number of tuples in the result array.
5855 * \return DataArrayInt * - the new instance of DataArrayInt.
5856 * The caller is to delete this result array using decrRef() as it is no more
5859 * \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
5861 * \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
5863 DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
5866 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
5867 ret->alloc(oldNbOfElem,1);
5868 const int *new2Old=getConstPointer();
5869 int *pt=ret->getPointer();
5870 std::fill(pt,pt+oldNbOfElem,-1);
5871 int nbOfNewElems=getNumberOfTuples();
5872 for(int i=0;i<nbOfNewElems;i++)
5878 * Equivalent to DataArrayInt::isEqual except that if false the reason of
5879 * mismatch is given.
5881 * \param [in] other the instance to be compared with \a this
5882 * \param [out] reason In case of inequality returns the reason.
5883 * \sa DataArrayInt::isEqual
5885 bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception)
5887 if(!areInfoEqualsIfNotWhy(other,reason))
5889 return _mem.isEqual(other._mem,0,reason);
5893 * Checks if \a this and another DataArrayInt are fully equal. For more info see
5894 * \ref MEDCouplingArrayBasicsCompare.
5895 * \param [in] other - an instance of DataArrayInt to compare with \a this one.
5896 * \return bool - \a true if the two arrays are equal, \a false else.
5898 bool DataArrayInt::isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
5901 return isEqualIfNotWhy(other,tmp);
5905 * Checks if values of \a this and another DataArrayInt are equal. For more info see
5906 * \ref MEDCouplingArrayBasicsCompare.
5907 * \param [in] other - an instance of DataArrayInt to compare with \a this one.
5908 * \return bool - \a true if the values of two arrays are equal, \a false else.
5910 bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
5913 return _mem.isEqual(other._mem,0,tmp);
5917 * Checks if values of \a this and another DataArrayInt are equal. Comparison is
5918 * performed on sorted value sequences.
5919 * For more info see\ref MEDCouplingArrayBasicsCompare.
5920 * \param [in] other - an instance of DataArrayInt to compare with \a this one.
5921 * \return bool - \a true if the sorted values of two arrays are equal, \a false else.
5923 bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
5925 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a=deepCpy();
5926 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> b=other.deepCpy();
5929 return a->isEqualWithoutConsideringStr(*b);
5933 * Sorts values of the array.
5934 * \param [in] asc - \a true means ascending order, \a false, descending.
5935 * \throw If \a this is not allocated.
5936 * \throw If \a this->getNumberOfComponents() != 1.
5938 void DataArrayInt::sort(bool asc) throw(INTERP_KERNEL::Exception)
5941 if(getNumberOfComponents()!=1)
5942 throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !");
5948 * Reverse the array values.
5949 * \throw If \a this->getNumberOfComponents() < 1.
5950 * \throw If \a this is not allocated.
5952 void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception)
5955 _mem.reverse(getNumberOfComponents());
5960 * Checks that \a this array is consistently **increasing** or **decreasing** in value.
5961 * If not an exception is thrown.
5962 * \param [in] increasing - if \a true, the array values should be increasing.
5963 * \throw If sequence of values is not strictly monotonic in agreement with \a
5965 * \throw If \a this->getNumberOfComponents() != 1.
5966 * \throw If \a this is not allocated.
5968 void DataArrayInt::checkMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
5970 if(!isMonotonic(increasing))
5973 throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
5975 throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
5980 * Checks that \a this array is consistently **increasing** or **decreasing** in value.
5981 * \param [in] increasing - if \a true, array values should be increasing.
5982 * \return bool - \a true if values change in accordance with \a increasing arg.
5983 * \throw If \a this->getNumberOfComponents() != 1.
5984 * \throw If \a this is not allocated.
5986 bool DataArrayInt::isMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
5989 if(getNumberOfComponents()!=1)
5990 throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !");
5991 int nbOfElements=getNumberOfTuples();
5992 const int *ptr=getConstPointer();
5998 for(int i=1;i<nbOfElements;i++)
6008 for(int i=1;i<nbOfElements;i++)
6020 * This method check that array consistently INCREASING or DECREASING in value.
6022 bool DataArrayInt::isStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6025 if(getNumberOfComponents()!=1)
6026 throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !");
6027 int nbOfElements=getNumberOfTuples();
6028 const int *ptr=getConstPointer();
6034 for(int i=1;i<nbOfElements;i++)
6044 for(int i=1;i<nbOfElements;i++)
6056 * This method check that array consistently INCREASING or DECREASING in value.
6058 void DataArrayInt::checkStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6060 if(!isStrictlyMonotonic(increasing))
6063 throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
6065 throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
6070 * Creates a new one-dimensional DataArrayInt of the same size as \a this and a given
6071 * one-dimensional arrays that must be of the same length. The result array describes
6072 * correspondence between \a this and \a other arrays, so that
6073 * <em> other.getIJ(i,0) == this->getIJ(ret->getIJ(i),0)</em>. If such a permutation is
6074 * not possible because some element in \a other is not in \a this, an exception is thrown.
6075 * \param [in] other - an array to compute permutation to.
6076 * \return DataArrayInt * - a new instance of DataArrayInt, which is a permutation array
6077 * from \a this to \a other. The caller is to delete this array using decrRef() as it is
6079 * \throw If \a this->getNumberOfComponents() != 1.
6080 * \throw If \a other->getNumberOfComponents() != 1.
6081 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples().
6082 * \throw If \a other includes a value which is not in \a this array.
6084 * \ref cpp_mcdataarrayint_buildpermutationarr "Here is a C++ example".
6086 * \ref py_mcdataarrayint_buildpermutationarr "Here is a Python example".
6088 DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
6091 if(getNumberOfComponents()!=1 || other.getNumberOfComponents()!=1)
6092 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' have to have exactly ONE component !");
6093 int nbTuple=getNumberOfTuples();
6094 other.checkAllocated();
6095 if(nbTuple!=other.getNumberOfTuples())
6096 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' must have the same number of tuple !");
6097 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6098 ret->alloc(nbTuple,1);
6099 ret->fillWithValue(-1);
6100 const int *pt=getConstPointer();
6101 std::map<int,int> mm;
6102 for(int i=0;i<nbTuple;i++)
6104 pt=other.getConstPointer();
6105 int *retToFill=ret->getPointer();
6106 for(int i=0;i<nbTuple;i++)
6108 std::map<int,int>::const_iterator it=mm.find(pt[i]);
6111 std::ostringstream oss; oss << "DataArrayInt::buildPermutationArr : Arrays mismatch : element (" << pt[i] << ") in 'other' not findable in 'this' !";
6112 throw INTERP_KERNEL::Exception(oss.str().c_str());
6114 retToFill[i]=(*it).second;
6120 * Sets a C array to be used as raw data of \a this. The previously set info
6121 * of components is retained and re-sized.
6122 * For more info see \ref MEDCouplingArraySteps1.
6123 * \param [in] array - the C array to be used as raw data of \a this.
6124 * \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
6125 * \param [in] type - specifies how to deallocate \a array. If \a type == ParaMEDMEM::CPP_DEALLOC,
6126 * \c delete [] \c array; will be called. If \a type == ParaMEDMEM::C_DEALLOC,
6127 * \c free(\c array ) will be called.
6128 * \param [in] nbOfTuple - new number of tuples in \a this.
6129 * \param [in] nbOfCompo - new number of components in \a this.
6131 void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
6133 _info_on_compo.resize(nbOfCompo);
6134 _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
6138 void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
6140 _info_on_compo.resize(nbOfCompo);
6141 _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
6146 * Returns a new DataArrayInt holding the same values as \a this array but differently
6147 * arranged in memory. If \a this array holds 2 components of 3 values:
6148 * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
6149 * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
6150 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6151 * is to delete using decrRef() as it is no more needed.
6152 * \throw If \a this is not allocated.
6153 * \warning Do not confuse this method with transpose()!
6155 DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
6159 throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
6160 int *tab=_mem.fromNoInterlace(getNumberOfComponents());
6161 DataArrayInt *ret=DataArrayInt::New();
6162 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
6167 * Returns a new DataArrayInt holding the same values as \a this array but differently
6168 * arranged in memory. If \a this array holds 2 components of 3 values:
6169 * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
6170 * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
6171 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6172 * is to delete using decrRef() as it is no more needed.
6173 * \throw If \a this is not allocated.
6174 * \warning Do not confuse this method with transpose()!
6176 DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception)
6180 throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
6181 int *tab=_mem.toNoInterlace(getNumberOfComponents());
6182 DataArrayInt *ret=DataArrayInt::New();
6183 ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
6188 * Permutes values of \a this array as required by \a old2New array. The values are
6189 * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains
6190 * the same as in \this one.
6191 * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
6192 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6193 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
6194 * giving a new position for i-th old value.
6196 void DataArrayInt::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception)
6199 int nbTuples=getNumberOfTuples();
6200 int nbOfCompo=getNumberOfComponents();
6201 int *tmp=new int[nbTuples*nbOfCompo];
6202 const int *iptr=getConstPointer();
6203 for(int i=0;i<nbTuples;i++)
6204 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
6205 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
6211 * Permutes values of \a this array as required by \a new2Old array. The values are
6212 * permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of tuples remains
6213 * the same as in \this one.
6214 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6215 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
6216 * giving a previous position of i-th new value.
6217 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6218 * is to delete using decrRef() as it is no more needed.
6220 void DataArrayInt::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception)
6223 int nbTuples=getNumberOfTuples();
6224 int nbOfCompo=getNumberOfComponents();
6225 int *tmp=new int[nbTuples*nbOfCompo];
6226 const int *iptr=getConstPointer();
6227 for(int i=0;i<nbTuples;i++)
6228 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
6229 std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
6235 * Returns a copy of \a this array with values permuted as required by \a old2New array.
6236 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ].
6237 * Number of tuples in the result array remains the same as in \this one.
6238 * If a permutation reduction is needed, renumberAndReduce() should be used.
6239 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6240 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
6241 * giving a new position for i-th old value.
6242 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6243 * is to delete using decrRef() as it is no more needed.
6244 * \throw If \a this is not allocated.
6246 DataArrayInt *DataArrayInt::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception)
6249 int nbTuples=getNumberOfTuples();
6250 int nbOfCompo=getNumberOfComponents();
6251 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6252 ret->alloc(nbTuples,nbOfCompo);
6253 ret->copyStringInfoFrom(*this);
6254 const int *iptr=getConstPointer();
6255 int *optr=ret->getPointer();
6256 for(int i=0;i<nbTuples;i++)
6257 std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
6258 ret->copyStringInfoFrom(*this);
6263 * Returns a copy of \a this array with values permuted as required by \a new2Old array.
6264 * The values are permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
6265 * tuples in the result array remains the same as in \this one.
6266 * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
6267 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6268 * \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
6269 * giving a previous position of i-th new value.
6270 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6271 * is to delete using decrRef() as it is no more needed.
6273 DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception)
6276 int nbTuples=getNumberOfTuples();
6277 int nbOfCompo=getNumberOfComponents();
6278 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6279 ret->alloc(nbTuples,nbOfCompo);
6280 ret->copyStringInfoFrom(*this);
6281 const int *iptr=getConstPointer();
6282 int *optr=ret->getPointer();
6283 for(int i=0;i<nbTuples;i++)
6284 std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+nbOfCompo*i);
6285 ret->copyStringInfoFrom(*this);
6290 * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
6291 * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
6292 * The values are permuted so that \c new[ \a old2New[ i ]] = \c old[ i ] for all
6293 * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which
6294 * \a old2New[ i ] is negative, is missing from the result array.
6295 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6296 * \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
6297 * giving a new position for i-th old tuple and giving negative position for
6298 * for i-th old tuple that should be omitted.
6299 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6300 * is to delete using decrRef() as it is no more needed.
6302 DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception)
6305 int nbTuples=getNumberOfTuples();
6306 int nbOfCompo=getNumberOfComponents();
6307 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6308 ret->alloc(newNbOfTuple,nbOfCompo);
6309 const int *iptr=getConstPointer();
6310 int *optr=ret->getPointer();
6311 for(int i=0;i<nbTuples;i++)
6315 std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
6317 ret->copyStringInfoFrom(*this);
6322 * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
6323 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
6324 * \a new2OldBg array.
6325 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
6326 * This method is equivalent to renumberAndReduce() except that convention in input is
6327 * \c new2old and \b not \c old2new.
6328 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6329 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
6330 * tuple index in \a this array to fill the i-th tuple in the new array.
6331 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
6332 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
6333 * \a new2OldBg <= \a pi < \a new2OldEnd.
6334 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6335 * is to delete using decrRef() as it is no more needed.
6337 DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
6340 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6341 int nbComp=getNumberOfComponents();
6342 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
6343 ret->copyStringInfoFrom(*this);
6344 int *pt=ret->getPointer();
6345 const int *srcPt=getConstPointer();
6347 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
6348 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
6349 ret->copyStringInfoFrom(*this);
6354 * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
6355 * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
6356 * \a new2OldBg array.
6357 * The values are permuted so that \c new[ i ] = \c old[ \a new2OldBg[ i ]].
6358 * This method is equivalent to renumberAndReduce() except that convention in input is
6359 * \c new2old and \b not \c old2new.
6360 * This method is equivalent to selectByTupleId() except that it prevents coping data
6361 * from behind the end of \a this array.
6362 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6363 * \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
6364 * tuple index in \a this array to fill the i-th tuple in the new array.
6365 * \param [in] new2OldEnd - specifies the end of the permutation array that starts at
6366 * \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
6367 * \a new2OldBg <= \a pi < \a new2OldEnd.
6368 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6369 * is to delete using decrRef() as it is no more needed.
6370 * \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
6372 DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
6375 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6376 int nbComp=getNumberOfComponents();
6377 int oldNbOfTuples=getNumberOfTuples();
6378 ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
6379 ret->copyStringInfoFrom(*this);
6380 int *pt=ret->getPointer();
6381 const int *srcPt=getConstPointer();
6383 for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
6384 if(*w>=0 && *w<oldNbOfTuples)
6385 std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
6387 throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
6388 ret->copyStringInfoFrom(*this);
6393 * Returns a shorten copy of \a this array. The new DataArrayInt contains every
6394 * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
6395 * tuple. Indices of the selected tuples are the same as ones returned by the Python
6396 * command \c range( \a bg, \a end2, \a step ).
6397 * This method is equivalent to selectByTupleIdSafe() except that the input array is
6398 * not constructed explicitly.
6399 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6400 * \param [in] bg - index of the first tuple to copy from \a this array.
6401 * \param [in] end2 - index of the tuple before which the tuples to copy are located.
6402 * \param [in] step - index increment to get index of the next tuple to copy.
6403 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6404 * is to delete using decrRef() as it is no more needed.
6405 * \throw If (\a end2 < \a bg) or (\a step <= 0).
6406 * \sa DataArrayInt::substr.
6408 DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
6411 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6412 int nbComp=getNumberOfComponents();
6413 int newNbOfTuples=GetNumberOfItemGivenBES(bg,end2,step,"DataArrayInt::selectByTupleId2 : ");
6414 ret->alloc(newNbOfTuples,nbComp);
6415 int *pt=ret->getPointer();
6416 const int *srcPt=getConstPointer()+bg*nbComp;
6417 for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
6418 std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
6419 ret->copyStringInfoFrom(*this);
6424 * Returns a shorten copy of \a this array. The new DataArrayInt contains ranges
6425 * of tuples specified by \a ranges parameter.
6426 * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6427 * \param [in] ranges - std::vector of std::pair's each of which defines a range
6428 * of tuples in [\c begin,\c end) format.
6429 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6430 * is to delete using decrRef() as it is no more needed.
6431 * \throw If \a end < \a begin.
6432 * \throw If \a end > \a this->getNumberOfTuples().
6433 * \throw If \a this is not allocated.
6435 DataArrayInt *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
6438 int nbOfComp=getNumberOfComponents();
6439 int nbOfTuplesThis=getNumberOfTuples();
6442 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6443 ret->alloc(0,nbOfComp);
6444 ret->copyStringInfoFrom(*this);
6447 int ref=ranges.front().first;
6449 bool isIncreasing=true;
6450 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
6452 if((*it).first<=(*it).second)
6454 if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
6456 nbOfTuples+=(*it).second-(*it).first;
6458 isIncreasing=ref<=(*it).first;
6463 std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
6464 oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
6465 throw INTERP_KERNEL::Exception(oss.str().c_str());
6470 std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
6471 oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
6472 throw INTERP_KERNEL::Exception(oss.str().c_str());
6475 if(isIncreasing && nbOfTuplesThis==nbOfTuples)
6477 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6478 ret->alloc(nbOfTuples,nbOfComp);
6479 ret->copyStringInfoFrom(*this);
6480 const int *src=getConstPointer();
6481 int *work=ret->getPointer();
6482 for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
6483 work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
6488 * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode.
6489 * This map, if applied to \a this array, would make it sorted. For example, if
6490 * \a this array contents are [9,10,0,6,4,11,3,7] then the contents of the result array
6491 * are [5,6,0,3,2,7,1,4]; if this result array (\a res) is used as an argument in call
6492 * \a this->renumber(\a res) then the returned array contains [0,3,4,6,7,9,10,11].
6493 * This method is useful for renumbering (in MED file for example). For more info
6494 * on renumbering see \ref MEDCouplingArrayRenumbering.
6495 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
6496 * array using decrRef() as it is no more needed.
6497 * \throw If \a this is not allocated.
6498 * \throw If \a this->getNumberOfComponents() != 1.
6499 * \throw If there are equal values in \a this array.
6501 DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception)
6504 if(getNumberOfComponents()!=1)
6505 throw INTERP_KERNEL::Exception("DataArrayInt::checkAndPreparePermutation : number of components must == 1 !");
6506 int nbTuples=getNumberOfTuples();
6507 const int *pt=getConstPointer();
6508 int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
6509 DataArrayInt *ret=DataArrayInt::New();
6510 ret->useArray(pt2,true,CPP_DEALLOC,nbTuples,1);
6515 * Returns two arrays describing a surjective mapping from \a this set of values (\a A)
6516 * onto a set of values of size \a targetNb (\a B). The surjective function is
6517 * \a B[ \a A[ i ]] = i. That is to say that for each \a id in [0,\a targetNb), where \a
6518 * targetNb < \a this->getNumberOfTuples(), there exists at least one tupleId (\a tid) so
6519 * that <em> this->getIJ( tid, 0 ) == id</em>. <br>
6520 * The first of out arrays returns indices of elements of \a this array, grouped by their
6521 * place in the set \a B. The second out array is the index of the first one; it shows how
6522 * many elements of \a A are mapped into each element of \a B. <br>
6524 * mapping and its usage in renumbering see \ref MEDCouplingArrayRenumbering. <br>
6526 * - \a this: [0,3,2,3,2,2,1,2]
6528 * - \a arr: [0, 6, 2,4,5,7, 1,3]
6529 * - \a arrI: [0,1,2,6,8]
6531 * This result means: <br>
6532 * the element of \a B 0 encounters within \a A once (\a arrI[ 0+1 ] - \a arrI[ 0 ]) and
6533 * its index within \a A is 0 ( \a arr[ 0:1 ] == \a arr[ \a arrI[ 0 ] : \a arrI[ 0+1 ]]);<br>
6534 * the element of \a B 2 encounters within \a A 4 times (\a arrI[ 2+1 ] - \a arrI[ 2 ]) and
6535 * its indices within \a A are [2,4,5,7] ( \a arr[ 2:6 ] == \a arr[ \a arrI[ 2 ] :
6536 * \a arrI[ 2+1 ]]); <br> etc.
6537 * \param [in] targetNb - the size of the set \a B. \a targetNb must be equal or more
6538 * than the maximal value of \a A.
6539 * \param [out] arr - a new instance of DataArrayInt returning indices of
6540 * elements of \a this, grouped by their place in the set \a B. The caller is to delete
6541 * this array using decrRef() as it is no more needed.
6542 * \param [out] arrI - a new instance of DataArrayInt returning size of groups of equal
6543 * elements of \a this. The caller is to delete this array using decrRef() as it
6544 * is no more needed.
6545 * \throw If \a this is not allocated.
6546 * \throw If \a this->getNumberOfComponents() != 1.
6547 * \throw If any value in \a this is more or equal to \a targetNb.
6549 void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception)
6552 if(getNumberOfComponents()!=1)
6553 throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : number of components must == 1 !");
6554 int nbOfTuples=getNumberOfTuples();
6555 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
6556 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retI(DataArrayInt::New());
6557 retI->alloc(targetNb+1,1);
6558 const int *input=getConstPointer();
6559 std::vector< std::vector<int> > tmp(targetNb);
6560 for(int i=0;i<nbOfTuples;i++)
6563 if(tmp2>=0 && tmp2<targetNb)
6564 tmp[tmp2].push_back(i);
6567 std::ostringstream oss; oss << "DataArrayInt::changeSurjectiveFormat : At pos " << i << " presence of element " << tmp2 << " ! should be in [0," << targetNb << ") !";
6568 throw INTERP_KERNEL::Exception(oss.str().c_str());
6571 int *retIPtr=retI->getPointer();
6573 for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++,retIPtr++)
6574 retIPtr[1]=retIPtr[0]+(int)((*it1).size());
6575 if(nbOfTuples!=retI->getIJ(targetNb,0))
6576 throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : big problem should never happen !");
6577 ret->alloc(nbOfTuples,1);
6578 int *retPtr=ret->getPointer();
6579 for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++)
6580 retPtr=std::copy((*it1).begin(),(*it1).end(),retPtr);
6587 * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode computed
6588 * from a zip representation of a surjective format (returned e.g. by
6589 * \ref ParaMEDMEM::DataArrayDouble::findCommonTuples() "DataArrayDouble::findCommonTuples()"
6590 * for example). The result array minimizes the permutation. <br>
6591 * For more info on renumbering see \ref MEDCouplingArrayRenumbering. <br>
6593 * - \a nbOfOldTuples: 10
6594 * - \a arr : [0,3, 5,7,9]
6595 * - \a arrIBg : [0,2,5]
6596 * - \a newNbOfTuples: 7
6597 * - result array : [0,1,2,0,3,4,5,4,6,4]
6599 * \param [in] nbOfOldTuples - number of tuples in the initial array \a arr.
6600 * \param [in] arr - the array of tuple indices grouped by \a arrIBg array.
6601 * \param [in] arrIBg - the array dividing all indices stored in \a arr into groups of
6602 * (indices of) equal values. Its every element (except the last one) points to
6603 * the first element of a group of equal values.
6604 * \param [in] arrIEnd - specifies the end of \a arrIBg, so that the last element of \a
6605 * arrIBg is \a arrIEnd[ -1 ].
6606 * \param [out] newNbOfTuples - number of tuples after surjection application.
6607 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
6608 * array using decrRef() as it is no more needed.
6609 * \throw If any value of \a arr breaks condition ( 0 <= \a arr[ i ] < \a nbOfOldTuples ).
6611 DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
6613 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6614 ret->alloc(nbOfOldTuples,1);
6615 int *pt=ret->getPointer();
6616 std::fill(pt,pt+nbOfOldTuples,-1);
6617 int nbOfGrps=((int)std::distance(arrIBg,arrIEnd))-1;
6618 const int *cIPtr=arrIBg;
6619 for(int i=0;i<nbOfGrps;i++)
6620 pt[arr[cIPtr[i]]]=-(i+2);
6622 for(int iNode=0;iNode<nbOfOldTuples;iNode++)
6630 int grpId=-(pt[iNode]+2);
6631 for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
6633 if(arr[j]>=0 && arr[j]<nbOfOldTuples)
6637 std::ostringstream oss; oss << "DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : With element #" << j << " value is " << arr[j] << " should be in [0," << nbOfOldTuples << ") !";
6638 throw INTERP_KERNEL::Exception(oss.str().c_str());
6645 newNbOfTuples=newNb;
6650 * Returns a new DataArrayInt containing a renumbering map in "New to Old" mode,
6651 * which if applied to \a this array would make it sorted ascendingly.
6652 * For more info on renumbering see \ref MEDCouplingArrayRenumbering. <br>
6654 * - \a this: [2,0,1,1,0,1,2,0,1,1,0,0]
6655 * - result: [10,0,5,6,1,7,11,2,8,9,3,4]
6656 * - after applying result to \a this: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2]
6658 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
6659 * array using decrRef() as it is no more needed.
6660 * \throw If \a this is not allocated.
6661 * \throw If \a this->getNumberOfComponents() != 1.
6663 DataArrayInt *DataArrayInt::buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception)
6666 if(getNumberOfComponents()!=1)
6667 throw INTERP_KERNEL::Exception("DataArrayInt::buildPermArrPerLevel : number of components must == 1 !");
6668 int nbOfTuples=getNumberOfTuples();
6669 const int *pt=getConstPointer();
6670 std::map<int,int> m;
6671 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6672 ret->alloc(nbOfTuples,1);
6673 int *opt=ret->getPointer();
6674 for(int i=0;i<nbOfTuples;i++,pt++,opt++)
6677 std::map<int,int>::iterator it=m.find(val);
6686 m.insert(std::pair<int,int>(val,1));
6690 for(std::map<int,int>::iterator it=m.begin();it!=m.end();it++)
6692 int vt=(*it).second;
6696 pt=getConstPointer();
6697 opt=ret->getPointer();
6698 for(int i=0;i<nbOfTuples;i++,pt++,opt++)
6705 * Checks if contents of \a this array are equal to that of an array filled with
6706 * iota(). This method is particularly useful for DataArrayInt instances that represent
6707 * a renumbering array to check the real need in renumbering.
6708 * \return bool - \a true if \a this array contents == \a range( \a this->getNumberOfTuples())
6709 * \throw If \a this is not allocated.
6710 * \throw If \a this->getNumberOfComponents() != 1.
6712 bool DataArrayInt::isIdentity() const throw(INTERP_KERNEL::Exception)
6715 if(getNumberOfComponents()!=1)
6717 int nbOfTuples=getNumberOfTuples();
6718 const int *pt=getConstPointer();
6719 for(int i=0;i<nbOfTuples;i++,pt++)
6726 * Checks if all values in \a this array are equal to \a val.
6727 * \param [in] val - value to check equality of array values to.
6728 * \return bool - \a true if all values are \a val.
6729 * \throw If \a this is not allocated.
6730 * \throw If \a this->getNumberOfComponents() != 1
6732 bool DataArrayInt::isUniform(int val) const throw(INTERP_KERNEL::Exception)
6735 if(getNumberOfComponents()!=1)
6736 throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
6737 int nbOfTuples=getNumberOfTuples();
6738 const int *w=getConstPointer();
6739 const int *end2=w+nbOfTuples;
6747 * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
6748 * array to the new one.
6749 * \return DataArrayDouble * - the new instance of DataArrayInt.
6751 DataArrayDouble *DataArrayInt::convertToDblArr() const
6754 DataArrayDouble *ret=DataArrayDouble::New();
6755 ret->alloc(getNumberOfTuples(),getNumberOfComponents());
6756 std::size_t nbOfVals=getNbOfElems();
6757 const int *src=getConstPointer();
6758 double *dest=ret->getPointer();
6759 std::copy(src,src+nbOfVals,dest);
6760 ret->copyStringInfoFrom(*this);
6765 * Returns a shorten copy of \a this array. The new DataArrayInt contains all
6766 * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
6767 * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
6768 * This method is a specialization of selectByTupleId2().
6769 * \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
6770 * \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
6771 * If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
6772 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6773 * is to delete using decrRef() as it is no more needed.
6774 * \throw If \a tupleIdBg < 0.
6775 * \throw If \a tupleIdBg > \a this->getNumberOfTuples().
6776 \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
6777 * \sa DataArrayInt::selectByTupleId2
6779 DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
6782 int nbt=getNumberOfTuples();
6784 throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
6786 throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
6787 int trueEnd=tupleIdEnd;
6791 throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
6795 int nbComp=getNumberOfComponents();
6796 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6797 ret->alloc(trueEnd-tupleIdBg,nbComp);
6798 ret->copyStringInfoFrom(*this);
6799 std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
6804 * Changes the number of components within \a this array so that its raw data **does
6805 * not** change, instead splitting this data into tuples changes.
6806 * \param [in] newNbOfComp - number of components for \a this array to have.
6807 * \throw If \a this is not allocated
6808 * \throw If getNbOfElems() % \a newNbOfCompo != 0.
6809 * \throw If \a newNbOfCompo is lower than 1.
6810 * \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
6811 * \warning This method erases all (name and unit) component info set before!
6813 void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
6817 throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : input newNbOfCompo must be > 0 !");
6818 std::size_t nbOfElems=getNbOfElems();
6819 if(nbOfElems%newNbOfCompo!=0)
6820 throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
6821 if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
6822 throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !");
6823 _info_on_compo.clear();
6824 _info_on_compo.resize(newNbOfCompo);
6829 * Changes the number of components within \a this array to be equal to its number
6830 * of tuples, and inversely its number of tuples to become equal to its number of
6831 * components. So that its raw data **does not** change, instead splitting this
6832 * data into tuples changes.
6833 * \throw If \a this is not allocated.
6834 * \warning This method erases all (name and unit) component info set before!
6835 * \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
6838 void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception)
6841 int nbOfTuples=getNumberOfTuples();
6842 rearrange(nbOfTuples);
6846 * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
6847 * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
6848 * is truncated to have \a newNbOfComp components, keeping first components. If \a
6849 * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
6850 * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
6852 * \param [in] newNbOfComp - number of components for the new array to have.
6853 * \param [in] dftValue - value assigned to new values added to the new array.
6854 * \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
6855 * is to delete using decrRef() as it is no more needed.
6856 * \throw If \a this is not allocated.
6858 DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception)
6861 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6862 ret->alloc(getNumberOfTuples(),newNbOfComp);
6863 const int *oldc=getConstPointer();
6864 int *nc=ret->getPointer();
6865 int nbOfTuples=getNumberOfTuples();
6866 int oldNbOfComp=getNumberOfComponents();
6867 int dim=std::min(oldNbOfComp,newNbOfComp);
6868 for(int i=0;i<nbOfTuples;i++)
6872 nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
6873 for(;j<newNbOfComp;j++)
6874 nc[newNbOfComp*i+j]=dftValue;
6876 ret->setName(getName().c_str());
6877 for(int i=0;i<dim;i++)
6878 ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
6879 ret->setName(getName().c_str());
6884 * Changes number of tuples in the array. If the new number of tuples is smaller
6885 * than the current number the array is truncated, otherwise the array is extended.
6886 * \param [in] nbOfTuples - new number of tuples.
6887 * \throw If \a this is not allocated.
6889 void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
6892 _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
6898 * Returns a copy of \a this array composed of selected components.
6899 * The new DataArrayInt has the same number of tuples but includes components
6900 * specified by \a compoIds parameter. So that getNbOfElems() of the result array
6901 * can be either less, same or more than \a this->getNbOfElems().
6902 * \param [in] compoIds - sequence of zero based indices of components to include
6903 * into the new array.
6904 * \return DataArrayInt * - the new instance of DataArrayInt that the caller
6905 * is to delete using decrRef() as it is no more needed.
6906 * \throw If \a this is not allocated.
6907 * \throw If a component index (\a i) is not valid:
6908 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
6910 * \ref cpp_mcdataarrayint_keepselectedcomponents "Here is a Python example".
6912 DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
6915 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
6916 int newNbOfCompo=(int)compoIds.size();
6917 int oldNbOfCompo=getNumberOfComponents();
6918 for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
6919 DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
6920 int nbOfTuples=getNumberOfTuples();
6921 ret->alloc(nbOfTuples,newNbOfCompo);
6922 ret->copyPartOfStringInfoFrom(*this,compoIds);
6923 const int *oldc=getConstPointer();
6924 int *nc=ret->getPointer();
6925 for(int i=0;i<nbOfTuples;i++)
6926 for(int j=0;j<newNbOfCompo;j++,nc++)
6927 *nc=oldc[i*oldNbOfCompo+compoIds[j]];
6932 * Appends components of another array to components of \a this one, tuple by tuple.
6933 * So that the number of tuples of \a this array remains the same and the number of
6934 * components increases.
6935 * \param [in] other - the DataArrayInt to append to \a this one.
6936 * \throw If \a this is not allocated.
6937 * \throw If \a this and \a other arrays have different number of tuples.
6939 * \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
6941 * \ref py_mcdataarrayint_meldwith "Here is a Python example".
6943 void DataArrayInt::meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
6946 throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
6948 other->checkAllocated();
6949 int nbOfTuples=getNumberOfTuples();
6950 if(nbOfTuples!=other->getNumberOfTuples())
6951 throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
6952 int nbOfComp1=getNumberOfComponents();
6953 int nbOfComp2=other->getNumberOfComponents();
6954 int *newArr=new int[nbOfTuples*(nbOfComp1+nbOfComp2)];
6956 const int *inp1=getConstPointer();
6957 const int *inp2=other->getConstPointer();
6958 for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
6960 w=std::copy(inp1,inp1+nbOfComp1,w);
6961 w=std::copy(inp2,inp2+nbOfComp2,w);
6963 useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
6964 std::vector<int> compIds(nbOfComp2);
6965 for(int i=0;i<nbOfComp2;i++)
6966 compIds[i]=nbOfComp1+i;
6967 copyPartOfStringInfoFrom2(compIds,*other);
6971 * Copy all components in a specified order from another DataArrayInt.
6972 * The specified components become the first ones in \a this array.
6973 * Both numerical and textual data is copied. The number of tuples in \a this and
6974 * the other array can be different.
6975 * \param [in] a - the array to copy data from.
6976 * \param [in] compoIds - sequence of zero based indices of components, data of which is
6978 * \throw If \a a is NULL.
6979 * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
6980 * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
6982 * \ref cpp_mcdataarrayint_setselectedcomponents "Here is a Python example".
6984 void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
6987 throw INTERP_KERNEL::Exception("DataArrayInt::setSelectedComponents : input DataArrayInt is NULL !");
6989 a->checkAllocated();
6990 copyPartOfStringInfoFrom2(compoIds,*a);
6991 std::size_t partOfCompoSz=compoIds.size();
6992 int nbOfCompo=getNumberOfComponents();
6993 int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
6994 const int *ac=a->getConstPointer();
6995 int *nc=getPointer();
6996 for(int i=0;i<nbOfTuples;i++)
6997 for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
6998 nc[nbOfCompo*i+compoIds[j]]=*ac;
7002 * Copy all values from another DataArrayInt into specified tuples and components
7003 * of \a this array. Textual data is not copied.
7004 * The tree parameters defining set of indices of tuples and components are similar to
7005 * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
7006 * \param [in] a - the array to copy values from.
7007 * \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
7008 * \param [in] endTuples - index of the tuple before which the tuples to assign to
7010 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
7011 * \param [in] bgComp - index of the first component of \a this array to assign values to.
7012 * \param [in] endComp - index of the component before which the components to assign
7014 * \param [in] stepComp - index increment to get index of the next component to assign to.
7015 * \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents()
7016 * must be equal to the number of columns to assign to, else an
7017 * exception is thrown; if \a false, then it is only required that \a
7018 * a->getNbOfElems() equals to number of values to assign to (this condition
7019 * must be respected even if \a strictCompoCompare is \a true). The number of
7020 * values to assign to is given by following Python expression:
7021 * \a nbTargetValues =
7022 * \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
7023 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
7024 * \throw If \a a is NULL.
7025 * \throw If \a a is not allocated.
7026 * \throw If \a this is not allocated.
7027 * \throw If parameters specifying tuples and components to assign to do not give a
7028 * non-empty range of increasing indices.
7029 * \throw If \a a->getNbOfElems() != \a nbTargetValues.
7030 * \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
7031 * \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
7033 * \ref cpp_mcdataarrayint_setpartofvalues1 "Here is a Python example".
7035 void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7038 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues1 : DataArrayInt pointer in input is NULL !");
7039 const char msg[]="DataArrayInt::setPartOfValues1";
7041 a->checkAllocated();
7042 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7043 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7044 int nbComp=getNumberOfComponents();
7045 int nbOfTuples=getNumberOfTuples();
7046 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7047 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7048 bool assignTech=true;
7049 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7051 if(strictCompoCompare)
7052 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7056 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7059 int *pt=getPointer()+bgTuples*nbComp+bgComp;
7060 const int *srcPt=a->getConstPointer();
7063 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7064 for(int j=0;j<newNbOfComp;j++,srcPt++)
7065 pt[j*stepComp]=*srcPt;
7069 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7071 const int *srcPt2=srcPt;
7072 for(int j=0;j<newNbOfComp;j++,srcPt2++)
7073 pt[j*stepComp]=*srcPt2;
7079 * Assign a given value to values at specified tuples and components of \a this array.
7080 * The tree parameters defining set of indices of tuples and components are similar to
7081 * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
7082 * \param [in] a - the value to assign.
7083 * \param [in] bgTuples - index of the first tuple of \a this array to assign to.
7084 * \param [in] endTuples - index of the tuple before which the tuples to assign to
7086 * \param [in] stepTuples - index increment to get index of the next tuple to assign to.
7087 * \param [in] bgComp - index of the first component of \a this array to assign to.
7088 * \param [in] endComp - index of the component before which the components to assign
7090 * \param [in] stepComp - index increment to get index of the next component to assign to.
7091 * \throw If \a this is not allocated.
7092 * \throw If parameters specifying tuples and components to assign to, do not give a
7093 * non-empty range of increasing indices or indices are out of a valid range
7096 * \ref cpp_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
7098 void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
7100 const char msg[]="DataArrayInt::setPartOfValuesSimple1";
7102 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7103 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7104 int nbComp=getNumberOfComponents();
7105 int nbOfTuples=getNumberOfTuples();
7106 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7107 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7108 int *pt=getPointer()+bgTuples*nbComp+bgComp;
7109 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7110 for(int j=0;j<newNbOfComp;j++)
7116 * Copy all values from another DataArrayInt (\a a) into specified tuples and
7117 * components of \a this array. Textual data is not copied.
7118 * The tuples and components to assign to are defined by C arrays of indices.
7119 * There are two *modes of usage*:
7120 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
7121 * of \a a is assigned to its own location within \a this array.
7122 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
7123 * components of every specified tuple of \a this array. In this mode it is required
7124 * that \a a->getNumberOfComponents() equals to the number of specified components.
7126 * \param [in] a - the array to copy values from.
7127 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7128 * assign values of \a a to.
7129 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7130 * pointer to a tuple index <em>(pi)</em> varies as this:
7131 * \a bgTuples <= \a pi < \a endTuples.
7132 * \param [in] bgComp - pointer to an array of component indices of \a this array to
7133 * assign values of \a a to.
7134 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
7135 * pointer to a component index <em>(pi)</em> varies as this:
7136 * \a bgComp <= \a pi < \a endComp.
7137 * \param [in] strictCompoCompare - this parameter is checked only if the
7138 * *mode of usage* is the first; if it is \a true (default),
7139 * then \a a->getNumberOfComponents() must be equal
7140 * to the number of specified columns, else this is not required.
7141 * \throw If \a a is NULL.
7142 * \throw If \a a is not allocated.
7143 * \throw If \a this is not allocated.
7144 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
7145 * out of a valid range for \a this array.
7146 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
7147 * if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
7148 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
7149 * <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
7151 * \ref cpp_mcdataarrayint_setpartofvalues2 "Here is a Python example".
7153 void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7156 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues2 : DataArrayInt pointer in input is NULL !");
7157 const char msg[]="DataArrayInt::setPartOfValues2";
7159 a->checkAllocated();
7160 int nbComp=getNumberOfComponents();
7161 int nbOfTuples=getNumberOfTuples();
7162 for(const int *z=bgComp;z!=endComp;z++)
7163 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7164 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
7165 int newNbOfComp=(int)std::distance(bgComp,endComp);
7166 bool assignTech=true;
7167 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7169 if(strictCompoCompare)
7170 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7174 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7177 int *pt=getPointer();
7178 const int *srcPt=a->getConstPointer();
7181 for(const int *w=bgTuples;w!=endTuples;w++)
7183 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7184 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
7186 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
7192 for(const int *w=bgTuples;w!=endTuples;w++)
7194 const int *srcPt2=srcPt;
7195 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7196 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
7198 pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
7205 * Assign a given value to values at specified tuples and components of \a this array.
7206 * The tuples and components to assign to are defined by C arrays of indices.
7207 * \param [in] a - the value to assign.
7208 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7210 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7211 * pointer to a tuple index (\a pi) varies as this:
7212 * \a bgTuples <= \a pi < \a endTuples.
7213 * \param [in] bgComp - pointer to an array of component indices of \a this array to
7215 * \param [in] endComp - specifies the end of the array \a bgTuples, so that
7216 * pointer to a component index (\a pi) varies as this:
7217 * \a bgComp <= \a pi < \a endComp.
7218 * \throw If \a this is not allocated.
7219 * \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
7220 * out of a valid range for \a this array.
7222 * \ref cpp_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
7224 void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
7227 int nbComp=getNumberOfComponents();
7228 int nbOfTuples=getNumberOfTuples();
7229 for(const int *z=bgComp;z!=endComp;z++)
7230 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7231 int *pt=getPointer();
7232 for(const int *w=bgTuples;w!=endTuples;w++)
7233 for(const int *z=bgComp;z!=endComp;z++)
7235 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7236 pt[(std::size_t)(*w)*nbComp+(*z)]=a;
7241 * Copy all values from another DataArrayInt (\a a) into specified tuples and
7242 * components of \a this array. Textual data is not copied.
7243 * The tuples to assign to are defined by a C array of indices.
7244 * The components to assign to are defined by three values similar to parameters of
7245 * the Python function \c range(\c start,\c stop,\c step).
7246 * There are two *modes of usage*:
7247 * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
7248 * of \a a is assigned to its own location within \a this array.
7249 * - If \a a includes one tuple, then all values of \a a are assigned to the specified
7250 * components of every specified tuple of \a this array. In this mode it is required
7251 * that \a a->getNumberOfComponents() equals to the number of specified components.
7253 * \param [in] a - the array to copy values from.
7254 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7255 * assign values of \a a to.
7256 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7257 * pointer to a tuple index <em>(pi)</em> varies as this:
7258 * \a bgTuples <= \a pi < \a endTuples.
7259 * \param [in] bgComp - index of the first component of \a this array to assign to.
7260 * \param [in] endComp - index of the component before which the components to assign
7262 * \param [in] stepComp - index increment to get index of the next component to assign to.
7263 * \param [in] strictCompoCompare - this parameter is checked only in the first
7264 * *mode of usage*; if \a strictCompoCompare is \a true (default),
7265 * then \a a->getNumberOfComponents() must be equal
7266 * to the number of specified columns, else this is not required.
7267 * \throw If \a a is NULL.
7268 * \throw If \a a is not allocated.
7269 * \throw If \a this is not allocated.
7270 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
7272 * \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
7273 * if <em> a->getNumberOfComponents()</em> is unequal to the number of components
7274 * defined by <em>(bgComp,endComp,stepComp)</em>.
7275 * \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
7276 * <em> a->getNumberOfComponents()</em> is unequal to the number of components
7277 * defined by <em>(bgComp,endComp,stepComp)</em>.
7278 * \throw If parameters specifying components to assign to, do not give a
7279 * non-empty range of increasing indices or indices are out of a valid range
7282 * \ref cpp_mcdataarrayint_setpartofvalues3 "Here is a Python example".
7284 void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7287 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues3 : DataArrayInt pointer in input is NULL !");
7288 const char msg[]="DataArrayInt::setPartOfValues3";
7290 a->checkAllocated();
7291 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7292 int nbComp=getNumberOfComponents();
7293 int nbOfTuples=getNumberOfTuples();
7294 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7295 int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
7296 bool assignTech=true;
7297 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7299 if(strictCompoCompare)
7300 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7304 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7307 int *pt=getPointer()+bgComp;
7308 const int *srcPt=a->getConstPointer();
7311 for(const int *w=bgTuples;w!=endTuples;w++)
7312 for(int j=0;j<newNbOfComp;j++,srcPt++)
7314 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7315 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
7320 for(const int *w=bgTuples;w!=endTuples;w++)
7322 const int *srcPt2=srcPt;
7323 for(int j=0;j<newNbOfComp;j++,srcPt2++)
7325 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7326 pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
7333 * Assign a given value to values at specified tuples and components of \a this array.
7334 * The tuples to assign to are defined by a C array of indices.
7335 * The components to assign to are defined by three values similar to parameters of
7336 * the Python function \c range(\c start,\c stop,\c step).
7337 * \param [in] a - the value to assign.
7338 * \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7340 * \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7341 * pointer to a tuple index <em>(pi)</em> varies as this:
7342 * \a bgTuples <= \a pi < \a endTuples.
7343 * \param [in] bgComp - index of the first component of \a this array to assign to.
7344 * \param [in] endComp - index of the component before which the components to assign
7346 * \param [in] stepComp - index increment to get index of the next component to assign to.
7347 * \throw If \a this is not allocated.
7348 * \throw If any index of tuple given by \a bgTuples is out of a valid range for
7350 * \throw If parameters specifying components to assign to, do not give a
7351 * non-empty range of increasing indices or indices are out of a valid range
7354 * \ref cpp_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
7356 void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
7358 const char msg[]="DataArrayInt::setPartOfValuesSimple3";
7360 int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7361 int nbComp=getNumberOfComponents();
7362 int nbOfTuples=getNumberOfTuples();
7363 DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7364 int *pt=getPointer()+bgComp;
7365 for(const int *w=bgTuples;w!=endTuples;w++)
7366 for(int j=0;j<newNbOfComp;j++)
7368 DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7369 pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
7373 void DataArrayInt::setPartOfValues4(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7376 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues4 : input DataArrayInt is NULL !");
7377 const char msg[]="DataArrayInt::setPartOfValues4";
7379 a->checkAllocated();
7380 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7381 int newNbOfComp=(int)std::distance(bgComp,endComp);
7382 int nbComp=getNumberOfComponents();
7383 for(const int *z=bgComp;z!=endComp;z++)
7384 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7385 int nbOfTuples=getNumberOfTuples();
7386 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7387 bool assignTech=true;
7388 if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7390 if(strictCompoCompare)
7391 a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7395 a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7398 const int *srcPt=a->getConstPointer();
7399 int *pt=getPointer()+bgTuples*nbComp;
7402 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7403 for(const int *z=bgComp;z!=endComp;z++,srcPt++)
7408 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7410 const int *srcPt2=srcPt;
7411 for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
7417 void DataArrayInt::setPartOfValuesSimple4(int a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
7419 const char msg[]="DataArrayInt::setPartOfValuesSimple4";
7421 int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7422 int nbComp=getNumberOfComponents();
7423 for(const int *z=bgComp;z!=endComp;z++)
7424 DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7425 int nbOfTuples=getNumberOfTuples();
7426 DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7427 int *pt=getPointer()+bgTuples*nbComp;
7428 for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7429 for(const int *z=bgComp;z!=endComp;z++)
7434 * Copy some tuples from another DataArrayInt into specified tuples
7435 * of \a this array. Textual data is not copied. Both arrays must have equal number of
7437 * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
7438 * All components of selected tuples are copied.
7439 * \param [in] a - the array to copy values from.
7440 * \param [in] tuplesSelec - the array specifying both source tuples of \a a and
7441 * target tuples of \a this. \a tuplesSelec has two components, and the
7442 * first component specifies index of the source tuple and the second
7443 * one specifies index of the target tuple.
7444 * \throw If \a this is not allocated.
7445 * \throw If \a a is NULL.
7446 * \throw If \a a is not allocated.
7447 * \throw If \a tuplesSelec is NULL.
7448 * \throw If \a tuplesSelec is not allocated.
7449 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
7450 * \throw If \a tuplesSelec->getNumberOfComponents() != 2.
7451 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
7452 * the corresponding (\a this or \a a) array.
7454 void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
7456 if(!a || !tuplesSelec)
7457 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : DataArrayInt pointer in input is NULL !");
7459 a->checkAllocated();
7460 tuplesSelec->checkAllocated();
7461 int nbOfComp=getNumberOfComponents();
7462 if(nbOfComp!=a->getNumberOfComponents())
7463 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : This and a do not have the same number of components !");
7464 if(tuplesSelec->getNumberOfComponents()!=2)
7465 throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
7466 int thisNt=getNumberOfTuples();
7467 int aNt=a->getNumberOfTuples();
7468 int *valsToSet=getPointer();
7469 const int *valsSrc=a->getConstPointer();
7470 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
7472 if(tuple[1]>=0 && tuple[1]<aNt)
7474 if(tuple[0]>=0 && tuple[0]<thisNt)
7475 std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
7478 std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
7479 oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
7480 throw INTERP_KERNEL::Exception(oss.str().c_str());
7485 std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
7486 oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
7487 throw INTERP_KERNEL::Exception(oss.str().c_str());
7493 * Copy some tuples from another DataArrayInt (\a a) into contiguous tuples
7494 * of \a this array. Textual data is not copied. Both arrays must have equal number of
7496 * The tuples to assign to are defined by index of the first tuple, and
7497 * their number is defined by \a tuplesSelec->getNumberOfTuples().
7498 * The tuples to copy are defined by values of a DataArrayInt.
7499 * All components of selected tuples are copied.
7500 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
7502 * \param [in] a - the array to copy values from.
7503 * \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
7504 * \throw If \a this is not allocated.
7505 * \throw If \a a is NULL.
7506 * \throw If \a a is not allocated.
7507 * \throw If \a tuplesSelec is NULL.
7508 * \throw If \a tuplesSelec is not allocated.
7509 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
7510 * \throw If \a tuplesSelec->getNumberOfComponents() != 1.
7511 * \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
7512 * \throw If any tuple index given by \a tuplesSelec is out of a valid range for
7515 void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
7518 a->checkAllocated();
7519 tuplesSelec->checkAllocated();
7520 int nbOfComp=getNumberOfComponents();
7521 if(nbOfComp!=a->getNumberOfComponents())
7522 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : This and a do not have the same number of components !");
7523 if(tuplesSelec->getNumberOfComponents()!=1)
7524 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
7525 int thisNt=getNumberOfTuples();
7526 int aNt=a->getNumberOfTuples();
7527 int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
7528 int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
7529 if(tupleIdStart+nbOfTupleToWrite>thisNt)
7530 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : invalid number range of values to write !");
7531 const int *valsSrc=a->getConstPointer();
7532 for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
7534 if(*tuple>=0 && *tuple<aNt)
7536 std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
7540 std::ostringstream oss; oss << "DataArrayInt::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
7541 oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
7542 throw INTERP_KERNEL::Exception(oss.str().c_str());
7548 * Copy some tuples from another DataArrayInt (\a a) into contiguous tuples
7549 * of \a this array. Textual data is not copied. Both arrays must have equal number of
7551 * The tuples to copy are defined by three values similar to parameters of
7552 * the Python function \c range(\c start,\c stop,\c step).
7553 * The tuples to assign to are defined by index of the first tuple, and
7554 * their number is defined by number of tuples to copy.
7555 * All components of selected tuples are copied.
7556 * \param [in] tupleIdStart - index of the first tuple of \a this array to assign
7558 * \param [in] a - the array to copy values from.
7559 * \param [in] bg - index of the first tuple to copy of the array \a a.
7560 * \param [in] end2 - index of the tuple of \a a before which the tuples to copy
7562 * \param [in] step - index increment to get index of the next tuple to copy.
7563 * \throw If \a this is not allocated.
7564 * \throw If \a a is NULL.
7565 * \throw If \a a is not allocated.
7566 * \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
7567 * \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
7568 * \throw If parameters specifying tuples to copy, do not give a
7569 * non-empty range of increasing indices or indices are out of a valid range
7570 * for the array \a a.
7572 void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
7575 a->checkAllocated();
7576 int nbOfComp=getNumberOfComponents();
7577 const char msg[]="DataArrayInt::setContigPartOfSelectedValues2";
7578 int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
7579 if(nbOfComp!=a->getNumberOfComponents())
7580 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
7581 int thisNt=getNumberOfTuples();
7582 int aNt=a->getNumberOfTuples();
7583 int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
7584 if(tupleIdStart+nbOfTupleToWrite>thisNt)
7585 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid number range of values to write !");
7587 throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid range of values to read !");
7588 const int *valsSrc=a->getConstPointer()+bg*nbOfComp;
7589 for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
7591 std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
7596 * Returns a value located at specified tuple and component.
7597 * This method is equivalent to DataArrayInt::getIJ() except that validity of
7598 * parameters is checked. So this method is safe but expensive if used to go through
7599 * all values of \a this.
7600 * \param [in] tupleId - index of tuple of interest.
7601 * \param [in] compoId - index of component of interest.
7602 * \return double - value located by \a tupleId and \a compoId.
7603 * \throw If \a this is not allocated.
7604 * \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
7605 * \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
7607 int DataArrayInt::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
7610 if(tupleId<0 || tupleId>=getNumberOfTuples())
7612 std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
7613 throw INTERP_KERNEL::Exception(oss.str().c_str());
7615 if(compoId<0 || compoId>=getNumberOfComponents())
7617 std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
7618 throw INTERP_KERNEL::Exception(oss.str().c_str());
7620 return _mem[tupleId*_info_on_compo.size()+compoId];
7624 * Returns the last value of \a this.
7625 * \return double - the last value of \a this array.
7626 * \throw If \a this is not allocated.
7627 * \throw If \a this->getNumberOfComponents() != 1.
7628 * \throw If \a this->getNumberOfTuples() < 1.
7630 int DataArrayInt::back() const throw(INTERP_KERNEL::Exception)
7633 if(getNumberOfComponents()!=1)
7634 throw INTERP_KERNEL::Exception("DataArrayInt::back : number of components not equal to one !");
7635 int nbOfTuples=getNumberOfTuples();
7637 throw INTERP_KERNEL::Exception("DataArrayInt::back : number of tuples must be >= 1 !");
7638 return *(getConstPointer()+nbOfTuples-1);
7642 * Assign pointer to one array to a pointer to another appay. Reference counter of
7643 * \a arrayToSet is incremented / decremented.
7644 * \param [in] newArray - the pointer to array to assign to \a arrayToSet.
7645 * \param [in,out] arrayToSet - the pointer to array to assign to.
7647 void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
7649 if(newArray!=arrayToSet)
7652 arrayToSet->decrRef();
7653 arrayToSet=newArray;
7655 arrayToSet->incrRef();
7659 DataArrayIntIterator *DataArrayInt::iterator() throw(INTERP_KERNEL::Exception)
7661 return new DataArrayIntIterator(this);
7665 * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to a
7667 * \param [in] val - the value to find within \a this.
7668 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
7669 * array using decrRef() as it is no more needed.
7670 * \throw If \a this is not allocated.
7671 * \throw If \a this->getNumberOfComponents() != 1.
7673 DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception)
7676 if(getNumberOfComponents()!=1)
7677 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
7678 const int *cptr=getConstPointer();
7679 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
7680 int nbOfTuples=getNumberOfTuples();
7681 for(int i=0;i<nbOfTuples;i++,cptr++)
7683 ret->pushBackSilent(i);
7688 * Creates a new DataArrayInt containing IDs (indices) of tuples holding value \b not
7689 * equal to a given one.
7690 * \param [in] val - the value to ignore within \a this.
7691 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
7692 * array using decrRef() as it is no more needed.
7693 * \throw If \a this is not allocated.
7694 * \throw If \a this->getNumberOfComponents() != 1.
7696 DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception)
7699 if(getNumberOfComponents()!=1)
7700 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !");
7701 const int *cptr=getConstPointer();
7702 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
7703 int nbOfTuples=getNumberOfTuples();
7704 for(int i=0;i<nbOfTuples;i++,cptr++)
7706 ret->pushBackSilent(i);
7712 * Assigns \a newValue to all elements holding \a oldValue within \a this
7713 * one-dimensional array.
7714 * \param [in] oldValue - the value to replace.
7715 * \param [in] newValue - the value to assign.
7716 * \return int - number of replacements performed.
7717 * \throw If \a this is not allocated.
7718 * \throw If \a this->getNumberOfComponents() != 1.
7720 int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception)
7723 if(getNumberOfComponents()!=1)
7724 throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !");
7725 int *start=getPointer();
7726 int *end2=start+getNbOfElems();
7728 for(int *val=start;val!=end2;val++)
7740 * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to
7741 * one of given values.
7742 * \param [in] valsBg - an array of values to find within \a this array.
7743 * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
7744 * the last value of \a valsBg is \a valsEnd[ -1 ].
7745 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
7746 * array using decrRef() as it is no more needed.
7747 * \throw If \a this->getNumberOfComponents() != 1.
7749 DataArrayInt *DataArrayInt::getIdsEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
7751 if(getNumberOfComponents()!=1)
7752 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component, you can call 'rearrange' method before !");
7753 std::set<int> vals2(valsBg,valsEnd);
7754 const int *cptr=getConstPointer();
7755 std::vector<int> res;
7756 int nbOfTuples=getNumberOfTuples();
7757 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
7758 for(int i=0;i<nbOfTuples;i++,cptr++)
7759 if(vals2.find(*cptr)!=vals2.end())
7760 ret->pushBackSilent(i);
7765 * Creates a new DataArrayInt containing IDs (indices) of tuples holding values \b not
7766 * equal to any of given values.
7767 * \param [in] valsBg - an array of values to ignore within \a this array.
7768 * \param [in] valsEnd - specifies the end of the array \a valsBg, so that
7769 * the last value of \a valsBg is \a valsEnd[ -1 ].
7770 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
7771 * array using decrRef() as it is no more needed.
7772 * \throw If \a this->getNumberOfComponents() != 1.
7774 DataArrayInt *DataArrayInt::getIdsNotEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
7776 if(getNumberOfComponents()!=1)
7777 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : the array must have only one component, you can call 'rearrange' method before !");
7778 std::set<int> vals2(valsBg,valsEnd);
7779 const int *cptr=getConstPointer();
7780 std::vector<int> res;
7781 int nbOfTuples=getNumberOfTuples();
7782 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
7783 for(int i=0;i<nbOfTuples;i++,cptr++)
7784 if(vals2.find(*cptr)==vals2.end())
7785 ret->pushBackSilent(i);
7790 * This method is an extension of DataArrayInt::locateValue method because this method works for DataArrayInt with
7791 * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
7792 * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
7793 * If any the tuple id is returned. If not -1 is returned.
7795 * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
7796 * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
7798 * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this.
7799 * \sa DataArrayInt::search, DataArrayInt::presenceOfTuple.
7801 int DataArrayInt::locateTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
7804 int nbOfCompo=getNumberOfComponents();
7806 throw INTERP_KERNEL::Exception("DataArrayInt::locateTuple : 0 components in 'this' !");
7807 if(nbOfCompo!=(int)tupl.size())
7809 std::ostringstream oss; oss << "DataArrayInt::locateTuple : 'this' contains " << nbOfCompo << " components and searching for a tuple of length " << tupl.size() << " !";
7810 throw INTERP_KERNEL::Exception(oss.str().c_str());
7812 const int *cptr=getConstPointer();
7813 std::size_t nbOfVals=getNbOfElems();
7814 for(const int *work=cptr;work!=cptr+nbOfVals;)
7816 work=std::search(work,cptr+nbOfVals,tupl.begin(),tupl.end());
7817 if(work!=cptr+nbOfVals)
7819 if(std::distance(cptr,work)%nbOfCompo!=0)
7822 return std::distance(cptr,work)/nbOfCompo;
7829 * This method searches the sequence specified in input parameter \b vals in \b this.
7830 * This works only for DataArrayInt having number of components equal to one (if not an INTERP_KERNEL::Exception will be thrown).
7831 * This method differs from DataArrayInt::locateTuple in that the position is internal raw data is not considered here contrary to DataArrayInt::locateTuple.
7832 * \sa DataArrayInt::locateTuple
7834 int DataArrayInt::search(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
7837 int nbOfCompo=getNumberOfComponents();
7839 throw INTERP_KERNEL::Exception("DataArrayInt::search : works only for DataArrayInt instance with one component !");
7840 const int *cptr=getConstPointer();
7841 std::size_t nbOfVals=getNbOfElems();
7842 const int *loc=std::search(cptr,cptr+nbOfVals,vals.begin(),vals.end());
7843 if(loc!=cptr+nbOfVals)
7844 return std::distance(cptr,loc);
7849 * This method expects to be called when number of components of this is equal to one.
7850 * This method returns the tuple id, if it exists, of the first tuple equal to \b value.
7851 * If not any tuple contains \b value -1 is returned.
7852 * \sa DataArrayInt::presenceOfValue
7854 int DataArrayInt::locateValue(int value) const throw(INTERP_KERNEL::Exception)
7857 if(getNumberOfComponents()!=1)
7858 throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
7859 const int *cptr=getConstPointer();
7860 int nbOfTuples=getNumberOfTuples();
7861 const int *ret=std::find(cptr,cptr+nbOfTuples,value);
7862 if(ret!=cptr+nbOfTuples)
7863 return std::distance(cptr,ret);
7868 * This method expects to be called when number of components of this is equal to one.
7869 * This method returns the tuple id, if it exists, of the first tuple so that the value is contained in \b vals.
7870 * If not any tuple contains one of the values contained in 'vals' false is returned.
7871 * \sa DataArrayInt::presenceOfValue
7873 int DataArrayInt::locateValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
7876 if(getNumberOfComponents()!=1)
7877 throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
7878 std::set<int> vals2(vals.begin(),vals.end());
7879 const int *cptr=getConstPointer();
7880 int nbOfTuples=getNumberOfTuples();
7881 for(const int *w=cptr;w!=cptr+nbOfTuples;w++)
7882 if(vals2.find(*w)!=vals2.end())
7883 return std::distance(cptr,w);
7888 * This method is an extension of DataArrayInt::presenceOfValue method because this method works for DataArrayInt with
7889 * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
7890 * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
7891 * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
7892 * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
7893 * \sa DataArrayInt::locateTuple
7895 bool DataArrayInt::presenceOfTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
7897 return locateTuple(tupl)!=-1;
7902 * Returns \a true if a given value is present within \a this one-dimensional array.
7903 * \param [in] value - the value to find within \a this array.
7904 * \return bool - \a true in case if \a value is present within \a this array.
7905 * \throw If \a this is not allocated.
7906 * \throw If \a this->getNumberOfComponents() != 1.
7909 bool DataArrayInt::presenceOfValue(int value) const throw(INTERP_KERNEL::Exception)
7911 return locateValue(value)!=-1;
7915 * This method expects to be called when number of components of this is equal to one.
7916 * This method returns true if it exists a tuple so that the value is contained in \b vals.
7917 * If not any tuple contains one of the values contained in 'vals' false is returned.
7918 * \sa DataArrayInt::locateValue
7920 bool DataArrayInt::presenceOfValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
7922 return locateValue(vals)!=-1;
7926 * Accumulates values of each component of \a this array.
7927 * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
7928 * by the caller, that is filled by this method with sum value for each
7930 * \throw If \a this is not allocated.
7932 void DataArrayInt::accumulate(int *res) const throw(INTERP_KERNEL::Exception)
7935 const int *ptr=getConstPointer();
7936 int nbTuple=getNumberOfTuples();
7937 int nbComps=getNumberOfComponents();
7938 std::fill(res,res+nbComps,0);
7939 for(int i=0;i<nbTuple;i++)
7940 std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<int>());
7943 int DataArrayInt::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
7946 const int *ptr=getConstPointer();
7947 int nbTuple=getNumberOfTuples();
7948 int nbComps=getNumberOfComponents();
7949 if(compId<0 || compId>=nbComps)
7950 throw INTERP_KERNEL::Exception("DataArrayInt::accumulate : Invalid compId specified : No such nb of components !");
7952 for(int i=0;i<nbTuple;i++)
7953 ret+=ptr[i*nbComps+compId];
7958 * Returns a new DataArrayInt by concatenating two given arrays, so that (1) the number
7959 * of tuples in the result array is <em> a1->getNumberOfTuples() + a2->getNumberOfTuples() -
7960 * offsetA2</em> and (2)
7961 * the number of component in the result array is same as that of each of given arrays.
7962 * First \a offsetA2 tuples of \a a2 are skipped and thus are missing from the result array.
7963 * Info on components is copied from the first of the given arrays. Number of components
7964 * in the given arrays must be the same.
7965 * \param [in] a1 - an array to include in the result array.
7966 * \param [in] a2 - another array to include in the result array.
7967 * \param [in] offsetA2 - number of tuples of \a a2 to skip.
7968 * \return DataArrayInt * - the new instance of DataArrayInt.
7969 * The caller is to delete this result array using decrRef() as it is no more
7971 * \throw If either \a a1 or \a a2 is NULL.
7972 * \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
7974 DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
7977 throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input DataArrayInt instance is NULL !");
7978 int nbOfComp=a1->getNumberOfComponents();
7979 if(nbOfComp!=a2->getNumberOfComponents())
7980 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
7981 int nbOfTuple1=a1->getNumberOfTuples();
7982 int nbOfTuple2=a2->getNumberOfTuples();
7983 DataArrayInt *ret=DataArrayInt::New();
7984 ret->alloc(nbOfTuple1+nbOfTuple2-offsetA2,nbOfComp);
7985 int *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer());
7986 std::copy(a2->getConstPointer()+offsetA2*nbOfComp,a2->getConstPointer()+nbOfTuple2*nbOfComp,pt);
7987 ret->copyStringInfoFrom(*a1);
7992 * Returns a new DataArrayInt by concatenating all given arrays, so that (1) the number
7993 * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
7994 * the number of component in the result array is same as that of each of given arrays.
7995 * Info on components is copied from the first of the given arrays. Number of components
7996 * in the given arrays must be the same.
7997 * \param [in] arr - a sequence of arrays to include in the result array.
7998 * \return DataArrayInt * - the new instance of DataArrayInt.
7999 * The caller is to delete this result array using decrRef() as it is no more
8001 * \throw If all arrays within \a arr are NULL.
8002 * \throw If getNumberOfComponents() of arrays within \a arr.
8004 DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8006 std::vector<const DataArrayInt *> a;
8007 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8011 throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
8012 std::vector<const DataArrayInt *>::const_iterator it=a.begin();
8013 int nbOfComp=(*it)->getNumberOfComponents();
8014 int nbt=(*it++)->getNumberOfTuples();
8015 for(int i=1;it!=a.end();it++,i++)
8017 if((*it)->getNumberOfComponents()!=nbOfComp)
8018 throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !");
8019 nbt+=(*it)->getNumberOfTuples();
8021 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8022 ret->alloc(nbt,nbOfComp);
8023 int *pt=ret->getPointer();
8024 for(it=a.begin();it!=a.end();it++)
8025 pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
8026 ret->copyStringInfoFrom(*(a[0]));
8031 * Returns the maximal value and its location within \a this one-dimensional array.
8032 * \param [out] tupleId - index of the tuple holding the maximal value.
8033 * \return double - the maximal value among all values of \a this array.
8034 * \throw If \a this->getNumberOfComponents() != 1
8035 * \throw If \a this->getNumberOfTuples() < 1
8037 int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
8040 if(getNumberOfComponents()!=1)
8041 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
8042 int nbOfTuples=getNumberOfTuples();
8044 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
8045 const int *vals=getConstPointer();
8046 const int *loc=std::max_element(vals,vals+nbOfTuples);
8047 tupleId=(int)std::distance(vals,loc);
8052 * Returns the maximal value within \a this array that is allowed to have more than
8054 * \return int - the maximal value among all values of \a this array.
8055 * \throw If \a this is not allocated.
8057 int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
8060 const int *loc=std::max_element(begin(),end());
8065 * Returns the minimal value and its location within \a this one-dimensional array.
8066 * \param [out] tupleId - index of the tuple holding the minimal value.
8067 * \return int - the minimal value among all values of \a this array.
8068 * \throw If \a this->getNumberOfComponents() != 1
8069 * \throw If \a this->getNumberOfTuples() < 1
8071 int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
8074 if(getNumberOfComponents()!=1)
8075 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
8076 int nbOfTuples=getNumberOfTuples();
8078 throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
8079 const int *vals=getConstPointer();
8080 const int *loc=std::min_element(vals,vals+nbOfTuples);
8081 tupleId=(int)std::distance(vals,loc);
8086 * Returns the minimal value within \a this array that is allowed to have more than
8088 * \return int - the minimal value among all values of \a this array.
8089 * \throw If \a this is not allocated.
8091 int DataArrayInt::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
8094 const int *loc=std::min_element(begin(),end());
8099 * Converts every value of \a this array to its absolute value.
8100 * \throw If \a this is not allocated.
8102 void DataArrayInt::abs() throw(INTERP_KERNEL::Exception)
8105 int *ptr=getPointer();
8106 std::size_t nbOfElems=getNbOfElems();
8107 std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
8112 * Apply a liner function to a given component of \a this array, so that
8113 * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
8114 * \param [in] a - the first coefficient of the function.
8115 * \param [in] b - the second coefficient of the function.
8116 * \param [in] compoId - the index of component to modify.
8117 * \throw If \a this is not allocated.
8119 void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception)
8122 int *ptr=getPointer()+compoId;
8123 int nbOfComp=getNumberOfComponents();
8124 int nbOfTuple=getNumberOfTuples();
8125 for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
8131 * Apply a liner function to all elements of \a this array, so that
8132 * an element _x_ becomes \f$ a * x + b \f$.
8133 * \param [in] a - the first coefficient of the function.
8134 * \param [in] b - the second coefficient of the function.
8135 * \throw If \a this is not allocated.
8137 void DataArrayInt::applyLin(int a, int b) throw(INTERP_KERNEL::Exception)
8140 int *ptr=getPointer();
8141 std::size_t nbOfElems=getNbOfElems();
8142 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8148 * Returns a full copy of \a this array except that sign of all elements is reversed.
8149 * \return DataArrayInt * - the new instance of DataArrayInt containing the
8150 * same number of tuples and component as \a this array.
8151 * The caller is to delete this result array using decrRef() as it is no more
8153 * \throw If \a this is not allocated.
8155 DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception)
8158 DataArrayInt *newArr=DataArrayInt::New();
8159 int nbOfTuples=getNumberOfTuples();
8160 int nbOfComp=getNumberOfComponents();
8161 newArr->alloc(nbOfTuples,nbOfComp);
8162 const int *cptr=getConstPointer();
8163 std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
8164 newArr->copyStringInfoFrom(*this);
8169 * Modify all elements of \a this array, so that
8170 * an element _x_ becomes \f$ numerator / x \f$.
8171 * \param [in] numerator - the numerator used to modify array elements.
8172 * \throw If \a this is not allocated.
8173 * \throw If there is an element equal to 0 in \a this array.
8174 * \warning If an exception is thrown because of presence of 0 element in \a this
8175 * array, all elements processed before detection of the zero element remain
8178 void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception)
8181 int *ptr=getPointer();
8182 std::size_t nbOfElems=getNbOfElems();
8183 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8187 *ptr=numerator/(*ptr);
8191 std::ostringstream oss; oss << "DataArrayInt::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8193 throw INTERP_KERNEL::Exception(oss.str().c_str());
8200 * Modify all elements of \a this array, so that
8201 * an element _x_ becomes \f$ x / val \f$.
8202 * \param [in] val - the denominator used to modify array elements.
8203 * \throw If \a this is not allocated.
8204 * \throw If \a val == 0.
8206 void DataArrayInt::applyDivideBy(int val) throw(INTERP_KERNEL::Exception)
8209 throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to divide by 0 !");
8211 int *ptr=getPointer();
8212 std::size_t nbOfElems=getNbOfElems();
8213 std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides<int>(),val));
8218 * Modify all elements of \a this array, so that
8219 * an element _x_ becomes <em> x % val </em>.
8220 * \param [in] val - the divisor used to modify array elements.
8221 * \throw If \a this is not allocated.
8222 * \throw If \a val <= 0.
8224 void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception)
8227 throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !");
8229 int *ptr=getPointer();
8230 std::size_t nbOfElems=getNbOfElems();
8231 std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus<int>(),val));
8236 * This method works only on data array with one component.
8237 * This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that
8238 * this[*id] in [\b vmin,\b vmax)
8240 * \param [in] vmin begin of range. This value is included in range.
8241 * \param [out] vmax end of range. This value is \b not included in range.
8242 * \return a newly allocated data array that the caller should deal with.
8244 DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
8247 if(getNumberOfComponents()!=1)
8248 throw INTERP_KERNEL::Exception("DataArrayInt::getIdsInRange : this must have exactly one component !");
8249 const int *cptr=getConstPointer();
8250 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
8251 int nbOfTuples=getNumberOfTuples();
8252 for(int i=0;i<nbOfTuples;i++,cptr++)
8253 if(*cptr>=vmin && *cptr<vmax)
8254 ret->pushBackSilent(i);
8259 * Modify all elements of \a this array, so that
8260 * an element _x_ becomes <em> val % x </em>.
8261 * \param [in] val - the divident used to modify array elements.
8262 * \throw If \a this is not allocated.
8263 * \throw If there is an element equal to or less than 0 in \a this array.
8264 * \warning If an exception is thrown because of presence of an element <= 0 in \a this
8265 * array, all elements processed before detection of the zero element remain
8268 void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception)
8271 int *ptr=getPointer();
8272 std::size_t nbOfElems=getNbOfElems();
8273 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8281 std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8283 throw INTERP_KERNEL::Exception(oss.str().c_str());
8290 * Modify all elements of \a this array, so that
8291 * an element _x_ becomes <em> val ^ x </em>.
8292 * \param [in] val - the value used to apply pow on all array elements.
8293 * \throw If \a this is not allocated.
8294 * \throw If \a val < 0.
8296 void DataArrayInt::applyPow(int val) throw(INTERP_KERNEL::Exception)
8300 throw INTERP_KERNEL::Exception("DataArrayInt::applyPow : input pow in < 0 !");
8301 int *ptr=getPointer();
8302 std::size_t nbOfElems=getNbOfElems();
8305 std::fill(ptr,ptr+nbOfElems,1.);
8308 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8311 for(int j=0;j<val;j++)
8319 * Modify all elements of \a this array, so that
8320 * an element _x_ becomes \f$ val ^ x \f$.
8321 * \param [in] val - the value used to apply pow on all array elements.
8322 * \throw If \a this is not allocated.
8323 * \throw If there is an element < 0 in \a this array.
8324 * \warning If an exception is thrown because of presence of 0 element in \a this
8325 * array, all elements processed before detection of the zero element remain
8328 void DataArrayInt::applyRPow(int val) throw(INTERP_KERNEL::Exception)
8331 int *ptr=getPointer();
8332 std::size_t nbOfElems=getNbOfElems();
8333 for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8338 for(int j=0;j<*ptr;j++)
8344 std::ostringstream oss; oss << "DataArrayInt::applyRPow : presence of negative value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8346 throw INTERP_KERNEL::Exception(oss.str().c_str());
8353 * Returns a new DataArrayInt by aggregating two given arrays, so that (1) the number
8354 * of components in the result array is a sum of the number of components of given arrays
8355 * and (2) the number of tuples in the result array is same as that of each of given
8356 * arrays. In other words the i-th tuple of result array includes all components of
8357 * i-th tuples of all given arrays.
8358 * Number of tuples in the given arrays must be the same.
8359 * \param [in] a1 - an array to include in the result array.
8360 * \param [in] a2 - another array to include in the result array.
8361 * \return DataArrayInt * - the new instance of DataArrayInt.
8362 * The caller is to delete this result array using decrRef() as it is no more
8364 * \throw If both \a a1 and \a a2 are NULL.
8365 * \throw If any given array is not allocated.
8366 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
8368 DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
8370 std::vector<const DataArrayInt *> arr(2);
8371 arr[0]=a1; arr[1]=a2;
8376 * Returns a new DataArrayInt by aggregating all given arrays, so that (1) the number
8377 * of components in the result array is a sum of the number of components of given arrays
8378 * and (2) the number of tuples in the result array is same as that of each of given
8379 * arrays. In other words the i-th tuple of result array includes all components of
8380 * i-th tuples of all given arrays.
8381 * Number of tuples in the given arrays must be the same.
8382 * \param [in] arr - a sequence of arrays to include in the result array.
8383 * \return DataArrayInt * - the new instance of DataArrayInt.
8384 * The caller is to delete this result array using decrRef() as it is no more
8386 * \throw If all arrays within \a arr are NULL.
8387 * \throw If any given array is not allocated.
8388 * \throw If getNumberOfTuples() of arrays within \a arr is different.
8390 DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8392 std::vector<const DataArrayInt *> a;
8393 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8397 throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !");
8398 std::vector<const DataArrayInt *>::const_iterator it;
8399 for(it=a.begin();it!=a.end();it++)
8400 (*it)->checkAllocated();
8402 int nbOfTuples=(*it)->getNumberOfTuples();
8403 std::vector<int> nbc(a.size());
8404 std::vector<const int *> pts(a.size());
8405 nbc[0]=(*it)->getNumberOfComponents();
8406 pts[0]=(*it++)->getConstPointer();
8407 for(int i=1;it!=a.end();it++,i++)
8409 if(nbOfTuples!=(*it)->getNumberOfTuples())
8410 throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !");
8411 nbc[i]=(*it)->getNumberOfComponents();
8412 pts[i]=(*it)->getConstPointer();
8414 int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
8415 DataArrayInt *ret=DataArrayInt::New();
8416 ret->alloc(nbOfTuples,totalNbOfComp);
8417 int *retPtr=ret->getPointer();
8418 for(int i=0;i<nbOfTuples;i++)
8419 for(int j=0;j<(int)a.size();j++)
8421 retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
8425 for(int i=0;i<(int)a.size();i++)
8426 for(int j=0;j<nbc[i];j++,k++)
8427 ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
8432 * Returns a new DataArrayInt which is a minimal partition of elements of \a groups.
8433 * The i-th item of the result array is an ID of a set of elements belonging to a
8434 * unique set of groups, which the i-th element is a part of. This set of elements
8435 * belonging to a unique set of groups is called \a family, so the result array contains
8436 * IDs of families each element belongs to.
8438 * \b Example: if we have two groups of elements: \a group1 [0,4] and \a group2 [ 0,1,2 ],
8439 * then there are 3 families:
8440 * - \a family1 (with ID 1) contains element [0] belonging to ( \a group1 + \a group2 ),
8441 * - \a family2 (with ID 2) contains elements [4] belonging to ( \a group1 ),
8442 * - \a family3 (with ID 3) contains element [1,2] belonging to ( \a group2 ), <br>
8443 * and the result array contains IDs of families [ 1,3,3,0,2 ]. <br> Note a family ID 0 which
8444 * stands for the element #3 which is in none of groups.
8446 * \param [in] groups - sequence of groups of element IDs.
8447 * \param [in] newNb - total number of elements; it must be more than max ID of element
8449 * \param [out] fidsOfGroups - IDs of families the elements of each group belong to.
8450 * \return DataArrayInt * - a new instance of DataArrayInt containing IDs of families
8451 * each element with ID from range [0, \a newNb ) belongs to. The caller is to
8452 * delete this array using decrRef() as it is no more needed.
8453 * \throw If any element ID in \a groups violates condition ( 0 <= ID < \a newNb ).
8455 DataArrayInt *DataArrayInt::MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups) throw(INTERP_KERNEL::Exception)
8457 std::vector<const DataArrayInt *> groups2;
8458 for(std::vector<const DataArrayInt *>::const_iterator it4=groups.begin();it4!=groups.end();it4++)
8460 groups2.push_back(*it4);
8461 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8462 ret->alloc(newNb,1);
8463 int *retPtr=ret->getPointer();
8464 std::fill(retPtr,retPtr+newNb,0);
8466 for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++)
8468 const int *ptr=(*iter)->getConstPointer();
8469 std::size_t nbOfElem=(*iter)->getNbOfElems();
8471 for(int j=0;j<sfid;j++)
8474 for(std::size_t i=0;i<nbOfElem;i++)
8476 if(ptr[i]>=0 && ptr[i]<newNb)
8478 if(retPtr[ptr[i]]==j)
8486 std::ostringstream oss; oss << "DataArrayInt::MakePartition : In group \"" << (*iter)->getName() << "\" in tuple #" << i << " value = " << ptr[i] << " ! Should be in [0," << newNb;
8488 throw INTERP_KERNEL::Exception(oss.str().c_str());
8495 fidsOfGroups.clear();
8496 fidsOfGroups.resize(groups2.size());
8498 for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++,grId++)
8501 const int *ptr=(*iter)->getConstPointer();
8502 std::size_t nbOfElem=(*iter)->getNbOfElems();
8503 for(const int *p=ptr;p!=ptr+nbOfElem;p++)
8504 tmp.insert(retPtr[*p]);
8505 fidsOfGroups[grId].insert(fidsOfGroups[grId].end(),tmp.begin(),tmp.end());
8511 * Returns a new DataArrayInt which contains all elements of given one-dimensional
8512 * not negative arrays. The result array does not contain any duplicates and its values
8513 * are sorted in ascending order.
8514 * \param [in] arr - sequence of DataArrayInt's to unite.
8515 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8516 * array using decrRef() as it is no more needed.
8517 * \throw If any \a arr[i] is not allocated.
8518 * \throw If \a arr[i]->getNumberOfComponents() != 1.
8519 * \throw If any value of \a arr[i] is negative.
8521 DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8523 std::vector<const DataArrayInt *> a;
8524 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8527 int valm=std::numeric_limits<int>::max();
8528 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8530 (*it)->checkAllocated();
8531 if((*it)->getNumberOfComponents()!=1)
8532 throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
8534 valm=std::min((*it)->getMinValue(tmp1),valm);
8537 throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
8540 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8542 const int *pt=(*it)->getConstPointer();
8543 int nbOfTuples=(*it)->getNumberOfTuples();
8544 r.insert(pt,pt+nbOfTuples);
8546 DataArrayInt *ret=DataArrayInt::New();
8547 ret->alloc((int)r.size(),1);
8548 std::copy(r.begin(),r.end(),ret->getPointer());
8553 * Returns a new DataArrayInt which contains elements present in each of given one-dimensional
8554 * not negative arrays. The result array does not contain any duplicates and its values
8555 * are sorted in ascending order.
8556 * \param [in] arr - sequence of DataArrayInt's to intersect.
8557 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8558 * array using decrRef() as it is no more needed.
8559 * \throw If any \a arr[i] is not allocated.
8560 * \throw If \a arr[i]->getNumberOfComponents() != 1.
8561 * \throw If any value of \a arr[i] < 0.
8563 DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8565 std::vector<const DataArrayInt *> a;
8566 for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8569 int valm=std::numeric_limits<int>::max();
8570 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8572 (*it)->checkAllocated();
8573 if((*it)->getNumberOfComponents()!=1)
8574 throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : only single component allowed !");
8576 valm=std::min((*it)->getMinValue(tmp1),valm);
8579 throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : a negative value has been detected !");
8582 for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8584 const int *pt=(*it)->getConstPointer();
8585 int nbOfTuples=(*it)->getNumberOfTuples();
8586 std::set<int> s1(pt,pt+nbOfTuples);
8590 std::set_intersection(r.begin(),r.end(),s1.begin(),s1.end(),inserter(r2,r2.end()));
8596 DataArrayInt *ret=DataArrayInt::New();
8597 ret->alloc((int)r.size(),1);
8598 std::copy(r.begin(),r.end(),ret->getPointer());
8603 * Returns a new DataArrayInt which contains a complement of elements of \a this
8604 * one-dimensional array. I.e. the result array contains all elements from the range [0,
8605 * \a nbOfElement) not present in \a this array.
8606 * \param [in] nbOfElement - maximal size of the result array.
8607 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8608 * array using decrRef() as it is no more needed.
8609 * \throw If \a this is not allocated.
8610 * \throw If \a this->getNumberOfComponents() != 1.
8611 * \throw If any element \a x of \a this array violates condition ( 0 <= \a x < \a
8614 DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception)
8617 if(getNumberOfComponents()!=1)
8618 throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : only single component allowed !");
8619 std::vector<bool> tmp(nbOfElement);
8620 const int *pt=getConstPointer();
8621 int nbOfTuples=getNumberOfTuples();
8622 for(const int *w=pt;w!=pt+nbOfTuples;w++)
8623 if(*w>=0 && *w<nbOfElement)
8626 throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : an element is not in valid range : [0,nbOfElement) !");
8627 int nbOfRetVal=(int)std::count(tmp.begin(),tmp.end(),false);
8628 DataArrayInt *ret=DataArrayInt::New();
8629 ret->alloc(nbOfRetVal,1);
8631 int *retPtr=ret->getPointer();
8632 for(int i=0;i<nbOfElement;i++)
8639 * Returns a new DataArrayInt containing elements of \a this one-dimensional missing
8640 * from an \a other one-dimensional array.
8641 * \param [in] other - a DataArrayInt containing elements not to include in the result array.
8642 * \return DataArrayInt * - a new instance of DataArrayInt with one component. The
8643 * caller is to delete this array using decrRef() as it is no more needed.
8644 * \throw If \a other is NULL.
8645 * \throw If \a other is not allocated.
8646 * \throw If \a other->getNumberOfComponents() != 1.
8647 * \throw If \a this is not allocated.
8648 * \throw If \a this->getNumberOfComponents() != 1.
8649 * \sa DataArrayInt::buildSubstractionOptimized()
8651 DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8654 throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : DataArrayInt pointer in input is NULL !");
8656 other->checkAllocated();
8657 if(getNumberOfComponents()!=1)
8658 throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !");
8659 if(other->getNumberOfComponents()!=1)
8660 throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !");
8661 const int *pt=getConstPointer();
8662 int nbOfTuples=getNumberOfTuples();
8663 std::set<int> s1(pt,pt+nbOfTuples);
8664 pt=other->getConstPointer();
8665 nbOfTuples=other->getNumberOfTuples();
8666 std::set<int> s2(pt,pt+nbOfTuples);
8668 std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<int> >(r));
8669 DataArrayInt *ret=DataArrayInt::New();
8670 ret->alloc((int)r.size(),1);
8671 std::copy(r.begin(),r.end(),ret->getPointer());
8676 * \a this is expected to have one component and to be sorted ascendingly (as for \a other).
8677 * \a other is expected to be a part of \a this. If not DataArrayInt::buildSubstraction should be called instead.
8679 * \param [in] other an array with one component and expected to be sorted ascendingly.
8680 * \ret list of ids in \a this but not in \a other.
8681 * \sa DataArrayInt::buildSubstraction
8683 DataArrayInt *DataArrayInt::buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8685 static const char *MSG="DataArrayInt::buildSubstractionOptimized : only single component allowed !";
8686 if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstractionOptimized : NULL input array !");
8687 checkAllocated(); other->checkAllocated();
8688 if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
8689 if(other->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
8690 const int *pt1Bg(begin()),*pt1End(end()),*pt2Bg(other->begin()),*pt2End(other->end()),*work1(pt1Bg),*work2(pt2Bg);
8691 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
8692 for(;work1!=pt1End;work1++)
8694 if(work2!=pt2End && *work1==*work2)
8697 ret->pushBackSilent(*work1);
8704 * Returns a new DataArrayInt which contains all elements of \a this and a given
8705 * one-dimensional not negative arrays. The result array does not contain any duplicates
8706 * and its values are sorted in ascending order.
8707 * \param [in] other - an array to unite with \a this one.
8708 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8709 * array using decrRef() as it is no more needed.
8710 * \throw If \a this or \a other is not allocated.
8711 * \throw If \a this->getNumberOfComponents() != 1.
8712 * \throw If \a other->getNumberOfComponents() != 1.
8713 * \throw If any value of \a this or \a other is negative.
8715 DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8717 std::vector<const DataArrayInt *>arrs(2);
8718 arrs[0]=this; arrs[1]=other;
8719 return BuildUnion(arrs);
8724 * Returns a new DataArrayInt which contains elements present in both \a this and a given
8725 * one-dimensional not negative arrays. The result array does not contain any duplicates
8726 * and its values are sorted in ascending order.
8727 * \param [in] other - an array to intersect with \a this one.
8728 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8729 * array using decrRef() as it is no more needed.
8730 * \throw If \a this or \a other is not allocated.
8731 * \throw If \a this->getNumberOfComponents() != 1.
8732 * \throw If \a other->getNumberOfComponents() != 1.
8733 * \throw If any value of \a this or \a other is negative.
8735 DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8737 std::vector<const DataArrayInt *>arrs(2);
8738 arrs[0]=this; arrs[1]=other;
8739 return BuildIntersection(arrs);
8743 * This method can be applied on allocated with one component DataArrayInt instance.
8744 * This method is typically relevant for sorted arrays. All consecutive duplicated items in \a this will appear only once in returned DataArrayInt instance.
8745 * Example : if \a this contains [1,2,2,3,3,3,3,4,5,5,7,7,7,19] the returned array will contain [1,2,3,4,5,7,19]
8747 * \return a newly allocated array that contain the result of the unique operation applied on \a this.
8748 * \throw if \a this is not allocated or if \a this has not exactly one component.
8750 DataArrayInt *DataArrayInt::buildUnique() const throw(INTERP_KERNEL::Exception)
8753 if(getNumberOfComponents()!=1)
8754 throw INTERP_KERNEL::Exception("DataArrayInt::buildUnique : only single component allowed !");
8755 int nbOfTuples=getNumberOfTuples();
8756 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=deepCpy();
8757 int *data=tmp->getPointer();
8758 int *last=std::unique(data,data+nbOfTuples);
8759 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8760 ret->alloc(std::distance(data,last),1);
8761 std::copy(data,last,ret->getPointer());
8766 * Returns a new DataArrayInt which contains size of every of groups described by \a this
8767 * "index" array. Such "index" array is returned for example by
8768 * \ref ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity
8769 * "MEDCouplingUMesh::buildDescendingConnectivity" and
8770 * \ref ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex
8771 * "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
8772 * \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
8773 * equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
8774 * The caller is to delete this array using decrRef() as it is no more needed.
8775 * \throw If \a this is not allocated.
8776 * \throw If \a this->getNumberOfComponents() != 1.
8777 * \throw If \a this->getNumberOfTuples() < 2.
8780 * - this contains [1,3,6,7,7,9,15]
8781 * - result array contains [2,3,1,0,2,6],
8782 * where 2 = 3 - 1, 3 = 6 - 3, 1 = 7 - 6 etc.
8784 DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
8787 if(getNumberOfComponents()!=1)
8788 throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
8789 int nbOfTuples=getNumberOfTuples();
8791 throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
8792 const int *ptr=getConstPointer();
8793 DataArrayInt *ret=DataArrayInt::New();
8794 ret->alloc(nbOfTuples-1,1);
8795 int *out=ret->getPointer();
8796 std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
8801 * Modifies \a this one-dimensional array so that value of each element \a x
8802 * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
8803 * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number of tuples
8804 * and components remains the same.<br>
8805 * This method is useful for allToAllV in MPI with contiguous policy. This method
8806 * differs from computeOffsets2() in that the number of tuples is \b not changed by
8808 * \throw If \a this is not allocated.
8809 * \throw If \a this->getNumberOfComponents() != 1.
8812 * - Before \a this contains [3,5,1,2,0,8]
8813 * - After \a this contains [0,3,8,9,11,11]<br>
8814 * Note that the last element 19 = 11 + 8 is missing because size of \a this
8815 * array is retained and thus there is no space to store the last element.
8817 void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception)
8820 if(getNumberOfComponents()!=1)
8821 throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
8822 int nbOfTuples=getNumberOfTuples();
8825 int *work=getPointer();
8828 for(int i=1;i<nbOfTuples;i++)
8831 work[i]=work[i-1]+tmp;
8839 * Modifies \a this one-dimensional array so that value of each element \a x
8840 * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
8841 * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number
8842 * components remains the same and number of tuples is inceamented by one.<br>
8843 * This method is useful for allToAllV in MPI with contiguous policy. This method
8844 * differs from computeOffsets() in that the number of tuples is changed by this one.
8845 * \throw If \a this is not allocated.
8846 * \throw If \a this->getNumberOfComponents() != 1.
8849 * - Before \a this contains [3,5,1,2,0,8]
8850 * - After \a this contains [0,3,8,9,11,11,19]<br>
8852 void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
8855 if(getNumberOfComponents()!=1)
8856 throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !");
8857 int nbOfTuples=getNumberOfTuples();
8858 int *ret=new int[nbOfTuples+1];
8861 const int *work=getConstPointer();
8863 for(int i=0;i<nbOfTuples;i++)
8864 ret[i+1]=work[i]+ret[i];
8865 useArray(ret,true,CPP_DEALLOC,nbOfTuples+1,1);
8870 * Returns two new DataArrayInt instances whose contents is computed from that of \a this and \a listOfIds arrays as follows.
8871 * \a this is expected to be an offset format ( as returned by DataArrayInt::computeOffsets2 ) that is to say with one component
8872 * and ** sorted strictly increasingly **. \a listOfIds is expected to be sorted ascendingly (not strictly needed for \a listOfIds).
8873 * This methods searches in \a this, considered as a set of contiguous \c this->getNumberOfComponents() ranges, all ids in \a listOfIds
8874 * filling completely one of the ranges in \a this.
8876 * \param [in] listOfIds a list of ids that has to be sorted ascendingly.
8877 * \param [out] rangeIdsFetched the range ids fetched
8878 * \param [out] idsInInputListThatFetch contains the list of ids in \a listOfIds that are \b fully included in a range in \a this. So
8879 * \a idsInInputListThatFetch is a part of input \a listOfIds.
8881 * \sa DataArrayInt::computeOffsets2
8884 * - \a this : [0,3,7,9,15,18]
8885 * - \a listOfIds contains [0,1,2,3,7,8,15,16,17]
8886 * - \a rangeIdsFetched result array: [0,2,4]
8887 * - \a idsInInputListThatFetch result array: [0,1,2,7,8,15,16,17]
8888 * In this example id 3 in input \a listOfIds is alone so it do not appear in output \a idsInInputListThatFetch.
8891 void DataArrayInt::searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception)
8894 throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids is null !");
8895 listOfIds->checkAllocated(); checkAllocated();
8896 if(listOfIds->getNumberOfComponents()!=1)
8897 throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids must have exactly one component !");
8898 if(getNumberOfComponents()!=1)
8899 throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : this must have exactly one component !");
8900 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret0=DataArrayInt::New(); ret0->alloc(0,1);
8901 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New(); ret1->alloc(0,1);
8902 const int *tupEnd(listOfIds->end()),*offBg(begin()),*offEnd(end()-1);
8903 const int *tupPtr(listOfIds->begin()),*offPtr(offBg);
8904 while(tupPtr!=tupEnd && offPtr!=offEnd)
8906 if(*tupPtr==*offPtr)
8909 while(i<offPtr[1] && *tupPtr==i && tupPtr!=tupEnd) { i++; tupPtr++; }
8912 ret0->pushBackSilent((int)std::distance(offBg,offPtr));
8913 ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
8918 { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
8920 rangeIdsFetched=ret0.retn();
8921 idsInInputListThatFetch=ret1.retn();
8925 * Returns a new DataArrayInt whose contents is computed from that of \a this and \a
8926 * offsets arrays as follows. \a offsets is a one-dimensional array considered as an
8927 * "index" array of a "iota" array, thus, whose each element gives an index of a group
8928 * beginning within the "iota" array. And \a this is a one-dimensional array
8929 * considered as a selector of groups described by \a offsets to include into the result array.
8930 * \throw If \a offsets is NULL.
8931 * \throw If \a offsets is not allocated.
8932 * \throw If \a offsets->getNumberOfComponents() != 1.
8933 * \throw If \a offsets is not monotonically increasing.
8934 * \throw If \a this is not allocated.
8935 * \throw If \a this->getNumberOfComponents() != 1.
8936 * \throw If any element of \a this is not a valid index for \a offsets array.
8939 * - \a this: [0,2,3]
8940 * - \a offsets: [0,3,6,10,14,20]
8941 * - result array: [0,1,2,6,7,8,9,10,11,12,13] == <br>
8942 * \c range(0,3) + \c range(6,10) + \c range(10,14) ==<br>
8943 * \c range( \a offsets[ \a this[0] ], offsets[ \a this[0]+1 ]) +
8944 * \c range( \a offsets[ \a this[1] ], offsets[ \a this[1]+1 ]) +
8945 * \c range( \a offsets[ \a this[2] ], offsets[ \a this[2]+1 ])
8947 DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception)
8950 throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : DataArrayInt pointer in input is NULL !");
8952 if(getNumberOfComponents()!=1)
8953 throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
8954 offsets->checkAllocated();
8955 if(offsets->getNumberOfComponents()!=1)
8956 throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
8957 int othNbTuples=offsets->getNumberOfTuples()-1;
8958 int nbOfTuples=getNumberOfTuples();
8959 int retNbOftuples=0;
8960 const int *work=getConstPointer();
8961 const int *offPtr=offsets->getConstPointer();
8962 for(int i=0;i<nbOfTuples;i++)
8965 if(val>=0 && val<othNbTuples)
8967 int delta=offPtr[val+1]-offPtr[val];
8969 retNbOftuples+=delta;
8972 std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
8973 throw INTERP_KERNEL::Exception(oss.str().c_str());
8978 std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
8979 oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
8980 throw INTERP_KERNEL::Exception(oss.str().c_str());
8983 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8984 ret->alloc(retNbOftuples,1);
8985 int *retPtr=ret->getPointer();
8986 for(int i=0;i<nbOfTuples;i++)
8989 int start=offPtr[val];
8990 int off=offPtr[val+1]-start;
8991 for(int j=0;j<off;j++,retPtr++)
8998 * 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.
8999 * 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
9000 * in tuple **i** of returned DataArrayInt.
9001 * If ranges overlapped (in theory it should not) this method do not detect it and always returns the first range.
9003 * 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)]
9004 * The return DataArrayInt will contain : **[0,4,1,2,2,3]**
9006 * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
9007 * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
9008 * \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
9009 * is thrown if no ranges in \a ranges contains value in \a this.
9011 * \sa DataArrayInt::findIdInRangeForEachTuple
9013 DataArrayInt *DataArrayInt::findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
9016 throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : null input pointer !");
9017 if(ranges->getNumberOfComponents()!=2)
9018 throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : input DataArrayInt instance should have 2 components !");
9020 if(getNumberOfComponents()!=1)
9021 throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : this should have only one component !");
9022 int nbTuples=getNumberOfTuples();
9023 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
9024 int nbOfRanges=ranges->getNumberOfTuples();
9025 const int *rangesPtr=ranges->getConstPointer();
9026 int *retPtr=ret->getPointer();
9027 const int *inPtr=getConstPointer();
9028 for(int i=0;i<nbTuples;i++,retPtr++)
9032 for(int j=0;j<nbOfRanges && !found;j++)
9033 if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
9034 { *retPtr=j; found=true; }
9039 std::ostringstream oss; oss << "DataArrayInt::findRangeIdForEachTuple : tuple #" << i << " not found by any ranges !";
9040 throw INTERP_KERNEL::Exception(oss.str().c_str());
9047 * 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.
9048 * 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
9049 * in tuple **i** of returned DataArrayInt.
9050 * If ranges overlapped (in theory it should not) this method do not detect it and always returns the sub position of the first range.
9052 * 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)]
9053 * The return DataArrayInt will contain : **[1,2,4,0,2,2]**
9054 * This method is often called in pair with DataArrayInt::findRangeIdForEachTuple method.
9056 * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
9057 * for lower value included and 2nd component is the upper value of corresponding range **excluded**.
9058 * \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
9059 * is thrown if no ranges in \a ranges contains value in \a this.
9060 * \sa DataArrayInt::findRangeIdForEachTuple
9062 DataArrayInt *DataArrayInt::findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
9065 throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : null input pointer !");
9066 if(ranges->getNumberOfComponents()!=2)
9067 throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : input DataArrayInt instance should have 2 components !");
9069 if(getNumberOfComponents()!=1)
9070 throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : this should have only one component !");
9071 int nbTuples=getNumberOfTuples();
9072 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
9073 int nbOfRanges=ranges->getNumberOfTuples();
9074 const int *rangesPtr=ranges->getConstPointer();
9075 int *retPtr=ret->getPointer();
9076 const int *inPtr=getConstPointer();
9077 for(int i=0;i<nbTuples;i++,retPtr++)
9081 for(int j=0;j<nbOfRanges && !found;j++)
9082 if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
9083 { *retPtr=val-rangesPtr[2*j]; found=true; }
9088 std::ostringstream oss; oss << "DataArrayInt::findIdInRangeForEachTuple : tuple #" << i << " not found by any ranges !";
9089 throw INTERP_KERNEL::Exception(oss.str().c_str());
9097 * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
9098 * \a nbTimes should be at least equal to 1.
9099 * \return a newly allocated DataArrayInt having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
9100 * \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.
9102 DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
9105 if(getNumberOfComponents()!=1)
9106 throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !");
9108 throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : nb times should be >= 1 !");
9109 int nbTuples=getNumberOfTuples();
9110 const int *inPtr=getConstPointer();
9111 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTimes*nbTuples,1);
9112 int *retPtr=ret->getPointer();
9113 for(int i=0;i<nbTuples;i++,inPtr++)
9116 for(int j=0;j<nbTimes;j++,retPtr++)
9119 ret->copyStringInfoFrom(*this);
9124 * This method returns all different values found in \a this. This method throws if \a this has not been allocated.
9125 * But the number of components can be different from one.
9126 * \return a newly allocated array (that should be dealt by the caller) containing different values in \a this.
9128 DataArrayInt *DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception)
9132 ret.insert(begin(),end());
9133 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=DataArrayInt::New(); ret2->alloc((int)ret.size(),1);
9134 std::copy(ret.begin(),ret.end(),ret2->getPointer());
9139 * This method is a refinement of DataArrayInt::getDifferentValues because it returns not only different values in \a this but also, for each of
9140 * them it tells which tuple id have this id.
9141 * This method works only on arrays with one component (if it is not the case call DataArrayInt::rearrange(1) ).
9142 * This method returns two arrays having same size.
9143 * The instances of DataArrayInt in the returned vector have be specially allocated and computed by this method. Each of them should be dealt by the caller of this method.
9144 * Example : if this is equal to [1,0,1,2,0,2,2,-3,2] -> differentIds=[-3,0,1,2] and returned array will be equal to [[7],[1,4],[0,2],[3,5,6,8]]
9146 std::vector<DataArrayInt *> DataArrayInt::partitionByDifferentValues(std::vector<int>& differentIds) const throw(INTERP_KERNEL::Exception)
9149 if(getNumberOfComponents()!=1)
9150 throw INTERP_KERNEL::Exception("DataArrayInt::partitionByDifferentValues : this should have only one component !");
9152 std::map<int,int> m,m2,m3;
9153 for(const int *w=begin();w!=end();w++)
9155 differentIds.resize(m.size());
9156 std::vector<DataArrayInt *> ret(m.size());
9157 std::vector<int *> retPtr(m.size());
9158 for(std::map<int,int>::const_iterator it=m.begin();it!=m.end();it++,id++)
9161 ret[id]=DataArrayInt::New();
9162 ret[id]->alloc((*it).second,1);
9163 retPtr[id]=ret[id]->getPointer();
9164 differentIds[id]=(*it).first;
9167 for(const int *w=begin();w!=end();w++,id++)
9169 retPtr[m2[*w]][m3[*w]++]=id;
9175 * Returns a new DataArrayInt that is a sum of two given arrays. There are 3
9177 * 1. The arrays have same number of tuples and components. Then each value of
9178 * the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
9179 * i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
9180 * 2. The arrays have same number of tuples and one array, say _a2_, has one
9182 * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
9183 * 3. The arrays have same number of components and one array, say _a2_, has one
9185 * _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
9187 * Info on components is copied either from the first array (in the first case) or from
9188 * the array with maximal number of elements (getNbOfElems()).
9189 * \param [in] a1 - an array to sum up.
9190 * \param [in] a2 - another array to sum up.
9191 * \return DataArrayInt * - the new instance of DataArrayInt.
9192 * The caller is to delete this result array using decrRef() as it is no more
9194 * \throw If either \a a1 or \a a2 is NULL.
9195 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9196 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9197 * none of them has number of tuples or components equal to 1.
9199 DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9202 throw INTERP_KERNEL::Exception("DataArrayInt::Add : input DataArrayInt instance is NULL !");
9203 int nbOfTuple=a1->getNumberOfTuples();
9204 int nbOfTuple2=a2->getNumberOfTuples();
9205 int nbOfComp=a1->getNumberOfComponents();
9206 int nbOfComp2=a2->getNumberOfComponents();
9207 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=0;
9208 if(nbOfTuple==nbOfTuple2)
9210 if(nbOfComp==nbOfComp2)
9212 ret=DataArrayInt::New();
9213 ret->alloc(nbOfTuple,nbOfComp);
9214 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<int>());
9215 ret->copyStringInfoFrom(*a1);
9219 int nbOfCompMin,nbOfCompMax;
9220 const DataArrayInt *aMin, *aMax;
9221 if(nbOfComp>nbOfComp2)
9223 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
9228 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
9233 ret=DataArrayInt::New();
9234 ret->alloc(nbOfTuple,nbOfCompMax);
9235 const int *aMinPtr=aMin->getConstPointer();
9236 const int *aMaxPtr=aMax->getConstPointer();
9237 int *res=ret->getPointer();
9238 for(int i=0;i<nbOfTuple;i++)
9239 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<int>(),aMinPtr[i]));
9240 ret->copyStringInfoFrom(*aMax);
9243 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
9246 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
9248 if(nbOfComp==nbOfComp2)
9250 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
9251 const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
9252 const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
9253 const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
9254 ret=DataArrayInt::New();
9255 ret->alloc(nbOfTupleMax,nbOfComp);
9256 int *res=ret->getPointer();
9257 for(int i=0;i<nbOfTupleMax;i++)
9258 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<int>());
9259 ret->copyStringInfoFrom(*aMax);
9262 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
9265 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
9270 * Adds values of another DataArrayInt to values of \a this one. There are 3
9272 * 1. The arrays have same number of tuples and components. Then each value of
9273 * \a other array is added to the corresponding value of \a this array, i.e.:
9274 * _a_ [ i, j ] += _other_ [ i, j ].
9275 * 2. The arrays have same number of tuples and \a other array has one component. Then
9276 * _a_ [ i, j ] += _other_ [ i, 0 ].
9277 * 3. The arrays have same number of components and \a other array has one tuple. Then
9278 * _a_ [ i, j ] += _a2_ [ 0, j ].
9280 * \param [in] other - an array to add to \a this one.
9281 * \throw If \a other is NULL.
9282 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9283 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9284 * \a other has number of both tuples and components not equal to 1.
9286 void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9289 throw INTERP_KERNEL::Exception("DataArrayInt::addEqual : input DataArrayInt instance is NULL !");
9290 const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual !";
9291 checkAllocated(); other->checkAllocated();
9292 int nbOfTuple=getNumberOfTuples();
9293 int nbOfTuple2=other->getNumberOfTuples();
9294 int nbOfComp=getNumberOfComponents();
9295 int nbOfComp2=other->getNumberOfComponents();
9296 if(nbOfTuple==nbOfTuple2)
9298 if(nbOfComp==nbOfComp2)
9300 std::transform(begin(),end(),other->begin(),getPointer(),std::plus<int>());
9302 else if(nbOfComp2==1)
9304 int *ptr=getPointer();
9305 const int *ptrc=other->getConstPointer();
9306 for(int i=0;i<nbOfTuple;i++)
9307 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<int>(),*ptrc++));
9310 throw INTERP_KERNEL::Exception(msg);
9312 else if(nbOfTuple2==1)
9314 if(nbOfComp2==nbOfComp)
9316 int *ptr=getPointer();
9317 const int *ptrc=other->getConstPointer();
9318 for(int i=0;i<nbOfTuple;i++)
9319 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<int>());
9322 throw INTERP_KERNEL::Exception(msg);
9325 throw INTERP_KERNEL::Exception(msg);
9330 * Returns a new DataArrayInt that is a subtraction of two given arrays. There are 3
9332 * 1. The arrays have same number of tuples and components. Then each value of
9333 * the result array (_a_) is a subtraction of the corresponding values of \a a1 and
9334 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
9335 * 2. The arrays have same number of tuples and one array, say _a2_, has one
9337 * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
9338 * 3. The arrays have same number of components and one array, say _a2_, has one
9340 * _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
9342 * Info on components is copied either from the first array (in the first case) or from
9343 * the array with maximal number of elements (getNbOfElems()).
9344 * \param [in] a1 - an array to subtract from.
9345 * \param [in] a2 - an array to subtract.
9346 * \return DataArrayInt * - the new instance of DataArrayInt.
9347 * The caller is to delete this result array using decrRef() as it is no more
9349 * \throw If either \a a1 or \a a2 is NULL.
9350 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9351 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9352 * none of them has number of tuples or components equal to 1.
9354 DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9357 throw INTERP_KERNEL::Exception("DataArrayInt::Substract : input DataArrayInt instance is NULL !");
9358 int nbOfTuple1=a1->getNumberOfTuples();
9359 int nbOfTuple2=a2->getNumberOfTuples();
9360 int nbOfComp1=a1->getNumberOfComponents();
9361 int nbOfComp2=a2->getNumberOfComponents();
9362 if(nbOfTuple2==nbOfTuple1)
9364 if(nbOfComp1==nbOfComp2)
9366 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9367 ret->alloc(nbOfTuple2,nbOfComp1);
9368 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<int>());
9369 ret->copyStringInfoFrom(*a1);
9372 else if(nbOfComp2==1)
9374 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9375 ret->alloc(nbOfTuple1,nbOfComp1);
9376 const int *a2Ptr=a2->getConstPointer();
9377 const int *a1Ptr=a1->getConstPointer();
9378 int *res=ret->getPointer();
9379 for(int i=0;i<nbOfTuple1;i++)
9380 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<int>(),a2Ptr[i]));
9381 ret->copyStringInfoFrom(*a1);
9386 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
9390 else if(nbOfTuple2==1)
9392 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
9393 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9394 ret->alloc(nbOfTuple1,nbOfComp1);
9395 const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
9396 int *pt=ret->getPointer();
9397 for(int i=0;i<nbOfTuple1;i++)
9398 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<int>());
9399 ret->copyStringInfoFrom(*a1);
9404 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
9410 * Subtract values of another DataArrayInt from values of \a this one. There are 3
9412 * 1. The arrays have same number of tuples and components. Then each value of
9413 * \a other array is subtracted from the corresponding value of \a this array, i.e.:
9414 * _a_ [ i, j ] -= _other_ [ i, j ].
9415 * 2. The arrays have same number of tuples and \a other array has one component. Then
9416 * _a_ [ i, j ] -= _other_ [ i, 0 ].
9417 * 3. The arrays have same number of components and \a other array has one tuple. Then
9418 * _a_ [ i, j ] -= _a2_ [ 0, j ].
9420 * \param [in] other - an array to subtract from \a this one.
9421 * \throw If \a other is NULL.
9422 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9423 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9424 * \a other has number of both tuples and components not equal to 1.
9426 void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9429 throw INTERP_KERNEL::Exception("DataArrayInt::substractEqual : input DataArrayInt instance is NULL !");
9430 const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual !";
9431 checkAllocated(); other->checkAllocated();
9432 int nbOfTuple=getNumberOfTuples();
9433 int nbOfTuple2=other->getNumberOfTuples();
9434 int nbOfComp=getNumberOfComponents();
9435 int nbOfComp2=other->getNumberOfComponents();
9436 if(nbOfTuple==nbOfTuple2)
9438 if(nbOfComp==nbOfComp2)
9440 std::transform(begin(),end(),other->begin(),getPointer(),std::minus<int>());
9442 else if(nbOfComp2==1)
9444 int *ptr=getPointer();
9445 const int *ptrc=other->getConstPointer();
9446 for(int i=0;i<nbOfTuple;i++)
9447 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<int>(),*ptrc++));
9450 throw INTERP_KERNEL::Exception(msg);
9452 else if(nbOfTuple2==1)
9454 int *ptr=getPointer();
9455 const int *ptrc=other->getConstPointer();
9456 for(int i=0;i<nbOfTuple;i++)
9457 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<int>());
9460 throw INTERP_KERNEL::Exception(msg);
9465 * Returns a new DataArrayInt that is a product of two given arrays. There are 3
9467 * 1. The arrays have same number of tuples and components. Then each value of
9468 * the result array (_a_) is a product of the corresponding values of \a a1 and
9469 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
9470 * 2. The arrays have same number of tuples and one array, say _a2_, has one
9472 * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
9473 * 3. The arrays have same number of components and one array, say _a2_, has one
9475 * _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
9477 * Info on components is copied either from the first array (in the first case) or from
9478 * the array with maximal number of elements (getNbOfElems()).
9479 * \param [in] a1 - a factor array.
9480 * \param [in] a2 - another factor array.
9481 * \return DataArrayInt * - the new instance of DataArrayInt.
9482 * The caller is to delete this result array using decrRef() as it is no more
9484 * \throw If either \a a1 or \a a2 is NULL.
9485 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9486 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9487 * none of them has number of tuples or components equal to 1.
9489 DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9492 throw INTERP_KERNEL::Exception("DataArrayInt::Multiply : input DataArrayInt instance is NULL !");
9493 int nbOfTuple=a1->getNumberOfTuples();
9494 int nbOfTuple2=a2->getNumberOfTuples();
9495 int nbOfComp=a1->getNumberOfComponents();
9496 int nbOfComp2=a2->getNumberOfComponents();
9497 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=0;
9498 if(nbOfTuple==nbOfTuple2)
9500 if(nbOfComp==nbOfComp2)
9502 ret=DataArrayInt::New();
9503 ret->alloc(nbOfTuple,nbOfComp);
9504 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<int>());
9505 ret->copyStringInfoFrom(*a1);
9509 int nbOfCompMin,nbOfCompMax;
9510 const DataArrayInt *aMin, *aMax;
9511 if(nbOfComp>nbOfComp2)
9513 nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
9518 nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
9523 ret=DataArrayInt::New();
9524 ret->alloc(nbOfTuple,nbOfCompMax);
9525 const int *aMinPtr=aMin->getConstPointer();
9526 const int *aMaxPtr=aMax->getConstPointer();
9527 int *res=ret->getPointer();
9528 for(int i=0;i<nbOfTuple;i++)
9529 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<int>(),aMinPtr[i]));
9530 ret->copyStringInfoFrom(*aMax);
9533 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
9536 else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
9538 if(nbOfComp==nbOfComp2)
9540 int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
9541 const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
9542 const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
9543 const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
9544 ret=DataArrayInt::New();
9545 ret->alloc(nbOfTupleMax,nbOfComp);
9546 int *res=ret->getPointer();
9547 for(int i=0;i<nbOfTupleMax;i++)
9548 res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<int>());
9549 ret->copyStringInfoFrom(*aMax);
9552 throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
9555 throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
9561 * Multiply values of another DataArrayInt to values of \a this one. There are 3
9563 * 1. The arrays have same number of tuples and components. Then each value of
9564 * \a other array is multiplied to the corresponding value of \a this array, i.e.:
9565 * _a_ [ i, j ] *= _other_ [ i, j ].
9566 * 2. The arrays have same number of tuples and \a other array has one component. Then
9567 * _a_ [ i, j ] *= _other_ [ i, 0 ].
9568 * 3. The arrays have same number of components and \a other array has one tuple. Then
9569 * _a_ [ i, j ] *= _a2_ [ 0, j ].
9571 * \param [in] other - an array to multiply to \a this one.
9572 * \throw If \a other is NULL.
9573 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9574 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9575 * \a other has number of both tuples and components not equal to 1.
9577 void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9580 throw INTERP_KERNEL::Exception("DataArrayInt::multiplyEqual : input DataArrayInt instance is NULL !");
9581 const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !";
9582 checkAllocated(); other->checkAllocated();
9583 int nbOfTuple=getNumberOfTuples();
9584 int nbOfTuple2=other->getNumberOfTuples();
9585 int nbOfComp=getNumberOfComponents();
9586 int nbOfComp2=other->getNumberOfComponents();
9587 if(nbOfTuple==nbOfTuple2)
9589 if(nbOfComp==nbOfComp2)
9591 std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<int>());
9593 else if(nbOfComp2==1)
9595 int *ptr=getPointer();
9596 const int *ptrc=other->getConstPointer();
9597 for(int i=0;i<nbOfTuple;i++)
9598 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<int>(),*ptrc++));
9601 throw INTERP_KERNEL::Exception(msg);
9603 else if(nbOfTuple2==1)
9605 if(nbOfComp2==nbOfComp)
9607 int *ptr=getPointer();
9608 const int *ptrc=other->getConstPointer();
9609 for(int i=0;i<nbOfTuple;i++)
9610 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<int>());
9613 throw INTERP_KERNEL::Exception(msg);
9616 throw INTERP_KERNEL::Exception(msg);
9622 * Returns a new DataArrayInt that is a division of two given arrays. There are 3
9624 * 1. The arrays have same number of tuples and components. Then each value of
9625 * the result array (_a_) is a division of the corresponding values of \a a1 and
9626 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
9627 * 2. The arrays have same number of tuples and one array, say _a2_, has one
9629 * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
9630 * 3. The arrays have same number of components and one array, say _a2_, has one
9632 * _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
9634 * Info on components is copied either from the first array (in the first case) or from
9635 * the array with maximal number of elements (getNbOfElems()).
9636 * \param [in] a1 - a numerator array.
9637 * \param [in] a2 - a denominator array.
9638 * \return DataArrayInt * - the new instance of DataArrayInt.
9639 * The caller is to delete this result array using decrRef() as it is no more
9641 * \throw If either \a a1 or \a a2 is NULL.
9642 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9643 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9644 * none of them has number of tuples or components equal to 1.
9645 * \warning No check of division by zero is performed!
9647 DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9650 throw INTERP_KERNEL::Exception("DataArrayInt::Divide : input DataArrayInt instance is NULL !");
9651 int nbOfTuple1=a1->getNumberOfTuples();
9652 int nbOfTuple2=a2->getNumberOfTuples();
9653 int nbOfComp1=a1->getNumberOfComponents();
9654 int nbOfComp2=a2->getNumberOfComponents();
9655 if(nbOfTuple2==nbOfTuple1)
9657 if(nbOfComp1==nbOfComp2)
9659 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9660 ret->alloc(nbOfTuple2,nbOfComp1);
9661 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<int>());
9662 ret->copyStringInfoFrom(*a1);
9665 else if(nbOfComp2==1)
9667 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9668 ret->alloc(nbOfTuple1,nbOfComp1);
9669 const int *a2Ptr=a2->getConstPointer();
9670 const int *a1Ptr=a1->getConstPointer();
9671 int *res=ret->getPointer();
9672 for(int i=0;i<nbOfTuple1;i++)
9673 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<int>(),a2Ptr[i]));
9674 ret->copyStringInfoFrom(*a1);
9679 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
9683 else if(nbOfTuple2==1)
9685 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
9686 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9687 ret->alloc(nbOfTuple1,nbOfComp1);
9688 const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
9689 int *pt=ret->getPointer();
9690 for(int i=0;i<nbOfTuple1;i++)
9691 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<int>());
9692 ret->copyStringInfoFrom(*a1);
9697 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
9703 * Divide values of \a this array by values of another DataArrayInt. There are 3
9705 * 1. The arrays have same number of tuples and components. Then each value of
9706 * \a this array is divided by the corresponding value of \a other one, i.e.:
9707 * _a_ [ i, j ] /= _other_ [ i, j ].
9708 * 2. The arrays have same number of tuples and \a other array has one component. Then
9709 * _a_ [ i, j ] /= _other_ [ i, 0 ].
9710 * 3. The arrays have same number of components and \a other array has one tuple. Then
9711 * _a_ [ i, j ] /= _a2_ [ 0, j ].
9713 * \param [in] other - an array to divide \a this one by.
9714 * \throw If \a other is NULL.
9715 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9716 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9717 * \a other has number of both tuples and components not equal to 1.
9718 * \warning No check of division by zero is performed!
9720 void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9723 throw INTERP_KERNEL::Exception("DataArrayInt::divideEqual : input DataArrayInt instance is NULL !");
9724 const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !";
9725 checkAllocated(); other->checkAllocated();
9726 int nbOfTuple=getNumberOfTuples();
9727 int nbOfTuple2=other->getNumberOfTuples();
9728 int nbOfComp=getNumberOfComponents();
9729 int nbOfComp2=other->getNumberOfComponents();
9730 if(nbOfTuple==nbOfTuple2)
9732 if(nbOfComp==nbOfComp2)
9734 std::transform(begin(),end(),other->begin(),getPointer(),std::divides<int>());
9736 else if(nbOfComp2==1)
9738 int *ptr=getPointer();
9739 const int *ptrc=other->getConstPointer();
9740 for(int i=0;i<nbOfTuple;i++)
9741 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<int>(),*ptrc++));
9744 throw INTERP_KERNEL::Exception(msg);
9746 else if(nbOfTuple2==1)
9748 if(nbOfComp2==nbOfComp)
9750 int *ptr=getPointer();
9751 const int *ptrc=other->getConstPointer();
9752 for(int i=0;i<nbOfTuple;i++)
9753 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<int>());
9756 throw INTERP_KERNEL::Exception(msg);
9759 throw INTERP_KERNEL::Exception(msg);
9765 * Returns a new DataArrayInt that is a modulus of two given arrays. There are 3
9767 * 1. The arrays have same number of tuples and components. Then each value of
9768 * the result array (_a_) is a division of the corresponding values of \a a1 and
9769 * \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ i, j ].
9770 * 2. The arrays have same number of tuples and one array, say _a2_, has one
9772 * _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ i, 0 ].
9773 * 3. The arrays have same number of components and one array, say _a2_, has one
9775 * _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ 0, j ].
9777 * Info on components is copied either from the first array (in the first case) or from
9778 * the array with maximal number of elements (getNbOfElems()).
9779 * \param [in] a1 - a dividend array.
9780 * \param [in] a2 - a divisor array.
9781 * \return DataArrayInt * - the new instance of DataArrayInt.
9782 * The caller is to delete this result array using decrRef() as it is no more
9784 * \throw If either \a a1 or \a a2 is NULL.
9785 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9786 * \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9787 * none of them has number of tuples or components equal to 1.
9788 * \warning No check of division by zero is performed!
9790 DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9793 throw INTERP_KERNEL::Exception("DataArrayInt::Modulus : input DataArrayInt instance is NULL !");
9794 int nbOfTuple1=a1->getNumberOfTuples();
9795 int nbOfTuple2=a2->getNumberOfTuples();
9796 int nbOfComp1=a1->getNumberOfComponents();
9797 int nbOfComp2=a2->getNumberOfComponents();
9798 if(nbOfTuple2==nbOfTuple1)
9800 if(nbOfComp1==nbOfComp2)
9802 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9803 ret->alloc(nbOfTuple2,nbOfComp1);
9804 std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::modulus<int>());
9805 ret->copyStringInfoFrom(*a1);
9808 else if(nbOfComp2==1)
9810 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9811 ret->alloc(nbOfTuple1,nbOfComp1);
9812 const int *a2Ptr=a2->getConstPointer();
9813 const int *a1Ptr=a1->getConstPointer();
9814 int *res=ret->getPointer();
9815 for(int i=0;i<nbOfTuple1;i++)
9816 res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::modulus<int>(),a2Ptr[i]));
9817 ret->copyStringInfoFrom(*a1);
9822 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
9826 else if(nbOfTuple2==1)
9828 a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
9829 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9830 ret->alloc(nbOfTuple1,nbOfComp1);
9831 const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
9832 int *pt=ret->getPointer();
9833 for(int i=0;i<nbOfTuple1;i++)
9834 pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::modulus<int>());
9835 ret->copyStringInfoFrom(*a1);
9840 a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Modulus !");//will always throw an exception
9846 * Modify \a this array so that each value becomes a modulus of division of this value by
9847 * a value of another DataArrayInt. There are 3 valid cases.
9848 * 1. The arrays have same number of tuples and components. Then each value of
9849 * \a this array is divided by the corresponding value of \a other one, i.e.:
9850 * _a_ [ i, j ] %= _other_ [ i, j ].
9851 * 2. The arrays have same number of tuples and \a other array has one component. Then
9852 * _a_ [ i, j ] %= _other_ [ i, 0 ].
9853 * 3. The arrays have same number of components and \a other array has one tuple. Then
9854 * _a_ [ i, j ] %= _a2_ [ 0, j ].
9856 * \param [in] other - a divisor array.
9857 * \throw If \a other is NULL.
9858 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9859 * \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9860 * \a other has number of both tuples and components not equal to 1.
9861 * \warning No check of division by zero is performed!
9863 void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9866 throw INTERP_KERNEL::Exception("DataArrayInt::modulusEqual : input DataArrayInt instance is NULL !");
9867 const char *msg="Nb of tuples mismatch for DataArrayInt::modulusEqual !";
9868 checkAllocated(); other->checkAllocated();
9869 int nbOfTuple=getNumberOfTuples();
9870 int nbOfTuple2=other->getNumberOfTuples();
9871 int nbOfComp=getNumberOfComponents();
9872 int nbOfComp2=other->getNumberOfComponents();
9873 if(nbOfTuple==nbOfTuple2)
9875 if(nbOfComp==nbOfComp2)
9877 std::transform(begin(),end(),other->begin(),getPointer(),std::modulus<int>());
9879 else if(nbOfComp2==1)
9881 if(nbOfComp2==nbOfComp)
9883 int *ptr=getPointer();
9884 const int *ptrc=other->getConstPointer();
9885 for(int i=0;i<nbOfTuple;i++)
9886 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::modulus<int>(),*ptrc++));
9889 throw INTERP_KERNEL::Exception(msg);
9892 throw INTERP_KERNEL::Exception(msg);
9894 else if(nbOfTuple2==1)
9896 int *ptr=getPointer();
9897 const int *ptrc=other->getConstPointer();
9898 for(int i=0;i<nbOfTuple;i++)
9899 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::modulus<int>());
9902 throw INTERP_KERNEL::Exception(msg);
9907 * Returns a new DataArrayInt that is the result of pow of two given arrays. There are 3
9910 * \param [in] a1 - an array to pow up.
9911 * \param [in] a2 - another array to sum up.
9912 * \return DataArrayInt * - the new instance of DataArrayInt.
9913 * The caller is to delete this result array using decrRef() as it is no more
9915 * \throw If either \a a1 or \a a2 is NULL.
9916 * \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
9917 * \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
9918 * \throw If there is a negative value in \a a2.
9920 DataArrayInt *DataArrayInt::Pow(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9923 throw INTERP_KERNEL::Exception("DataArrayInt::Pow : at least one of input instances is null !");
9924 int nbOfTuple=a1->getNumberOfTuples();
9925 int nbOfTuple2=a2->getNumberOfTuples();
9926 int nbOfComp=a1->getNumberOfComponents();
9927 int nbOfComp2=a2->getNumberOfComponents();
9928 if(nbOfTuple!=nbOfTuple2)
9929 throw INTERP_KERNEL::Exception("DataArrayInt::Pow : number of tuples mismatches !");
9930 if(nbOfComp!=1 || nbOfComp2!=1)
9931 throw INTERP_KERNEL::Exception("DataArrayInt::Pow : number of components of both arrays must be equal to 1 !");
9932 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuple,1);
9933 const int *ptr1(a1->begin()),*ptr2(a2->begin());
9934 int *ptr=ret->getPointer();
9935 for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
9940 for(int j=0;j<*ptr2;j++)
9946 std::ostringstream oss; oss << "DataArrayInt::Pow : on tuple #" << i << " of a2 value is < 0 (" << *ptr2 << ") !";
9947 throw INTERP_KERNEL::Exception(oss.str().c_str());
9954 * Apply pow on values of another DataArrayInt to values of \a this one.
9956 * \param [in] other - an array to pow to \a this one.
9957 * \throw If \a other is NULL.
9958 * \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
9959 * \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
9960 * \throw If there is a negative value in \a other.
9962 void DataArrayInt::powEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9965 throw INTERP_KERNEL::Exception("DataArrayInt::powEqual : input instance is null !");
9966 int nbOfTuple=getNumberOfTuples();
9967 int nbOfTuple2=other->getNumberOfTuples();
9968 int nbOfComp=getNumberOfComponents();
9969 int nbOfComp2=other->getNumberOfComponents();
9970 if(nbOfTuple!=nbOfTuple2)
9971 throw INTERP_KERNEL::Exception("DataArrayInt::powEqual : number of tuples mismatches !");
9972 if(nbOfComp!=1 || nbOfComp2!=1)
9973 throw INTERP_KERNEL::Exception("DataArrayInt::powEqual : number of components of both arrays must be equal to 1 !");
9974 int *ptr=getPointer();
9975 const int *ptrc=other->begin();
9976 for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
9981 for(int j=0;j<*ptrc;j++)
9987 std::ostringstream oss; oss << "DataArrayInt::powEqual : on tuple #" << i << " of other value is < 0 (" << *ptrc << ") !";
9988 throw INTERP_KERNEL::Exception(oss.str().c_str());
9995 * Returns a C array which is a renumbering map in "Old to New" mode for the input array.
9996 * This map, if applied to \a start array, would make it sorted. For example, if
9997 * \a start array contents are [9,10,0,6,4,11,3,7] then the contents of the result array is
9998 * [5,6,0,3,2,7,1,4].
9999 * \param [in] start - pointer to the first element of the array for which the
10000 * permutation map is computed.
10001 * \param [in] end - pointer specifying the end of the array \a start, so that
10002 * the last value of \a start is \a end[ -1 ].
10003 * \return int * - the result permutation array that the caller is to delete as it is no
10005 * \throw If there are equal values in the input array.
10007 int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end)
10009 std::size_t sz=std::distance(start,end);
10010 int *ret=new int[sz];
10011 int *work=new int[sz];
10012 std::copy(start,end,work);
10013 std::sort(work,work+sz);
10014 if(std::unique(work,work+sz)!=work+sz)
10018 throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
10021 for(const int *iter=start;iter!=end;iter++,iter2++)
10022 *iter2=(int)std::distance(work,std::find(work,work+sz,*iter));
10028 * Returns a new DataArrayInt containing an arithmetic progression
10029 * that is equal to the sequence returned by Python \c range(\a begin,\a end,\a step )
10031 * \param [in] begin - the start value of the result sequence.
10032 * \param [in] end - limiting value, so that every value of the result array is less than
10034 * \param [in] step - specifies the increment or decrement.
10035 * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
10036 * array using decrRef() as it is no more needed.
10037 * \throw If \a step == 0.
10038 * \throw If \a end < \a begin && \a step > 0.
10039 * \throw If \a end > \a begin && \a step < 0.
10041 DataArrayInt *DataArrayInt::Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception)
10043 int nbOfTuples=GetNumberOfItemGivenBESRelative(begin,end,step,"DataArrayInt::Range");
10044 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10045 ret->alloc(nbOfTuples,1);
10046 int *ptr=ret->getPointer();
10049 for(int i=begin;i<end;i+=step,ptr++)
10054 for(int i=begin;i>end;i+=step,ptr++)
10061 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10064 void DataArrayInt::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
10066 tinyInfo.resize(2);
10069 tinyInfo[0]=getNumberOfTuples();
10070 tinyInfo[1]=getNumberOfComponents();
10080 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10083 void DataArrayInt::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
10087 int nbOfCompo=getNumberOfComponents();
10088 tinyInfo.resize(nbOfCompo+1);
10089 tinyInfo[0]=getName();
10090 for(int i=0;i<nbOfCompo;i++)
10091 tinyInfo[i+1]=getInfoOnComponent(i);
10095 tinyInfo.resize(1);
10096 tinyInfo[0]=getName();
10101 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10102 * This method returns if a feeding is needed.
10104 bool DataArrayInt::resizeForUnserialization(const std::vector<int>& tinyInfoI)
10106 int nbOfTuple=tinyInfoI[0];
10107 int nbOfComp=tinyInfoI[1];
10108 if(nbOfTuple!=-1 || nbOfComp!=-1)
10110 alloc(nbOfTuple,nbOfComp);
10117 * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10118 * This method returns if a feeding is needed.
10120 void DataArrayInt::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
10122 setName(tinyInfoS[0].c_str());
10125 int nbOfCompo=getNumberOfComponents();
10126 for(int i=0;i<nbOfCompo;i++)
10127 setInfoOnComponent(i,tinyInfoS[i+1].c_str());
10131 DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
10136 if(_da->isAllocated())
10138 _nb_comp=da->getNumberOfComponents();
10139 _nb_tuple=da->getNumberOfTuples();
10140 _pt=da->getPointer();
10145 DataArrayIntIterator::~DataArrayIntIterator()
10151 DataArrayIntTuple *DataArrayIntIterator::nextt() throw(INTERP_KERNEL::Exception)
10153 if(_tuple_id<_nb_tuple)
10156 DataArrayIntTuple *ret=new DataArrayIntTuple(_pt,_nb_comp);
10164 DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
10168 std::string DataArrayIntTuple::repr() const throw(INTERP_KERNEL::Exception)
10170 std::ostringstream oss; oss << "(";
10171 for(int i=0;i<_nb_of_compo-1;i++)
10172 oss << _pt[i] << ", ";
10173 oss << _pt[_nb_of_compo-1] << ")";
10177 int DataArrayIntTuple::intValue() const throw(INTERP_KERNEL::Exception)
10179 if(_nb_of_compo==1)
10181 throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
10185 * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayInt::decrRef.
10186 * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayInt::useArray with ownership set to \b false.
10187 * 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
10188 * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
10190 DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
10192 if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
10194 DataArrayInt *ret=DataArrayInt::New();
10195 ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
10200 std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
10201 oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
10202 throw INTERP_KERNEL::Exception(oss.str().c_str());