Salome HOME
7e146a3bd3f05804988ce1fc8f158714d91d1787
[modules/med.git] / src / MEDCoupling / MEDCouplingMemArray.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCouplingMemArray.txx"
22 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
23
24 #include "GenMathFormulae.hxx"
25 #include "InterpKernelExprParser.hxx"
26
27 #include <set>
28 #include <cmath>
29 #include <limits>
30 #include <numeric>
31 #include <algorithm>
32 #include <functional>
33
34 typedef double (*MYFUNCPTR)(double);
35
36 using namespace ParaMEDMEM;
37
38 template<int SPACEDIM>
39 void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
40 {
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++)
45     {
46       if(!isDone[i])
47         {
48           std::vector<int> intersectingElems;
49           myTree.getElementsAroundPoint(coordsPtr+i*SPACEDIM,intersectingElems);
50           if(intersectingElems.size()>1)
51             {
52               std::vector<int> commonNodes;
53               for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
54                 if(*it!=i)
55                   if(*it>=limitNodeId)
56                     {
57                       commonNodes.push_back(*it);
58                       isDone[*it]=true;
59                     }
60               if(!commonNodes.empty())
61                 {
62                   cI->pushBackSilent(cI->back()+(int)commonNodes.size()+1);
63                   c->pushBackSilent(i);
64                   c->insertAtTheEnd(commonNodes.begin(),commonNodes.end());
65                 }
66             }
67         }
68     }
69 }
70
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)
74 {
75   for(int i=0;i<nbOfTuples;i++)
76     {
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());
84     }
85 }
86
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)
89 {
90   double distOpt(dist);
91   const double *p(pos);
92   int *r(res);
93   for(int i=0;i<nbOfTuples;i++,p+=SPACEDIM,r++)
94     {
95       while(true)
96         {
97           int elem=-1;
98           double ret=myTree.getElementsAroundPoint2(p,distOpt,elem);
99           if(ret!=std::numeric_limits<double>::max())
100             {
101               distOpt=std::max(ret,1e-4);
102               *r=elem;
103               break;
104             }
105           else
106             { distOpt=2*distOpt; continue; }
107         }
108     }
109 }
110
111 std::size_t DataArray::getHeapMemorySize() const
112 {
113   std::size_t sz1=_name.capacity();
114   std::size_t sz2=_info_on_compo.capacity();
115   std::size_t sz3=0;
116   for(std::vector<std::string>::const_iterator it=_info_on_compo.begin();it!=_info_on_compo.end();it++)
117     sz3+=(*it).capacity();
118   return sz1+sz2+sz3;
119 }
120
121 /*!
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
125  */
126 void DataArray::setName(const char *name)
127 {
128   _name=name;
129 }
130
131 /*!
132  * Copies textual data from an \a other DataArray. The copied data are
133  * - the name attribute,
134  * - the information of components.
135  *
136  * For more information on these data see \ref MEDCouplingArrayBasicsName "DataArrays infos".
137  *
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.
140  */
141 void DataArray::copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception)
142 {
143   if(_info_on_compo.size()!=other._info_on_compo.size())
144     throw INTERP_KERNEL::Exception("Size of arrays mismatches on copyStringInfoFrom !");
145   _name=other._name;
146   _info_on_compo=other._info_on_compo;
147 }
148
149 void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
150 {
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)
155       {
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());
158       }
159   for(std::size_t i=0;i<newNbOfCompo;i++)
160     setInfoOnComponent((int)i,other.getInfoOnComponent(compoIds[i]).c_str());
161 }
162
163 void DataArray::copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception)
164 {
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)
171       {
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());
174       }
175   for(std::size_t i=0;i<partOfCompoToSet;i++)
176     setInfoOnComponent(compoIds[i],other.getInfoOnComponent((int)i).c_str());
177 }
178
179 bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const throw(INTERP_KERNEL::Exception)
180 {
181   std::ostringstream oss;
182   if(_name!=other._name)
183     {
184       oss << "Names DataArray mismatch : this name=\"" << _name << " other name=\"" << other._name << "\" !";
185       reason=oss.str();
186       return false;
187     }
188   if(_info_on_compo!=other._info_on_compo)
189     {
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 << "\",";
196       reason=oss.str();
197       return false;
198     }
199   return true;
200 }
201
202 /*!
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.
207  *
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.
211  */
212 bool DataArray::areInfoEquals(const DataArray& other) const throw(INTERP_KERNEL::Exception)
213 {
214   std::string tmp;
215   return areInfoEqualsIfNotWhy(other,tmp);
216 }
217
218 void DataArray::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
219 {
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 << "\"   ";
224   stream << "\n";
225 }
226
227 std::string DataArray::cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception)
228 {
229   std::ostringstream ret;
230   reprCppStream(varName,ret);
231   return ret.str();
232 }
233
234 /*!
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.
239  */
240 void DataArray::setInfoOnComponents(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
241 {
242   if(getNumberOfComponents()!=(int)info.size())
243     {
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());
246     }
247   _info_on_compo=info;
248 }
249
250 std::vector<std::string> DataArray::getVarsOnComponent() const throw(INTERP_KERNEL::Exception)
251 {
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);
256   return ret;
257 }
258
259 std::vector<std::string> DataArray::getUnitsOnComponent() const throw(INTERP_KERNEL::Exception)
260 {
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);
265   return ret;
266 }
267
268 /*!
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.
275  */
276 std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
277 {
278   if(i<(int)_info_on_compo.size() && i>=0)
279     return _info_on_compo[i];
280   else
281     {
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());
284     }
285 }
286
287 /*!
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.
298  */
299 std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception)
300 {
301   if(i<(int)_info_on_compo.size() && i>=0)
302     {
303       return GetVarNameFromInfo(_info_on_compo[i]);
304     }
305   else
306     {
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());
309     }
310 }
311
312 /*!
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.
323  */
324 std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception)
325 {
326   if(i<(int)_info_on_compo.size() && i>=0)
327     {
328       return GetUnitFromInfo(_info_on_compo[i]);
329     }
330   else
331     {
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());
334     }
335 }
336
337 /*!
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.
346  */
347 std::string DataArray::GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
348 {
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)
352     return info;
353   if(p1>p2)
354     return info;
355   if(p1==0)
356     return std::string();
357   std::size_t p3=info.find_last_not_of(' ',p1-1);
358   return info.substr(0,p3+1);
359 }
360
361 /*!
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 "".
370  */
371 std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
372 {
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();
377   if(p1>p2)
378     return std::string();
379   return info.substr(p1+1,p2-p1-1);
380 }
381
382 /*!
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!
390  */
391 void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
392 {
393   if(i<(int)_info_on_compo.size() && i>=0)
394     _info_on_compo[i]=info;
395   else
396     {
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());
399     }
400 }
401
402 void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception)
403 {
404   if(getNumberOfTuples()!=nbOfTuples)
405     {
406       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  nbOfTuples << " having " << getNumberOfTuples() << " !";
407       throw INTERP_KERNEL::Exception(oss.str().c_str());
408     }
409 }
410
411 void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
412 {
413   if(getNumberOfComponents()!=nbOfCompo)
414     {
415       std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
416       throw INTERP_KERNEL::Exception(oss.str().c_str());
417     }
418 }
419
420 void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception)
421 {
422   if(getNbOfElems()!=nbOfElems)
423     {
424       std::ostringstream oss; oss << msg << " : mismatch number of elems : Expected " << nbOfElems << " having " << getNbOfElems() << " !";
425       throw INTERP_KERNEL::Exception(oss.str().c_str());
426     }
427 }
428
429 void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception)
430 {
431    if(getNumberOfTuples()!=other.getNumberOfTuples())
432     {
433       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  other.getNumberOfTuples() << " having " << getNumberOfTuples() << " !";
434       throw INTERP_KERNEL::Exception(oss.str().c_str());
435     }
436   if(getNumberOfComponents()!=other.getNumberOfComponents())
437     {
438       std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << other.getNumberOfComponents() << " having " << getNumberOfComponents() << " !";
439       throw INTERP_KERNEL::Exception(oss.str().c_str());
440     }
441 }
442
443 void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
444 {
445   checkNbOfTuples(nbOfTuples,msg);
446   checkNbOfComps(nbOfCompo,msg);
447 }
448
449 /*!
450  * Simply this method checks that \b value is in [0,\b ref).
451  */
452 void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
453 {
454   if(value<0 || value>=ref)
455     {
456       std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg  << " ! Expected in range [0," << ref << "[ having " << value << " !";
457       throw INTERP_KERNEL::Exception(oss.str().c_str());
458     }
459 }
460
461 /*!
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.
464  */
465 void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception)
466 {
467   if(start<0 || start>=value)
468     {
469       if(value!=start || end!=start)
470         {
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());
473         }
474     }
475   if(end<0 || end>value)
476     {
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());
479     }
480 }
481
482 void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
483 {
484   if(value<0 || value>ref)
485     {
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());
488     }
489 }
490
491 int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
492 {
493   if(end<begin)
494     {
495       std::ostringstream oss; oss << msg << " : end before begin !";
496       throw INTERP_KERNEL::Exception(oss.str().c_str());
497     }
498   if(end==begin)
499     return 0;
500   if(step<=0)
501     {
502       std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
503       throw INTERP_KERNEL::Exception(oss.str().c_str());
504     }
505   return (end-1-begin)/step+1;
506 }
507
508 int DataArray::GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
509 {
510   if(step==0)
511     throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES : step=0 is not allowed !");
512   if(end<begin && step>0)
513     {
514       std::ostringstream oss; oss << msg << " : end before begin whereas step is positive !";
515       throw INTERP_KERNEL::Exception(oss.str().c_str());
516     }
517   if(begin<end && step<0)
518     {
519       std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
520       throw INTERP_KERNEL::Exception(oss.str().c_str());
521     }
522   if(begin!=end)
523     return (std::max(begin,end)-1-std::min(begin,end))/std::abs(step)+1;
524   else
525     return 0;
526 }
527
528 int DataArray::GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception)
529 {
530   if(step!=0)
531     {
532       if(step>0)
533         {
534           if(begin<=value && value<end)
535             {
536               if((value-begin)%step==0)
537                 return (value-begin)/step;
538               else
539                 return -1;
540             }
541           else
542             return -1;
543         }
544       else
545         {
546           if(begin>=value && value>end)
547             {
548               if((begin-value)%(-step)==0)
549                 return (begin-value)/(-step);
550               else
551                 return -1;
552             }
553           else
554             return -1;
555         }
556     }
557   else
558     return -1;
559 }
560
561 /*!
562  * Returns a new instance of DataArrayDouble. The caller is to delete this array
563  * using decrRef() as it is no more needed. 
564  */
565 DataArrayDouble *DataArrayDouble::New()
566 {
567   return new DataArrayDouble;
568 }
569
570 /*!
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.
574  */
575 bool DataArrayDouble::isAllocated() const throw(INTERP_KERNEL::Exception)
576 {
577   return getConstPointer()!=0;
578 }
579
580 /*!
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.
583  */
584 void DataArrayDouble::checkAllocated() const throw(INTERP_KERNEL::Exception)
585 {
586   if(!isAllocated())
587     throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
588 }
589
590 std::size_t DataArrayDouble::getHeapMemorySize() const
591 {
592   std::size_t sz=_mem.getNbOfElemAllocated();
593   sz*=sizeof(double);
594   return DataArray::getHeapMemorySize()+sz;
595 }
596
597 /*!
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.
601  *
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()
606  */
607 void DataArrayDouble::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
608 {
609   if(getNumberOfComponents()!=(int)info.size())
610     {
611       if(!isAllocated())
612         _info_on_compo=info;
613       else
614         {
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());
617         }
618     }
619   else
620     _info_on_compo=info;
621 }
622
623 /*!
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.
628  */
629 double DataArrayDouble::doubleValue() const throw(INTERP_KERNEL::Exception)
630 {
631   if(isAllocated())
632     {
633       if(getNbOfElems()==1)
634         {
635           return *getConstPointer();
636         }
637       else
638         throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is allocated but number of elements is not equal to 1 !");
639     }
640   else
641     throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is not allocated !");
642 }
643
644 /*!
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.
648  */
649 bool DataArrayDouble::empty() const throw(INTERP_KERNEL::Exception)
650 {
651   checkAllocated();
652   return getNumberOfTuples()==0;
653 }
654
655 /*!
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.
659  */
660 DataArrayDouble *DataArrayDouble::deepCpy() const throw(INTERP_KERNEL::Exception)
661 {
662   return new DataArrayDouble(*this);
663 }
664
665 /*!
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).
671  */
672 DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception)
673 {
674   if(dCpy)
675     return deepCpy();
676   else
677     {
678       incrRef();
679       return const_cast<DataArrayDouble *>(this);
680     }
681 }
682
683 /*!
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.
688  */
689 void DataArrayDouble::cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception)
690 {
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++)
699     pt[i]=ptI[i];
700   copyStringInfoFrom(other);
701 }
702
703 /*!
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.
708  * 
709  * \sa DataArrayDouble::pack, DataArrayDouble::pushBackSilent, DataArrayDouble::pushBackValsSilent
710  */
711 void DataArrayDouble::reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception)
712 {
713   int nbCompo=getNumberOfComponents();
714   if(nbCompo==1)
715     {
716       _mem.reserve(nbOfElems);
717     }
718   else if(nbCompo==0)
719     {
720       _mem.reserve(nbOfElems);
721       _info_on_compo.resize(1);
722     }
723   else
724     throw INTERP_KERNEL::Exception("DataArrayDouble::reserve : not available for DataArrayDouble with number of components different than 1 !");
725 }
726
727 /*!
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.
730  *
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
734  */
735 void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception)
736 {
737   int nbCompo=getNumberOfComponents();
738   if(nbCompo==1)
739     _mem.pushBack(val);
740   else if(nbCompo==0)
741     {
742       _info_on_compo.resize(1);
743       _mem.pushBack(val);
744     }
745   else
746     throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !");
747 }
748
749 /*!
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.
752  *
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
758  */
759 void DataArrayDouble::pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception)
760 {
761   int nbCompo=getNumberOfComponents();
762   if(nbCompo==1)
763     _mem.insertAtTheEnd(valsBg,valsEnd);
764   else if(nbCompo==0)
765     {
766       _info_on_compo.resize(1);
767       _mem.insertAtTheEnd(valsBg,valsEnd);
768     }
769   else
770     throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackValsSilent : not available for DataArrayDouble with number of components different than 1 !");
771 }
772
773 /*!
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.
777  */
778 double DataArrayDouble::popBackSilent() throw(INTERP_KERNEL::Exception)
779 {
780   if(getNumberOfComponents()==1)
781     return _mem.popBack();
782   else
783     throw INTERP_KERNEL::Exception("DataArrayDouble::popBackSilent : not available for DataArrayDouble with number of components different than 1 !");
784 }
785
786 /*!
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.
788  *
789  * \sa DataArrayDouble::getHeapMemorySize, DataArrayDouble::reserve
790  */
791 void DataArrayDouble::pack() const throw(INTERP_KERNEL::Exception)
792 {
793   _mem.pack();
794 }
795
796 /*!
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.
802  */
803 void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
804 {
805   if(isAllocated())
806     {
807       if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
808         alloc(nbOfTuple,nbOfCompo);
809     }
810   else
811     alloc(nbOfTuple,nbOfCompo);
812 }
813
814 /*!
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.
821  */
822 void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
823 {
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);
828   declareAsNew();
829 }
830
831 /*!
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.
835  */
836 void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception)
837 {
838   checkAllocated();
839   _mem.fillWithValue(0.);
840   declareAsNew();
841 }
842
843 /*!
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.
848  */
849 void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception)
850 {
851   checkAllocated();
852   _mem.fillWithValue(val);
853   declareAsNew();
854 }
855
856 /*!
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.
862  */
863 void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception)
864 {
865   checkAllocated();
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);
872   declareAsNew();
873 }
874
875 /*!
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_),
880  *                 \a false else.
881  *  \throw If \a this->getNumberOfComponents() != 1
882  *  \throw If \a this is not allocated.
883  */
884 bool DataArrayDouble::isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception)
885 {
886   checkAllocated();
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;
894   for(;w!=end2;w++)
895     if(*w<vmin || *w>vmax)
896       return false;
897   return true;
898 }
899
900 /*!
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.
905  */
906 void DataArrayDouble::sort(bool asc) throw(INTERP_KERNEL::Exception)
907 {
908   checkAllocated();
909   if(getNumberOfComponents()!=1)
910     throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !");
911   _mem.sort(asc);
912   declareAsNew();
913 }
914
915 /*!
916  * Reverse the array values.
917  *  \throw If \a this->getNumberOfComponents() < 1.
918  *  \throw If \a this is not allocated.
919  */
920 void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception)
921 {
922   checkAllocated();
923   _mem.reverse(getNumberOfComponents());
924   declareAsNew();
925 }
926
927 /*!
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
935  *         increasing arg.
936  *  \throw If \a this->getNumberOfComponents() != 1.
937  *  \throw If \a this is not allocated.
938  */
939 void DataArrayDouble::checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
940 {
941   if(!isMonotonic(increasing,eps))
942     {
943       if (increasing)
944         throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not INCREASING monotonic !");
945       else
946         throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not DECREASING monotonic !");
947     }
948 }
949
950 /*!
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.
959  */
960 bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
961 {
962   checkAllocated();
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();
967   if(nbOfElements==0)
968     return true;
969   double ref=ptr[0];
970   double absEps=fabs(eps);
971   if(increasing)
972     {
973       for(int i=1;i<nbOfElements;i++)
974         {
975           if(ptr[i]<(ref+absEps))
976             return false;
977           ref=ptr[i];
978         }
979       return true;
980     }
981   else
982     {
983       for(int i=1;i<nbOfElements;i++)
984         {
985           if(ptr[i]>(ref-absEps))
986             return false;
987           ref=ptr[i];
988         }
989       return true;
990     }
991 }
992
993 /*!
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.
997  */
998 std::string DataArrayDouble::repr() const throw(INTERP_KERNEL::Exception)
999 {
1000   std::ostringstream ret;
1001   reprStream(ret);
1002   return ret.str();
1003 }
1004
1005 std::string DataArrayDouble::reprZip() const throw(INTERP_KERNEL::Exception)
1006 {
1007   std::ostringstream ret;
1008   reprZipStream(ret);
1009   return ret.str();
1010 }
1011
1012 void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
1013 {
1014   std::string idt(indent,' ');
1015   ofs.precision(17);
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";
1020 }
1021
1022 void DataArrayDouble::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1023 {
1024   stream << "Name of double array : \"" << _name << "\"\n";
1025   reprWithoutNameStream(stream);
1026 }
1027
1028 void DataArrayDouble::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1029 {
1030   stream << "Name of double array : \"" << _name << "\"\n";
1031   reprZipWithoutNameStream(stream);
1032 }
1033
1034 void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1035 {
1036   DataArray::reprWithoutNameStream(stream);
1037   stream.precision(17);
1038   _mem.repr(getNumberOfComponents(),stream);
1039 }
1040
1041 void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1042 {
1043   DataArray::reprWithoutNameStream(stream);
1044   stream.precision(17);
1045   _mem.reprZip(getNumberOfComponents(),stream);
1046 }
1047
1048 void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1049 {
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)
1055     {
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;
1060     }
1061   else
1062     stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
1063   stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
1064 }
1065
1066 /*!
1067  * Method that gives a quick overvien of \a this for python.
1068  */
1069 void DataArrayDouble::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1070 {
1071   static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
1072   stream << "DataArrayDouble C++ instance at " << this << ". ";
1073   if(isAllocated())
1074     {
1075       int nbOfCompo=(int)_info_on_compo.size();
1076       if(nbOfCompo>=1)
1077         {
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 << "[";
1082           oss2.precision(17);
1083           std::string oss2Str(oss2.str());
1084           bool isFinished=true;
1085           for(int i=0;i<nbOfTuples && isFinished;i++)
1086             {
1087               if(nbOfCompo>1)
1088                 {
1089                   oss2 << "(";
1090                   for(int j=0;j<nbOfCompo;j++,data++)
1091                     {
1092                       oss2 << *data;
1093                       if(j!=nbOfCompo-1) oss2 << ", ";
1094                     }
1095                   oss2 << ")";
1096                 }
1097               else
1098                 oss2 << *data++;
1099               if(i!=nbOfTuples-1) oss2 << ", ";
1100               std::string oss3Str(oss2.str());
1101               if(oss3Str.length()<MAX_NB_OF_BYTE_IN_REPR)
1102                 oss2Str=oss3Str;
1103               else
1104                 isFinished=false;
1105             }
1106           stream << oss2Str;
1107           if(!isFinished)
1108             stream << "... ";
1109           stream << "]";
1110         }
1111       else
1112         stream << "Number of components : 0.";
1113     }
1114   else
1115     stream << "*** No data allocated ****";
1116 }
1117
1118 /*!
1119  * Equivalent to DataArrayDouble::isEqual except that if false the reason of
1120  * mismatch is given.
1121  * 
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
1126  */
1127 bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
1128 {
1129   if(!areInfoEqualsIfNotWhy(other,reason))
1130     return false;
1131   return _mem.isEqual(other._mem,prec,reason);
1132 }
1133
1134 /*!
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.
1140  */
1141 bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception)
1142 {
1143   std::string tmp;
1144   return isEqualIfNotWhy(other,prec,tmp);
1145 }
1146
1147 /*!
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.
1153  */
1154 bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception)
1155 {
1156   std::string tmp;
1157   return _mem.isEqual(other._mem,prec,tmp);
1158 }
1159
1160 /*!
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.
1165  */
1166 void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
1167 {
1168   checkAllocated();
1169   _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
1170   declareAsNew();
1171 }
1172
1173 /*!
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.
1177  */
1178 DataArrayInt *DataArrayDouble::convertToIntArr() const
1179 {
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);
1187   return ret;
1188 }
1189
1190 /*!
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()!
1199  */
1200 DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
1201 {
1202   if(_mem.isNull())
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());
1207   return ret;
1208 }
1209
1210 /*!
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()!
1219  */
1220 DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception)
1221 {
1222   if(_mem.isNull())
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());
1227   return ret;
1228 }
1229
1230 /*!
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.
1238  */
1239 void DataArrayDouble::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception)
1240 {
1241   checkAllocated();
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());
1249   delete [] tmp;
1250   declareAsNew();
1251 }
1252
1253 /*!
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.
1262  */
1263 void DataArrayDouble::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception)
1264 {
1265   checkAllocated();
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());
1273   delete [] tmp;
1274   declareAsNew();
1275 }
1276
1277 /*!
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.
1288  */
1289 DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception)
1290 {
1291   checkAllocated();
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);
1302   return ret.retn();
1303 }
1304
1305 /*!
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.
1315  */
1316 DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception)
1317 {
1318   checkAllocated();
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);
1329   return ret.retn();
1330 }
1331
1332 /*!
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.
1344  */
1345 DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception)
1346 {
1347   checkAllocated();
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++)
1355     {
1356       int w=old2New[i];
1357       if(w>=0)
1358         std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
1359     }
1360   ret->copyStringInfoFrom(*this);
1361   return ret.retn();
1362 }
1363
1364 /*!
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.
1379  */
1380 DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
1381 {
1382   checkAllocated();
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();
1389   int i=0;
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);
1393   return ret.retn();
1394 }
1395
1396 /*!
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().
1414  */
1415 DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
1416 {
1417   checkAllocated();
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();
1425   int i=0;
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);
1429     else
1430       throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
1431   ret->copyStringInfoFrom(*this);
1432   return ret.retn();
1433 }
1434
1435 /*!
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.
1450  */
1451 DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
1452 {
1453   checkAllocated();
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);
1463   return ret.retn();
1464 }
1465
1466 /*!
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.
1477  */
1478 DataArrayDouble *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
1479 {
1480   checkAllocated();
1481   int nbOfComp=getNumberOfComponents();
1482   int nbOfTuplesThis=getNumberOfTuples();
1483   if(ranges.empty())
1484     {
1485       DataArrayDouble *ret=DataArrayDouble::New();
1486       ret->alloc(0,nbOfComp);
1487       ret->copyStringInfoFrom(*this);
1488       return ret;
1489     }
1490   int ref=ranges.front().first;
1491   int nbOfTuples=0;
1492   bool isIncreasing=true;
1493   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
1494     {
1495       if((*it).first<=(*it).second)
1496         {
1497           if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
1498             {
1499               nbOfTuples+=(*it).second-(*it).first;
1500               if(isIncreasing)
1501                 isIncreasing=ref<=(*it).first;
1502               ref=(*it).second;
1503             }
1504           else
1505             {
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());
1509             }
1510         }
1511       else
1512         {
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());
1516         }
1517     }
1518   if(isIncreasing && nbOfTuplesThis==nbOfTuples)
1519     return deepCpy();
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);
1527   return ret.retn();
1528 }
1529
1530 /*!
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
1544  */
1545 DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
1546 {
1547   checkAllocated();
1548   int nbt=getNumberOfTuples();
1549   if(tupleIdBg<0)
1550     throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter must be greater than 0 !");
1551   if(tupleIdBg>nbt)
1552     throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater than number of tuples !");
1553   int trueEnd=tupleIdEnd;
1554   if(tupleIdEnd!=-1)
1555     {
1556       if(tupleIdEnd>nbt)
1557         throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
1558     }
1559   else
1560     trueEnd=nbt;
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());
1566   return ret.retn();
1567 }
1568
1569 /*!
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
1575  * components.  
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.
1581  */
1582 DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception)
1583 {
1584   checkAllocated();
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++)
1593     {
1594       int j=0;
1595       for(;j<dim;j++)
1596         nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
1597       for(;j<newNbOfComp;j++)
1598         nc[newNbOfComp*i+j]=dftValue;
1599     }
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());
1604   return ret.retn();
1605 }
1606
1607 /*!
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!
1616  */
1617 void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
1618 {
1619   checkAllocated();
1620   if(newNbOfCompo<1)
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);
1629   declareAsNew();
1630 }
1631
1632 /*!
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()!
1640  *  \sa rearrange()
1641  */
1642 void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception)
1643 {
1644   checkAllocated();
1645   int nbOfTuples=getNumberOfTuples();
1646   rearrange(nbOfTuples);
1647 }
1648
1649 /*!
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().
1661  *
1662  *  \ref cpp_mcdataarraydouble_keepselectedcomponents "Here is a Python example".
1663  */
1664 DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
1665 {
1666   checkAllocated();
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)
1672       {
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());
1675       }
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]];
1684   return ret.retn();
1685 }
1686
1687 /*!
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.
1694  *
1695  *  \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
1696  *
1697  *  \ref py_mcdataarraydouble_meldwith "Here is a Python example".
1698  */
1699 void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
1700 {
1701   checkAllocated();
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)];
1709   double *w=newArr;
1710   const double *inp1=getConstPointer();
1711   const double *inp2=other->getConstPointer();
1712   for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
1713     {
1714       w=std::copy(inp1,inp1+nbOfComp1,w);
1715       w=std::copy(inp2,inp2+nbOfComp2,w);
1716     }
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);
1722 }
1723
1724 /*!
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.
1728  *
1729  * Indices of coincident tuples are stored in output arrays.
1730  * A pair of arrays (\a comm, \a commIndex) is called "Surjective Format 2".
1731  *
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].
1749  *
1750  *  \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example".
1751  *
1752  *  \ref py_mcdataarraydouble_findcommontuples  "Here is a Python example".
1753  *  \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2().
1754  */
1755 void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
1756 {
1757   checkAllocated();
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.");
1761   
1762   int nbOfTuples=getNumberOfTuples();
1763   //
1764   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=computeBBoxPerTuple(prec);
1765   //
1766   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0);
1767   switch(nbOfCompo)
1768     {
1769     case 3:
1770       findCommonTuplesAlg<3>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1771       break;
1772     case 2:
1773       findCommonTuplesAlg<2>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1774       break;
1775     case 1:
1776       findCommonTuplesAlg<1>(bbox->getConstPointer(),nbOfTuples,limitTupleId,prec,c,cI);
1777       break;
1778     default:
1779       throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !");
1780     }
1781   comm=c.retn();
1782   commIndex=cI.retn();
1783 }
1784
1785 /*!
1786  * 
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.
1791  */
1792 DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
1793 {
1794   checkAllocated();
1795   if(getNumberOfComponents()!=1)
1796     throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
1797   if(nbTimes<1)
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++)
1804     {
1805       double val=*inPtr;
1806       for(int j=0;j<nbTimes;j++,retPtr++)
1807         *retPtr=val;
1808     }
1809   ret->copyStringInfoFrom(*this);
1810   return ret.retn();
1811 }
1812
1813 /*!
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.
1817  *
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
1822  */
1823 double DataArrayDouble::minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const throw(INTERP_KERNEL::Exception)
1824 {
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)
1832     {
1833       double tmp(0.);
1834       for(int j=0;j<nbOfCompo;j++)
1835         tmp+=(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j])*(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j]);
1836       if(tmp<ret)
1837         { ret=tmp; thisTupleId=*part1Pt; otherTupleId=i; }
1838     }
1839   return sqrt(ret);
1840 }
1841
1842 /*!
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.
1846  *
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
1849  */
1850 DataArrayInt *DataArrayDouble::findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
1851 {
1852   if(!other)
1853     throw INTERP_KERNEL::Exception("DataArrayDouble::findClosestTupleId : other instance is NULL !");
1854   checkAllocated(); other->checkAllocated();
1855   int nbOfCompo=getNumberOfComponents();
1856   if(nbOfCompo!=other->getNumberOfComponents())
1857     {
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());
1861     }
1862   int nbOfTuples=other->getNumberOfTuples();
1863   int thisNbOfTuples=getNumberOfTuples();
1864   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
1865   double bounds[6];
1866   getMinMaxPerComponent(bounds);
1867   switch(nbOfCompo)
1868     {
1869     case 3:
1870       {
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());
1876         break;
1877       }
1878     case 2:
1879       {
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());
1885         break;
1886       }
1887     case 1:
1888       {
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());
1892         break;
1893       }
1894     default:
1895       throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for findClosestTupleId. Must be 1, 2 or 3.");
1896     }
1897   return ret.retn();
1898 }
1899
1900 /*!
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].
1915  *
1916  *  \ref cpp_mcdataarraydouble_getdifferentvalues "Here is a Python example".
1917  */
1918 DataArrayDouble *DataArrayDouble::getDifferentValues(double prec, int limitTupleId) const throw(INTERP_KERNEL::Exception)
1919 {
1920   checkAllocated();
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);
1927 }
1928
1929 /*!
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
1936  *              to be copied.
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().
1940  *
1941  *  \ref cpp_mcdataarraydouble_setselectedcomponents "Here is a Python example".
1942  */
1943 void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
1944 {
1945   if(!a)
1946     throw INTERP_KERNEL::Exception("DataArrayDouble::setSelectedComponents : input DataArrayDouble is NULL !");
1947   checkAllocated();
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;
1957 }
1958
1959 /*!
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
1967  *              are located.
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
1971  *              to are located.
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)).
1990  *
1991  *  \ref cpp_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
1992  */
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)
1994 {
1995   if(!a)
1996     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues1 : input DataArrayDouble is NULL !");
1997   const char msg[]="DataArrayDouble::setPartOfValues1";
1998   checkAllocated();
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)
2008     {
2009       if(strictCompoCompare)
2010         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2011     }
2012   else
2013     {
2014       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2015       assignTech=false;
2016     }
2017   const double *srcPt=a->getConstPointer();
2018   double *pt=getPointer()+bgTuples*nbComp+bgComp;
2019   if(assignTech)
2020     {
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;
2024     }
2025   else
2026     {
2027       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2028         {
2029           const double *srcPt2=srcPt;
2030           for(int j=0;j<newNbOfComp;j++,srcPt2++)
2031             pt[j*stepComp]=*srcPt2;
2032         }
2033     }
2034 }
2035
2036 /*!
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
2043  *              are located.
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
2047  *              to are located.
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
2052  *            for \this array.
2053  *
2054  *  \ref cpp_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
2055  */
2056 void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
2057 {
2058   const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
2059   checkAllocated();
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++)
2069       pt[j*stepComp]=a;
2070 }
2071
2072 /*!
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.
2082  *
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>.
2107  *
2108  *  \ref cpp_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
2109  */
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)
2111 {
2112   if(!a)
2113     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
2114   const char msg[]="DataArrayDouble::setPartOfValues2";
2115   checkAllocated();
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)
2125     {
2126       if(strictCompoCompare)
2127         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2128     }
2129   else
2130     {
2131       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2132       assignTech=false;
2133     }
2134   double *pt=getPointer();
2135   const double *srcPt=a->getConstPointer();
2136   if(assignTech)
2137     {    
2138       for(const int *w=bgTuples;w!=endTuples;w++)
2139         {
2140           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2141           for(const int *z=bgComp;z!=endComp;z++,srcPt++)
2142             {    
2143               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
2144             }
2145         }
2146     }
2147   else
2148     {
2149       for(const int *w=bgTuples;w!=endTuples;w++)
2150         {
2151           const double *srcPt2=srcPt;
2152           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2153           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
2154             {    
2155               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
2156             }
2157         }
2158     }
2159 }
2160
2161 /*!
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
2166  *              assign \a a 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
2171  *              assign \a a 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.
2178  *
2179  *  \ref cpp_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
2180  */
2181 void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
2182 {
2183   checkAllocated();
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++)
2191       {
2192         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2193         pt[(std::size_t)(*w)*nbComp+(*z)]=a;
2194       }
2195 }
2196
2197 /*!
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.
2209  *
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
2218  *              to are located.
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 
2228  *         \a this array.
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
2237  *            for \this array.
2238  *
2239  *  \ref cpp_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
2240  */
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)
2242 {
2243   if(!a)
2244     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues3 : input DataArrayDouble is NULL !");
2245   const char msg[]="DataArrayDouble::setPartOfValues3";
2246   checkAllocated();
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)
2255     {
2256       if(strictCompoCompare)
2257         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2258     }
2259   else
2260     {
2261       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2262       assignTech=false;
2263     }
2264   double *pt=getPointer()+bgComp;
2265   const double *srcPt=a->getConstPointer();
2266   if(assignTech)
2267     {
2268       for(const int *w=bgTuples;w!=endTuples;w++)
2269         for(int j=0;j<newNbOfComp;j++,srcPt++)
2270           {
2271             DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2272             pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
2273           }
2274     }
2275   else
2276     {
2277       for(const int *w=bgTuples;w!=endTuples;w++)
2278         {
2279           const double *srcPt2=srcPt;
2280           for(int j=0;j<newNbOfComp;j++,srcPt2++)
2281             {
2282               DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2283               pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
2284             }
2285         }
2286     }
2287 }
2288
2289 /*!
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
2296  *              assign \a a 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
2302  *              to are located.
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 
2306  *         \a this array.
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
2309  *            for \this array.
2310  *
2311  *  \ref cpp_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
2312  */
2313 void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
2314 {
2315   const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
2316   checkAllocated();
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++)
2324       {
2325         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2326         pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
2327       }
2328 }
2329
2330 /*!
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
2338  *              are located.
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
2341  *              assign \a a 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)).
2362  *
2363  */
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)
2365 {
2366   if(!a)
2367     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues4 : input DataArrayDouble is NULL !");
2368   const char msg[]="DataArrayDouble::setPartOfValues4";
2369   checkAllocated();
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)
2380     {
2381       if(strictCompoCompare)
2382         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2383     }
2384   else
2385     {
2386       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2387       assignTech=false;
2388     }
2389   const double *srcPt=a->getConstPointer();
2390   double *pt=getPointer()+bgTuples*nbComp;
2391   if(assignTech)
2392     {
2393       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2394         for(const int *z=bgComp;z!=endComp;z++,srcPt++)
2395           pt[*z]=*srcPt;
2396     }
2397   else
2398     {
2399       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2400         {
2401           const double *srcPt2=srcPt;
2402           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
2403             pt[*z]=*srcPt2;
2404         }
2405     }
2406 }
2407
2408 void DataArrayDouble::setPartOfValuesSimple4(double a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
2409 {
2410   const char msg[]="DataArrayDouble::setPartOfValuesSimple4";
2411   checkAllocated();
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++)
2421       pt[*z]=a;
2422 }
2423
2424 /*!
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
2427  * components.
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.
2444  */
2445 void DataArrayDouble::setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
2446 {
2447   if(!a || !tuplesSelec)
2448     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : input DataArrayDouble is NULL !");
2449   checkAllocated();
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)
2462     {
2463       if(tuple[1]>=0 && tuple[1]<aNt)
2464         {
2465           if(tuple[0]>=0 && tuple[0]<thisNt)
2466             std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
2467           else
2468             {
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());
2472             }
2473         }
2474       else
2475         {
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());
2479         }
2480     }
2481 }
2482
2483 /*!
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
2486  * components.
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
2492  *              values to.
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 
2504  *         \a a array.
2505  */
2506 void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
2507 {
2508   if(!a || !tuplesSelec)
2509     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray is NULL !");
2510   checkAllocated();
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)
2526     {
2527       if(*tuple>=0 && *tuple<aNt)
2528         {
2529           std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
2530         }
2531       else
2532         {
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());
2536         }
2537     }
2538 }
2539
2540 /*!
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
2543  * components.
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
2550  *              values to.
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
2554  *              are located.
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.
2564  */
2565 void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
2566 {
2567   if(!a)
2568     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArrayDouble is NULL !");
2569   checkAllocated();
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 !");
2581   if(end2>aNt)
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)
2585     {
2586       std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
2587     }
2588 }
2589
2590 /*!
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.
2601  */
2602 double DataArrayDouble::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
2603 {
2604   checkAllocated();
2605   if(tupleId<0 || tupleId>=getNumberOfTuples())
2606     {
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());
2609     }
2610   if(compoId<0 || compoId>=getNumberOfComponents())
2611     {
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());
2614     }
2615   return _mem[tupleId*_info_on_compo.size()+compoId];
2616 }
2617
2618 /*!
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.
2624  */
2625 double DataArrayDouble::back() const throw(INTERP_KERNEL::Exception)
2626 {
2627   checkAllocated();
2628   if(getNumberOfComponents()!=1)
2629     throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of components not equal to one !");
2630   int nbOfTuples=getNumberOfTuples();
2631   if(nbOfTuples<1)
2632     throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of tuples must be >= 1 !");
2633   return *(getConstPointer()+nbOfTuples-1);
2634 }
2635
2636 void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
2637 {
2638   if(newArray!=arrayToSet)
2639     {
2640       if(arrayToSet)
2641         arrayToSet->decrRef();
2642       arrayToSet=newArray;
2643       if(arrayToSet)
2644         arrayToSet->incrRef();
2645     }
2646 }
2647
2648 /*!
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.
2659  */
2660 void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
2661 {
2662   _info_on_compo.resize(nbOfCompo);
2663   _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo);
2664   declareAsNew();
2665 }
2666
2667 void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
2668 {
2669   _info_on_compo.resize(nbOfCompo);
2670   _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo);
2671   declareAsNew();
2672 }
2673
2674 /*!
2675  * Checks if 0.0 value is present in \a this array. If it is the case, an exception
2676  * is thrown.
2677  * \throw If zero is found in \a this array.
2678  */
2679 void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception)
2680 {
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 !");
2686 }
2687
2688 /*!
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>
2698  *               ...
2699  */
2700 void DataArrayDouble::getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception)
2701 {
2702   checkAllocated();
2703   int dim=getNumberOfComponents();
2704   for (int idim=0; idim<dim; idim++)
2705     {
2706       bounds[idim*2]=std::numeric_limits<double>::max();
2707       bounds[idim*2+1]=-std::numeric_limits<double>::max();
2708     } 
2709   const double *ptr=getConstPointer();
2710   int nbOfTuples=getNumberOfTuples();
2711   for(int i=0;i<nbOfTuples;i++)
2712     {
2713       for(int idim=0;idim<dim;idim++)
2714         {
2715           if(bounds[idim*2]>ptr[i*dim+idim])
2716             {
2717               bounds[idim*2]=ptr[i*dim+idim];
2718             }
2719           if(bounds[idim*2+1]<ptr[i*dim+idim])
2720             {
2721               bounds[idim*2+1]=ptr[i*dim+idim];
2722             }
2723         }
2724     }
2725 }
2726
2727 /*!
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
2731  *
2732  * \return a newly created DataArrayDouble instance having \c this->getNumberOfTuples() tuples and 2 * \c this->getNumberOfComponent() components
2733  *
2734  * \throw If \a this is not allocated yet.
2735  */
2736 DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon)const throw(INTERP_KERNEL::Exception)
2737 {
2738   checkAllocated();
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++)
2746     {
2747       for(int j=0;j<nbOfCompo;j++)
2748         {
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;
2751         }
2752     }
2753   return bbox.retn();
2754 }
2755
2756 /*!
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.
2759  * 
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.
2765  *
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]
2771  *
2772  * \sa MEDCouplingPointSet::getNodeIdsNearPoints, DataArrayDouble::getDifferentValues
2773  */
2774 void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception)
2775 {
2776   if(!other)
2777     throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !");
2778   checkAllocated();
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);
2787   switch(nbOfCompo)
2788     {
2789     case 3:
2790       {
2791         BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
2792         FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2793         break;
2794       }
2795     case 2:
2796       {
2797         BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
2798         FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2799         break;
2800       }
2801     case 1:
2802       {
2803         BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10);
2804         FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2805         break;
2806       }
2807     default:
2808       throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for computeTupleIdsNearTuples. Must be 1, 2 or 3.");
2809     }
2810   c=cArr.retn(); cI=cIArr.retn();
2811 }
2812
2813 /*!
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.
2816  * 
2817  * \param [in] eps absolute epsilon. under that value of delta between max and min no scale is performed.
2818  */
2819 void DataArrayDouble::recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception)
2820 {
2821   checkAllocated();
2822   int dim=getNumberOfComponents();
2823   std::vector<double> bounds(2*dim);
2824   getMinMaxPerComponent(&bounds[0]);
2825   for(int i=0;i<dim;i++)
2826     {
2827       double delta=bounds[2*i+1]-bounds[2*i];
2828       double offset=(bounds[2*i]+bounds[2*i+1])/2.;
2829       if(delta>eps)
2830         applyLin(1./delta,-offset/delta,i);
2831       else
2832         applyLin(1.,-offset,i);
2833     }
2834 }
2835
2836 /*!
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
2842  */
2843 double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
2844 {
2845   checkAllocated();
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();
2849   if(nbOfTuples<=0)
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);
2854   return *loc;
2855 }
2856
2857 /*!
2858  * Returns the maximal value within \a this array that is allowed to have more than
2859  *  one component.
2860  *  \return double - the maximal value among all values of \a this array.
2861  *  \throw If \a this is not allocated.
2862  */
2863 double DataArrayDouble::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
2864 {
2865   checkAllocated();
2866   const double *loc=std::max_element(begin(),end());
2867   return *loc;
2868 }
2869
2870 /*!
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
2878  */
2879 double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
2880 {
2881   int tmp;
2882   tupleIds=0;
2883   double ret=getMaxValue(tmp);
2884   tupleIds=getIdsInRange(ret,ret);
2885   return ret;
2886 }
2887
2888 /*!
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
2894  */
2895 double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
2896 {
2897   checkAllocated();
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();
2901   if(nbOfTuples<=0)
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);
2906   return *loc;
2907 }
2908
2909 /*!
2910  * Returns the minimal value within \a this array that is allowed to have more than
2911  *  one component.
2912  *  \return double - the minimal value among all values of \a this array.
2913  *  \throw If \a this is not allocated.
2914  */
2915 double DataArrayDouble::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
2916 {
2917   checkAllocated();
2918   const double *loc=std::min_element(begin(),end());
2919   return *loc;
2920 }
2921
2922 /*!
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
2930  */
2931 double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
2932 {
2933   int tmp;
2934   tupleIds=0;
2935   double ret=getMinValue(tmp);
2936   tupleIds=getIdsInRange(ret,ret);
2937   return ret;
2938 }
2939
2940 /*!
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
2945  */
2946 double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
2947 {
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();
2951   if(nbOfTuples<=0)
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;
2956 }
2957
2958 /*!
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.
2963  */
2964 double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
2965 {
2966   checkAllocated();
2967   double ret=0.;
2968   std::size_t nbOfElems=getNbOfElems();
2969   const double *pt=getConstPointer();
2970   for(std::size_t i=0;i<nbOfElems;i++,pt++)
2971     ret+=(*pt)*(*pt);
2972   return sqrt(ret);
2973 }
2974
2975 /*!
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.
2980  */
2981 double DataArrayDouble::normMax() const throw(INTERP_KERNEL::Exception)
2982 {
2983   checkAllocated();
2984   double ret=-1.;
2985   std::size_t nbOfElems=getNbOfElems();
2986   const double *pt=getConstPointer();
2987   for(std::size_t i=0;i<nbOfElems;i++,pt++)
2988     {
2989       double val=std::abs(*pt);
2990       if(val>ret)
2991         ret=val;
2992     }
2993   return ret;
2994 }
2995
2996 /*!
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
3000  *         component.
3001  *  \throw If \a this is not allocated.
3002  */
3003 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
3004 {
3005   checkAllocated();
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>());
3012 }
3013
3014 /*!
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.
3017  *
3018  *
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.
3021  *
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
3027  */
3028 double DataArrayDouble::distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const throw(INTERP_KERNEL::Exception)
3029 {
3030   checkAllocated();
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()); }
3035   if(nbTuple==0)
3036     throw INTERP_KERNEL::Exception("DataArrayDouble::distanceToTuple : no tuple in this ! No distance to compute !");
3037   double ret0=std::numeric_limits<double>::max();
3038   tupleId=-1;
3039   const double *work=getConstPointer();
3040   for(int i=0;i<nbTuple;i++)
3041     {
3042       double val=0.;
3043       for(int j=0;j<nbComps;j++,work++) 
3044         val+=(*work-tupleBg[j])*((*work-tupleBg[j]));
3045       if(val>=ret0)
3046         continue;
3047       else
3048         { ret0=val; tupleId=i; }
3049     }
3050   return sqrt(ret0);
3051 }
3052
3053 /*!
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
3059  *         not respected.
3060  */
3061 double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
3062 {
3063   checkAllocated();
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 !");
3069   double ret=0.;
3070   for(int i=0;i<nbTuple;i++)
3071     ret+=ptr[i*nbComps+compId];
3072   return ret;
3073 }
3074
3075 /*!
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.
3084  */
3085 DataArrayDouble *DataArrayDouble::fromPolarToCart() const throw(INTERP_KERNEL::Exception)
3086 {
3087   checkAllocated();
3088   int nbOfComp=getNumberOfComponents();
3089   if(nbOfComp!=2)
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)
3097     {
3098       w[0]=wIn[0]*cos(wIn[1]);
3099       w[1]=wIn[0]*sin(wIn[1]);
3100     }
3101   return ret;
3102 }
3103
3104 /*!
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.
3114  */
3115 DataArrayDouble *DataArrayDouble::fromCylToCart() const throw(INTERP_KERNEL::Exception)
3116 {
3117   checkAllocated();
3118   int nbOfComp=getNumberOfComponents();
3119   if(nbOfComp!=3)
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)
3127     {
3128       w[0]=wIn[0]*cos(wIn[1]);
3129       w[1]=wIn[0]*sin(wIn[1]);
3130       w[2]=wIn[2];
3131     }
3132   ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str());
3133   return ret;
3134 }
3135
3136 /*!
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.
3146  */
3147 DataArrayDouble *DataArrayDouble::fromSpherToCart() const throw(INTERP_KERNEL::Exception)
3148 {
3149   checkAllocated();
3150   int nbOfComp=getNumberOfComponents();
3151   if(nbOfComp!=3)
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)
3159     {
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]);
3163     }
3164   return ret;
3165 }
3166
3167 /*!
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.
3175  */
3176 DataArrayDouble *DataArrayDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
3177 {
3178   checkAllocated();
3179   int nbOfComp=getNumberOfComponents();
3180   if(nbOfComp!=6)
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];
3189   return ret;
3190 }
3191
3192 /*!
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
3199  *          needed. 
3200  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3201  */
3202 DataArrayDouble *DataArrayDouble::determinant() const throw(INTERP_KERNEL::Exception)
3203 {
3204   checkAllocated();
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())
3211     {
3212     case 6:
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];
3215       return ret;
3216     case 4:
3217       for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
3218         *dest=src[0]*src[3]-src[1]*src[2];
3219       return ret;
3220     case 9:
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];
3223       return ret;
3224     default:
3225       ret->decrRef();
3226       throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
3227     }
3228 }
3229
3230 /*!
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
3237  *          needed. 
3238  *  \throw If \a this->getNumberOfComponents() != 6.
3239  */
3240 DataArrayDouble *DataArrayDouble::eigenValues() const throw(INTERP_KERNEL::Exception)
3241 {
3242   checkAllocated();
3243   int nbOfComp=getNumberOfComponents();
3244   if(nbOfComp!=6)
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);
3253   return ret;
3254 }
3255
3256 /*!
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
3263  *          needed.
3264  *  \throw If \a this->getNumberOfComponents() != 6.
3265  */
3266 DataArrayDouble *DataArrayDouble::eigenVectors() const throw(INTERP_KERNEL::Exception)
3267 {
3268   checkAllocated();
3269   int nbOfComp=getNumberOfComponents();
3270   if(nbOfComp!=6)
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)
3278     {
3279       double tmp[3];
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);
3283     }
3284   return ret;
3285 }
3286
3287 /*!
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
3295  *          needed. 
3296  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3297  */
3298 DataArrayDouble *DataArrayDouble::inverse() const throw(INTERP_KERNEL::Exception)
3299 {
3300   checkAllocated();
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();
3309 if(nbOfComp==6)
3310     for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
3311       {
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;
3319       }
3320   else if(nbOfComp==4)
3321     for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
3322       {
3323         double det=src[0]*src[3]-src[1]*src[2];
3324         dest[0]=src[3]/det;
3325         dest[1]=-src[1]/det;
3326         dest[2]=-src[2]/det;
3327         dest[3]=src[0]/det;
3328       }
3329   else
3330     for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
3331       {
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;
3342       }
3343   return ret;
3344 }
3345
3346 /*!
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
3354  *          needed. 
3355  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3356  */
3357 DataArrayDouble *DataArrayDouble::trace() const throw(INTERP_KERNEL::Exception)
3358 {
3359   checkAllocated();
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();
3368   if(nbOfComp==6)
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];
3374   else
3375     for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
3376       *dest=src[0]+src[4]+src[8];
3377   return ret;
3378 }
3379
3380 /*!
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
3386  *          needed.
3387  *  \throw If \a this->getNumberOfComponents() != 6.
3388  */
3389 DataArrayDouble *DataArrayDouble::deviator() const throw(INTERP_KERNEL::Exception)
3390 {
3391   checkAllocated();
3392   int nbOfComp=getNumberOfComponents();
3393   if(nbOfComp!=6)
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)
3401     {
3402       double tr=(src[0]+src[1]+src[2])/3.;
3403       dest[0]=src[0]-tr;
3404       dest[1]=src[1]-tr;
3405       dest[2]=src[2]-tr;
3406       dest[3]=src[3];
3407       dest[4]=src[4];
3408       dest[5]=src[5];
3409     }
3410   return ret;
3411 }
3412
3413 /*!
3414  * Computes the magnitude of every vector defined by the tuple of
3415  * \a this array.
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
3419  *          needed.
3420  *  \throw If \a this is not allocated.
3421  */
3422 DataArrayDouble *DataArrayDouble::magnitude() const throw(INTERP_KERNEL::Exception)
3423 {
3424   checkAllocated();
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++)
3432     {
3433       double sum=0.;
3434       for(int j=0;j<nbOfComp;j++,src++)
3435         sum+=(*src)*(*src);
3436       *dest=sqrt(sum);
3437     }
3438   return ret;
3439 }
3440
3441 /*!
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
3446  *          needed.
3447  *  \throw If \a this is not allocated.
3448  */
3449 DataArrayDouble *DataArrayDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
3450 {
3451   checkAllocated();
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);
3460   return ret;
3461 }
3462
3463 /*!
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)
3468  *
3469  * \warning use this method with care because it can leads to big amount of consumed memory !
3470  * 
3471  * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
3472  *
3473  * \throw If \a this is not allocated.
3474  *
3475  * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrixWith
3476  */
3477 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception)
3478 {
3479   checkAllocated();
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++)
3487     {
3488       outData[i*nbOfTuples+i]=0.;
3489       for(int j=i+1;j<nbOfTuples;j++)
3490         {
3491           double dist=0.;
3492           for(int k=0;k<nbOfComp;k++)
3493             { double delta=inData[i*nbOfComp+k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
3494           dist=sqrt(dist);
3495           outData[i*nbOfTuples+j]=dist;
3496           outData[j*nbOfTuples+i]=dist;
3497         }
3498     }
3499   return ret.retn();
3500 }
3501
3502 /*!
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)
3508  *
3509  * \warning use this method with care because it can leads to big amount of consumed memory !
3510  * 
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.
3513  *
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.
3515  *
3516  * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrix
3517  */
3518 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
3519 {
3520   if(!other)
3521     throw INTERP_KERNEL::Exception("DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : input parameter is null !");
3522   checkAllocated();
3523   other->checkAllocated();
3524   int nbOfComp=getNumberOfComponents();
3525   int otherNbOfComp=other->getNumberOfComponents();
3526   if(nbOfComp!=otherNbOfComp)
3527     {
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());
3530     }
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)
3539     {
3540       for(int j=0;j<nbOfTuples;j++)
3541         {
3542           double dist=0.;
3543           for(int k=0;k<nbOfComp;k++)
3544             { double delta=inDataOther[k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
3545           dist=sqrt(dist);
3546           outData[i*nbOfTuples+j]=dist;
3547         }
3548     }
3549   return ret.retn();
3550 }
3551
3552 /*!
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.
3557  */
3558 void DataArrayDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
3559 {
3560   checkAllocated();
3561   double *pt=getPointer();
3562   int nbOfTuple=getNumberOfTuples();
3563   int nbOfComp=getNumberOfComponents();
3564   if(asc)
3565     for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
3566       std::sort(pt,pt+nbOfComp);
3567   else
3568     for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
3569       std::sort(pt,pt+nbOfComp,std::greater<double>());
3570   declareAsNew();
3571 }
3572
3573 /*!
3574  * Converts every value of \a this array to its absolute value.
3575  *  \throw If \a this is not allocated.
3576  */
3577 void DataArrayDouble::abs() throw(INTERP_KERNEL::Exception)
3578 {
3579   checkAllocated();
3580   double *ptr=getPointer();
3581   std::size_t nbOfElems=getNbOfElems();
3582   std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
3583   declareAsNew();
3584 }
3585
3586 /*!
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.
3593  */
3594 void DataArrayDouble::applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception)
3595 {
3596   checkAllocated();
3597   double *ptr=getPointer()+compoId;
3598   int nbOfComp=getNumberOfComponents();
3599   int nbOfTuple=getNumberOfTuples();
3600   for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
3601     *ptr=a*(*ptr)+b;
3602   declareAsNew();
3603 }
3604
3605 /*!
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.
3611  */
3612 void DataArrayDouble::applyLin(double a, double b) throw(INTERP_KERNEL::Exception)
3613 {
3614   checkAllocated();
3615   double *ptr=getPointer();
3616   std::size_t nbOfElems=getNbOfElems();
3617   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3618     *ptr=a*(*ptr)+b;
3619   declareAsNew();
3620 }
3621
3622 /*!
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
3630  *           modified.
3631  */
3632 void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception)
3633 {
3634   checkAllocated();
3635   double *ptr=getPointer();
3636   std::size_t nbOfElems=getNbOfElems();
3637   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3638     {
3639       if(std::abs(*ptr)>std::numeric_limits<double>::min())
3640         {
3641           *ptr=numerator/(*ptr);
3642         }
3643       else
3644         {
3645           std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
3646           oss << " !";
3647           throw INTERP_KERNEL::Exception(oss.str().c_str());
3648         }
3649     }
3650   declareAsNew();
3651 }
3652
3653 /*!
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
3658  *          needed.
3659  *  \throw If \a this is not allocated.
3660  */
3661 DataArrayDouble *DataArrayDouble::negate() const throw(INTERP_KERNEL::Exception)
3662 {
3663   checkAllocated();
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);
3671   return newArr;
3672 }
3673
3674 /*!
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
3682  *           modified.
3683  */
3684 void DataArrayDouble::applyPow(double val) throw(INTERP_KERNEL::Exception)
3685 {
3686   checkAllocated();
3687   double *ptr=getPointer();
3688   std::size_t nbOfElems=getNbOfElems();
3689   int val2=(int)val;
3690   bool isInt=((double)val2)==val;
3691   if(!isInt)
3692     {
3693       for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3694         {
3695           if(*ptr>=0)
3696             *ptr=pow(*ptr,val);
3697           else
3698             {
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());
3701             }
3702         }
3703     }
3704   else
3705     {
3706       for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3707         *ptr=pow(*ptr,val2);
3708     }
3709   declareAsNew();
3710 }
3711
3712 /*!
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
3720  *           modified.
3721  */
3722 void DataArrayDouble::applyRPow(double val) throw(INTERP_KERNEL::Exception)
3723 {
3724   checkAllocated();
3725   if(val<0.)
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++)
3730     *ptr=pow(val,*ptr);
3731   declareAsNew();
3732 }
3733
3734 /*!
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
3744  *              that of \a res.
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
3748  *          needed.
3749  *  \throw If \a this is not allocated.
3750  *  \throw If \a func returns \a false.
3751  */
3752 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
3753 {
3754   checkAllocated();
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++)
3762     {
3763       if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
3764         {
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 !";
3768           newArr->decrRef();
3769           throw INTERP_KERNEL::Exception(oss.str().c_str());
3770         }
3771     }
3772   return newArr;
3773 }
3774
3775 /*!
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
3785  *          needed.
3786  *  \throw If \a this is not allocated.
3787  *  \throw If computing \a func fails.
3788  */
3789 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
3790 {
3791   checkAllocated();
3792   INTERP_KERNEL::ExprParser expr(func);
3793   expr.parse();
3794   std::set<std::string> vars;
3795   expr.getTrueSetOfVars(vars);
3796   int oldNbOfComp=getNumberOfComponents();
3797   if((int)vars.size()>oldNbOfComp)
3798     {
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());
3803     }
3804   std::vector<std::string> varsV(vars.begin(),vars.end());
3805   expr.prepareExprEvaluation(varsV,oldNbOfComp,nbOfComp);
3806   //
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++)
3813     {
3814       try
3815         {
3816           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
3817         }
3818       catch(INTERP_KERNEL::Exception& e)
3819         {
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();
3823           newArr->decrRef();
3824           throw INTERP_KERNEL::Exception(oss.str().c_str());
3825         }
3826     }
3827   return newArr;
3828 }
3829
3830 /*!
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
3839  *          needed.
3840  *  \throw If \a this is not allocated.
3841  *  \throw If computing \a func fails.
3842  */
3843 DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const throw(INTERP_KERNEL::Exception)
3844 {
3845   checkAllocated();
3846   INTERP_KERNEL::ExprParser expr(func);
3847   expr.parse();
3848   expr.prepareExprEvaluationVec();
3849   //
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++)
3857     {
3858       try
3859         {
3860           expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
3861         }
3862       catch(INTERP_KERNEL::Exception& e)
3863         {
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();
3867           newArr->decrRef();
3868           throw INTERP_KERNEL::Exception(oss.str().c_str());
3869         }
3870     }
3871   return newArr;
3872 }
3873
3874 /*!
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
3884  *          needed.
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.
3888  */
3889 DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
3890 {
3891   checkAllocated();
3892   INTERP_KERNEL::ExprParser expr(func);
3893   expr.parse();
3894   std::set<std::string> vars;
3895   expr.getTrueSetOfVars(vars);
3896   int oldNbOfComp=getNumberOfComponents();
3897   if((int)vars.size()>oldNbOfComp)
3898     {
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());
3903     }
3904   expr.prepareExprEvaluation(getVarsOnComponent(),oldNbOfComp,nbOfComp);
3905   //
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++)
3912     {
3913       try
3914         {
3915           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
3916         }
3917       catch(INTERP_KERNEL::Exception& e)
3918         {
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();
3922           newArr->decrRef();
3923           throw INTERP_KERNEL::Exception(oss.str().c_str());
3924         }
3925     }
3926   return newArr;
3927 }
3928
3929 /*!
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
3940  *          needed.
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.
3944  */
3945 DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception)
3946 {
3947   checkAllocated();
3948   INTERP_KERNEL::ExprParser expr(func);
3949   expr.parse();
3950   std::set<std::string> vars;
3951   expr.getTrueSetOfVars(vars);
3952   int oldNbOfComp=getNumberOfComponents();
3953   if((int)vars.size()>oldNbOfComp)
3954     {
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());
3959     }
3960   expr.prepareExprEvaluation(varsOrder,oldNbOfComp,nbOfComp);
3961   //
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++)
3968     {
3969       try
3970         {
3971           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
3972         }
3973       catch(INTERP_KERNEL::Exception& e)
3974         {
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();
3978           newArr->decrRef();
3979           throw INTERP_KERNEL::Exception(oss.str().c_str());
3980         }
3981     }
3982   return newArr;
3983 }
3984
3985 void DataArrayDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
3986 {
3987   checkAllocated();
3988   INTERP_KERNEL::ExprParser expr(func);
3989   expr.parse();
3990   char *funcStr=expr.compileX86();
3991   MYFUNCPTR funcPtr;
3992   *((void **)&funcPtr)=funcStr;//he he...
3993   //
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++)
3999     *ptr=funcPtr(*ptr);
4000   declareAsNew();
4001 }
4002
4003 void DataArrayDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
4004 {
4005   checkAllocated();
4006   INTERP_KERNEL::ExprParser expr(func);
4007   expr.parse();
4008   char *funcStr=expr.compileX86_64();
4009   MYFUNCPTR funcPtr;
4010   *((void **)&funcPtr)=funcStr;//he he...
4011   //
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++)
4017     *ptr=funcPtr(*ptr);
4018   declareAsNew();
4019 }
4020
4021 DataArrayDoubleIterator *DataArrayDouble::iterator() throw(INTERP_KERNEL::Exception)
4022 {
4023   return new DataArrayDoubleIterator(this);
4024 }
4025
4026 /*!
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
4033  *          needed.
4034  *  \throw If \a this->getNumberOfComponents() != 1
4035  *
4036  *  \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".
4037  *
4038  *  \ref py_mcdataarraydouble_getidsinrange "Here is a Python example".
4039  */
4040 DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
4041 {
4042   checkAllocated();
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);
4051   return ret.retn();
4052 }
4053
4054 /*!
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
4064  *          needed.
4065  *  \throw If both \a a1 and \a a2 are NULL.
4066  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
4067  */
4068 DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4069 {
4070   std::vector<const DataArrayDouble *> tmp(2);
4071   tmp[0]=a1; tmp[1]=a2;
4072   return Aggregate(tmp);
4073 }
4074
4075 /*!
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
4084  *          needed.
4085  *  \throw If all arrays within \a arr are NULL.
4086  *  \throw If getNumberOfComponents() of arrays within \a arr.
4087  */
4088 DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
4089 {
4090   std::vector<const DataArrayDouble *> a;
4091   for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4092     if(*it4)
4093       a.push_back(*it4);
4094   if(a.empty())
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++)
4100     {
4101       if((*it)->getNumberOfComponents()!=nbOfComp)
4102         throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
4103       nbt+=(*it)->getNumberOfTuples();
4104     }
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]));
4111   return ret.retn();
4112 }
4113
4114 /*!
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
4125  *          needed.
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()
4129  */
4130 DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4131 {
4132   std::vector<const DataArrayDouble *> arr(2);
4133   arr[0]=a1; arr[1]=a2;
4134   return Meld(arr);
4135 }
4136
4137 /*!
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
4147  *          needed.
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.
4151  */
4152 DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
4153 {
4154   std::vector<const DataArrayDouble *> a;
4155   for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4156     if(*it4)
4157       a.push_back(*it4);
4158   if(a.empty())
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();
4163   it=a.begin();
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++)
4170     {
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();
4175     }
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++)
4182       {
4183         retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
4184         pts[j]+=nbc[j];
4185       }
4186   int k=0;
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());
4190   return ret;
4191 }
4192
4193 /*!
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
4203  *          needed.
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()
4208  */
4209 DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4210 {
4211   if(!a1 || !a2)
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++)
4227     {
4228       double sum=0.;
4229       for(int j=0;j<nbOfComp;j++)
4230         sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
4231       retPtr[i]=sum;
4232     }
4233   ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str());
4234   ret->setName(a1->getName().c_str());
4235   return ret;
4236 }
4237
4238 /*!
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
4249  *          needed.
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
4254  */
4255 DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4256 {
4257   if(!a1 || !a2)
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 !");
4262   if(nbOfComp!=3)
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++)
4273     {
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];
4277     }
4278   ret->copyStringInfoFrom(*a1);
4279   return ret;
4280 }
4281
4282 /*!
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
4290  *          needed.
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()
4294  */
4295 DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4296 {
4297   if(!a1 || !a2)
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);
4314   return ret;
4315 }
4316
4317 /*!
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
4325  *          needed.
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()
4329  */
4330 DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4331 {
4332   if(!a1 || !a2)
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);
4349   return ret;
4350 }
4351
4352 /*!
4353  * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
4354  * valid cases.
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
4359  *   component. Then
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
4362  *   tuple. Then
4363  *   _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
4364  *
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
4371  *          needed.
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.
4376  */
4377 DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4378 {
4379   if(!a1 || !a2)
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)
4387     {
4388       if(nbOfComp==nbOfComp2)
4389         {
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);
4394         }
4395       else
4396         {
4397           int nbOfCompMin,nbOfCompMax;
4398           const DataArrayDouble *aMin, *aMax;
4399           if(nbOfComp>nbOfComp2)
4400             {
4401               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
4402               aMin=a2; aMax=a1;
4403             }
4404           else
4405             {
4406               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
4407               aMin=a1; aMax=a2;
4408             }
4409           if(nbOfCompMin==1)
4410             {
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);
4419             }
4420           else
4421             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
4422         }
4423     }
4424   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
4425     {
4426       if(nbOfComp==nbOfComp2)
4427         {
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);
4438         }
4439       else
4440         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
4441     }
4442   else
4443     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
4444   return ret.retn();
4445 }
4446
4447 /*!
4448  * Adds values of another DataArrayDouble to values of \a this one. There are 3
4449  * valid cases.
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 ].
4457  *
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.
4463  */
4464 void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4465 {
4466   if(!other)
4467     throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
4468   const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual  !";
4469   checkAllocated();
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)
4476     {
4477       if(nbOfComp==nbOfComp2)
4478         {
4479           std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
4480         }
4481       else if(nbOfComp2==1)
4482         {
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++));
4487         }
4488       else
4489         throw INTERP_KERNEL::Exception(msg);
4490     }
4491   else if(nbOfTuple2==1)
4492     {
4493       if(nbOfComp2==nbOfComp)
4494         {
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>());
4499         }
4500       else
4501         throw INTERP_KERNEL::Exception(msg);
4502     }
4503   else
4504     throw INTERP_KERNEL::Exception(msg);
4505   declareAsNew();
4506 }
4507
4508 /*!
4509  * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
4510  * valid cases.
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
4515  *   component. Then
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
4518  *   tuple. Then
4519  *   _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
4520  *
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
4527  *          needed.
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.
4532  */
4533 DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4534 {
4535   if(!a1 || !a2)
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)
4542     {
4543       if(nbOfComp1==nbOfComp2)
4544         {
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);
4549           return ret.retn();
4550         }
4551       else if(nbOfComp2==1)
4552         {
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);
4561           return ret.retn();
4562         }
4563       else
4564         {
4565           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
4566           return 0;
4567         }
4568     }
4569   else if(nbOfTuple2==1)
4570     {
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);
4579       return ret.retn();
4580     }
4581   else
4582     {
4583       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
4584       return 0;
4585     }
4586 }
4587
4588 /*!
4589  * Subtract values of another DataArrayDouble from values of \a this one. There are 3
4590  * valid cases.
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 ].
4598  *
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.
4604  */
4605 void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4606 {
4607   if(!other)
4608     throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !");
4609   const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual  !";
4610   checkAllocated();
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)
4617     {
4618       if(nbOfComp==nbOfComp2)
4619         {
4620           std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
4621         }
4622       else if(nbOfComp2==1)
4623         {
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++)); 
4628         }
4629       else
4630         throw INTERP_KERNEL::Exception(msg);
4631     }
4632   else if(nbOfTuple2==1)
4633     {
4634       if(nbOfComp2==nbOfComp)
4635         {
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>());
4640         }
4641       else
4642         throw INTERP_KERNEL::Exception(msg);
4643     }
4644   else
4645     throw INTERP_KERNEL::Exception(msg);
4646   declareAsNew();
4647 }
4648
4649 /*!
4650  * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
4651  * valid cases.
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
4656  *   component. Then
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
4659  *   tuple. Then
4660  *   _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
4661  *
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
4668  *          needed.
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.
4673  */
4674 DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4675 {
4676   if(!a1 || !a2)
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)
4684     {
4685       if(nbOfComp==nbOfComp2)
4686         {
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);
4691         }
4692       else
4693         {
4694           int nbOfCompMin,nbOfCompMax;
4695           const DataArrayDouble *aMin, *aMax;
4696           if(nbOfComp>nbOfComp2)
4697             {
4698               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
4699               aMin=a2; aMax=a1;
4700             }
4701           else
4702             {
4703               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
4704               aMin=a1; aMax=a2;
4705             }
4706           if(nbOfCompMin==1)
4707             {
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);
4716             }
4717           else
4718             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
4719         }
4720     }
4721   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
4722     {
4723       if(nbOfComp==nbOfComp2)
4724         {
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);
4735         }
4736       else
4737         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
4738     }
4739   else
4740     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
4741   return ret.retn();
4742 }
4743
4744 /*!
4745  * Multiply values of another DataArrayDouble to values of \a this one. There are 3
4746  * valid cases.
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 ].
4754  *
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.
4760  */
4761 void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4762 {
4763   if(!other)
4764     throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
4765   const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
4766   checkAllocated();
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)
4773     {
4774       if(nbOfComp==nbOfComp2)
4775         {
4776           std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
4777         }
4778       else if(nbOfComp2==1)
4779         {
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++));
4784         }
4785       else
4786         throw INTERP_KERNEL::Exception(msg);
4787     }
4788   else if(nbOfTuple2==1)
4789     {
4790       if(nbOfComp2==nbOfComp)
4791         {
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>());
4796         }
4797       else
4798         throw INTERP_KERNEL::Exception(msg);
4799     }
4800   else
4801     throw INTERP_KERNEL::Exception(msg);
4802   declareAsNew();
4803 }
4804
4805 /*!
4806  * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
4807  * valid cases.
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
4812  *   component. Then
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
4815  *   tuple. Then
4816  *   _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
4817  *
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
4824  *          needed.
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!
4830  */
4831 DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4832 {
4833   if(!a1 || !a2)
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)
4840     {
4841       if(nbOfComp1==nbOfComp2)
4842         {
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);
4847           return ret.retn();
4848         }
4849       else if(nbOfComp2==1)
4850         {
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);
4859           return ret.retn();
4860         }
4861       else
4862         {
4863           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
4864           return 0;
4865         }
4866     }
4867   else if(nbOfTuple2==1)
4868     {
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);
4877       return ret.retn();
4878     }
4879   else
4880     {
4881       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
4882       return 0;
4883     }
4884 }
4885
4886 /*!
4887  * Divide values of \a this array by values of another DataArrayDouble. There are 3
4888  * valid cases.
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 ].
4896  *
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!
4903  */
4904 void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4905 {
4906   if(!other)
4907     throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !");
4908   const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
4909   checkAllocated();
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)
4916     {
4917       if(nbOfComp==nbOfComp2)
4918         {
4919           std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
4920         }
4921       else if(nbOfComp2==1)
4922         {
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++));
4927         }
4928       else
4929         throw INTERP_KERNEL::Exception(msg);
4930     }
4931   else if(nbOfTuple2==1)
4932     {
4933       if(nbOfComp2==nbOfComp)
4934         {
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>());
4939         }
4940       else
4941         throw INTERP_KERNEL::Exception(msg);
4942     }
4943   else
4944     throw INTERP_KERNEL::Exception(msg);
4945   declareAsNew();
4946 }
4947
4948 /*!
4949  * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3
4950  * valid cases.
4951  *
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
4956  *          needed.
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.
4961  */
4962 DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4963 {
4964   if(!a1 || !a2)
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++)
4978     {
4979       if(*ptr1>=0)
4980         {
4981           *ptr=pow(*ptr1,*ptr2);
4982         }
4983       else
4984         {
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());
4987         }
4988     }
4989   return ret.retn();
4990 }
4991
4992 /*!
4993  * Apply pow on values of another DataArrayDouble to values of \a this one.
4994  *
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.
5000  */
5001 void DataArrayDouble::powEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
5002 {
5003   if(!other)
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++)
5016     {
5017       if(*ptr>=0)
5018         *ptr=pow(*ptr,*ptrc);
5019       else
5020         {
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());
5023         }
5024     }
5025   declareAsNew();
5026 }
5027
5028 /*!
5029  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5030  * Server side.
5031  */
5032 void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
5033 {
5034   tinyInfo.resize(2);
5035   if(isAllocated())
5036     {
5037       tinyInfo[0]=getNumberOfTuples();
5038       tinyInfo[1]=getNumberOfComponents();
5039     }
5040   else
5041     {
5042       tinyInfo[0]=-1;
5043       tinyInfo[1]=-1;
5044     }
5045 }
5046
5047 /*!
5048  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5049  * Server side.
5050  */
5051 void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
5052 {
5053   if(isAllocated())
5054     {
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);
5060     }
5061   else
5062     {
5063       tinyInfo.resize(1);
5064       tinyInfo[0]=getName();
5065     }
5066 }
5067
5068 /*!
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.
5071  */
5072 bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
5073 {
5074   int nbOfTuple=tinyInfoI[0];
5075   int nbOfComp=tinyInfoI[1];
5076   if(nbOfTuple!=-1 || nbOfComp!=-1)
5077     {
5078       alloc(nbOfTuple,nbOfComp);
5079       return true;
5080     }
5081   return false;
5082 }
5083
5084 /*!
5085  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5086  */
5087 void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
5088 {
5089   setName(tinyInfoS[0].c_str());
5090   if(isAllocated())
5091     {
5092       int nbOfCompo=getNumberOfComponents();
5093       for(int i=0;i<nbOfCompo;i++)
5094         setInfoOnComponent(i,tinyInfoS[i+1].c_str());
5095     }
5096 }
5097
5098 DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
5099 {
5100   if(_da)
5101     {
5102       _da->incrRef();
5103       if(_da->isAllocated())
5104         {
5105           _nb_comp=da->getNumberOfComponents();
5106           _nb_tuple=da->getNumberOfTuples();
5107           _pt=da->getPointer();
5108         }
5109     }
5110 }
5111
5112 DataArrayDoubleIterator::~DataArrayDoubleIterator()
5113 {
5114   if(_da)
5115     _da->decrRef();
5116 }
5117
5118 DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() throw(INTERP_KERNEL::Exception)
5119 {
5120   if(_tuple_id<_nb_tuple)
5121     {
5122       _tuple_id++;
5123       DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
5124       _pt+=_nb_comp;
5125       return ret;
5126     }
5127   else
5128     return 0;
5129 }
5130
5131 DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
5132 {
5133 }
5134
5135
5136 std::string DataArrayDoubleTuple::repr() const throw(INTERP_KERNEL::Exception)
5137 {
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] << ")";
5142   return oss.str();
5143 }
5144
5145 double DataArrayDoubleTuple::doubleValue() const throw(INTERP_KERNEL::Exception)
5146 {
5147   if(_nb_of_compo==1)
5148     return *_pt;
5149   throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
5150 }
5151
5152 /*!
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.
5157  */
5158 DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
5159 {
5160   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
5161     {
5162       DataArrayDouble *ret=DataArrayDouble::New();
5163       ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
5164       return ret;
5165     }
5166   else
5167     {
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());
5171     }
5172 }
5173
5174 /*!
5175  * Returns a new instance of DataArrayInt. The caller is to delete this array
5176  * using decrRef() as it is no more needed. 
5177  */
5178 DataArrayInt *DataArrayInt::New()
5179 {
5180   return new DataArrayInt;
5181 }
5182
5183 /*!
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.
5187  */
5188 bool DataArrayInt::isAllocated() const throw(INTERP_KERNEL::Exception)
5189 {
5190   return getConstPointer()!=0;
5191 }
5192
5193 /*!
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.
5196  */
5197 void DataArrayInt::checkAllocated() const throw(INTERP_KERNEL::Exception)
5198 {
5199   if(!isAllocated())
5200     throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
5201 }
5202
5203 std::size_t DataArrayInt::getHeapMemorySize() const
5204 {
5205   std::size_t sz=_mem.getNbOfElemAllocated();
5206   sz*=sizeof(int);
5207   return DataArray::getHeapMemorySize()+sz;
5208 }
5209
5210 /*!
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.
5214  *
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()
5219  */
5220 void DataArrayInt::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
5221 {
5222   if(getNumberOfComponents()!=(int)info.size())
5223     {
5224       if(!isAllocated())
5225         _info_on_compo=info;
5226       else
5227         {
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());
5230         }
5231     }
5232   else
5233     _info_on_compo=info;
5234 }
5235
5236 /*!
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.
5241  */
5242 int DataArrayInt::intValue() const throw(INTERP_KERNEL::Exception)
5243 {
5244   if(isAllocated())
5245     {
5246       if(getNbOfElems()==1)
5247         {
5248           return *getConstPointer();
5249         }
5250       else
5251         throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is allocated but number of elements is not equal to 1 !");
5252     }
5253   else
5254     throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
5255 }
5256
5257 /*!
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.
5262  */
5263 int DataArrayInt::getHashCode() const throw(INTERP_KERNEL::Exception)
5264 {
5265   checkAllocated();
5266   std::size_t nbOfElems=getNbOfElems();
5267   int ret=nbOfElems*65536;
5268   int delta=3;
5269   if(nbOfElems>48)
5270     delta=nbOfElems/8;
5271   int ret0=0;
5272   const int *pt=begin();
5273   for(std::size_t i=0;i<nbOfElems;i+=delta)
5274     ret0+=pt[i] & 0x1FFF;
5275   return ret+ret0;
5276 }
5277
5278 /*!
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.
5282  */
5283 bool DataArrayInt::empty() const throw(INTERP_KERNEL::Exception)
5284 {
5285   checkAllocated();
5286   return getNumberOfTuples()==0;
5287 }
5288
5289 /*!
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.
5293  */
5294 DataArrayInt *DataArrayInt::deepCpy() const throw(INTERP_KERNEL::Exception)
5295 {
5296   return new DataArrayInt(*this);
5297 }
5298
5299 /*!
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).
5305  */
5306 DataArrayInt *DataArrayInt::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception)
5307 {
5308   if(dCpy)
5309     return deepCpy();
5310   else
5311     {
5312       incrRef();
5313       return const_cast<DataArrayInt *>(this);
5314     }
5315 }
5316
5317 /*!
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.
5322  */
5323 void DataArrayInt::cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception)
5324 {
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++)
5333     pt[i]=ptI[i];
5334   copyStringInfoFrom(other);
5335 }
5336
5337 /*!
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.
5342  * 
5343  * \sa DataArrayInt::pack, DataArrayInt::pushBackSilent, DataArrayInt::pushBackValsSilent
5344  */
5345 void DataArrayInt::reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception)
5346 {
5347   int nbCompo=getNumberOfComponents();
5348   if(nbCompo==1)
5349     {
5350       _mem.reserve(nbOfElems);
5351     }
5352   else if(nbCompo==0)
5353     {
5354       _mem.reserve(nbOfElems);
5355       _info_on_compo.resize(1);
5356     }
5357   else
5358     throw INTERP_KERNEL::Exception("DataArrayInt::reserve : not available for DataArrayInt with number of components different than 1 !");
5359 }
5360
5361 /*!
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.
5364  *
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
5368  */
5369 void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception)
5370 {
5371   int nbCompo=getNumberOfComponents();
5372   if(nbCompo==1)
5373     _mem.pushBack(val);
5374   else if(nbCompo==0)
5375     {
5376       _info_on_compo.resize(1);
5377       _mem.pushBack(val);
5378     }
5379   else
5380     throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !");
5381 }
5382
5383 /*!
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.
5386  *
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
5392  */
5393 void DataArrayInt::pushBackValsSilent(const int *valsBg, const int *valsEnd) throw(INTERP_KERNEL::Exception)
5394 {
5395   int nbCompo=getNumberOfComponents();
5396   if(nbCompo==1)
5397     _mem.insertAtTheEnd(valsBg,valsEnd);
5398   else if(nbCompo==0)
5399     {
5400       _info_on_compo.resize(1);
5401       _mem.insertAtTheEnd(valsBg,valsEnd);
5402     }
5403   else
5404     throw INTERP_KERNEL::Exception("DataArrayInt::pushBackValsSilent : not available for DataArrayInt with number of components different than 1 !");
5405 }
5406
5407 /*!
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.
5411  */
5412 int DataArrayInt::popBackSilent() throw(INTERP_KERNEL::Exception)
5413 {
5414   if(getNumberOfComponents()==1)
5415     return _mem.popBack();
5416   else
5417     throw INTERP_KERNEL::Exception("DataArrayInt::popBackSilent : not available for DataArrayInt with number of components different than 1 !");
5418 }
5419
5420 /*!
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.
5422  *
5423  * \sa DataArrayInt::getHeapMemorySize, DataArrayInt::reserve
5424  */
5425 void DataArrayInt::pack() const throw(INTERP_KERNEL::Exception)
5426 {
5427   _mem.pack();
5428 }
5429
5430 /*!
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.
5436  */
5437 void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
5438 {
5439   if(isAllocated())
5440     {
5441       if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
5442         alloc(nbOfTuple,nbOfCompo);
5443     }
5444   else
5445     alloc(nbOfTuple,nbOfCompo);
5446 }
5447
5448 /*!
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.
5455  */
5456 void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
5457 {
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);
5462   declareAsNew();
5463 }
5464
5465 /*!
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.
5469  */
5470 void DataArrayInt::fillWithZero() throw(INTERP_KERNEL::Exception)
5471 {
5472   checkAllocated();
5473   _mem.fillWithValue(0);
5474   declareAsNew();
5475 }
5476
5477 /*!
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.
5482  */
5483 void DataArrayInt::fillWithValue(int val) throw(INTERP_KERNEL::Exception)
5484 {
5485   checkAllocated();
5486   _mem.fillWithValue(val);
5487   declareAsNew();
5488 }
5489
5490 /*!
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.
5496  */
5497 void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception)
5498 {
5499   checkAllocated();
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++)
5505     ptr[i]=init+i;
5506   declareAsNew();
5507 }
5508
5509 /*!
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.
5513  */
5514 std::string DataArrayInt::repr() const throw(INTERP_KERNEL::Exception)
5515 {
5516   std::ostringstream ret;
5517   reprStream(ret);
5518   return ret.str();
5519 }
5520
5521 std::string DataArrayInt::reprZip() const throw(INTERP_KERNEL::Exception)
5522 {
5523   std::ostringstream ret;
5524   reprZipStream(ret);
5525   return ret.str();
5526 }
5527
5528 void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
5529 {
5530   checkAllocated();
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";
5536 }
5537
5538 void DataArrayInt::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5539 {
5540   stream << "Name of int array : \"" << _name << "\"\n";
5541   reprWithoutNameStream(stream);
5542 }
5543
5544 void DataArrayInt::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5545 {
5546   stream << "Name of int array : \"" << _name << "\"\n";
5547   reprZipWithoutNameStream(stream);
5548 }
5549
5550 void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5551 {
5552   DataArray::reprWithoutNameStream(stream);
5553   _mem.repr(getNumberOfComponents(),stream);
5554 }
5555
5556 void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5557 {
5558   DataArray::reprWithoutNameStream(stream);
5559   _mem.reprZip(getNumberOfComponents(),stream);
5560 }
5561
5562 void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5563 {
5564   int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
5565   const int *data=getConstPointer();
5566   stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl;
5567   if(nbTuples*nbComp>=1)
5568     {
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;
5573     }
5574   else
5575     stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
5576   stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
5577 }
5578
5579 /*!
5580  * Method that gives a quick overvien of \a this for python.
5581  */
5582 void DataArrayInt::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5583 {
5584   static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
5585   stream << "DataArrayInt C++ instance at " << this << ". ";
5586   if(isAllocated())
5587     {
5588       int nbOfCompo=(int)_info_on_compo.size();
5589       if(nbOfCompo>=1)
5590         {
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++)
5598             {
5599               if(nbOfCompo>1)
5600                 {
5601                   oss2 << "(";
5602                   for(int j=0;j<nbOfCompo;j++,data++)
5603                     {
5604                       oss2 << *data;
5605                       if(j!=nbOfCompo-1) oss2 << ", ";
5606                     }
5607                   oss2 << ")";
5608                 }
5609               else
5610                 oss2 << *data++;
5611               if(i!=nbOfTuples-1) oss2 << ", ";
5612               std::string oss3Str(oss2.str());
5613               if(oss3Str.length()<MAX_NB_OF_BYTE_IN_REPR)
5614                 oss2Str=oss3Str;
5615               else
5616                 isFinished=false;
5617             }
5618           stream << oss2Str;
5619           if(!isFinished)
5620             stream << "... ";
5621           stream << "]";
5622         }
5623       else
5624         stream << "Number of components : 0.";
5625     }
5626   else
5627     stream << "*** No data allocated ****";
5628 }
5629
5630 /*!
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
5634  *         to \a this array.
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).
5640  */
5641 void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception)
5642 {
5643   checkAllocated();
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++)
5650     {
5651       if(*pt>=0 && *pt<nbElemsIn)
5652         *pt=indArrBg[*pt];
5653       else
5654         {
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());
5657         }
5658     }
5659   declareAsNew();
5660 }
5661
5662 /*!
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,
5665  * for example. 
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.
5692  *
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]
5698  *
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.
5701  *
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. 
5707  * 
5708  */
5709 void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
5710                                      DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception)
5711 {
5712   checkAllocated();
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);
5717   if(nbOfCast<2)
5718     throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !");
5719   nbOfCast--;
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++)
5733     {
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;
5737       if(pos2<nbOfCast)
5738         {
5739           ret1Ptr[i]=(int)pos2;
5740           ret2Ptr[i]=work[i]-arrBg[pos2];
5741           castsDetected.insert(pos2);
5742         }
5743       else
5744         {
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());
5747         }
5748     }
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();
5754 }
5755
5756 /*!
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
5767  *          needed.
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.
5771  */
5772 DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception)
5773 {
5774   checkAllocated();
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++)
5785     {
5786       if(*pt>=0 && *pt<nbElemsIn)
5787         {
5788           int pos=indArrBg[*pt];
5789           if(pos>=0 && pos<nbOfTuples)
5790             tmp[pos]=i;
5791           else
5792             {
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());
5795             }
5796         }
5797       else
5798         {
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());
5801         }
5802     }
5803   return ret.retn();
5804 }
5805
5806 /*!
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
5814  *          needed.
5815  * 
5816  *  \ref cpp_mcdataarrayint_invertarrayo2n2n2o "Here is a C++ example".<br>
5817  *  \ref py_mcdataarrayint_invertarrayo2n2n2o  "Here is a Python example".
5818  */
5819 DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
5820 {
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++)
5827     if(old2New[i]!=-1)
5828       pt[old2New[i]]=i;
5829   return ret.retn();
5830 }
5831
5832 /*!
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]
5835  */
5836 DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception)
5837 {
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--)
5844     if(old2New[i]!=-1)
5845       pt[old2New[i]]=i;
5846   return ret.retn();
5847 }
5848
5849 /*!
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
5857  *          needed.
5858  * 
5859  *  \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
5860  *
5861  *  \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
5862  */
5863 DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
5864 {
5865   checkAllocated();
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++)
5873     pt[new2Old[i]]=i;
5874   return ret.retn();
5875 }
5876
5877 /*!
5878  * Equivalent to DataArrayInt::isEqual except that if false the reason of
5879  * mismatch is given.
5880  * 
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
5884  */
5885 bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception)
5886 {
5887   if(!areInfoEqualsIfNotWhy(other,reason))
5888     return false;
5889   return _mem.isEqual(other._mem,0,reason);
5890 }
5891
5892 /*!
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.
5897  */
5898 bool DataArrayInt::isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
5899 {
5900   std::string tmp;
5901   return isEqualIfNotWhy(other,tmp);
5902 }
5903
5904 /*!
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.
5909  */
5910 bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
5911 {
5912   std::string tmp;
5913   return _mem.isEqual(other._mem,0,tmp);
5914 }
5915
5916 /*!
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.
5922  */
5923 bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
5924 {
5925   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a=deepCpy();
5926   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> b=other.deepCpy();
5927   a->sort();
5928   b->sort();
5929   return a->isEqualWithoutConsideringStr(*b);
5930 }
5931
5932 /*!
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.
5937  */
5938 void DataArrayInt::sort(bool asc) throw(INTERP_KERNEL::Exception)
5939 {
5940   checkAllocated();
5941   if(getNumberOfComponents()!=1)
5942     throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !");
5943   _mem.sort(asc);
5944   declareAsNew();
5945 }
5946
5947 /*!
5948  * Reverse the array values.
5949  *  \throw If \a this->getNumberOfComponents() < 1.
5950  *  \throw If \a this is not allocated.
5951  */
5952 void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception)
5953 {
5954   checkAllocated();
5955   _mem.reverse(getNumberOfComponents());
5956   declareAsNew();
5957 }
5958
5959 /*!
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
5964  *         increasing arg.
5965  *  \throw If \a this->getNumberOfComponents() != 1.
5966  *  \throw If \a this is not allocated.
5967  */
5968 void DataArrayInt::checkMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
5969 {
5970   if(!isMonotonic(increasing))
5971     {
5972       if (increasing)
5973         throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
5974       else
5975         throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
5976     }
5977 }
5978
5979 /*!
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.
5985  */
5986 bool DataArrayInt::isMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
5987 {
5988   checkAllocated();
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();
5993   if(nbOfElements==0)
5994     return true;
5995   int ref=ptr[0];
5996   if(increasing)
5997     {
5998       for(int i=1;i<nbOfElements;i++)
5999         {
6000           if(ptr[i]>=ref)
6001             ref=ptr[i];
6002           else
6003             return false;
6004         }
6005     }
6006   else
6007     {
6008       for(int i=1;i<nbOfElements;i++)
6009         {
6010           if(ptr[i]<=ref)
6011             ref=ptr[i];
6012           else
6013             return false;
6014         }
6015     }
6016   return true;
6017 }
6018
6019 /*!
6020  * This method check that array consistently INCREASING or DECREASING in value.
6021  */
6022 bool DataArrayInt::isStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6023 {
6024   checkAllocated();
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();
6029   if(nbOfElements==0)
6030     return true;
6031   int ref=ptr[0];
6032   if(increasing)
6033     {
6034       for(int i=1;i<nbOfElements;i++)
6035         {
6036           if(ptr[i]>ref)
6037             ref=ptr[i];
6038           else
6039             return false;
6040         }
6041     }
6042   else
6043     {
6044       for(int i=1;i<nbOfElements;i++)
6045         {
6046           if(ptr[i]<ref)
6047             ref=ptr[i];
6048           else
6049             return false;
6050         }
6051     }
6052   return true;
6053 }
6054
6055 /*!
6056  * This method check that array consistently INCREASING or DECREASING in value.
6057  */
6058 void DataArrayInt::checkStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6059 {
6060   if(!isStrictlyMonotonic(increasing))
6061     {
6062       if (increasing)
6063         throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
6064       else
6065         throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
6066     }
6067 }
6068
6069 /*!
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
6078  * no more needed.
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.
6083  * 
6084  *  \ref cpp_mcdataarrayint_buildpermutationarr "Here is a C++ example".
6085  *
6086  *  \ref py_mcdataarrayint_buildpermutationarr "Here is a Python example".
6087  */
6088 DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
6089 {
6090   checkAllocated();
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++)
6103     mm[pt[i]]=i;
6104   pt=other.getConstPointer();
6105   int *retToFill=ret->getPointer();
6106   for(int i=0;i<nbTuple;i++)
6107     {
6108       std::map<int,int>::const_iterator it=mm.find(pt[i]);
6109       if(it==mm.end())
6110         {
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());
6113         }
6114       retToFill[i]=(*it).second;
6115     }
6116   return ret.retn();
6117 }
6118
6119 /*!
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.
6130  */
6131 void DataArrayInt::useArray(const int *array, bool ownership,  DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
6132 {
6133   _info_on_compo.resize(nbOfCompo);
6134   _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
6135   declareAsNew();
6136 }
6137
6138 void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
6139 {
6140   _info_on_compo.resize(nbOfCompo);
6141   _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
6142   declareAsNew();
6143 }
6144
6145 /*!
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()!
6154  */
6155 DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
6156 {
6157   checkAllocated();
6158   if(_mem.isNull())
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());
6163   return ret;
6164 }
6165
6166 /*!
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()!
6175  */
6176 DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception)
6177 {
6178   checkAllocated();
6179   if(_mem.isNull())
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());
6184   return ret;
6185 }
6186
6187 /*!
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.
6195  */
6196 void DataArrayInt::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception)
6197 {
6198   checkAllocated();
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());
6206   delete [] tmp;
6207   declareAsNew();
6208 }
6209
6210 /*!
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.
6219  */
6220 void DataArrayInt::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception)
6221 {
6222   checkAllocated();
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());
6230   delete [] tmp;
6231   declareAsNew();
6232 }
6233
6234 /*!
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.
6245  */
6246 DataArrayInt *DataArrayInt::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception)
6247 {
6248   checkAllocated();
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);
6259   return ret.retn();
6260 }
6261
6262 /*!
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.
6272  */
6273 DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception)
6274 {
6275   checkAllocated();
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);
6286   return ret.retn();
6287 }
6288
6289 /*!
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.
6301  */
6302 DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception)
6303 {
6304   checkAllocated();
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++)
6312     {
6313       int w=old2New[i];
6314       if(w>=0)
6315         std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
6316     }
6317   ret->copyStringInfoFrom(*this);
6318   return ret.retn();
6319 }
6320
6321 /*!
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.
6336  */
6337 DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
6338 {
6339   checkAllocated();
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();
6346   int i=0;
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);
6350   return ret.retn();
6351 }
6352
6353 /*!
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().
6371  */
6372 DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
6373 {
6374   checkAllocated();
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();
6382   int i=0;
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);
6386     else
6387       throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
6388   ret->copyStringInfoFrom(*this);
6389   return ret.retn();
6390 }
6391
6392 /*!
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.
6407  */
6408 DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
6409 {
6410   checkAllocated();
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);
6420   return ret.retn();
6421 }
6422
6423 /*!
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.
6434  */
6435 DataArrayInt *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
6436 {
6437   checkAllocated();
6438   int nbOfComp=getNumberOfComponents();
6439   int nbOfTuplesThis=getNumberOfTuples();
6440   if(ranges.empty())
6441     {
6442       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6443       ret->alloc(0,nbOfComp);
6444       ret->copyStringInfoFrom(*this);
6445       return ret.retn();
6446     }
6447   int ref=ranges.front().first;
6448   int nbOfTuples=0;
6449   bool isIncreasing=true;
6450   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
6451     {
6452       if((*it).first<=(*it).second)
6453         {
6454           if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
6455             {
6456               nbOfTuples+=(*it).second-(*it).first;
6457               if(isIncreasing)
6458                 isIncreasing=ref<=(*it).first;
6459               ref=(*it).second;
6460             }
6461           else
6462             {
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());
6466             }
6467         }
6468       else
6469         {
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());
6473         }
6474     }
6475   if(isIncreasing && nbOfTuplesThis==nbOfTuples)
6476     return deepCpy();
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);
6484   return ret.retn();
6485 }
6486
6487 /*!
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.
6500  */
6501 DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception)
6502 {
6503   checkAllocated();
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);
6511   return ret;
6512 }
6513
6514 /*!
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>
6523  * For more info on
6524  * mapping and its usage in renumbering see \ref MEDCouplingArrayRenumbering. <br>
6525  * \b Example:
6526  * - \a this: [0,3,2,3,2,2,1,2]
6527  * - \a targetNb: 4
6528  * - \a arr:  [0,  6,  2,4,5,7,  1,3]
6529  * - \a arrI: [0,1,2,6,8]
6530  *
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.
6548  */
6549 void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception)
6550 {
6551   checkAllocated();
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++)
6561     {
6562       int tmp2=input[i];
6563       if(tmp2>=0 && tmp2<targetNb)
6564         tmp[tmp2].push_back(i);
6565       else
6566         {
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());
6569         }
6570     }
6571   int *retIPtr=retI->getPointer();
6572   *retIPtr=0;
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);
6581   arr=ret.retn();
6582   arrI=retI.retn();
6583 }
6584
6585
6586 /*!
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>
6592  * \b Example: <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]
6598  *
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 ).
6610  */
6611 DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
6612 {
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);
6621   int newNb=0;
6622   for(int iNode=0;iNode<nbOfOldTuples;iNode++)
6623     {
6624       if(pt[iNode]<0)
6625         {
6626           if(pt[iNode]==-1)
6627             pt[iNode]=newNb++;
6628           else
6629             {
6630               int grpId=-(pt[iNode]+2);
6631               for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
6632                 {
6633                   if(arr[j]>=0 && arr[j]<nbOfOldTuples)
6634                     pt[arr[j]]=newNb;
6635                   else
6636                     {
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());
6639                     }
6640                 }
6641               newNb++;
6642             }
6643         }
6644     }
6645   newNbOfTuples=newNb;
6646   return ret.retn();
6647 }
6648
6649 /*!
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>
6653  * \b Example: <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] 
6657  *
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.
6662  */
6663 DataArrayInt *DataArrayInt::buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception)
6664 {
6665   checkAllocated();
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++)
6675     {
6676       int val=*pt;
6677       std::map<int,int>::iterator it=m.find(val);
6678       if(it!=m.end())
6679         {
6680           *opt=(*it).second;
6681           (*it).second++;
6682         }
6683       else
6684         {
6685           *opt=0;
6686           m.insert(std::pair<int,int>(val,1));
6687         }
6688     }
6689   int sum=0;
6690   for(std::map<int,int>::iterator it=m.begin();it!=m.end();it++)
6691     {
6692       int vt=(*it).second;
6693       (*it).second=sum;
6694       sum+=vt;
6695     }
6696   pt=getConstPointer();
6697   opt=ret->getPointer();
6698   for(int i=0;i<nbOfTuples;i++,pt++,opt++)
6699     *opt+=m[*pt];
6700   //
6701   return ret.retn();
6702 }
6703
6704 /*!
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.
6711  */
6712 bool DataArrayInt::isIdentity() const throw(INTERP_KERNEL::Exception)
6713 {
6714   checkAllocated();
6715   if(getNumberOfComponents()!=1)
6716     return false;
6717   int nbOfTuples=getNumberOfTuples();
6718   const int *pt=getConstPointer();
6719   for(int i=0;i<nbOfTuples;i++,pt++)
6720     if(*pt!=i)
6721       return false;
6722   return true;
6723 }
6724
6725 /*!
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
6731  */
6732 bool DataArrayInt::isUniform(int val) const throw(INTERP_KERNEL::Exception)
6733 {
6734   checkAllocated();
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;
6740   for(;w!=end2;w++)
6741     if(*w!=val)
6742       return false;
6743   return true;
6744 }
6745
6746 /*!
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.
6750  */
6751 DataArrayDouble *DataArrayInt::convertToDblArr() const
6752 {
6753   checkAllocated();
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);
6761   return ret;
6762 }
6763
6764 /*!
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
6778  */
6779 DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
6780 {
6781   checkAllocated();
6782   int nbt=getNumberOfTuples();
6783   if(tupleIdBg<0)
6784     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
6785   if(tupleIdBg>nbt)
6786     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
6787   int trueEnd=tupleIdEnd;
6788   if(tupleIdEnd!=-1)
6789     {
6790       if(tupleIdEnd>nbt)
6791         throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
6792     }
6793   else
6794     trueEnd=nbt;
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());
6800   return ret.retn();
6801 }
6802
6803 /*!
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!
6812  */
6813 void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
6814 {
6815   checkAllocated();
6816   if(newNbOfCompo<1)
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);
6825   declareAsNew();
6826 }
6827
6828 /*!
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()!
6836  *  \sa rearrange()
6837  */
6838 void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception)
6839 {
6840   checkAllocated();
6841   int nbOfTuples=getNumberOfTuples();
6842   rearrange(nbOfTuples);
6843 }
6844
6845 /*!
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
6851  * components.  
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.
6857  */
6858 DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception)
6859 {
6860   checkAllocated();
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++)
6869     {
6870       int j=0;
6871       for(;j<dim;j++)
6872         nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
6873       for(;j<newNbOfComp;j++)
6874         nc[newNbOfComp*i+j]=dftValue;
6875     }
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());
6880   return ret.retn();
6881 }
6882
6883 /*!
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.
6888  */
6889 void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
6890 {
6891   checkAllocated();
6892   _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
6893   declareAsNew();
6894 }
6895
6896
6897 /*!
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().
6909  *
6910  *  \ref cpp_mcdataarrayint_keepselectedcomponents "Here is a Python example".
6911  */
6912 DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
6913 {
6914   checkAllocated();
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]];
6928   return ret.retn();
6929 }
6930
6931 /*!
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.
6938  *
6939  *  \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
6940  *
6941  *  \ref py_mcdataarrayint_meldwith "Here is a Python example".
6942  */
6943 void DataArrayInt::meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
6944 {
6945   if(!other)
6946     throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
6947   checkAllocated();
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)];
6955   int *w=newArr;
6956   const int *inp1=getConstPointer();
6957   const int *inp2=other->getConstPointer();
6958   for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
6959     {
6960       w=std::copy(inp1,inp1+nbOfComp1,w);
6961       w=std::copy(inp2,inp2+nbOfComp2,w);
6962     }
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);
6968 }
6969
6970 /*!
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
6977  *              to be copied.
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().
6981  *
6982  *  \ref cpp_mcdataarrayint_setselectedcomponents "Here is a Python example".
6983  */
6984 void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
6985 {
6986   if(!a)
6987     throw INTERP_KERNEL::Exception("DataArrayInt::setSelectedComponents : input DataArrayInt is NULL !");
6988   checkAllocated();
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;
6999 }
7000
7001 /*!
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
7009  *              are located.
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
7013  *              to are located.
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)).
7032  *
7033  *  \ref cpp_mcdataarrayint_setpartofvalues1 "Here is a Python example".
7034  */
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)
7036 {
7037   if(!a)
7038     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues1 : DataArrayInt pointer in input is NULL !");
7039   const char msg[]="DataArrayInt::setPartOfValues1";
7040   checkAllocated();
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)
7050     {
7051       if(strictCompoCompare)
7052         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7053     }
7054   else
7055     {
7056       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7057       assignTech=false;
7058     }
7059   int *pt=getPointer()+bgTuples*nbComp+bgComp;
7060   const int *srcPt=a->getConstPointer();
7061   if(assignTech)
7062     {
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;
7066     }
7067   else
7068     {
7069       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7070         {
7071           const int *srcPt2=srcPt;
7072           for(int j=0;j<newNbOfComp;j++,srcPt2++)
7073             pt[j*stepComp]=*srcPt2;
7074         }
7075     }
7076 }
7077
7078 /*!
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
7085  *              are located.
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
7089  *              to are located.
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
7094  *            for \this array.
7095  *
7096  *  \ref cpp_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
7097  */
7098 void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
7099 {
7100   const char msg[]="DataArrayInt::setPartOfValuesSimple1";
7101   checkAllocated();
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++)
7111       pt[j*stepComp]=a;
7112 }
7113
7114
7115 /*!
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.
7125  * 
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>.
7150  *
7151  *  \ref cpp_mcdataarrayint_setpartofvalues2 "Here is a Python example".
7152  */
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)
7154 {
7155   if(!a)
7156     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues2 : DataArrayInt pointer in input is NULL !");
7157   const char msg[]="DataArrayInt::setPartOfValues2";
7158   checkAllocated();
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)
7168     {
7169       if(strictCompoCompare)
7170         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7171     }
7172   else
7173     {
7174       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7175       assignTech=false;
7176     }
7177   int *pt=getPointer();
7178   const int *srcPt=a->getConstPointer();
7179   if(assignTech)
7180     {    
7181       for(const int *w=bgTuples;w!=endTuples;w++)
7182         {
7183           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7184           for(const int *z=bgComp;z!=endComp;z++,srcPt++)
7185             {    
7186               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
7187             }
7188         }
7189     }
7190   else
7191     {
7192       for(const int *w=bgTuples;w!=endTuples;w++)
7193         {
7194           const int *srcPt2=srcPt;
7195           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7196           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
7197             {    
7198               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
7199             }
7200         }
7201     }
7202 }
7203
7204 /*!
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
7209  *              assign \a a 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
7214  *              assign \a a 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.
7221  *
7222  *  \ref cpp_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
7223  */
7224 void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
7225 {
7226   checkAllocated();
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++)
7234       {
7235         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7236         pt[(std::size_t)(*w)*nbComp+(*z)]=a;
7237       }
7238 }
7239
7240 /*!
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.
7252  *
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
7261  *              to are located.
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 
7271  *         \a this array.
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
7280  *            for \this array.
7281  *
7282  *  \ref cpp_mcdataarrayint_setpartofvalues3 "Here is a Python example".
7283  */
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)
7285 {
7286   if(!a)
7287     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues3 : DataArrayInt pointer in input is NULL !");
7288   const char msg[]="DataArrayInt::setPartOfValues3";
7289   checkAllocated();
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)
7298     {
7299       if(strictCompoCompare)
7300         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7301     }
7302   else
7303     {
7304       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7305       assignTech=false;
7306     }
7307   int *pt=getPointer()+bgComp;
7308   const int *srcPt=a->getConstPointer();
7309   if(assignTech)
7310     {
7311       for(const int *w=bgTuples;w!=endTuples;w++)
7312         for(int j=0;j<newNbOfComp;j++,srcPt++)
7313           {
7314             DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7315             pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
7316           }
7317     }
7318   else
7319     {
7320       for(const int *w=bgTuples;w!=endTuples;w++)
7321         {
7322           const int *srcPt2=srcPt;
7323           for(int j=0;j<newNbOfComp;j++,srcPt2++)
7324             {
7325               DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7326               pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
7327             }
7328         }
7329     }
7330 }
7331
7332 /*!
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
7339  *              assign \a a 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
7345  *              to are located.
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 
7349  *         \a this array.
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
7352  *            for \this array.
7353  *
7354  *  \ref cpp_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
7355  */
7356 void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
7357 {
7358   const char msg[]="DataArrayInt::setPartOfValuesSimple3";
7359   checkAllocated();
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++)
7367       {
7368         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7369         pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
7370       }
7371 }
7372
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)
7374 {
7375   if(!a)
7376     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues4 : input DataArrayInt is NULL !");
7377   const char msg[]="DataArrayInt::setPartOfValues4";
7378   checkAllocated();
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)
7389     {
7390       if(strictCompoCompare)
7391         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7392     }
7393   else
7394     {
7395       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7396       assignTech=false;
7397     }
7398   const int *srcPt=a->getConstPointer();
7399   int *pt=getPointer()+bgTuples*nbComp;
7400   if(assignTech)
7401     {
7402       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7403         for(const int *z=bgComp;z!=endComp;z++,srcPt++)
7404           pt[*z]=*srcPt;
7405     }
7406   else
7407     {
7408       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7409         {
7410           const int *srcPt2=srcPt;
7411           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
7412             pt[*z]=*srcPt2;
7413         }
7414     }
7415 }
7416
7417 void DataArrayInt::setPartOfValuesSimple4(int a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
7418 {
7419   const char msg[]="DataArrayInt::setPartOfValuesSimple4";
7420   checkAllocated();
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++)
7430       pt[*z]=a;
7431 }
7432
7433 /*!
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
7436  * components.
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.
7453  */
7454 void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
7455 {
7456   if(!a || !tuplesSelec)
7457     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : DataArrayInt pointer in input is NULL !");
7458   checkAllocated();
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)
7471     {
7472       if(tuple[1]>=0 && tuple[1]<aNt)
7473         {
7474           if(tuple[0]>=0 && tuple[0]<thisNt)
7475             std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
7476           else
7477             {
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());
7481             }
7482         }
7483       else
7484         {
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());
7488         }
7489     }
7490 }
7491
7492 /*!
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
7495  * components.
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
7501  *              values to.
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 
7513  *         \a a array.
7514  */
7515 void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
7516 {
7517   checkAllocated();
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)
7533     {
7534       if(*tuple>=0 && *tuple<aNt)
7535         {
7536           std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
7537         }
7538       else
7539         {
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());
7543         }
7544     }
7545 }
7546
7547 /*!
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
7550  * components.
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
7557  *              values to.
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
7561  *              are located.
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.
7571  */
7572 void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
7573 {
7574   checkAllocated();
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 !");
7586   if(end2>aNt)
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)
7590     {
7591       std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
7592     }
7593 }
7594
7595 /*!
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.
7606  */
7607 int DataArrayInt::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
7608 {
7609   checkAllocated();
7610   if(tupleId<0 || tupleId>=getNumberOfTuples())
7611     {
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());
7614     }
7615   if(compoId<0 || compoId>=getNumberOfComponents())
7616     {
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());
7619     }
7620   return _mem[tupleId*_info_on_compo.size()+compoId];
7621 }
7622
7623 /*!
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.
7629  */
7630 int DataArrayInt::back() const throw(INTERP_KERNEL::Exception)
7631 {
7632   checkAllocated();
7633   if(getNumberOfComponents()!=1)
7634     throw INTERP_KERNEL::Exception("DataArrayInt::back : number of components not equal to one !");
7635   int nbOfTuples=getNumberOfTuples();
7636   if(nbOfTuples<1)
7637     throw INTERP_KERNEL::Exception("DataArrayInt::back : number of tuples must be >= 1 !");
7638   return *(getConstPointer()+nbOfTuples-1);
7639 }
7640
7641 /*!
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.
7646  */
7647 void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
7648 {
7649   if(newArray!=arrayToSet)
7650     {
7651       if(arrayToSet)
7652         arrayToSet->decrRef();
7653       arrayToSet=newArray;
7654       if(arrayToSet)
7655         arrayToSet->incrRef();
7656     }
7657 }
7658
7659 DataArrayIntIterator *DataArrayInt::iterator() throw(INTERP_KERNEL::Exception)
7660 {
7661   return new DataArrayIntIterator(this);
7662 }
7663
7664 /*!
7665  * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to a
7666  * given one.
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.
7672  */
7673 DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception)
7674 {
7675   checkAllocated();
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++)
7682     if(*cptr==val)
7683       ret->pushBackSilent(i);
7684   return ret.retn();
7685 }
7686
7687 /*!
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.
7695  */
7696 DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception)
7697 {
7698   checkAllocated();
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++)
7705     if(*cptr!=val)
7706       ret->pushBackSilent(i);
7707   return ret.retn();
7708 }
7709
7710
7711 /*!
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.
7719  */
7720 int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception)
7721 {
7722   checkAllocated();
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();
7727   int ret=0;
7728   for(int *val=start;val!=end2;val++)
7729     {
7730       if(*val==oldValue)
7731         {
7732           *val=newValue;
7733           ret++;
7734         }
7735     }
7736   return ret;
7737 }
7738
7739 /*!
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.
7748  */
7749 DataArrayInt *DataArrayInt::getIdsEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
7750 {
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);
7761   return ret.retn();
7762 }
7763
7764 /*!
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.
7773  */
7774 DataArrayInt *DataArrayInt::getIdsNotEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
7775 {
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);
7786   return ret.retn();
7787 }
7788
7789 /*!
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.
7794  * 
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.
7797  *
7798  * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this.
7799  * \sa DataArrayInt::search, DataArrayInt::presenceOfTuple.
7800  */
7801 int DataArrayInt::locateTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
7802 {
7803   checkAllocated();
7804   int nbOfCompo=getNumberOfComponents();
7805   if(nbOfCompo==0)
7806     throw INTERP_KERNEL::Exception("DataArrayInt::locateTuple : 0 components in 'this' !");
7807   if(nbOfCompo!=(int)tupl.size())
7808     {
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());
7811     }
7812   const int *cptr=getConstPointer();
7813   std::size_t nbOfVals=getNbOfElems();
7814   for(const int *work=cptr;work!=cptr+nbOfVals;)
7815     {
7816       work=std::search(work,cptr+nbOfVals,tupl.begin(),tupl.end());
7817       if(work!=cptr+nbOfVals)
7818         {
7819           if(std::distance(cptr,work)%nbOfCompo!=0)
7820             work++;
7821           else
7822             return std::distance(cptr,work)/nbOfCompo;
7823         }
7824     }
7825   return -1;
7826 }
7827
7828 /*!
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
7833  */
7834 int DataArrayInt::search(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
7835 {
7836   checkAllocated();
7837   int nbOfCompo=getNumberOfComponents();
7838   if(nbOfCompo!=1)
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);
7845   return -1;
7846 }
7847
7848 /*!
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
7853  */
7854 int DataArrayInt::locateValue(int value) const throw(INTERP_KERNEL::Exception)
7855 {
7856   checkAllocated();
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);
7864   return -1;
7865 }
7866
7867 /*!
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
7872  */
7873 int DataArrayInt::locateValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
7874 {
7875   checkAllocated();
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);
7884   return -1;
7885 }
7886
7887 /*!
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
7894  */
7895 bool DataArrayInt::presenceOfTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
7896 {
7897   return locateTuple(tupl)!=-1;
7898 }
7899
7900
7901 /*!
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.
7907  *  \sa locateValue()
7908  */
7909 bool DataArrayInt::presenceOfValue(int value) const throw(INTERP_KERNEL::Exception)
7910 {
7911   return locateValue(value)!=-1;
7912 }
7913
7914 /*!
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
7919  */
7920 bool DataArrayInt::presenceOfValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
7921 {
7922   return locateValue(vals)!=-1;
7923 }
7924
7925 /*!
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
7929  *         component.
7930  *  \throw If \a this is not allocated.
7931  */
7932 void DataArrayInt::accumulate(int *res) const throw(INTERP_KERNEL::Exception)
7933 {
7934   checkAllocated();
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>());
7941 }
7942
7943 int DataArrayInt::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
7944 {
7945   checkAllocated();
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 !");
7951   int ret=0;
7952   for(int i=0;i<nbTuple;i++)
7953     ret+=ptr[i*nbComps+compId];
7954   return ret;
7955 }
7956
7957 /*!
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
7970  *          needed.
7971  *  \throw If either \a a1 or \a a2 is NULL.
7972  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
7973  */
7974 DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
7975 {
7976   if(!a1 || !a2)
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);
7988   return ret;
7989 }
7990
7991 /*!
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
8000  *          needed.
8001  *  \throw If all arrays within \a arr are NULL.
8002  *  \throw If getNumberOfComponents() of arrays within \a arr.
8003  */
8004 DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8005 {
8006   std::vector<const DataArrayInt *> a;
8007   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8008     if(*it4)
8009       a.push_back(*it4);
8010   if(a.empty())
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++)
8016     {
8017       if((*it)->getNumberOfComponents()!=nbOfComp)
8018         throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !");
8019       nbt+=(*it)->getNumberOfTuples();
8020     }
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]));
8027   return ret.retn();
8028 }
8029
8030 /*!
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
8036  */
8037 int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
8038 {
8039   checkAllocated();
8040   if(getNumberOfComponents()!=1)
8041     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
8042   int nbOfTuples=getNumberOfTuples();
8043   if(nbOfTuples<=0)
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);
8048   return *loc;
8049 }
8050
8051 /*!
8052  * Returns the maximal value within \a this array that is allowed to have more than
8053  *  one component.
8054  *  \return int - the maximal value among all values of \a this array.
8055  *  \throw If \a this is not allocated.
8056  */
8057 int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
8058 {
8059   checkAllocated();
8060   const int *loc=std::max_element(begin(),end());
8061   return *loc;
8062 }
8063
8064 /*!
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
8070  */
8071 int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
8072 {
8073   checkAllocated();
8074   if(getNumberOfComponents()!=1)
8075     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
8076   int nbOfTuples=getNumberOfTuples();
8077   if(nbOfTuples<=0)
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);
8082   return *loc;
8083 }
8084
8085 /*!
8086  * Returns the minimal value within \a this array that is allowed to have more than
8087  *  one component.
8088  *  \return int - the minimal value among all values of \a this array.
8089  *  \throw If \a this is not allocated.
8090  */
8091 int DataArrayInt::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
8092 {
8093   checkAllocated();
8094   const int *loc=std::min_element(begin(),end());
8095   return *loc;
8096 }
8097
8098 /*!
8099  * Converts every value of \a this array to its absolute value.
8100  *  \throw If \a this is not allocated.
8101  */
8102 void DataArrayInt::abs() throw(INTERP_KERNEL::Exception)
8103 {
8104   checkAllocated();
8105   int *ptr=getPointer();
8106   std::size_t nbOfElems=getNbOfElems();
8107   std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
8108   declareAsNew();
8109 }
8110
8111 /*!
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.
8118  */
8119 void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception)
8120 {
8121   checkAllocated();
8122   int *ptr=getPointer()+compoId;
8123   int nbOfComp=getNumberOfComponents();
8124   int nbOfTuple=getNumberOfTuples();
8125   for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
8126     *ptr=a*(*ptr)+b;
8127   declareAsNew();
8128 }
8129
8130 /*!
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.
8136  */
8137 void DataArrayInt::applyLin(int a, int b) throw(INTERP_KERNEL::Exception)
8138 {
8139   checkAllocated();
8140   int *ptr=getPointer();
8141   std::size_t nbOfElems=getNbOfElems();
8142   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8143     *ptr=a*(*ptr)+b;
8144   declareAsNew();
8145 }
8146
8147 /*!
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
8152  *          needed.
8153  *  \throw If \a this is not allocated.
8154  */
8155 DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception)
8156 {
8157   checkAllocated();
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);
8165   return newArr;
8166 }
8167
8168 /*!
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
8176  *           modified.
8177  */
8178 void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception)
8179 {
8180   checkAllocated();
8181   int *ptr=getPointer();
8182   std::size_t nbOfElems=getNbOfElems();
8183   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8184     {
8185       if(*ptr!=0)
8186         {
8187           *ptr=numerator/(*ptr);
8188         }
8189       else
8190         {
8191           std::ostringstream oss; oss << "DataArrayInt::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8192           oss << " !";
8193           throw INTERP_KERNEL::Exception(oss.str().c_str());
8194         }
8195     }
8196   declareAsNew();
8197 }
8198
8199 /*!
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.
8205  */
8206 void DataArrayInt::applyDivideBy(int val) throw(INTERP_KERNEL::Exception)
8207 {
8208   if(val==0)
8209     throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to divide by 0 !");
8210   checkAllocated();
8211   int *ptr=getPointer();
8212   std::size_t nbOfElems=getNbOfElems();
8213   std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides<int>(),val));
8214   declareAsNew();
8215 }
8216
8217 /*!
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.
8223  */
8224 void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception)
8225 {
8226   if(val<=0)
8227     throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !");
8228   checkAllocated();
8229   int *ptr=getPointer();
8230   std::size_t nbOfElems=getNbOfElems();
8231   std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus<int>(),val));
8232   declareAsNew();
8233 }
8234
8235 /*!
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)
8239  * 
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.
8243  */
8244 DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
8245 {
8246   checkAllocated();
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);
8255   return ret.retn();
8256 }
8257
8258 /*!
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
8266  *           modified.
8267  */
8268 void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception)
8269 {
8270   checkAllocated();
8271   int *ptr=getPointer();
8272   std::size_t nbOfElems=getNbOfElems();
8273   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8274     {
8275       if(*ptr>0)
8276         {
8277           *ptr=val%(*ptr);
8278         }
8279       else
8280         {
8281           std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8282           oss << " !";
8283           throw INTERP_KERNEL::Exception(oss.str().c_str());
8284         }
8285     }
8286   declareAsNew();
8287 }
8288
8289 /*!
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.
8295  */
8296 void DataArrayInt::applyPow(int val) throw(INTERP_KERNEL::Exception)
8297 {
8298   checkAllocated();
8299   if(val<0)
8300     throw INTERP_KERNEL::Exception("DataArrayInt::applyPow : input pow in < 0 !");
8301   int *ptr=getPointer();
8302   std::size_t nbOfElems=getNbOfElems();
8303   if(val==0)
8304     {
8305       std::fill(ptr,ptr+nbOfElems,1.);
8306       return ;
8307     }
8308   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8309     {
8310       int tmp=1;
8311       for(int j=0;j<val;j++)
8312         tmp*=*ptr;
8313       *ptr=tmp;
8314     }
8315   declareAsNew();
8316 }
8317
8318 /*!
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
8326  *           modified.
8327  */
8328 void DataArrayInt::applyRPow(int val) throw(INTERP_KERNEL::Exception)
8329 {
8330   checkAllocated();
8331   int *ptr=getPointer();
8332   std::size_t nbOfElems=getNbOfElems();
8333   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8334     {
8335       if(*ptr>=0)
8336         {
8337           int tmp=1;
8338           for(int j=0;j<*ptr;j++)
8339             tmp*=val;
8340           *ptr=tmp;
8341         }
8342       else
8343         {
8344           std::ostringstream oss; oss << "DataArrayInt::applyRPow : presence of negative value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8345           oss << " !";
8346           throw INTERP_KERNEL::Exception(oss.str().c_str());
8347         }
8348     }
8349   declareAsNew();
8350 }
8351
8352 /*!
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
8363  *          needed.
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()
8367  */
8368 DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
8369 {
8370   std::vector<const DataArrayInt *> arr(2);
8371   arr[0]=a1; arr[1]=a2;
8372   return Meld(arr);
8373 }
8374
8375 /*!
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
8385  *          needed.
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.
8389  */
8390 DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8391 {
8392   std::vector<const DataArrayInt *> a;
8393   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8394     if(*it4)
8395       a.push_back(*it4);
8396   if(a.empty())
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();
8401   it=a.begin();
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++)
8408     {
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();
8413     }
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++)
8420       {
8421         retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
8422         pts[j]+=nbc[j];
8423       }
8424   int k=0;
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());
8428   return ret;
8429 }
8430
8431 /*!
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.
8437  *
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.
8445  *
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
8448  *         in \a groups.
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 ).
8454  */
8455 DataArrayInt *DataArrayInt::MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups) throw(INTERP_KERNEL::Exception)
8456 {
8457   std::vector<const DataArrayInt *> groups2;
8458   for(std::vector<const DataArrayInt *>::const_iterator it4=groups.begin();it4!=groups.end();it4++)
8459     if(*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);
8465   int fid=1;
8466   for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++)
8467     {
8468       const int *ptr=(*iter)->getConstPointer();
8469       std::size_t nbOfElem=(*iter)->getNbOfElems();
8470       int sfid=fid;
8471       for(int j=0;j<sfid;j++)
8472         {
8473           bool found=false;
8474           for(std::size_t i=0;i<nbOfElem;i++)
8475             {
8476               if(ptr[i]>=0 && ptr[i]<newNb)
8477                 {
8478                   if(retPtr[ptr[i]]==j)
8479                     {
8480                       retPtr[ptr[i]]=fid;
8481                       found=true;
8482                     }
8483                 }
8484               else
8485                 {
8486                   std::ostringstream oss; oss << "DataArrayInt::MakePartition : In group \"" << (*iter)->getName() << "\" in tuple #" << i << " value = " << ptr[i] << " ! Should be in [0," << newNb;
8487                   oss << ") !";
8488                   throw INTERP_KERNEL::Exception(oss.str().c_str());
8489                 }
8490             }
8491           if(found)
8492             fid++;
8493         }
8494     }
8495   fidsOfGroups.clear();
8496   fidsOfGroups.resize(groups2.size());
8497   int grId=0;
8498   for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++,grId++)
8499     {
8500       std::set<int> tmp;
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());
8506     }
8507   return ret.retn();
8508 }
8509
8510 /*!
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.
8520  */
8521 DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8522 {
8523   std::vector<const DataArrayInt *> a;
8524   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8525     if(*it4)
8526       a.push_back(*it4);
8527   int valm=std::numeric_limits<int>::max();
8528   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8529     {
8530       (*it)->checkAllocated();
8531       if((*it)->getNumberOfComponents()!=1)
8532         throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
8533       int tmp1;
8534       valm=std::min((*it)->getMinValue(tmp1),valm);
8535     }
8536   if(valm<0)
8537     throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
8538   //
8539   std::set<int> r;
8540   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8541     {
8542       const int *pt=(*it)->getConstPointer();
8543       int nbOfTuples=(*it)->getNumberOfTuples();
8544       r.insert(pt,pt+nbOfTuples);
8545     }
8546   DataArrayInt *ret=DataArrayInt::New();
8547   ret->alloc((int)r.size(),1);
8548   std::copy(r.begin(),r.end(),ret->getPointer());
8549   return ret;
8550 }
8551
8552 /*!
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.
8562  */
8563 DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8564 {
8565   std::vector<const DataArrayInt *> a;
8566   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8567     if(*it4)
8568       a.push_back(*it4);
8569   int valm=std::numeric_limits<int>::max();
8570   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8571     {
8572       (*it)->checkAllocated();
8573       if((*it)->getNumberOfComponents()!=1)
8574         throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : only single component allowed !");
8575       int tmp1;
8576       valm=std::min((*it)->getMinValue(tmp1),valm);
8577     }
8578   if(valm<0)
8579     throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : a negative value has been detected !");
8580   //
8581   std::set<int> r;
8582   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
8583     {
8584       const int *pt=(*it)->getConstPointer();
8585       int nbOfTuples=(*it)->getNumberOfTuples();
8586       std::set<int> s1(pt,pt+nbOfTuples);
8587       if(it!=a.begin())
8588         {
8589           std::set<int> r2;
8590           std::set_intersection(r.begin(),r.end(),s1.begin(),s1.end(),inserter(r2,r2.end()));
8591           r=r2;
8592         }
8593       else
8594         r=s1;
8595     }
8596   DataArrayInt *ret=DataArrayInt::New();
8597   ret->alloc((int)r.size(),1);
8598   std::copy(r.begin(),r.end(),ret->getPointer());
8599   return ret;
8600 }
8601
8602 /*!
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
8612  *         nbOfElement ).
8613  */
8614 DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception)
8615 {
8616    checkAllocated();
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)
8624        tmp[*w]=true;
8625      else
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);
8630    int j=0;
8631    int *retPtr=ret->getPointer();
8632    for(int i=0;i<nbOfElement;i++)
8633      if(!tmp[i])
8634        retPtr[j++]=i;
8635    return ret;
8636 }
8637
8638 /*!
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()
8650  */
8651 DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8652 {
8653   if(!other)
8654     throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : DataArrayInt pointer in input is NULL !");
8655   checkAllocated();
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);
8667   std::vector<int> r;
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());
8672   return ret;
8673 }
8674
8675 /*!
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.
8678  * 
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
8682  */
8683 DataArrayInt *DataArrayInt::buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8684 {
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++)
8693     {
8694       if(work2!=pt2End && *work1==*work2)
8695         work2++;
8696       else
8697         ret->pushBackSilent(*work1);
8698     }
8699   return ret.retn();
8700 }
8701
8702
8703 /*!
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.
8714  */
8715 DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8716 {
8717   std::vector<const DataArrayInt *>arrs(2);
8718   arrs[0]=this; arrs[1]=other;
8719   return BuildUnion(arrs);
8720 }
8721
8722
8723 /*!
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.
8734  */
8735 DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
8736 {
8737   std::vector<const DataArrayInt *>arrs(2);
8738   arrs[0]=this; arrs[1]=other;
8739   return BuildIntersection(arrs);
8740 }
8741
8742 /*!
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]
8746  * 
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.
8749  */
8750 DataArrayInt *DataArrayInt::buildUnique() const throw(INTERP_KERNEL::Exception)
8751 {
8752   checkAllocated();
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());
8762   return ret.retn();
8763 }
8764
8765 /*!
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.
8778  *
8779  *  \b Example: <br> 
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.
8783  */
8784 DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
8785 {
8786   checkAllocated();
8787   if(getNumberOfComponents()!=1)
8788      throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
8789   int nbOfTuples=getNumberOfTuples();
8790   if(nbOfTuples<2)
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>());
8797   return ret;
8798 }
8799
8800 /*!
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
8807  * this one.
8808  *  \throw If \a this is not allocated.
8809  *  \throw If \a this->getNumberOfComponents() != 1.
8810  *
8811  *  \b Example: <br>
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.
8816  */
8817 void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception)
8818 {
8819   checkAllocated();
8820   if(getNumberOfComponents()!=1)
8821      throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
8822   int nbOfTuples=getNumberOfTuples();
8823   if(nbOfTuples==0)
8824     return ;
8825   int *work=getPointer();
8826   int tmp=work[0];
8827   work[0]=0;
8828   for(int i=1;i<nbOfTuples;i++)
8829     {
8830       int tmp2=work[i];
8831       work[i]=work[i-1]+tmp;
8832       tmp=tmp2;
8833     }
8834   declareAsNew();
8835 }
8836
8837
8838 /*!
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.
8847  *
8848  *  \b Example: <br>
8849  *          - Before \a this contains [3,5,1,2,0,8]
8850  *          - After \a this contains  [0,3,8,9,11,11,19]<br>
8851  */
8852 void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
8853 {
8854   checkAllocated();
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];
8859   if(nbOfTuples==0)
8860     return ;
8861   const int *work=getConstPointer();
8862   ret[0]=0;
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);
8866   declareAsNew();
8867 }
8868
8869 /*!
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.
8875  *
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.
8880  *
8881  * \sa DataArrayInt::computeOffsets2
8882  *
8883  *  \b Example: <br>
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.
8889  * <br>
8890  */
8891 void DataArrayInt::searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception)
8892 {
8893   if(!listOfIds)
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)
8905     {
8906       if(*tupPtr==*offPtr)
8907         {
8908           int i=offPtr[0];
8909           while(i<offPtr[1] && *tupPtr==i && tupPtr!=tupEnd) { i++; tupPtr++; }
8910           if(i==offPtr[1])
8911             {
8912               ret0->pushBackSilent((int)std::distance(offBg,offPtr));
8913               ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
8914               offPtr++;
8915             }
8916         }
8917       else
8918         { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
8919     }
8920   rangeIdsFetched=ret0.retn();
8921   idsInInputListThatFetch=ret1.retn();
8922 }
8923
8924 /*!
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.
8937  *
8938  *  \b Example: <br>
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 ])
8946  */
8947 DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception)
8948 {
8949   if(!offsets)
8950     throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : DataArrayInt pointer in input is NULL !");
8951   checkAllocated();
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++)
8963     {
8964       int val=work[i];
8965       if(val>=0 && val<othNbTuples)
8966         {
8967           int delta=offPtr[val+1]-offPtr[val];
8968           if(delta>=0)
8969             retNbOftuples+=delta;
8970           else
8971             {
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());
8974             }
8975         }
8976       else
8977         {
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());
8981         }
8982     }
8983   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8984   ret->alloc(retNbOftuples,1);
8985   int *retPtr=ret->getPointer();
8986   for(int i=0;i<nbOfTuples;i++)
8987     {
8988       int val=work[i];
8989       int start=offPtr[val];
8990       int off=offPtr[val+1]-start;
8991       for(int j=0;j<off;j++,retPtr++)
8992         *retPtr=start+j;
8993     }
8994   return ret.retn();
8995 }
8996
8997 /*!
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.
9002  *
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]**
9005  * 
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.
9010  * 
9011  * \sa DataArrayInt::findIdInRangeForEachTuple
9012  */
9013 DataArrayInt *DataArrayInt::findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
9014 {
9015   if(!ranges)
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 !");
9019   checkAllocated();
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++)
9029     {
9030       int val=inPtr[i];
9031       bool found=false;
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; }
9035       if(found)
9036         continue;
9037       else
9038         {
9039           std::ostringstream oss; oss << "DataArrayInt::findRangeIdForEachTuple : tuple #" << i << " not found by any ranges !";
9040           throw INTERP_KERNEL::Exception(oss.str().c_str());
9041         }
9042     }
9043   return ret.retn();
9044 }
9045
9046 /*!
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.
9051  *
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.
9055  * 
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
9061  */
9062 DataArrayInt *DataArrayInt::findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
9063 {
9064   if(!ranges)
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 !");
9068   checkAllocated();
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++)
9078     {
9079       int val=inPtr[i];
9080       bool found=false;
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; }
9084       if(found)
9085         continue;
9086       else
9087         {
9088           std::ostringstream oss; oss << "DataArrayInt::findIdInRangeForEachTuple : tuple #" << i << " not found by any ranges !";
9089           throw INTERP_KERNEL::Exception(oss.str().c_str());
9090         }
9091     }
9092   return ret.retn();
9093 }
9094
9095 /*!
9096  * 
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.
9101  */
9102 DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
9103 {
9104   checkAllocated();
9105   if(getNumberOfComponents()!=1)
9106     throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !");
9107   if(nbTimes<1)
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++)
9114     {
9115       int val=*inPtr;
9116       for(int j=0;j<nbTimes;j++,retPtr++)
9117         *retPtr=val;
9118     }
9119   ret->copyStringInfoFrom(*this);
9120   return ret.retn();
9121 }
9122
9123 /*!
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.
9127  */
9128 DataArrayInt *DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception)
9129 {
9130   checkAllocated();
9131   std::set<int> ret;
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());
9135   return ret2.retn();
9136 }
9137
9138 /*!
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]]
9145  */
9146 std::vector<DataArrayInt *> DataArrayInt::partitionByDifferentValues(std::vector<int>& differentIds) const throw(INTERP_KERNEL::Exception)
9147 {
9148   checkAllocated();
9149   if(getNumberOfComponents()!=1)
9150     throw INTERP_KERNEL::Exception("DataArrayInt::partitionByDifferentValues : this should have only one component !");
9151   int id=0;
9152   std::map<int,int> m,m2,m3;
9153   for(const int *w=begin();w!=end();w++)
9154     m[*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++)
9159     {
9160       m2[(*it).first]=id;
9161       ret[id]=DataArrayInt::New();
9162       ret[id]->alloc((*it).second,1);
9163       retPtr[id]=ret[id]->getPointer();
9164       differentIds[id]=(*it).first;
9165     }
9166   id=0;
9167   for(const int *w=begin();w!=end();w++,id++)
9168     {
9169       retPtr[m2[*w]][m3[*w]++]=id;
9170     }
9171   return ret;
9172 }
9173
9174 /*!
9175  * Returns a new DataArrayInt that is a sum of two given arrays. There are 3
9176  * valid cases.
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
9181  *   component. Then
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
9184  *   tuple. Then
9185  *   _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
9186  *
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
9193  *          needed.
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.
9198  */
9199 DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9200 {
9201   if(!a1 || !a2)
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)
9209     {
9210       if(nbOfComp==nbOfComp2)
9211         {
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);
9216         }
9217       else
9218         {
9219           int nbOfCompMin,nbOfCompMax;
9220           const DataArrayInt *aMin, *aMax;
9221           if(nbOfComp>nbOfComp2)
9222             {
9223               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
9224               aMin=a2; aMax=a1;
9225             }
9226           else
9227             {
9228               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
9229               aMin=a1; aMax=a2;
9230             }
9231           if(nbOfCompMin==1)
9232             {
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);
9241             }
9242           else
9243             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
9244         }
9245     }
9246   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
9247     {
9248       if(nbOfComp==nbOfComp2)
9249         {
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);
9260         }
9261       else
9262         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
9263     }
9264   else
9265     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
9266   return ret.retn();
9267 }
9268
9269 /*!
9270  * Adds values of another DataArrayInt to values of \a this one. There are 3
9271  * valid cases.
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 ].
9279  *
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.
9285  */
9286 void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9287 {
9288   if(!other)
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)
9297     {
9298       if(nbOfComp==nbOfComp2)
9299         {
9300           std::transform(begin(),end(),other->begin(),getPointer(),std::plus<int>());
9301         }
9302       else if(nbOfComp2==1)
9303         {
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++));
9308         }
9309       else
9310         throw INTERP_KERNEL::Exception(msg);
9311     }
9312   else if(nbOfTuple2==1)
9313     {
9314       if(nbOfComp2==nbOfComp)
9315         {
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>());
9320         }
9321       else
9322         throw INTERP_KERNEL::Exception(msg);
9323     }
9324   else
9325     throw INTERP_KERNEL::Exception(msg);
9326   declareAsNew();
9327 }
9328
9329 /*!
9330  * Returns a new DataArrayInt that is a subtraction of two given arrays. There are 3
9331  * valid cases.
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
9336  *   component. Then
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
9339  *   tuple. Then
9340  *   _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
9341  *
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
9348  *          needed.
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.
9353  */
9354 DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9355 {
9356   if(!a1 || !a2)
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)
9363     {
9364       if(nbOfComp1==nbOfComp2)
9365         {
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);
9370           return ret.retn();
9371         }
9372       else if(nbOfComp2==1)
9373         {
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);
9382           return ret.retn();
9383         }
9384       else
9385         {
9386           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
9387           return 0;
9388         }
9389     }
9390   else if(nbOfTuple2==1)
9391     {
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);
9400       return ret.retn();
9401     }
9402   else
9403     {
9404       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
9405       return 0;
9406     }
9407 }
9408
9409 /*!
9410  * Subtract values of another DataArrayInt from values of \a this one. There are 3
9411  * valid cases.
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 ].
9419  *
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.
9425  */
9426 void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9427 {
9428   if(!other)
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)
9437     {
9438       if(nbOfComp==nbOfComp2)
9439         {
9440           std::transform(begin(),end(),other->begin(),getPointer(),std::minus<int>());
9441         }
9442       else if(nbOfComp2==1)
9443         {
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++));
9448         }
9449       else
9450         throw INTERP_KERNEL::Exception(msg);
9451     }
9452   else if(nbOfTuple2==1)
9453     {
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>());
9458     }
9459   else
9460     throw INTERP_KERNEL::Exception(msg);
9461   declareAsNew();
9462 }
9463
9464 /*!
9465  * Returns a new DataArrayInt that is a product of two given arrays. There are 3
9466  * valid cases.
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
9471  *   component. Then
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
9474  *   tuple. Then
9475  *   _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
9476  *
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
9483  *          needed.
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.
9488  */
9489 DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9490 {
9491   if(!a1 || !a2)
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)
9499     {
9500       if(nbOfComp==nbOfComp2)
9501         {
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);
9506         }
9507       else
9508         {
9509           int nbOfCompMin,nbOfCompMax;
9510           const DataArrayInt *aMin, *aMax;
9511           if(nbOfComp>nbOfComp2)
9512             {
9513               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
9514               aMin=a2; aMax=a1;
9515             }
9516           else
9517             {
9518               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
9519               aMin=a1; aMax=a2;
9520             }
9521           if(nbOfCompMin==1)
9522             {
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);
9531             }
9532           else
9533             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
9534         }
9535     }
9536   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
9537     {
9538       if(nbOfComp==nbOfComp2)
9539         {
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);
9550         }
9551       else
9552         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
9553     }
9554   else
9555     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
9556   return ret.retn();
9557 }
9558
9559
9560 /*!
9561  * Multiply values of another DataArrayInt to values of \a this one. There are 3
9562  * valid cases.
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 ].
9570  *
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.
9576  */
9577 void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9578 {
9579   if(!other)
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)
9588     {
9589       if(nbOfComp==nbOfComp2)
9590         {
9591           std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<int>());
9592         }
9593       else if(nbOfComp2==1)
9594         {
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++));    
9599         }
9600       else
9601         throw INTERP_KERNEL::Exception(msg);
9602     }
9603   else if(nbOfTuple2==1)
9604     {
9605       if(nbOfComp2==nbOfComp)
9606         {
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>());
9611         }
9612       else
9613         throw INTERP_KERNEL::Exception(msg);
9614     }
9615   else
9616     throw INTERP_KERNEL::Exception(msg);
9617   declareAsNew();
9618 }
9619
9620
9621 /*!
9622  * Returns a new DataArrayInt that is a division of two given arrays. There are 3
9623  * valid cases.
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
9628  *   component. Then
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
9631  *   tuple. Then
9632  *   _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
9633  *
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
9640  *          needed.
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!
9646  */
9647 DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9648 {
9649   if(!a1 || !a2)
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)
9656     {
9657       if(nbOfComp1==nbOfComp2)
9658         {
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);
9663           return ret.retn();
9664         }
9665       else if(nbOfComp2==1)
9666         {
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);
9675           return ret.retn();
9676         }
9677       else
9678         {
9679           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
9680           return 0;
9681         }
9682     }
9683   else if(nbOfTuple2==1)
9684     {
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);
9693       return ret.retn();
9694     }
9695   else
9696     {
9697       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
9698       return 0;
9699     }
9700 }
9701
9702 /*!
9703  * Divide values of \a this array by values of another DataArrayInt. There are 3
9704  * valid cases.
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 ].
9712  *
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!
9719  */
9720 void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9721 {
9722   if(!other)
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)
9731     {
9732       if(nbOfComp==nbOfComp2)
9733         {
9734           std::transform(begin(),end(),other->begin(),getPointer(),std::divides<int>());
9735         }
9736       else if(nbOfComp2==1)
9737         {
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++));
9742         }
9743       else
9744         throw INTERP_KERNEL::Exception(msg);
9745     }
9746   else if(nbOfTuple2==1)
9747     {
9748       if(nbOfComp2==nbOfComp)
9749         {
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>());
9754         }
9755       else
9756         throw INTERP_KERNEL::Exception(msg);
9757     }
9758   else
9759     throw INTERP_KERNEL::Exception(msg);
9760   declareAsNew();
9761 }
9762
9763
9764 /*!
9765  * Returns a new DataArrayInt that is a modulus of two given arrays. There are 3
9766  * valid cases.
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
9771  *   component. Then
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
9774  *   tuple. Then
9775  *   _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ 0, j ].
9776  *
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
9783  *          needed.
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!
9789  */
9790 DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9791 {
9792     if(!a1 || !a2)
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)
9799     {
9800       if(nbOfComp1==nbOfComp2)
9801         {
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);
9806           return ret.retn();
9807         }
9808       else if(nbOfComp2==1)
9809         {
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);
9818           return ret.retn();
9819         }
9820       else
9821         {
9822           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
9823           return 0;
9824         }
9825     }
9826   else if(nbOfTuple2==1)
9827     {
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);
9836       return ret.retn();
9837     }
9838   else
9839     {
9840       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Modulus !");//will always throw an exception
9841       return 0;
9842     }
9843 }
9844
9845 /*!
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 ].
9855  *
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!
9862  */
9863 void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9864 {
9865   if(!other)
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)
9874     {
9875       if(nbOfComp==nbOfComp2)
9876         {
9877           std::transform(begin(),end(),other->begin(),getPointer(),std::modulus<int>());
9878         }
9879       else if(nbOfComp2==1)
9880         {
9881           if(nbOfComp2==nbOfComp)
9882             {
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++));
9887             }
9888           else
9889             throw INTERP_KERNEL::Exception(msg);
9890         }
9891       else
9892         throw INTERP_KERNEL::Exception(msg);
9893     }
9894   else if(nbOfTuple2==1)
9895     {
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>());
9900     }
9901   else
9902     throw INTERP_KERNEL::Exception(msg);
9903   declareAsNew();
9904 }
9905
9906 /*!
9907  * Returns a new DataArrayInt that is the result of pow of two given arrays. There are 3
9908  * valid cases.
9909  *
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
9914  *          needed.
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.
9919  */
9920 DataArrayInt *DataArrayInt::Pow(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9921 {
9922   if(!a1 || !a2)
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++)
9936     {
9937       if(*ptr2>=0)
9938         {
9939           int tmp=1;
9940           for(int j=0;j<*ptr2;j++)
9941             tmp*=*ptr1;
9942           *ptr=tmp;
9943         }
9944       else
9945         {
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());
9948         }
9949     }
9950   return ret.retn();
9951 }
9952
9953 /*!
9954  * Apply pow on values of another DataArrayInt to values of \a this one.
9955  *
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.
9961  */
9962 void DataArrayInt::powEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9963 {
9964   if(!other)
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++)
9977     {
9978       if(*ptrc>=0)
9979         {
9980           int tmp=1;
9981           for(int j=0;j<*ptrc;j++)
9982             tmp*=*ptr;
9983           *ptr=tmp;
9984         }
9985       else
9986         {
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());
9989         }
9990     }
9991   declareAsNew();
9992 }
9993
9994 /*!
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
10004  *         more needed.
10005  *  \throw If there are equal values in the input array.
10006  */
10007 int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end)
10008 {
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)
10015     {
10016       delete [] work;
10017       delete [] ret;
10018       throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
10019     }
10020   int *iter2=ret;
10021   for(const int *iter=start;iter!=end;iter++,iter2++)
10022     *iter2=(int)std::distance(work,std::find(work,work+sz,*iter));
10023   delete [] work;
10024   return ret;
10025 }
10026
10027 /*!
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 )
10030  * function.
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
10033  *              \a end.
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.
10040  */
10041 DataArrayInt *DataArrayInt::Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception)
10042 {
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();
10047   if(step>0)
10048     {
10049       for(int i=begin;i<end;i+=step,ptr++)
10050         *ptr=i;
10051     }
10052   else
10053     {
10054       for(int i=begin;i>end;i+=step,ptr++)
10055         *ptr=i;
10056     }
10057   return ret.retn();
10058 }
10059
10060 /*!
10061  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10062  * Server side.
10063  */
10064 void DataArrayInt::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
10065 {
10066   tinyInfo.resize(2);
10067   if(isAllocated())
10068     {
10069       tinyInfo[0]=getNumberOfTuples();
10070       tinyInfo[1]=getNumberOfComponents();
10071     }
10072   else
10073     {
10074       tinyInfo[0]=-1;
10075       tinyInfo[1]=-1;
10076     }
10077 }
10078
10079 /*!
10080  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10081  * Server side.
10082  */
10083 void DataArrayInt::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
10084 {
10085   if(isAllocated())
10086     {
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);
10092     }
10093   else
10094     {
10095       tinyInfo.resize(1);
10096       tinyInfo[0]=getName();
10097     }
10098 }
10099
10100 /*!
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.
10103  */
10104 bool DataArrayInt::resizeForUnserialization(const std::vector<int>& tinyInfoI)
10105 {
10106   int nbOfTuple=tinyInfoI[0];
10107   int nbOfComp=tinyInfoI[1];
10108   if(nbOfTuple!=-1 || nbOfComp!=-1)
10109     {
10110       alloc(nbOfTuple,nbOfComp);
10111       return true;
10112     }
10113   return false;
10114 }
10115
10116 /*!
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.
10119  */
10120 void DataArrayInt::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
10121 {
10122   setName(tinyInfoS[0].c_str());
10123   if(isAllocated())
10124     {
10125       int nbOfCompo=getNumberOfComponents();
10126       for(int i=0;i<nbOfCompo;i++)
10127         setInfoOnComponent(i,tinyInfoS[i+1].c_str());
10128     }
10129 }
10130
10131 DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
10132 {
10133   if(_da)
10134     {
10135       _da->incrRef();
10136       if(_da->isAllocated())
10137         {
10138           _nb_comp=da->getNumberOfComponents();
10139           _nb_tuple=da->getNumberOfTuples();
10140           _pt=da->getPointer();
10141         }
10142     }
10143 }
10144
10145 DataArrayIntIterator::~DataArrayIntIterator()
10146 {
10147   if(_da)
10148     _da->decrRef();
10149 }
10150
10151 DataArrayIntTuple *DataArrayIntIterator::nextt() throw(INTERP_KERNEL::Exception)
10152 {
10153   if(_tuple_id<_nb_tuple)
10154     {
10155       _tuple_id++;
10156       DataArrayIntTuple *ret=new DataArrayIntTuple(_pt,_nb_comp);
10157       _pt+=_nb_comp;
10158       return ret;
10159     }
10160   else
10161     return 0;
10162 }
10163
10164 DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
10165 {
10166 }
10167
10168 std::string DataArrayIntTuple::repr() const throw(INTERP_KERNEL::Exception)
10169 {
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] << ")";
10174   return oss.str();
10175 }
10176
10177 int DataArrayIntTuple::intValue() const throw(INTERP_KERNEL::Exception)
10178 {
10179   if(_nb_of_compo==1)
10180     return *_pt;
10181   throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
10182 }
10183
10184 /*!
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.
10189  */
10190 DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
10191 {
10192   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
10193     {
10194       DataArrayInt *ret=DataArrayInt::New();
10195       ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
10196       return ret;
10197     }
10198   else
10199     {
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());
10203     }
10204 }