Salome HOME
03cf0c323ccc5d0b5d0e689e6b20a1743f0afa1d
[tools/medcoupling.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   BBTreePts<SPACEDIM,int> myTree(bbox,0,0,nbNodes,prec);
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 BBTreePts<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  * Returns a new DataArray by concatenating all given arrays, so that (1) the number
384  * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
385  * the number of component in the result array is same as that of each of given arrays.
386  * Info on components is copied from the first of the given arrays. Number of components
387  * in the given arrays must be  the same.
388  *  \param [in] arrs - a sequence of arrays to include in the result array. All arrays must have the same type.
389  *  \return DataArray * - the new instance of DataArray (that can be either DataArrayInt, DataArrayDouble, DataArrayChar).
390  *          The caller is to delete this result array using decrRef() as it is no more
391  *          needed.
392  *  \throw If all arrays within \a arrs are NULL.
393  *  \throw If all not null arrays in \a arrs have not the same type.
394  *  \throw If getNumberOfComponents() of arrays within \a arrs.
395  */
396 DataArray *DataArray::Aggregate(const std::vector<const DataArray *>& arrs) throw(INTERP_KERNEL::Exception)
397 {
398   std::vector<const DataArray *> arr2;
399   for(std::vector<const DataArray *>::const_iterator it=arrs.begin();it!=arrs.end();it++)
400     if(*it)
401       arr2.push_back(*it);
402   if(arr2.empty())
403     throw INTERP_KERNEL::Exception("DataArray::Aggregate : only null instance in input vector !");
404   std::vector<const DataArrayDouble *> arrd;
405   std::vector<const DataArrayInt *> arri;
406   std::vector<const DataArrayChar *> arrc;
407   for(std::vector<const DataArray *>::const_iterator it=arr2.begin();it!=arr2.end();it++)
408     {
409       const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(*it);
410       if(a)
411         { arrd.push_back(a); continue; }
412       const DataArrayInt *b=dynamic_cast<const DataArrayInt *>(*it);
413       if(b)
414         { arri.push_back(b); continue; }
415       const DataArrayChar *c=dynamic_cast<const DataArrayChar *>(*it);
416       if(c)
417         { arrc.push_back(c); continue; }
418       throw INTERP_KERNEL::Exception("DataArray::Aggregate : presence of not null instance in inuput that is not in [DataArrayDouble, DataArrayInt, DataArrayChar] !");
419     }
420   if(arr2.size()==arrd.size())
421     return DataArrayDouble::Aggregate(arrd);
422   if(arr2.size()==arri.size())
423     return DataArrayInt::Aggregate(arri);
424   if(arr2.size()==arrc.size())
425     return DataArrayChar::Aggregate(arrc);
426   throw INTERP_KERNEL::Exception("DataArray::Aggregate : all input arrays must have the same type !");
427 }
428
429 /*!
430  * Sets information on a component specified by an index.
431  * To know more on format of this information
432  * see \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
433  *  \warning Don't pass NULL as \a info!
434  *  \param [in] i - the index (zero based) of the component of interest.
435  *  \param [in] info - the string containing the information.
436  *  \throw If \a i is not a valid component index.
437  */
438 void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
439 {
440   if(i<(int)_info_on_compo.size() && i>=0)
441     _info_on_compo[i]=info;
442   else
443     {
444       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();
445       throw INTERP_KERNEL::Exception(oss.str().c_str());
446     }
447 }
448
449 /*!
450  * Sets information on all components. This method can change number of components
451  * at certain conditions; if the conditions are not respected, an exception is thrown.
452  * The number of components can be changed in \a this only if \a this is not allocated.
453  * The condition of number of components must not be changed.
454  *
455  * To know more on format of the component information see
456  * \ref MEDCouplingArrayBasicsCompoName "DataArrays infos".
457  *  \param [in] info - a vector of component infos.
458  *  \throw If \a this->getNumberOfComponents() != \a info.size() && \a this->isAllocated()
459  */
460 void DataArray::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
461 {
462   if(getNumberOfComponents()!=(int)info.size())
463     {
464       if(!isAllocated())
465         _info_on_compo=info;
466       else
467         {
468           std::ostringstream oss; oss << "DataArray::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << "  and this is already allocated !";
469           throw INTERP_KERNEL::Exception(oss.str().c_str());
470         }
471     }
472   else
473     _info_on_compo=info;
474 }
475
476 void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception)
477 {
478   if(getNumberOfTuples()!=nbOfTuples)
479     {
480       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  nbOfTuples << " having " << getNumberOfTuples() << " !";
481       throw INTERP_KERNEL::Exception(oss.str().c_str());
482     }
483 }
484
485 void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
486 {
487   if(getNumberOfComponents()!=nbOfCompo)
488     {
489       std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
490       throw INTERP_KERNEL::Exception(oss.str().c_str());
491     }
492 }
493
494 void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception)
495 {
496   if(getNbOfElems()!=nbOfElems)
497     {
498       std::ostringstream oss; oss << msg << " : mismatch number of elems : Expected " << nbOfElems << " having " << getNbOfElems() << " !";
499       throw INTERP_KERNEL::Exception(oss.str().c_str());
500     }
501 }
502
503 void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception)
504 {
505    if(getNumberOfTuples()!=other.getNumberOfTuples())
506     {
507       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  other.getNumberOfTuples() << " having " << getNumberOfTuples() << " !";
508       throw INTERP_KERNEL::Exception(oss.str().c_str());
509     }
510   if(getNumberOfComponents()!=other.getNumberOfComponents())
511     {
512       std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << other.getNumberOfComponents() << " having " << getNumberOfComponents() << " !";
513       throw INTERP_KERNEL::Exception(oss.str().c_str());
514     }
515 }
516
517 void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
518 {
519   checkNbOfTuples(nbOfTuples,msg);
520   checkNbOfComps(nbOfCompo,msg);
521 }
522
523 /*!
524  * Simply this method checks that \b value is in [0,\b ref).
525  */
526 void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
527 {
528   if(value<0 || value>=ref)
529     {
530       std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg  << " ! Expected in range [0," << ref << "[ having " << value << " !";
531       throw INTERP_KERNEL::Exception(oss.str().c_str());
532     }
533 }
534
535 /*!
536  * This method checks that [\b start, \b end) is compliant with ref length \b value.
537  * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
538  */
539 void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception)
540 {
541   if(start<0 || start>=value)
542     {
543       if(value!=start || end!=start)
544         {
545           std::ostringstream oss; oss << "DataArray::CheckValueInRangeEx : " << msg  << " ! Expected start " << start << " of input range, in [0," << value << "[ !";
546           throw INTERP_KERNEL::Exception(oss.str().c_str());
547         }
548     }
549   if(end<0 || end>value)
550     {
551       std::ostringstream oss; oss << "DataArray::CheckValueInRangeEx : " << msg  << " ! Expected end " << end << " of input range, in [0," << value << "] !";
552       throw INTERP_KERNEL::Exception(oss.str().c_str());
553     }
554 }
555
556 void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
557 {
558   if(value<0 || value>ref)
559     {
560       std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg  << " ! Expected input range in [0," << ref << "] having closing open parenthesis " << value << " !";
561       throw INTERP_KERNEL::Exception(oss.str().c_str());
562     }
563 }
564
565 /*!
566  * This method is useful to slice work among a pool of threads or processes. \a begin, \a end \a step is the input whole slice of work to perform, 
567  * typically it is a whole slice of tuples of DataArray or cells, nodes of a mesh...
568  *
569  * The input \a sliceId should be an id in [0, \a nbOfSlices) that specifies the slice of work.
570  *
571  * \param [in] start - the start of the input slice of the whole work to perform splitted into slices.
572  * \param [in] stop - the stop of the input slice of the whole work to perform splitted into slices.
573  * \param [in] step - the step (that can be <0) of the input slice of the whole work to perform splitted into slices.
574  * \param [in] sliceId - the slice id considered
575  * \param [in] nbOfSlices - the number of slices (typically the number of cores on which the work is expected to be sliced)
576  * \param [out] startSlice - the start of the slice considered
577  * \param [out] stopSlice - the stop of the slice consided
578  * 
579  * \throw If \a step == 0
580  * \throw If \a nbOfSlices not > 0
581  * \throw If \a sliceId not in [0,nbOfSlices)
582  */
583 void DataArray::GetSlice(int start, int stop, int step, int sliceId, int nbOfSlices, int& startSlice, int& stopSlice) throw(INTERP_KERNEL::Exception)
584 {
585   if(nbOfSlices<=0)
586     {
587       std::ostringstream oss; oss << "DataArray::GetSlice : nbOfSlices (" << nbOfSlices << ") must be > 0 !";
588       throw INTERP_KERNEL::Exception(oss.str().c_str());
589     }
590   if(sliceId<0 || sliceId>=nbOfSlices)
591     {
592       std::ostringstream oss; oss << "DataArray::GetSlice : sliceId (" << nbOfSlices << ") must be in [0 , nbOfSlices (" << nbOfSlices << ") ) !";
593       throw INTERP_KERNEL::Exception(oss.str().c_str());
594     }
595   int nbElems=GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice");
596   int minNbOfElemsPerSlice=nbElems/nbOfSlices;
597   startSlice=start+minNbOfElemsPerSlice*step*sliceId;
598   if(sliceId<nbOfSlices-1)
599     stopSlice=start+minNbOfElemsPerSlice*step*(sliceId+1);
600   else
601     stopSlice=stop;
602 }
603
604 int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
605 {
606   if(end<begin)
607     {
608       std::ostringstream oss; oss << msg << " : end before begin !";
609       throw INTERP_KERNEL::Exception(oss.str().c_str());
610     }
611   if(end==begin)
612     return 0;
613   if(step<=0)
614     {
615       std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
616       throw INTERP_KERNEL::Exception(oss.str().c_str());
617     }
618   return (end-1-begin)/step+1;
619 }
620
621 int DataArray::GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
622 {
623   if(step==0)
624     throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES : step=0 is not allowed !");
625   if(end<begin && step>0)
626     {
627       std::ostringstream oss; oss << msg << " : end before begin whereas step is positive !";
628       throw INTERP_KERNEL::Exception(oss.str().c_str());
629     }
630   if(begin<end && step<0)
631     {
632       std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
633       throw INTERP_KERNEL::Exception(oss.str().c_str());
634     }
635   if(begin!=end)
636     return (std::max(begin,end)-1-std::min(begin,end))/std::abs(step)+1;
637   else
638     return 0;
639 }
640
641 int DataArray::GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception)
642 {
643   if(step!=0)
644     {
645       if(step>0)
646         {
647           if(begin<=value && value<end)
648             {
649               if((value-begin)%step==0)
650                 return (value-begin)/step;
651               else
652                 return -1;
653             }
654           else
655             return -1;
656         }
657       else
658         {
659           if(begin>=value && value>end)
660             {
661               if((begin-value)%(-step)==0)
662                 return (begin-value)/(-step);
663               else
664                 return -1;
665             }
666           else
667             return -1;
668         }
669     }
670   else
671     return -1;
672 }
673
674 /*!
675  * Returns a new instance of DataArrayDouble. The caller is to delete this array
676  * using decrRef() as it is no more needed. 
677  */
678 DataArrayDouble *DataArrayDouble::New()
679 {
680   return new DataArrayDouble;
681 }
682
683 /*!
684  * Checks if raw data is allocated. Read more on the raw data
685  * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information.
686  *  \return bool - \a true if the raw data is allocated, \a false else.
687  */
688 bool DataArrayDouble::isAllocated() const throw(INTERP_KERNEL::Exception)
689 {
690   return getConstPointer()!=0;
691 }
692
693 /*!
694  * Checks if raw data is allocated and throws an exception if it is not the case.
695  *  \throw If the raw data is not allocated.
696  */
697 void DataArrayDouble::checkAllocated() const throw(INTERP_KERNEL::Exception)
698 {
699   if(!isAllocated())
700     throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
701 }
702
703 /*!
704  * This method desallocated \a this without modification of informations relative to the components.
705  * After call of this method, DataArrayDouble::isAllocated will return false.
706  * If \a this is already not allocated, \a this is let unchanged.
707  */
708 void DataArrayDouble::desallocate() throw(INTERP_KERNEL::Exception)
709 {
710   _mem.destroy();
711 }
712
713 std::size_t DataArrayDouble::getHeapMemorySize() const
714 {
715   std::size_t sz=_mem.getNbOfElemAllocated();
716   sz*=sizeof(double);
717   return DataArray::getHeapMemorySize()+sz;
718 }
719
720 /*!
721  * Returns the only one value in \a this, if and only if number of elements
722  * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated.
723  *  \return double - the sole value stored in \a this array.
724  *  \throw If at least one of conditions stated above is not fulfilled.
725  */
726 double DataArrayDouble::doubleValue() const throw(INTERP_KERNEL::Exception)
727 {
728   if(isAllocated())
729     {
730       if(getNbOfElems()==1)
731         {
732           return *getConstPointer();
733         }
734       else
735         throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is allocated but number of elements is not equal to 1 !");
736     }
737   else
738     throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is not allocated !");
739 }
740
741 /*!
742  * Checks the number of tuples.
743  *  \return bool - \a true if getNumberOfTuples() == 0, \a false else.
744  *  \throw If \a this is not allocated.
745  */
746 bool DataArrayDouble::empty() const throw(INTERP_KERNEL::Exception)
747 {
748   checkAllocated();
749   return getNumberOfTuples()==0;
750 }
751
752 /*!
753  * Returns a full copy of \a this. For more info on copying data arrays see
754  * \ref MEDCouplingArrayBasicsCopyDeep.
755  *  \return DataArrayDouble * - a new instance of DataArrayDouble. The caller is to
756  *          delete this array using decrRef() as it is no more needed. 
757  */
758 DataArrayDouble *DataArrayDouble::deepCpy() const throw(INTERP_KERNEL::Exception)
759 {
760   return new DataArrayDouble(*this);
761 }
762
763 /*!
764  * Returns either a \a deep or \a shallow copy of this array. For more info see
765  * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
766  *  \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
767  *  \return DataArrayDouble * - either a new instance of DataArrayDouble (if \a dCpy
768  *          == \a true) or \a this instance (if \a dCpy == \a false).
769  */
770 DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception)
771 {
772   if(dCpy)
773     return deepCpy();
774   else
775     {
776       incrRef();
777       return const_cast<DataArrayDouble *>(this);
778     }
779 }
780
781 /*!
782  * Copies all the data from another DataArrayDouble. For more info see
783  * \ref MEDCouplingArrayBasicsCopyDeepAssign.
784  *  \param [in] other - another instance of DataArrayDouble to copy data from.
785  *  \throw If the \a other is not allocated.
786  */
787 void DataArrayDouble::cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception)
788 {
789   other.checkAllocated();
790   int nbOfTuples=other.getNumberOfTuples();
791   int nbOfComp=other.getNumberOfComponents();
792   allocIfNecessary(nbOfTuples,nbOfComp);
793   std::size_t nbOfElems=(std::size_t)nbOfTuples*nbOfComp;
794   double *pt=getPointer();
795   const double *ptI=other.getConstPointer();
796   for(std::size_t i=0;i<nbOfElems;i++)
797     pt[i]=ptI[i];
798   copyStringInfoFrom(other);
799 }
800
801 /*!
802  * This method reserve nbOfElems elements in memory ( nbOfElems*8 bytes ) \b without impacting the number of tuples in \a this.
803  * 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.
804  * If \a this has not already been allocated, number of components is set to one.
805  * This method allows to reduce number of reallocations on invokation of DataArrayDouble::pushBackSilent and DataArrayDouble::pushBackValsSilent on \a this.
806  * 
807  * \sa DataArrayDouble::pack, DataArrayDouble::pushBackSilent, DataArrayDouble::pushBackValsSilent
808  */
809 void DataArrayDouble::reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception)
810 {
811   int nbCompo=getNumberOfComponents();
812   if(nbCompo==1)
813     {
814       _mem.reserve(nbOfElems);
815     }
816   else if(nbCompo==0)
817     {
818       _mem.reserve(nbOfElems);
819       _info_on_compo.resize(1);
820     }
821   else
822     throw INTERP_KERNEL::Exception("DataArrayDouble::reserve : not available for DataArrayDouble with number of components different than 1 !");
823 }
824
825 /*!
826  * 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
827  * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
828  *
829  * \param [in] val the value to be added in \a this
830  * \throw If \a this has already been allocated with number of components different from one.
831  * \sa DataArrayDouble::pushBackValsSilent
832  */
833 void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception)
834 {
835   int nbCompo=getNumberOfComponents();
836   if(nbCompo==1)
837     _mem.pushBack(val);
838   else if(nbCompo==0)
839     {
840       _info_on_compo.resize(1);
841       _mem.pushBack(val);
842     }
843   else
844     throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !");
845 }
846
847 /*!
848  * 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
849  * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
850  *
851  *  \param [in] valsBg - an array of values to push at the end of \this.
852  *  \param [in] valsEnd - specifies the end of the array \a valsBg, so that
853  *              the last value of \a valsBg is \a valsEnd[ -1 ].
854  * \throw If \a this has already been allocated with number of components different from one.
855  * \sa DataArrayDouble::pushBackSilent
856  */
857 void DataArrayDouble::pushBackValsSilent(const double *valsBg, const double *valsEnd) throw(INTERP_KERNEL::Exception)
858 {
859   int nbCompo=getNumberOfComponents();
860   if(nbCompo==1)
861     _mem.insertAtTheEnd(valsBg,valsEnd);
862   else if(nbCompo==0)
863     {
864       _info_on_compo.resize(1);
865       _mem.insertAtTheEnd(valsBg,valsEnd);
866     }
867   else
868     throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackValsSilent : not available for DataArrayDouble with number of components different than 1 !");
869 }
870
871 /*!
872  * This method returns silently ( without updating time label in \a this ) the last value, if any and suppress it.
873  * \throw If \a this is already empty.
874  * \throw If \a this has number of components different from one.
875  */
876 double DataArrayDouble::popBackSilent() throw(INTERP_KERNEL::Exception)
877 {
878   if(getNumberOfComponents()==1)
879     return _mem.popBack();
880   else
881     throw INTERP_KERNEL::Exception("DataArrayDouble::popBackSilent : not available for DataArrayDouble with number of components different than 1 !");
882 }
883
884 /*!
885  * 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.
886  *
887  * \sa DataArrayDouble::getHeapMemorySize, DataArrayDouble::reserve
888  */
889 void DataArrayDouble::pack() const throw(INTERP_KERNEL::Exception)
890 {
891   _mem.pack();
892 }
893
894 /*!
895  * Allocates the raw data in memory. If exactly same memory as needed already
896  * allocated, it is not re-allocated.
897  *  \param [in] nbOfTuple - number of tuples of data to allocate.
898  *  \param [in] nbOfCompo - number of components of data to allocate.
899  *  \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
900  */
901 void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
902 {
903   if(isAllocated())
904     {
905       if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
906         alloc(nbOfTuple,nbOfCompo);
907     }
908   else
909     alloc(nbOfTuple,nbOfCompo);
910 }
911
912 /*!
913  * Allocates the raw data in memory. If the memory was already allocated, then it is
914  * freed and re-allocated. See an example of this method use
915  * \ref MEDCouplingArraySteps1WC "here".
916  *  \param [in] nbOfTuple - number of tuples of data to allocate.
917  *  \param [in] nbOfCompo - number of components of data to allocate.
918  *  \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
919  */
920 void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
921 {
922   if(nbOfTuple<0 || nbOfCompo<0)
923     throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
924   _info_on_compo.resize(nbOfCompo);
925   _mem.alloc(nbOfCompo*(std::size_t)nbOfTuple);
926   declareAsNew();
927 }
928
929 /*!
930  * Assign zero to all values in \a this array. To know more on filling arrays see
931  * \ref MEDCouplingArrayFill.
932  * \throw If \a this is not allocated.
933  */
934 void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception)
935 {
936   checkAllocated();
937   _mem.fillWithValue(0.);
938   declareAsNew();
939 }
940
941 /*!
942  * Assign \a val to all values in \a this array. To know more on filling arrays see
943  * \ref MEDCouplingArrayFill.
944  *  \param [in] val - the value to fill with.
945  *  \throw If \a this is not allocated.
946  */
947 void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception)
948 {
949   checkAllocated();
950   _mem.fillWithValue(val);
951   declareAsNew();
952 }
953
954 /*!
955  * Set all values in \a this array so that the i-th element equals to \a init + i
956  * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
957  *  \param [in] init - value to assign to the first element of array.
958  *  \throw If \a this->getNumberOfComponents() != 1
959  *  \throw If \a this is not allocated.
960  */
961 void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception)
962 {
963   checkAllocated();
964   if(getNumberOfComponents()!=1)
965     throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
966   double *ptr=getPointer();
967   int ntuples=getNumberOfTuples();
968   for(int i=0;i<ntuples;i++)
969     ptr[i]=init+double(i);
970   declareAsNew();
971 }
972
973 /*!
974  * Checks if all values in \a this array are equal to \a val at precision \a eps.
975  *  \param [in] val - value to check equality of array values to.
976  *  \param [in] eps - precision to check the equality.
977  *  \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
978  *                 \a false else.
979  *  \throw If \a this->getNumberOfComponents() != 1
980  *  \throw If \a this is not allocated.
981  */
982 bool DataArrayDouble::isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception)
983 {
984   checkAllocated();
985   if(getNumberOfComponents()!=1)
986     throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
987   int nbOfTuples=getNumberOfTuples();
988   const double *w=getConstPointer();
989   const double *end2=w+nbOfTuples;
990   const double vmin=val-eps;
991   const double vmax=val+eps;
992   for(;w!=end2;w++)
993     if(*w<vmin || *w>vmax)
994       return false;
995   return true;
996 }
997
998 /*!
999  * Sorts values of the array.
1000  *  \param [in] asc - \a true means ascending order, \a false, descending.
1001  *  \throw If \a this is not allocated.
1002  *  \throw If \a this->getNumberOfComponents() != 1.
1003  */
1004 void DataArrayDouble::sort(bool asc) throw(INTERP_KERNEL::Exception)
1005 {
1006   checkAllocated();
1007   if(getNumberOfComponents()!=1)
1008     throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !");
1009   _mem.sort(asc);
1010   declareAsNew();
1011 }
1012
1013 /*!
1014  * Reverse the array values.
1015  *  \throw If \a this->getNumberOfComponents() < 1.
1016  *  \throw If \a this is not allocated.
1017  */
1018 void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception)
1019 {
1020   checkAllocated();
1021   _mem.reverse(getNumberOfComponents());
1022   declareAsNew();
1023 }
1024
1025 /*!
1026  * Checks that \a this array is consistently **increasing** or **decreasing** in value,
1027  * with at least absolute difference value of |\a eps| at each step.
1028  * If not an exception is thrown.
1029  *  \param [in] increasing - if \a true, the array values should be increasing.
1030  *  \param [in] eps - minimal absolute difference between the neighbor values at which 
1031  *                    the values are considered different.
1032  *  \throw If sequence of values is not strictly monotonic in agreement with \a
1033  *         increasing arg.
1034  *  \throw If \a this->getNumberOfComponents() != 1.
1035  *  \throw If \a this is not allocated.
1036  */
1037 void DataArrayDouble::checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
1038 {
1039   if(!isMonotonic(increasing,eps))
1040     {
1041       if (increasing)
1042         throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not INCREASING monotonic !");
1043       else
1044         throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not DECREASING monotonic !");
1045     }
1046 }
1047
1048 /*!
1049  * Checks that \a this array is consistently **increasing** or **decreasing** in value,
1050  * with at least absolute difference value of |\a eps| at each step.
1051  *  \param [in] increasing - if \a true, array values should be increasing.
1052  *  \param [in] eps - minimal absolute difference between the neighbor values at which 
1053  *                    the values are considered different.
1054  *  \return bool - \a true if values change in accordance with \a increasing arg.
1055  *  \throw If \a this->getNumberOfComponents() != 1.
1056  *  \throw If \a this is not allocated.
1057  */
1058 bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
1059 {
1060   checkAllocated();
1061   if(getNumberOfComponents()!=1)
1062     throw INTERP_KERNEL::Exception("DataArrayDouble::isMonotonic : only supported with 'this' array with ONE component !");
1063   int nbOfElements=getNumberOfTuples();
1064   const double *ptr=getConstPointer();
1065   if(nbOfElements==0)
1066     return true;
1067   double ref=ptr[0];
1068   double absEps=fabs(eps);
1069   if(increasing)
1070     {
1071       for(int i=1;i<nbOfElements;i++)
1072         {
1073           if(ptr[i]<(ref+absEps))
1074             return false;
1075           ref=ptr[i];
1076         }
1077       return true;
1078     }
1079   else
1080     {
1081       for(int i=1;i<nbOfElements;i++)
1082         {
1083           if(ptr[i]>(ref-absEps))
1084             return false;
1085           ref=ptr[i];
1086         }
1087       return true;
1088     }
1089 }
1090
1091 /*!
1092  * Returns a textual and human readable representation of \a this instance of
1093  * DataArrayDouble. This text is shown when a DataArrayDouble is printed in Python.
1094  *  \return std::string - text describing \a this DataArrayDouble.
1095  */
1096 std::string DataArrayDouble::repr() const throw(INTERP_KERNEL::Exception)
1097 {
1098   std::ostringstream ret;
1099   reprStream(ret);
1100   return ret.str();
1101 }
1102
1103 std::string DataArrayDouble::reprZip() const throw(INTERP_KERNEL::Exception)
1104 {
1105   std::ostringstream ret;
1106   reprZipStream(ret);
1107   return ret.str();
1108 }
1109
1110 void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
1111 {
1112   std::string idt(indent,' ');
1113   ofs.precision(17);
1114   ofs << idt << "<DataArray type=\"Float32\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
1115   ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
1116   std::copy(begin(),end(),std::ostream_iterator<double>(ofs," "));
1117   ofs << std::endl << idt << "</DataArray>\n";
1118 }
1119
1120 void DataArrayDouble::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1121 {
1122   stream << "Name of double array : \"" << _name << "\"\n";
1123   reprWithoutNameStream(stream);
1124 }
1125
1126 void DataArrayDouble::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1127 {
1128   stream << "Name of double array : \"" << _name << "\"\n";
1129   reprZipWithoutNameStream(stream);
1130 }
1131
1132 void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1133 {
1134   DataArray::reprWithoutNameStream(stream);
1135   stream.precision(17);
1136   _mem.repr(getNumberOfComponents(),stream);
1137 }
1138
1139 void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1140 {
1141   DataArray::reprWithoutNameStream(stream);
1142   stream.precision(17);
1143   _mem.reprZip(getNumberOfComponents(),stream);
1144 }
1145
1146 void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1147 {
1148   int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
1149   const double *data=getConstPointer();
1150   stream.precision(17);
1151   stream << "DataArrayDouble *" << varName << "=DataArrayDouble::New();" << std::endl;
1152   if(nbTuples*nbComp>=1)
1153     {
1154       stream << "const double " << varName << "Data[" << nbTuples*nbComp << "]={";
1155       std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<double>(stream,","));
1156       stream << data[nbTuples*nbComp-1] << "};" << std::endl;
1157       stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
1158     }
1159   else
1160     stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
1161   stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
1162 }
1163
1164 /*!
1165  * Method that gives a quick overvien of \a this for python.
1166  */
1167 void DataArrayDouble::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
1168 {
1169   static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
1170   stream << "DataArrayDouble C++ instance at " << this << ". ";
1171   if(isAllocated())
1172     {
1173       int nbOfCompo=(int)_info_on_compo.size();
1174       if(nbOfCompo>=1)
1175         {
1176           int nbOfTuples=getNumberOfTuples();
1177           stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
1178           reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
1179         }
1180       else
1181         stream << "Number of components : 0.";
1182     }
1183   else
1184     stream << "*** No data allocated ****";
1185 }
1186
1187 void DataArrayDouble::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception)
1188 {
1189   const double *data=begin();
1190   int nbOfTuples=getNumberOfTuples();
1191   int nbOfCompo=(int)_info_on_compo.size();
1192   std::ostringstream oss2; oss2 << "[";
1193   oss2.precision(17);
1194   std::string oss2Str(oss2.str());
1195   bool isFinished=true;
1196   for(int i=0;i<nbOfTuples && isFinished;i++)
1197     {
1198       if(nbOfCompo>1)
1199         {
1200           oss2 << "(";
1201           for(int j=0;j<nbOfCompo;j++,data++)
1202             {
1203               oss2 << *data;
1204               if(j!=nbOfCompo-1) oss2 << ", ";
1205             }
1206           oss2 << ")";
1207         }
1208       else
1209         oss2 << *data++;
1210       if(i!=nbOfTuples-1) oss2 << ", ";
1211       std::string oss3Str(oss2.str());
1212       if(oss3Str.length()<maxNbOfByteInRepr)
1213         oss2Str=oss3Str;
1214       else
1215         isFinished=false;
1216     }
1217   stream << oss2Str;
1218   if(!isFinished)
1219     stream << "... ";
1220   stream << "]";
1221 }
1222
1223 /*!
1224  * Equivalent to DataArrayDouble::isEqual except that if false the reason of
1225  * mismatch is given.
1226  * 
1227  * \param [in] other the instance to be compared with \a this
1228  * \param [in] prec the precision to compare numeric data of the arrays.
1229  * \param [out] reason In case of inequality returns the reason.
1230  * \sa DataArrayDouble::isEqual
1231  */
1232 bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception)
1233 {
1234   if(!areInfoEqualsIfNotWhy(other,reason))
1235     return false;
1236   return _mem.isEqual(other._mem,prec,reason);
1237 }
1238
1239 /*!
1240  * Checks if \a this and another DataArrayDouble are fully equal. For more info see
1241  * \ref MEDCouplingArrayBasicsCompare.
1242  *  \param [in] other - an instance of DataArrayDouble to compare with \a this one.
1243  *  \param [in] prec - precision value to compare numeric data of the arrays.
1244  *  \return bool - \a true if the two arrays are equal, \a false else.
1245  */
1246 bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception)
1247 {
1248   std::string tmp;
1249   return isEqualIfNotWhy(other,prec,tmp);
1250 }
1251
1252 /*!
1253  * Checks if values of \a this and another DataArrayDouble are equal. For more info see
1254  * \ref MEDCouplingArrayBasicsCompare.
1255  *  \param [in] other - an instance of DataArrayDouble to compare with \a this one.
1256  *  \param [in] prec - precision value to compare numeric data of the arrays.
1257  *  \return bool - \a true if the values of two arrays are equal, \a false else.
1258  */
1259 bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const throw(INTERP_KERNEL::Exception)
1260 {
1261   std::string tmp;
1262   return _mem.isEqual(other._mem,prec,tmp);
1263 }
1264
1265 /*!
1266  * Changes number of tuples in the array. If the new number of tuples is smaller
1267  * than the current number the array is truncated, otherwise the array is extended.
1268  *  \param [in] nbOfTuples - new number of tuples. 
1269  *  \throw If \a this is not allocated.
1270  *  \throw If \a nbOfTuples is negative.
1271  */
1272 void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
1273 {
1274   if(nbOfTuples<0)
1275     throw INTERP_KERNEL::Exception("DataArrayDouble::reAlloc : input new number of tuples should be >=0 !");
1276   checkAllocated();
1277   _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
1278   declareAsNew();
1279 }
1280
1281 /*!
1282  * Creates a new DataArrayInt and assigns all (textual and numerical) data of \a this
1283  * array to the new one.
1284  *  \return DataArrayInt * - the new instance of DataArrayInt.
1285  */
1286 DataArrayInt *DataArrayDouble::convertToIntArr() const
1287 {
1288   DataArrayInt *ret=DataArrayInt::New();
1289   ret->alloc(getNumberOfTuples(),getNumberOfComponents());
1290   std::size_t nbOfVals=getNbOfElems();
1291   const double *src=getConstPointer();
1292   int *dest=ret->getPointer();
1293   std::copy(src,src+nbOfVals,dest);
1294   ret->copyStringInfoFrom(*this);
1295   return ret;
1296 }
1297
1298 /*!
1299  * Returns a new DataArrayDouble holding the same values as \a this array but differently
1300  * arranged in memory. If \a this array holds 2 components of 3 values:
1301  * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
1302  * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
1303  *  \warning Do not confuse this method with transpose()!
1304  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1305  *          is to delete using decrRef() as it is no more needed.
1306  *  \throw If \a this is not allocated.
1307  */
1308 DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
1309 {
1310   if(_mem.isNull())
1311     throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
1312   double *tab=_mem.fromNoInterlace(getNumberOfComponents());
1313   DataArrayDouble *ret=DataArrayDouble::New();
1314   ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
1315   return ret;
1316 }
1317
1318 /*!
1319  * Returns a new DataArrayDouble holding the same values as \a this array but differently
1320  * arranged in memory. If \a this array holds 2 components of 3 values:
1321  * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
1322  * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
1323  *  \warning Do not confuse this method with transpose()!
1324  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1325  *          is to delete using decrRef() as it is no more needed.
1326  *  \throw If \a this is not allocated.
1327  */
1328 DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception)
1329 {
1330   if(_mem.isNull())
1331     throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
1332   double *tab=_mem.toNoInterlace(getNumberOfComponents());
1333   DataArrayDouble *ret=DataArrayDouble::New();
1334   ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
1335   return ret;
1336 }
1337
1338 /*!
1339  * Permutes values of \a this array as required by \a old2New array. The values are
1340  * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains
1341  * the same as in \this one.
1342  * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
1343  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1344  *  \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1345  *     giving a new position for i-th old value.
1346  */
1347 void DataArrayDouble::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception)
1348 {
1349   checkAllocated();
1350   int nbTuples=getNumberOfTuples();
1351   int nbOfCompo=getNumberOfComponents();
1352   double *tmp=new double[nbTuples*nbOfCompo];
1353   const double *iptr=getConstPointer();
1354   for(int i=0;i<nbTuples;i++)
1355     {
1356       int v=old2New[i];
1357       if(v>=0 && v<nbTuples)
1358         std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*v);
1359       else
1360         {
1361           std::ostringstream oss; oss << "DataArrayDouble::renumberInPlace : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
1362           throw INTERP_KERNEL::Exception(oss.str().c_str());
1363         }
1364     }
1365   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
1366   delete [] tmp;
1367   declareAsNew();
1368 }
1369
1370 /*!
1371  * Permutes values of \a this array as required by \a new2Old array. The values are
1372  * permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of tuples remains
1373  * the same as in \this one.
1374  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1375  *  \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
1376  *     giving a previous position of i-th new value.
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 void DataArrayDouble::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception)
1381 {
1382   checkAllocated();
1383   int nbTuples=getNumberOfTuples();
1384   int nbOfCompo=getNumberOfComponents();
1385   double *tmp=new double[nbTuples*nbOfCompo];
1386   const double *iptr=getConstPointer();
1387   for(int i=0;i<nbTuples;i++)
1388     {
1389       int v=new2Old[i];
1390       if(v>=0 && v<nbTuples)
1391         std::copy(iptr+nbOfCompo*v,iptr+nbOfCompo*(v+1),tmp+nbOfCompo*i);
1392       else
1393         {
1394           std::ostringstream oss; oss << "DataArrayDouble::renumberInPlaceR : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
1395           throw INTERP_KERNEL::Exception(oss.str().c_str());
1396         }
1397     }
1398   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
1399   delete [] tmp;
1400   declareAsNew();
1401 }
1402
1403 /*!
1404  * Returns a copy of \a this array with values permuted as required by \a old2New array.
1405  * The values are permuted so that  \c new[ \a old2New[ i ]] = \c old[ i ].
1406  * Number of tuples in the result array remains the same as in \this one.
1407  * If a permutation reduction is needed, renumberAndReduce() should be used.
1408  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1409  *  \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1410  *          giving a new position for i-th old value.
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 this is not allocated.
1414  */
1415 DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception)
1416 {
1417   checkAllocated();
1418   int nbTuples=getNumberOfTuples();
1419   int nbOfCompo=getNumberOfComponents();
1420   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1421   ret->alloc(nbTuples,nbOfCompo);
1422   ret->copyStringInfoFrom(*this);
1423   const double *iptr=getConstPointer();
1424   double *optr=ret->getPointer();
1425   for(int i=0;i<nbTuples;i++)
1426     std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
1427   ret->copyStringInfoFrom(*this);
1428   return ret.retn();
1429 }
1430
1431 /*!
1432  * Returns a copy of \a this array with values permuted as required by \a new2Old array.
1433  * The values are permuted so that  \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
1434  * tuples in the result array remains the same as in \this one.
1435  * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
1436  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1437  *  \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
1438  *     giving a previous position of i-th new value.
1439  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1440  *          is to delete using decrRef() as it is no more needed.
1441  */
1442 DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception)
1443 {
1444   checkAllocated();
1445   int nbTuples=getNumberOfTuples();
1446   int nbOfCompo=getNumberOfComponents();
1447   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1448   ret->alloc(nbTuples,nbOfCompo);
1449   ret->copyStringInfoFrom(*this);
1450   const double *iptr=getConstPointer();
1451   double *optr=ret->getPointer();
1452   for(int i=0;i<nbTuples;i++)
1453     std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
1454   ret->copyStringInfoFrom(*this);
1455   return ret.retn();
1456 }
1457
1458 /*!
1459  * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1460  * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
1461  * The values are permuted so that  \c new[ \a old2New[ i ]] = \c old[ i ] for all
1462  * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which 
1463  * \a old2New[ i ] is negative, is missing from the result array.
1464  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1465  *  \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
1466  *     giving a new position for i-th old tuple and giving negative position for
1467  *     for i-th old tuple that should be omitted.
1468  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1469  *          is to delete using decrRef() as it is no more needed.
1470  */
1471 DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception)
1472 {
1473   checkAllocated();
1474   int nbTuples=getNumberOfTuples();
1475   int nbOfCompo=getNumberOfComponents();
1476   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1477   ret->alloc(newNbOfTuple,nbOfCompo);
1478   const double *iptr=getConstPointer();
1479   double *optr=ret->getPointer();
1480   for(int i=0;i<nbTuples;i++)
1481     {
1482       int w=old2New[i];
1483       if(w>=0)
1484         std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
1485     }
1486   ret->copyStringInfoFrom(*this);
1487   return ret.retn();
1488 }
1489
1490 /*!
1491  * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1492  * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1493  * \a new2OldBg array.
1494  * The values are permuted so that  \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1495  * This method is equivalent to renumberAndReduce() except that convention in input is
1496  * \c new2old and \b not \c old2new.
1497  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1498  *  \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1499  *              tuple index in \a this array to fill the i-th tuple in the new array.
1500  *  \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1501  *              \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1502  *              \a new2OldBg <= \a pi < \a new2OldEnd.
1503  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1504  *          is to delete using decrRef() as it is no more needed.
1505  */
1506 DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
1507 {
1508   checkAllocated();
1509   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1510   int nbComp=getNumberOfComponents();
1511   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1512   ret->copyStringInfoFrom(*this);
1513   double *pt=ret->getPointer();
1514   const double *srcPt=getConstPointer();
1515   int i=0;
1516   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1517     std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1518   ret->copyStringInfoFrom(*this);
1519   return ret.retn();
1520 }
1521
1522 /*!
1523  * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is
1524  * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
1525  * \a new2OldBg array.
1526  * The values are permuted so that  \c new[ i ] = \c old[ \a new2OldBg[ i ]].
1527  * This method is equivalent to renumberAndReduce() except that convention in input is
1528  * \c new2old and \b not \c old2new.
1529  * This method is equivalent to selectByTupleId() except that it prevents coping data
1530  * from behind the end of \a this array.
1531  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1532  *  \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
1533  *              tuple index in \a this array to fill the i-th tuple in the new array.
1534  *  \param [in] new2OldEnd - specifies the end of the permutation array that starts at
1535  *              \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
1536  *              \a new2OldBg <= \a pi < \a new2OldEnd.
1537  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1538  *          is to delete using decrRef() as it is no more needed.
1539  *  \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
1540  */
1541 DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
1542 {
1543   checkAllocated();
1544   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1545   int nbComp=getNumberOfComponents();
1546   int oldNbOfTuples=getNumberOfTuples();
1547   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
1548   ret->copyStringInfoFrom(*this);
1549   double *pt=ret->getPointer();
1550   const double *srcPt=getConstPointer();
1551   int i=0;
1552   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
1553     if(*w>=0 && *w<oldNbOfTuples)
1554       std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
1555     else
1556       throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
1557   ret->copyStringInfoFrom(*this);
1558   return ret.retn();
1559 }
1560
1561 /*!
1562  * Returns a shorten copy of \a this array. The new DataArrayDouble contains every
1563  * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
1564  * tuple. Indices of the selected tuples are the same as ones returned by the Python
1565  * command \c range( \a bg, \a end2, \a step ).
1566  * This method is equivalent to selectByTupleIdSafe() except that the input array is
1567  * not constructed explicitly.
1568  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1569  *  \param [in] bg - index of the first tuple to copy from \a this array.
1570  *  \param [in] end2 - index of the tuple before which the tuples to copy are located.
1571  *  \param [in] step - index increment to get index of the next tuple to copy.
1572  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1573  *          is to delete using decrRef() as it is no more needed.
1574  *  \sa DataArrayDouble::substr.
1575  */
1576 DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
1577 {
1578   checkAllocated();
1579   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1580   int nbComp=getNumberOfComponents();
1581   int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayDouble::selectByTupleId2 : ");
1582   ret->alloc(newNbOfTuples,nbComp);
1583   double *pt=ret->getPointer();
1584   const double *srcPt=getConstPointer()+bg*nbComp;
1585   for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
1586     std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
1587   ret->copyStringInfoFrom(*this);
1588   return ret.retn();
1589 }
1590
1591 /*!
1592  * Returns a shorten copy of \a this array. The new DataArrayDouble contains ranges
1593  * of tuples specified by \a ranges parameter.
1594  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
1595  *  \param [in] ranges - std::vector of std::pair's each of which defines a range
1596  *              of tuples in [\c begin,\c end) format.
1597  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1598  *          is to delete using decrRef() as it is no more needed.
1599  *  \throw If \a end < \a begin.
1600  *  \throw If \a end > \a this->getNumberOfTuples().
1601  *  \throw If \a this is not allocated.
1602  */
1603 DataArray *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
1604 {
1605   checkAllocated();
1606   int nbOfComp=getNumberOfComponents();
1607   int nbOfTuplesThis=getNumberOfTuples();
1608   if(ranges.empty())
1609     {
1610       DataArrayDouble *ret=DataArrayDouble::New();
1611       ret->alloc(0,nbOfComp);
1612       ret->copyStringInfoFrom(*this);
1613       return ret;
1614     }
1615   int ref=ranges.front().first;
1616   int nbOfTuples=0;
1617   bool isIncreasing=true;
1618   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
1619     {
1620       if((*it).first<=(*it).second)
1621         {
1622           if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
1623             {
1624               nbOfTuples+=(*it).second-(*it).first;
1625               if(isIncreasing)
1626                 isIncreasing=ref<=(*it).first;
1627               ref=(*it).second;
1628             }
1629           else
1630             {
1631               std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
1632               oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
1633               throw INTERP_KERNEL::Exception(oss.str().c_str());
1634             }
1635         }
1636       else
1637         {
1638           std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
1639           oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
1640           throw INTERP_KERNEL::Exception(oss.str().c_str());
1641         }
1642     }
1643   if(isIncreasing && nbOfTuplesThis==nbOfTuples)
1644     return deepCpy();
1645   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1646   ret->alloc(nbOfTuples,nbOfComp);
1647   ret->copyStringInfoFrom(*this);
1648   const double *src=getConstPointer();
1649   double *work=ret->getPointer();
1650   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
1651     work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
1652   return ret.retn();
1653 }
1654
1655 /*!
1656  * Returns a shorten copy of \a this array. The new DataArrayDouble contains all
1657  * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
1658  * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
1659  * This method is a specialization of selectByTupleId2().
1660  *  \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
1661  *  \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
1662  *          If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
1663  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1664  *          is to delete using decrRef() as it is no more needed.
1665  *  \throw If \a tupleIdBg < 0.
1666  *  \throw If \a tupleIdBg > \a this->getNumberOfTuples().
1667     \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
1668  *  \sa DataArrayDouble::selectByTupleId2
1669  */
1670 DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
1671 {
1672   checkAllocated();
1673   int nbt=getNumberOfTuples();
1674   if(tupleIdBg<0)
1675     throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter must be greater than 0 !");
1676   if(tupleIdBg>nbt)
1677     throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater than number of tuples !");
1678   int trueEnd=tupleIdEnd;
1679   if(tupleIdEnd!=-1)
1680     {
1681       if(tupleIdEnd>nbt)
1682         throw INTERP_KERNEL::Exception("DataArrayDouble::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
1683     }
1684   else
1685     trueEnd=nbt;
1686   int nbComp=getNumberOfComponents();
1687   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1688   ret->alloc(trueEnd-tupleIdBg,nbComp);
1689   ret->copyStringInfoFrom(*this);
1690   std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
1691   return ret.retn();
1692 }
1693
1694 /*!
1695  * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
1696  * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
1697  * is truncated to have \a newNbOfComp components, keeping first components. If \a
1698  * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
1699  * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
1700  * components.  
1701  *  \param [in] newNbOfComp - number of components for the new array to have.
1702  *  \param [in] dftValue - value assigned to new values added to the new array.
1703  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1704  *          is to delete using decrRef() as it is no more needed.
1705  *  \throw If \a this is not allocated.
1706  */
1707 DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception)
1708 {
1709   checkAllocated();
1710   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
1711   ret->alloc(getNumberOfTuples(),newNbOfComp);
1712   const double *oldc=getConstPointer();
1713   double *nc=ret->getPointer();
1714   int nbOfTuples=getNumberOfTuples();
1715   int oldNbOfComp=getNumberOfComponents();
1716   int dim=std::min(oldNbOfComp,newNbOfComp);
1717   for(int i=0;i<nbOfTuples;i++)
1718     {
1719       int j=0;
1720       for(;j<dim;j++)
1721         nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
1722       for(;j<newNbOfComp;j++)
1723         nc[newNbOfComp*i+j]=dftValue;
1724     }
1725   ret->setName(getName().c_str());
1726   for(int i=0;i<dim;i++)
1727     ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
1728   ret->setName(getName().c_str());
1729   return ret.retn();
1730 }
1731
1732 /*!
1733  * Changes the number of components within \a this array so that its raw data **does
1734  * not** change, instead splitting this data into tuples changes.
1735  *  \warning This method erases all (name and unit) component info set before!
1736  *  \param [in] newNbOfComp - number of components for \a this array to have.
1737  *  \throw If \a this is not allocated
1738  *  \throw If getNbOfElems() % \a newNbOfCompo != 0.
1739  *  \throw If \a newNbOfCompo is lower than 1.
1740  *  \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
1741  *  \warning This method erases all (name and unit) component info set before!
1742  */
1743 void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
1744 {
1745   checkAllocated();
1746   if(newNbOfCompo<1)
1747     throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : input newNbOfCompo must be > 0 !");
1748   std::size_t nbOfElems=getNbOfElems();
1749   if(nbOfElems%newNbOfCompo!=0)
1750     throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !");
1751   if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
1752     throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !");
1753   _info_on_compo.clear();
1754   _info_on_compo.resize(newNbOfCompo);
1755   declareAsNew();
1756 }
1757
1758 /*!
1759  * Changes the number of components within \a this array to be equal to its number
1760  * of tuples, and inversely its number of tuples to become equal to its number of 
1761  * components. So that its raw data **does not** change, instead splitting this
1762  * data into tuples changes.
1763  *  \warning This method erases all (name and unit) component info set before!
1764  *  \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
1765  *  \throw If \a this is not allocated.
1766  *  \sa rearrange()
1767  */
1768 void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception)
1769 {
1770   checkAllocated();
1771   int nbOfTuples=getNumberOfTuples();
1772   rearrange(nbOfTuples);
1773 }
1774
1775 /*!
1776  * Returns a copy of \a this array composed of selected components.
1777  * The new DataArrayDouble has the same number of tuples but includes components
1778  * specified by \a compoIds parameter. So that getNbOfElems() of the result array
1779  * can be either less, same or more than \a this->getNbOfElems().
1780  *  \param [in] compoIds - sequence of zero based indices of components to include
1781  *              into the new array.
1782  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
1783  *          is to delete using decrRef() as it is no more needed.
1784  *  \throw If \a this is not allocated.
1785  *  \throw If a component index (\a i) is not valid: 
1786  *         \a i < 0 || \a i >= \a this->getNumberOfComponents().
1787  *
1788  *  \ref py_mcdataarraydouble_KeepSelectedComponents "Here is a Python example".
1789  */
1790 DataArray *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
1791 {
1792   checkAllocated();
1793   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
1794   std::size_t newNbOfCompo=compoIds.size();
1795   int oldNbOfCompo=getNumberOfComponents();
1796   for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
1797     if((*it)<0 || (*it)>=oldNbOfCompo)
1798       {
1799         std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
1800         throw INTERP_KERNEL::Exception(oss.str().c_str());
1801       }
1802   int nbOfTuples=getNumberOfTuples();
1803   ret->alloc(nbOfTuples,(int)newNbOfCompo);
1804   ret->copyPartOfStringInfoFrom(*this,compoIds);
1805   const double *oldc=getConstPointer();
1806   double *nc=ret->getPointer();
1807   for(int i=0;i<nbOfTuples;i++)
1808     for(std::size_t j=0;j<newNbOfCompo;j++,nc++)
1809       *nc=oldc[i*oldNbOfCompo+compoIds[j]];
1810   return ret.retn();
1811 }
1812
1813 /*!
1814  * Appends components of another array to components of \a this one, tuple by tuple.
1815  * So that the number of tuples of \a this array remains the same and the number of 
1816  * components increases.
1817  *  \param [in] other - the DataArrayDouble to append to \a this one.
1818  *  \throw If \a this is not allocated.
1819  *  \throw If \a this and \a other arrays have different number of tuples.
1820  *
1821  *  \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
1822  *
1823  *  \ref py_mcdataarraydouble_meldwith "Here is a Python example".
1824  */
1825 void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
1826 {
1827   checkAllocated();
1828   other->checkAllocated();
1829   int nbOfTuples=getNumberOfTuples();
1830   if(nbOfTuples!=other->getNumberOfTuples())
1831     throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
1832   int nbOfComp1=getNumberOfComponents();
1833   int nbOfComp2=other->getNumberOfComponents();
1834   double *newArr=(double *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(double));
1835   double *w=newArr;
1836   const double *inp1=getConstPointer();
1837   const double *inp2=other->getConstPointer();
1838   for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
1839     {
1840       w=std::copy(inp1,inp1+nbOfComp1,w);
1841       w=std::copy(inp2,inp2+nbOfComp2,w);
1842     }
1843   useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
1844   std::vector<int> compIds(nbOfComp2);
1845   for(int i=0;i<nbOfComp2;i++)
1846     compIds[i]=nbOfComp1+i;
1847   copyPartOfStringInfoFrom2(compIds,*other);
1848 }
1849
1850 /*!
1851  * This method checks that all tuples in \a other are in \a this.
1852  * If true, the output param \a tupleIds contains the tuples ids of \a this that correspond to tupes in \a this.
1853  * For each i in [ 0 , other->getNumberOfTuples() ) tuple #i in \a other is equal ( regarding input precision \a prec ) to tuple tupleIds[i] in \a this.
1854  *
1855  * \param [in] other - the array having the same number of components than \a this.
1856  * \param [out] tupleIds - the tuple ids containing the same number of tuples than \a other has.
1857  * \sa DataArrayDouble::findCommonTuples
1858  */
1859 bool DataArrayDouble::areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const throw(INTERP_KERNEL::Exception)
1860 {
1861   if(!other)
1862     throw INTERP_KERNEL::Exception("DataArrayDouble::areIncludedInMe : input array is NULL !");
1863   checkAllocated(); other->checkAllocated();
1864   if(getNumberOfComponents()!=other->getNumberOfComponents())
1865     throw INTERP_KERNEL::Exception("DataArrayDouble::areIncludedInMe : the number of components does not match !");
1866   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a=DataArrayDouble::Aggregate(this,other);
1867   DataArrayInt *c=0,*ci=0;
1868   a->findCommonTuples(prec,getNumberOfTuples(),c,ci);
1869   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cSafe(c),ciSafe(ci);
1870   int newNbOfTuples=-1;
1871   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(a->getNumberOfTuples(),c->begin(),ci->begin(),ci->end(),newNbOfTuples);
1872   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=ids->selectByTupleId2(getNumberOfTuples(),a->getNumberOfTuples(),1);
1873   tupleIds=ret1.retn();
1874   return newNbOfTuples==getNumberOfTuples();
1875 }
1876
1877 /*!
1878  * Searches for tuples coincident within \a prec tolerance. Each tuple is considered
1879  * as coordinates of a point in getNumberOfComponents()-dimensional space. The
1880  * distance separating two points is computed with the infinite norm.
1881  *
1882  * Indices of coincident tuples are stored in output arrays.
1883  * A pair of arrays (\a comm, \a commIndex) is called "Surjective Format 2".
1884  *
1885  * This method is typically used by MEDCouplingPointSet::findCommonNodes() and
1886  * MEDCouplingUMesh::mergeNodes().
1887  *  \param [in] prec - minimal absolute distance between two tuples (infinite norm) at which they are
1888  *              considered not coincident.
1889  *  \param [in] limitTupleId - limit tuple id. If all tuples within a group of coincident
1890  *              tuples have id strictly lower than \a limitTupleId then they are not returned.
1891  *  \param [out] comm - the array holding ids (== indices) of coincident tuples. 
1892  *               \a comm->getNumberOfComponents() == 1. 
1893  *               \a comm->getNumberOfTuples() == \a commIndex->back().
1894  *  \param [out] commIndex - the array dividing all indices stored in \a comm into
1895  *               groups of (indices of) coincident tuples. Its every value is a tuple
1896  *               index where a next group of tuples begins. For example the second
1897  *               group of tuples in \a comm is described by following range of indices:
1898  *               [ \a commIndex[1], \a commIndex[2] ). \a commIndex->getNumberOfTuples()-1
1899  *               gives the number of groups of coincident tuples.
1900  *  \throw If \a this is not allocated.
1901  *  \throw If the number of components is not in [1,2,3].
1902  *
1903  *  \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example".
1904  *
1905  *  \ref py_mcdataarraydouble_findcommontuples  "Here is a Python example".
1906  *  \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(), DataArrayDouble::areIncludedInMe
1907  */
1908 void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
1909 {
1910   checkAllocated();
1911   int nbOfCompo=getNumberOfComponents();
1912   if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work
1913     throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3.");
1914   
1915   int nbOfTuples=getNumberOfTuples();
1916   //
1917   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0);
1918   switch(nbOfCompo)
1919     {
1920     case 3:
1921       findCommonTuplesAlg<3>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
1922       break;
1923     case 2:
1924       findCommonTuplesAlg<2>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
1925       break;
1926     case 1:
1927       findCommonTuplesAlg<1>(begin(),nbOfTuples,limitTupleId,prec,c,cI);
1928       break;
1929     default:
1930       throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !");
1931     }
1932   comm=c.retn();
1933   commIndex=cI.retn();
1934 }
1935
1936 /*!
1937  * 
1938  * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
1939  *             \a nbTimes  should be at least equal to 1.
1940  * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
1941  * \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.
1942  */
1943 DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
1944 {
1945   checkAllocated();
1946   if(getNumberOfComponents()!=1)
1947     throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
1948   if(nbTimes<1)
1949     throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
1950   int nbTuples=getNumberOfTuples();
1951   const double *inPtr=getConstPointer();
1952   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1);
1953   double *retPtr=ret->getPointer();
1954   for(int i=0;i<nbTuples;i++,inPtr++)
1955     {
1956       double val=*inPtr;
1957       for(int j=0;j<nbTimes;j++,retPtr++)
1958         *retPtr=val;
1959     }
1960   ret->copyStringInfoFrom(*this);
1961   return ret.retn();
1962 }
1963
1964 /*!
1965  * This methods returns the minimal distance between the two set of points \a this and \a other.
1966  * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
1967  * This method works only if number of components of \a this (equal to those of \a other) is in 1, 2 or 3.
1968  *
1969  * \param [out] thisTupleId the tuple id in \a this corresponding to the returned minimal distance
1970  * \param [out] otherTupleId the tuple id in \a other corresponding to the returned minimal distance
1971  * \return the minimal distance between the two set of points \a this and \a other.
1972  * \sa DataArrayDouble::findClosestTupleId
1973  */
1974 double DataArrayDouble::minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const throw(INTERP_KERNEL::Exception)
1975 {
1976   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> part1=findClosestTupleId(other);
1977   int nbOfCompo(getNumberOfComponents());
1978   int otherNbTuples(other->getNumberOfTuples());
1979   const double *thisPt(begin()),*otherPt(other->begin());
1980   const int *part1Pt(part1->begin());
1981   double ret=std::numeric_limits<double>::max();
1982   for(int i=0;i<otherNbTuples;i++,part1Pt++,otherPt+=nbOfCompo)
1983     {
1984       double tmp(0.);
1985       for(int j=0;j<nbOfCompo;j++)
1986         tmp+=(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j])*(otherPt[j]-thisPt[nbOfCompo*(*part1Pt)+j]);
1987       if(tmp<ret)
1988         { ret=tmp; thisTupleId=*part1Pt; otherTupleId=i; }
1989     }
1990   return sqrt(ret);
1991 }
1992
1993 /*!
1994  * This methods returns for each tuple in \a other which tuple in \a this is the closest.
1995  * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
1996  * This method works only if number of components of \a this (equal to those of \a other) is in 1, 2 or 3.
1997  *
1998  * \return a newly allocated (new object to be dealt by the caller) DataArrayInt having \c other->getNumberOfTuples() tuples and one components.
1999  * \sa DataArrayDouble::minimalDistanceTo
2000  */
2001 DataArrayInt *DataArrayDouble::findClosestTupleId(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
2002 {
2003   if(!other)
2004     throw INTERP_KERNEL::Exception("DataArrayDouble::findClosestTupleId : other instance is NULL !");
2005   checkAllocated(); other->checkAllocated();
2006   int nbOfCompo=getNumberOfComponents();
2007   if(nbOfCompo!=other->getNumberOfComponents())
2008     {
2009       std::ostringstream oss; oss << "DataArrayDouble::findClosestTupleId : number of components in this is " << nbOfCompo;
2010       oss << ", whereas number of components in other is " << other->getNumberOfComponents() << "! Should be equal !";
2011       throw INTERP_KERNEL::Exception(oss.str().c_str());
2012     }
2013   int nbOfTuples=other->getNumberOfTuples();
2014   int thisNbOfTuples=getNumberOfTuples();
2015   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuples,1);
2016   double bounds[6];
2017   getMinMaxPerComponent(bounds);
2018   switch(nbOfCompo)
2019     {
2020     case 3:
2021       {
2022         double xDelta(fabs(bounds[1]-bounds[0])),yDelta(fabs(bounds[3]-bounds[2])),zDelta(fabs(bounds[5]-bounds[4]));
2023         double delta=std::max(xDelta,yDelta); delta=std::max(delta,zDelta);
2024         double characSize=pow((delta*delta*delta)/((double)thisNbOfTuples),1./3.);
2025         BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
2026         FindClosestTupleIdAlg<3>(myTree,3.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
2027         break;
2028       }
2029     case 2:
2030       {
2031         double xDelta(fabs(bounds[1]-bounds[0])),yDelta(fabs(bounds[3]-bounds[2]));
2032         double delta=std::max(xDelta,yDelta);
2033         double characSize=sqrt(delta/(double)thisNbOfTuples);
2034         BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
2035         FindClosestTupleIdAlg<2>(myTree,2.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
2036         break;
2037       }
2038     case 1:
2039       {
2040         double characSize=fabs(bounds[1]-bounds[0])/thisNbOfTuples;
2041         BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),characSize*1e-12);
2042         FindClosestTupleIdAlg<1>(myTree,1.*characSize*characSize,other->begin(),nbOfTuples,begin(),thisNbOfTuples,ret->getPointer());
2043         break;
2044       }
2045     default:
2046       throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for findClosestTupleId. Must be 1, 2 or 3.");
2047     }
2048   return ret.retn();
2049 }
2050
2051 /*!
2052  * Returns a copy of \a this array by excluding coincident tuples. Each tuple is
2053  * considered as coordinates of a point in getNumberOfComponents()-dimensional
2054  * space. The distance between tuples is computed using norm2. If several tuples are
2055  * not far each from other than \a prec, only one of them remains in the result
2056  * array. The order of tuples in the result array is same as in \a this one except
2057  * that coincident tuples are excluded.
2058  *  \param [in] prec - minimal absolute distance between two tuples at which they are
2059  *              considered not coincident.
2060  *  \param [in] limitTupleId - limit tuple id. If all tuples within a group of coincident
2061  *              tuples have id strictly lower than \a limitTupleId then they are not excluded.
2062  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
2063  *          is to delete using decrRef() as it is no more needed.
2064  *  \throw If \a this is not allocated.
2065  *  \throw If the number of components is not in [1,2,3].
2066  *
2067  *  \ref py_mcdataarraydouble_getdifferentvalues "Here is a Python example".
2068  */
2069 DataArrayDouble *DataArrayDouble::getDifferentValues(double prec, int limitTupleId) const throw(INTERP_KERNEL::Exception)
2070 {
2071   checkAllocated();
2072   DataArrayInt *c0=0,*cI0=0;
2073   findCommonTuples(prec,limitTupleId,c0,cI0);
2074   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(c0),cI(cI0);
2075   int newNbOfTuples=-1;
2076   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0->begin(),cI0->begin(),cI0->end(),newNbOfTuples);
2077   return renumberAndReduce(o2n->getConstPointer(),newNbOfTuples);
2078 }
2079
2080 /*!
2081  * Copy all components in a specified order from another DataArrayDouble.
2082  * Both numerical and textual data is copied. The number of tuples in \a this and
2083  * the other array can be different.
2084  *  \param [in] a - the array to copy data from.
2085  *  \param [in] compoIds - sequence of zero based indices of components, data of which is
2086  *              to be copied.
2087  *  \throw If \a a is NULL.
2088  *  \throw If \a compoIds.size() != \a a->getNumberOfComponents().
2089  *  \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
2090  *
2091  *  \ref py_mcdataarraydouble_setselectedcomponents "Here is a Python example".
2092  */
2093 void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
2094 {
2095   if(!a)
2096     throw INTERP_KERNEL::Exception("DataArrayDouble::setSelectedComponents : input DataArrayDouble is NULL !");
2097   checkAllocated();
2098   copyPartOfStringInfoFrom2(compoIds,*a);
2099   std::size_t partOfCompoSz=compoIds.size();
2100   int nbOfCompo=getNumberOfComponents();
2101   int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
2102   const double *ac=a->getConstPointer();
2103   double *nc=getPointer();
2104   for(int i=0;i<nbOfTuples;i++)
2105     for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
2106       nc[nbOfCompo*i+compoIds[j]]=*ac;
2107 }
2108
2109 /*!
2110  * Copy all values from another DataArrayDouble into specified tuples and components
2111  * of \a this array. Textual data is not copied.
2112  * The tree parameters defining set of indices of tuples and components are similar to
2113  * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
2114  *  \param [in] a - the array to copy values from.
2115  *  \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
2116  *  \param [in] endTuples - index of the tuple before which the tuples to assign to
2117  *              are located.
2118  *  \param [in] stepTuples - index increment to get index of the next tuple to assign to.
2119  *  \param [in] bgComp - index of the first component of \a this array to assign values to.
2120  *  \param [in] endComp - index of the component before which the components to assign
2121  *              to are located.
2122  *  \param [in] stepComp - index increment to get index of the next component to assign to.
2123  *  \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents() 
2124  *              must be equal to the number of columns to assign to, else an
2125  *              exception is thrown; if \a false, then it is only required that \a
2126  *              a->getNbOfElems() equals to number of values to assign to (this condition
2127  *              must be respected even if \a strictCompoCompare is \a true). The number of 
2128  *              values to assign to is given by following Python expression:
2129  *              \a nbTargetValues = 
2130  *              \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
2131  *              \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
2132  *  \throw If \a a is NULL.
2133  *  \throw If \a a is not allocated.
2134  *  \throw If \a this is not allocated.
2135  *  \throw If parameters specifying tuples and components to assign to do not give a
2136  *            non-empty range of increasing indices.
2137  *  \throw If \a a->getNbOfElems() != \a nbTargetValues.
2138  *  \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
2139  *            \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
2140  *
2141  *  \ref py_mcdataarraydouble_setpartofvalues1 "Here is a Python example".
2142  */
2143 void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2144 {
2145   if(!a)
2146     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues1 : input DataArrayDouble is NULL !");
2147   const char msg[]="DataArrayDouble::setPartOfValues1";
2148   checkAllocated();
2149   a->checkAllocated();
2150   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2151   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2152   int nbComp=getNumberOfComponents();
2153   int nbOfTuples=getNumberOfTuples();
2154   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2155   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2156   bool assignTech=true;
2157   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2158     {
2159       if(strictCompoCompare)
2160         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2161     }
2162   else
2163     {
2164       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2165       assignTech=false;
2166     }
2167   const double *srcPt=a->getConstPointer();
2168   double *pt=getPointer()+bgTuples*nbComp+bgComp;
2169   if(assignTech)
2170     {
2171       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2172         for(int j=0;j<newNbOfComp;j++,srcPt++)
2173           pt[j*stepComp]=*srcPt;
2174     }
2175   else
2176     {
2177       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2178         {
2179           const double *srcPt2=srcPt;
2180           for(int j=0;j<newNbOfComp;j++,srcPt2++)
2181             pt[j*stepComp]=*srcPt2;
2182         }
2183     }
2184 }
2185
2186 /*!
2187  * Assign a given value to values at specified tuples and components of \a this array.
2188  * The tree parameters defining set of indices of tuples and components are similar to
2189  * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
2190  *  \param [in] a - the value to assign.
2191  *  \param [in] bgTuples - index of the first tuple of \a this array to assign to.
2192  *  \param [in] endTuples - index of the tuple before which the tuples to assign to
2193  *              are located.
2194  *  \param [in] stepTuples - index increment to get index of the next tuple to assign to.
2195  *  \param [in] bgComp - index of the first component of \a this array to assign to.
2196  *  \param [in] endComp - index of the component before which the components to assign
2197  *              to are located.
2198  *  \param [in] stepComp - index increment to get index of the next component to assign to.
2199  *  \throw If \a this is not allocated.
2200  *  \throw If parameters specifying tuples and components to assign to, do not give a
2201  *            non-empty range of increasing indices or indices are out of a valid range
2202  *            for \this array.
2203  *
2204  *  \ref py_mcdataarraydouble_setpartofvaluessimple1 "Here is a Python example".
2205  */
2206 void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
2207 {
2208   const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
2209   checkAllocated();
2210   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2211   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2212   int nbComp=getNumberOfComponents();
2213   int nbOfTuples=getNumberOfTuples();
2214   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2215   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2216   double *pt=getPointer()+bgTuples*nbComp+bgComp;
2217   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2218     for(int j=0;j<newNbOfComp;j++)
2219       pt[j*stepComp]=a;
2220 }
2221
2222 /*!
2223  * Copy all values from another DataArrayDouble (\a a) into specified tuples and 
2224  * components of \a this array. Textual data is not copied.
2225  * The tuples and components to assign to are defined by C arrays of indices.
2226  * There are two *modes of usage*:
2227  * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
2228  *   of \a a is assigned to its own location within \a this array. 
2229  * - If \a a includes one tuple, then all values of \a a are assigned to the specified
2230  *   components of every specified tuple of \a this array. In this mode it is required
2231  *   that \a a->getNumberOfComponents() equals to the number of specified components.
2232  *
2233  *  \param [in] a - the array to copy values from.
2234  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2235  *              assign values of \a a to.
2236  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2237  *              pointer to a tuple index <em>(pi)</em> varies as this: 
2238  *              \a bgTuples <= \a pi < \a endTuples.
2239  *  \param [in] bgComp - pointer to an array of component indices of \a this array to
2240  *              assign values of \a a to.
2241  *  \param [in] endComp - specifies the end of the array \a bgTuples, so that
2242  *              pointer to a component index <em>(pi)</em> varies as this: 
2243  *              \a bgComp <= \a pi < \a endComp.
2244  *  \param [in] strictCompoCompare - this parameter is checked only if the
2245  *               *mode of usage* is the first; if it is \a true (default), 
2246  *               then \a a->getNumberOfComponents() must be equal 
2247  *               to the number of specified columns, else this is not required.
2248  *  \throw If \a a is NULL.
2249  *  \throw If \a a is not allocated.
2250  *  \throw If \a this is not allocated.
2251  *  \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
2252  *         out of a valid range for \a this array.
2253  *  \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
2254  *         if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
2255  *  \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
2256  *         <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
2257  *
2258  *  \ref py_mcdataarraydouble_setpartofvalues2 "Here is a Python example".
2259  */
2260 void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2261 {
2262   if(!a)
2263     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues2 : input DataArrayDouble is NULL !");
2264   const char msg[]="DataArrayDouble::setPartOfValues2";
2265   checkAllocated();
2266   a->checkAllocated();
2267   int nbComp=getNumberOfComponents();
2268   int nbOfTuples=getNumberOfTuples();
2269   for(const int *z=bgComp;z!=endComp;z++)
2270     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2271   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
2272   int newNbOfComp=(int)std::distance(bgComp,endComp);
2273   bool assignTech=true;
2274   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2275     {
2276       if(strictCompoCompare)
2277         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2278     }
2279   else
2280     {
2281       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2282       assignTech=false;
2283     }
2284   double *pt=getPointer();
2285   const double *srcPt=a->getConstPointer();
2286   if(assignTech)
2287     {    
2288       for(const int *w=bgTuples;w!=endTuples;w++)
2289         {
2290           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2291           for(const int *z=bgComp;z!=endComp;z++,srcPt++)
2292             {    
2293               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
2294             }
2295         }
2296     }
2297   else
2298     {
2299       for(const int *w=bgTuples;w!=endTuples;w++)
2300         {
2301           const double *srcPt2=srcPt;
2302           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2303           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
2304             {    
2305               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
2306             }
2307         }
2308     }
2309 }
2310
2311 /*!
2312  * Assign a given value to values at specified tuples and components of \a this array.
2313  * The tuples and components to assign to are defined by C arrays of indices.
2314  *  \param [in] a - the value to assign.
2315  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2316  *              assign \a a to.
2317  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2318  *              pointer to a tuple index (\a pi) varies as this: 
2319  *              \a bgTuples <= \a pi < \a endTuples.
2320  *  \param [in] bgComp - pointer to an array of component indices of \a this array to
2321  *              assign \a a to.
2322  *  \param [in] endComp - specifies the end of the array \a bgTuples, so that
2323  *              pointer to a component index (\a pi) varies as this: 
2324  *              \a bgComp <= \a pi < \a endComp.
2325  *  \throw If \a this is not allocated.
2326  *  \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
2327  *         out of a valid range for \a this array.
2328  *
2329  *  \ref py_mcdataarraydouble_setpartofvaluessimple2 "Here is a Python example".
2330  */
2331 void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
2332 {
2333   checkAllocated();
2334   int nbComp=getNumberOfComponents();
2335   int nbOfTuples=getNumberOfTuples();
2336   for(const int *z=bgComp;z!=endComp;z++)
2337     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2338   double *pt=getPointer();
2339   for(const int *w=bgTuples;w!=endTuples;w++)
2340     for(const int *z=bgComp;z!=endComp;z++)
2341       {
2342         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2343         pt[(std::size_t)(*w)*nbComp+(*z)]=a;
2344       }
2345 }
2346
2347 /*!
2348  * Copy all values from another DataArrayDouble (\a a) into specified tuples and 
2349  * components of \a this array. Textual data is not copied.
2350  * The tuples to assign to are defined by a C array of indices.
2351  * The components to assign to are defined by three values similar to parameters of
2352  * the Python function \c range(\c start,\c stop,\c step).
2353  * There are two *modes of usage*:
2354  * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
2355  *   of \a a is assigned to its own location within \a this array. 
2356  * - If \a a includes one tuple, then all values of \a a are assigned to the specified
2357  *   components of every specified tuple of \a this array. In this mode it is required
2358  *   that \a a->getNumberOfComponents() equals to the number of specified components.
2359  *
2360  *  \param [in] a - the array to copy values from.
2361  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2362  *              assign values of \a a to.
2363  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2364  *              pointer to a tuple index <em>(pi)</em> varies as this: 
2365  *              \a bgTuples <= \a pi < \a endTuples.
2366  *  \param [in] bgComp - index of the first component of \a this array to assign to.
2367  *  \param [in] endComp - index of the component before which the components to assign
2368  *              to are located.
2369  *  \param [in] stepComp - index increment to get index of the next component to assign to.
2370  *  \param [in] strictCompoCompare - this parameter is checked only in the first
2371  *               *mode of usage*; if \a strictCompoCompare is \a true (default), 
2372  *               then \a a->getNumberOfComponents() must be equal 
2373  *               to the number of specified columns, else this is not required.
2374  *  \throw If \a a is NULL.
2375  *  \throw If \a a is not allocated.
2376  *  \throw If \a this is not allocated.
2377  *  \throw If any index of tuple given by \a bgTuples is out of a valid range for 
2378  *         \a this array.
2379  *  \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
2380  *         if <em> a->getNumberOfComponents()</em> is unequal to the number of components
2381  *         defined by <em>(bgComp,endComp,stepComp)</em>.
2382  *  \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
2383  *         <em> a->getNumberOfComponents()</em> is unequal to the number of components
2384  *         defined by <em>(bgComp,endComp,stepComp)</em>.
2385  *  \throw If parameters specifying components to assign to, do not give a
2386  *            non-empty range of increasing indices or indices are out of a valid range
2387  *            for \this array.
2388  *
2389  *  \ref py_mcdataarraydouble_setpartofvalues3 "Here is a Python example".
2390  */
2391 void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2392 {
2393   if(!a)
2394     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues3 : input DataArrayDouble is NULL !");
2395   const char msg[]="DataArrayDouble::setPartOfValues3";
2396   checkAllocated();
2397   a->checkAllocated();
2398   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2399   int nbComp=getNumberOfComponents();
2400   int nbOfTuples=getNumberOfTuples();
2401   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2402   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
2403   bool assignTech=true;
2404   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2405     {
2406       if(strictCompoCompare)
2407         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2408     }
2409   else
2410     {
2411       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2412       assignTech=false;
2413     }
2414   double *pt=getPointer()+bgComp;
2415   const double *srcPt=a->getConstPointer();
2416   if(assignTech)
2417     {
2418       for(const int *w=bgTuples;w!=endTuples;w++)
2419         for(int j=0;j<newNbOfComp;j++,srcPt++)
2420           {
2421             DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2422             pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
2423           }
2424     }
2425   else
2426     {
2427       for(const int *w=bgTuples;w!=endTuples;w++)
2428         {
2429           const double *srcPt2=srcPt;
2430           for(int j=0;j<newNbOfComp;j++,srcPt2++)
2431             {
2432               DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2433               pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
2434             }
2435         }
2436     }
2437 }
2438
2439 /*!
2440  * Assign a given value to values at specified tuples and components of \a this array.
2441  * The tuples to assign to are defined by a C array of indices.
2442  * The components to assign to are defined by three values similar to parameters of
2443  * the Python function \c range(\c start,\c stop,\c step).
2444  *  \param [in] a - the value to assign.
2445  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
2446  *              assign \a a to.
2447  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
2448  *              pointer to a tuple index <em>(pi)</em> varies as this: 
2449  *              \a bgTuples <= \a pi < \a endTuples.
2450  *  \param [in] bgComp - index of the first component of \a this array to assign to.
2451  *  \param [in] endComp - index of the component before which the components to assign
2452  *              to are located.
2453  *  \param [in] stepComp - index increment to get index of the next component to assign to.
2454  *  \throw If \a this is not allocated.
2455  *  \throw If any index of tuple given by \a bgTuples is out of a valid range for 
2456  *         \a this array.
2457  *  \throw If parameters specifying components to assign to, do not give a
2458  *            non-empty range of increasing indices or indices are out of a valid range
2459  *            for \this array.
2460  *
2461  *  \ref py_mcdataarraydouble_setpartofvaluessimple3 "Here is a Python example".
2462  */
2463 void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
2464 {
2465   const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
2466   checkAllocated();
2467   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
2468   int nbComp=getNumberOfComponents();
2469   int nbOfTuples=getNumberOfTuples();
2470   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
2471   double *pt=getPointer()+bgComp;
2472   for(const int *w=bgTuples;w!=endTuples;w++)
2473     for(int j=0;j<newNbOfComp;j++)
2474       {
2475         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
2476         pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
2477       }
2478 }
2479
2480 /*!
2481  * Copy all values from another DataArrayDouble into specified tuples and components
2482  * of \a this array. Textual data is not copied.
2483  * The tree parameters defining set of indices of tuples and components are similar to
2484  * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
2485  *  \param [in] a - the array to copy values from.
2486  *  \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
2487  *  \param [in] endTuples - index of the tuple before which the tuples to assign to
2488  *              are located.
2489  *  \param [in] stepTuples - index increment to get index of the next tuple to assign to.
2490  *  \param [in] bgComp - pointer to an array of component indices of \a this array to
2491  *              assign \a a to.
2492  *  \param [in] endComp - specifies the end of the array \a bgTuples, so that
2493  *              pointer to a component index (\a pi) varies as this: 
2494  *              \a bgComp <= \a pi < \a endComp.
2495  *  \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents() 
2496  *              must be equal to the number of columns to assign to, else an
2497  *              exception is thrown; if \a false, then it is only required that \a
2498  *              a->getNbOfElems() equals to number of values to assign to (this condition
2499  *              must be respected even if \a strictCompoCompare is \a true). The number of 
2500  *              values to assign to is given by following Python expression:
2501  *              \a nbTargetValues = 
2502  *              \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
2503  *              \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
2504  *  \throw If \a a is NULL.
2505  *  \throw If \a a is not allocated.
2506  *  \throw If \a this is not allocated.
2507  *  \throw If parameters specifying tuples and components to assign to do not give a
2508  *            non-empty range of increasing indices.
2509  *  \throw If \a a->getNbOfElems() != \a nbTargetValues.
2510  *  \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
2511  *            \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
2512  *
2513  */
2514 void DataArrayDouble::setPartOfValues4(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
2515 {
2516   if(!a)
2517     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValues4 : input DataArrayDouble is NULL !");
2518   const char msg[]="DataArrayDouble::setPartOfValues4";
2519   checkAllocated();
2520   a->checkAllocated();
2521   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2522   int newNbOfComp=(int)std::distance(bgComp,endComp);
2523   int nbComp=getNumberOfComponents();
2524   for(const int *z=bgComp;z!=endComp;z++)
2525     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2526   int nbOfTuples=getNumberOfTuples();
2527   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2528   bool assignTech=true;
2529   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
2530     {
2531       if(strictCompoCompare)
2532         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
2533     }
2534   else
2535     {
2536       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
2537       assignTech=false;
2538     }
2539   const double *srcPt=a->getConstPointer();
2540   double *pt=getPointer()+bgTuples*nbComp;
2541   if(assignTech)
2542     {
2543       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2544         for(const int *z=bgComp;z!=endComp;z++,srcPt++)
2545           pt[*z]=*srcPt;
2546     }
2547   else
2548     {
2549       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2550         {
2551           const double *srcPt2=srcPt;
2552           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
2553             pt[*z]=*srcPt2;
2554         }
2555     }
2556 }
2557
2558 void DataArrayDouble::setPartOfValuesSimple4(double a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
2559 {
2560   const char msg[]="DataArrayDouble::setPartOfValuesSimple4";
2561   checkAllocated();
2562   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
2563   int nbComp=getNumberOfComponents();
2564   for(const int *z=bgComp;z!=endComp;z++)
2565     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
2566   int nbOfTuples=getNumberOfTuples();
2567   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
2568   double *pt=getPointer()+bgTuples*nbComp;
2569   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
2570     for(const int *z=bgComp;z!=endComp;z++)
2571       pt[*z]=a;
2572 }
2573
2574 /*!
2575  * Copy some tuples from another DataArrayDouble into specified tuples
2576  * of \a this array. Textual data is not copied. Both arrays must have equal number of
2577  * components.
2578  * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
2579  * All components of selected tuples are copied.
2580  *  \param [in] a - the array to copy values from.
2581  *  \param [in] tuplesSelec - the array specifying both source tuples of \a a and
2582  *              target tuples of \a this. \a tuplesSelec has two components, and the
2583  *              first component specifies index of the source tuple and the second
2584  *              one specifies index of the target tuple.
2585  *  \throw If \a this is not allocated.
2586  *  \throw If \a a is NULL.
2587  *  \throw If \a a is not allocated.
2588  *  \throw If \a tuplesSelec is NULL.
2589  *  \throw If \a tuplesSelec is not allocated.
2590  *  \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
2591  *  \throw If \a tuplesSelec->getNumberOfComponents() != 2.
2592  *  \throw If any tuple index given by \a tuplesSelec is out of a valid range for 
2593  *         the corresponding (\a this or \a a) array.
2594  */
2595 void DataArrayDouble::setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
2596 {
2597   if(!a || !tuplesSelec)
2598     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : input DataArrayDouble is NULL !");
2599   checkAllocated();
2600   a->checkAllocated();
2601   tuplesSelec->checkAllocated();
2602   int nbOfComp=getNumberOfComponents();
2603   if(nbOfComp!=a->getNumberOfComponents())
2604     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : This and a do not have the same number of components !");
2605   if(tuplesSelec->getNumberOfComponents()!=2)
2606     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
2607   int thisNt=getNumberOfTuples();
2608   int aNt=a->getNumberOfTuples();
2609   double *valsToSet=getPointer();
2610   const double *valsSrc=a->getConstPointer();
2611   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
2612     {
2613       if(tuple[1]>=0 && tuple[1]<aNt)
2614         {
2615           if(tuple[0]>=0 && tuple[0]<thisNt)
2616             std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
2617           else
2618             {
2619               std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
2620               oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
2621               throw INTERP_KERNEL::Exception(oss.str().c_str());
2622             }
2623         }
2624       else
2625         {
2626           std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
2627           oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
2628           throw INTERP_KERNEL::Exception(oss.str().c_str());
2629         }
2630     }
2631 }
2632
2633 /*!
2634  * Copy some tuples from another DataArrayDouble (\a a) into contiguous tuples
2635  * of \a this array. Textual data is not copied. Both arrays must have equal number of
2636  * components.
2637  * The tuples to assign to are defined by index of the first tuple, and
2638  * their number is defined by \a tuplesSelec->getNumberOfTuples().
2639  * The tuples to copy are defined by values of a DataArrayInt.
2640  * All components of selected tuples are copied.
2641  *  \param [in] tupleIdStart - index of the first tuple of \a this array to assign
2642  *              values to.
2643  *  \param [in] a - the array to copy values from.
2644  *  \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
2645  *  \throw If \a this is not allocated.
2646  *  \throw If \a a is NULL.
2647  *  \throw If \a a is not allocated.
2648  *  \throw If \a tuplesSelec is NULL.
2649  *  \throw If \a tuplesSelec is not allocated.
2650  *  \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
2651  *  \throw If \a tuplesSelec->getNumberOfComponents() != 1.
2652  *  \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
2653  *  \throw If any tuple index given by \a tuplesSelec is out of a valid range for 
2654  *         \a a array.
2655  */
2656 void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
2657 {
2658   if(!aBase || !tuplesSelec)
2659     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray is NULL !");
2660   const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(aBase);
2661   if(!a)
2662     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayDouble !");
2663   checkAllocated();
2664   a->checkAllocated();
2665   tuplesSelec->checkAllocated();
2666   int nbOfComp=getNumberOfComponents();
2667   if(nbOfComp!=a->getNumberOfComponents())
2668     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : This and a do not have the same number of components !");
2669   if(tuplesSelec->getNumberOfComponents()!=1)
2670     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
2671   int thisNt=getNumberOfTuples();
2672   int aNt=a->getNumberOfTuples();
2673   int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
2674   double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
2675   if(tupleIdStart+nbOfTupleToWrite>thisNt)
2676     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : invalid number range of values to write !");
2677   const double *valsSrc=a->getConstPointer();
2678   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
2679     {
2680       if(*tuple>=0 && *tuple<aNt)
2681         {
2682           std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
2683         }
2684       else
2685         {
2686           std::ostringstream oss; oss << "DataArrayDouble::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
2687           oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
2688           throw INTERP_KERNEL::Exception(oss.str().c_str());
2689         }
2690     }
2691 }
2692
2693 /*!
2694  * Copy some tuples from another DataArrayDouble (\a a) into contiguous tuples
2695  * of \a this array. Textual data is not copied. Both arrays must have equal number of
2696  * components.
2697  * The tuples to copy are defined by three values similar to parameters of
2698  * the Python function \c range(\c start,\c stop,\c step).
2699  * The tuples to assign to are defined by index of the first tuple, and
2700  * their number is defined by number of tuples to copy.
2701  * All components of selected tuples are copied.
2702  *  \param [in] tupleIdStart - index of the first tuple of \a this array to assign
2703  *              values to.
2704  *  \param [in] a - the array to copy values from.
2705  *  \param [in] bg - index of the first tuple to copy of the array \a a.
2706  *  \param [in] end2 - index of the tuple of \a a before which the tuples to copy
2707  *              are located.
2708  *  \param [in] step - index increment to get index of the next tuple to copy.
2709  *  \throw If \a this is not allocated.
2710  *  \throw If \a a is NULL.
2711  *  \throw If \a a is not allocated.
2712  *  \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
2713  *  \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
2714  *  \throw If parameters specifying tuples to copy, do not give a
2715  *            non-empty range of increasing indices or indices are out of a valid range
2716  *            for the array \a a.
2717  */
2718 void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
2719 {
2720   if(!aBase)
2721     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArray is NULL !");
2722   const DataArrayDouble *a=dynamic_cast<const DataArrayDouble *>(aBase);
2723   if(!a)
2724     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : input DataArray aBase is not a DataArrayDouble !");
2725   checkAllocated();
2726   a->checkAllocated();
2727   int nbOfComp=getNumberOfComponents();
2728   const char msg[]="DataArrayDouble::setContigPartOfSelectedValues2";
2729   int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
2730   if(nbOfComp!=a->getNumberOfComponents())
2731     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
2732   int thisNt=getNumberOfTuples();
2733   int aNt=a->getNumberOfTuples();
2734   double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
2735   if(tupleIdStart+nbOfTupleToWrite>thisNt)
2736     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid number range of values to write !");
2737   if(end2>aNt)
2738     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid range of values to read !");
2739   const double *valsSrc=a->getConstPointer()+bg*nbOfComp;
2740   for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
2741     {
2742       std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
2743     }
2744 }
2745
2746 /*!
2747  * Returns a value located at specified tuple and component.
2748  * This method is equivalent to DataArrayDouble::getIJ() except that validity of
2749  * parameters is checked. So this method is safe but expensive if used to go through
2750  * all values of \a this.
2751  *  \param [in] tupleId - index of tuple of interest.
2752  *  \param [in] compoId - index of component of interest.
2753  *  \return double - value located by \a tupleId and \a compoId.
2754  *  \throw If \a this is not allocated.
2755  *  \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
2756  *  \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
2757  */
2758 double DataArrayDouble::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
2759 {
2760   checkAllocated();
2761   if(tupleId<0 || tupleId>=getNumberOfTuples())
2762     {
2763       std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
2764       throw INTERP_KERNEL::Exception(oss.str().c_str());
2765     }
2766   if(compoId<0 || compoId>=getNumberOfComponents())
2767     {
2768       std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
2769       throw INTERP_KERNEL::Exception(oss.str().c_str());
2770     }
2771   return _mem[tupleId*_info_on_compo.size()+compoId];
2772 }
2773
2774 /*!
2775  * Returns the first value of \a this. 
2776  *  \return double - the last value of \a this array.
2777  *  \throw If \a this is not allocated.
2778  *  \throw If \a this->getNumberOfComponents() != 1.
2779  *  \throw If \a this->getNumberOfTuples() < 1.
2780  */
2781 double DataArrayDouble::front() const throw(INTERP_KERNEL::Exception)
2782 {
2783   checkAllocated();
2784   if(getNumberOfComponents()!=1)
2785     throw INTERP_KERNEL::Exception("DataArrayDouble::front : number of components not equal to one !");
2786   int nbOfTuples=getNumberOfTuples();
2787   if(nbOfTuples<1)
2788     throw INTERP_KERNEL::Exception("DataArrayDouble::front : number of tuples must be >= 1 !");
2789   return *(getConstPointer());
2790 }
2791
2792 /*!
2793  * Returns the last value of \a this. 
2794  *  \return double - the last value of \a this array.
2795  *  \throw If \a this is not allocated.
2796  *  \throw If \a this->getNumberOfComponents() != 1.
2797  *  \throw If \a this->getNumberOfTuples() < 1.
2798  */
2799 double DataArrayDouble::back() const throw(INTERP_KERNEL::Exception)
2800 {
2801   checkAllocated();
2802   if(getNumberOfComponents()!=1)
2803     throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of components not equal to one !");
2804   int nbOfTuples=getNumberOfTuples();
2805   if(nbOfTuples<1)
2806     throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of tuples must be >= 1 !");
2807   return *(getConstPointer()+nbOfTuples-1);
2808 }
2809
2810 void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
2811 {
2812   if(newArray!=arrayToSet)
2813     {
2814       if(arrayToSet)
2815         arrayToSet->decrRef();
2816       arrayToSet=newArray;
2817       if(arrayToSet)
2818         arrayToSet->incrRef();
2819     }
2820 }
2821
2822 /*!
2823  * Sets a C array to be used as raw data of \a this. The previously set info
2824  *  of components is retained and re-sized. 
2825  * For more info see \ref MEDCouplingArraySteps1.
2826  *  \param [in] array - the C array to be used as raw data of \a this.
2827  *  \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
2828  *  \param [in] type - specifies how to deallocate \a array. If \a type == ParaMEDMEM::CPP_DEALLOC,
2829  *                     \c delete [] \c array; will be called. If \a type == ParaMEDMEM::C_DEALLOC,
2830  *                     \c free(\c array ) will be called.
2831  *  \param [in] nbOfTuple - new number of tuples in \a this.
2832  *  \param [in] nbOfCompo - new number of components in \a this.
2833  */
2834 void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
2835 {
2836   _info_on_compo.resize(nbOfCompo);
2837   _mem.useArray(array,ownership,type,(std::size_t)nbOfTuple*nbOfCompo);
2838   declareAsNew();
2839 }
2840
2841 void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
2842 {
2843   _info_on_compo.resize(nbOfCompo);
2844   _mem.useExternalArrayWithRWAccess(array,(std::size_t)nbOfTuple*nbOfCompo);
2845   declareAsNew();
2846 }
2847
2848 /*!
2849  * Checks if 0.0 value is present in \a this array. If it is the case, an exception
2850  * is thrown.
2851  * \throw If zero is found in \a this array.
2852  */
2853 void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception)
2854 {
2855   const double *tmp=getConstPointer();
2856   std::size_t nbOfElems=getNbOfElems();
2857   const double *where=std::find(tmp,tmp+nbOfElems,0.);
2858   if(where!=tmp+nbOfElems)
2859     throw INTERP_KERNEL::Exception("A value 0.0 have been detected !");
2860 }
2861
2862 /*!
2863  * Computes minimal and maximal value in each component. An output array is filled
2864  * with \c 2 * \a this->getNumberOfComponents() values, so the caller is to allocate
2865  * enough memory before calling this method.
2866  *  \param [out] bounds - array of size at least 2 *\a this->getNumberOfComponents().
2867  *               It is filled as follows:<br>
2868  *               \a bounds[0] = \c min_of_component_0 <br>
2869  *               \a bounds[1] = \c max_of_component_0 <br>
2870  *               \a bounds[2] = \c min_of_component_1 <br>
2871  *               \a bounds[3] = \c max_of_component_1 <br>
2872  *               ...
2873  */
2874 void DataArrayDouble::getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception)
2875 {
2876   checkAllocated();
2877   int dim=getNumberOfComponents();
2878   for (int idim=0; idim<dim; idim++)
2879     {
2880       bounds[idim*2]=std::numeric_limits<double>::max();
2881       bounds[idim*2+1]=-std::numeric_limits<double>::max();
2882     } 
2883   const double *ptr=getConstPointer();
2884   int nbOfTuples=getNumberOfTuples();
2885   for(int i=0;i<nbOfTuples;i++)
2886     {
2887       for(int idim=0;idim<dim;idim++)
2888         {
2889           if(bounds[idim*2]>ptr[i*dim+idim])
2890             {
2891               bounds[idim*2]=ptr[i*dim+idim];
2892             }
2893           if(bounds[idim*2+1]<ptr[i*dim+idim])
2894             {
2895               bounds[idim*2+1]=ptr[i*dim+idim];
2896             }
2897         }
2898     }
2899 }
2900
2901 /*!
2902  * This method retrieves a newly allocated DataArrayDouble instance having same number of tuples than \a this and twice number of components than \a this
2903  * to store both the min and max per component of each tuples. 
2904  * \param [in] epsilon the width of the bbox (identical in each direction) - 0.0 by default
2905  *
2906  * \return a newly created DataArrayDouble instance having \c this->getNumberOfTuples() tuples and 2 * \c this->getNumberOfComponent() components
2907  *
2908  * \throw If \a this is not allocated yet.
2909  */
2910 DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon)const throw(INTERP_KERNEL::Exception)
2911 {
2912   checkAllocated();
2913   const double *dataPtr=getConstPointer();
2914   int nbOfCompo=getNumberOfComponents();
2915   int nbTuples=getNumberOfTuples();
2916   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> bbox=DataArrayDouble::New();
2917   bbox->alloc(nbTuples,2*nbOfCompo);
2918   double *bboxPtr=bbox->getPointer();
2919   for(int i=0;i<nbTuples;i++)
2920     {
2921       for(int j=0;j<nbOfCompo;j++)
2922         {
2923           bboxPtr[2*nbOfCompo*i+2*j]=dataPtr[nbOfCompo*i+j]-epsilon;
2924           bboxPtr[2*nbOfCompo*i+2*j+1]=dataPtr[nbOfCompo*i+j]+epsilon;
2925         }
2926     }
2927   return bbox.retn();
2928 }
2929
2930 /*!
2931  * For each tuples **t** in \a other, this method retrieves tuples in \a this that are equal to **t**.
2932  * Two tuples are considered equal if the euclidian distance between the two tuples is lower than \a eps.
2933  * 
2934  * \param [in] other a DataArrayDouble having same number of components than \a this.
2935  * \param [in] eps absolute precision representing distance (using infinite norm) between 2 tuples behind which 2 tuples are considered equal.
2936  * \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.
2937  *             \a cI allows to extract information in \a c.
2938  * \param [out] cI is an indirection array that allows to extract the data contained in \a c.
2939  *
2940  * \throw In case of:
2941  *  - \a this is not allocated
2942  *  - \a other is not allocated or null
2943  *  - \a this and \a other do not have the same number of components
2944  *  - if number of components of \a this is not in [1,2,3]
2945  *
2946  * \sa MEDCouplingPointSet::getNodeIdsNearPoints, DataArrayDouble::getDifferentValues
2947  */
2948 void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception)
2949 {
2950   if(!other)
2951     throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !");
2952   checkAllocated();
2953   other->checkAllocated();
2954   int nbOfCompo=getNumberOfComponents();
2955   int otherNbOfCompo=other->getNumberOfComponents();
2956   if(nbOfCompo!=otherNbOfCompo)
2957     throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : number of components should be equal between this and other !");
2958   int nbOfTuplesOther=other->getNumberOfTuples();
2959   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cArr(DataArrayInt::New()),cIArr(DataArrayInt::New()); cArr->alloc(0,1); cIArr->pushBackSilent(0);
2960   switch(nbOfCompo)
2961     {
2962     case 3:
2963       {
2964         BBTreePts<3,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
2965         FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2966         break;
2967       }
2968     case 2:
2969       {
2970         BBTreePts<2,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
2971         FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2972         break;
2973       }
2974     case 1:
2975       {
2976         BBTreePts<1,int> myTree(begin(),0,0,getNumberOfTuples(),eps);
2977         FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr);
2978         break;
2979       }
2980     default:
2981       throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for computeTupleIdsNearTuples. Must be 1, 2 or 3.");
2982     }
2983   c=cArr.retn(); cI=cIArr.retn();
2984 }
2985
2986 /*!
2987  * 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
2988  * around origin of 'radius' 1.
2989  * 
2990  * \param [in] eps absolute epsilon. under that value of delta between max and min no scale is performed.
2991  */
2992 void DataArrayDouble::recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception)
2993 {
2994   checkAllocated();
2995   int dim=getNumberOfComponents();
2996   std::vector<double> bounds(2*dim);
2997   getMinMaxPerComponent(&bounds[0]);
2998   for(int i=0;i<dim;i++)
2999     {
3000       double delta=bounds[2*i+1]-bounds[2*i];
3001       double offset=(bounds[2*i]+bounds[2*i+1])/2.;
3002       if(delta>eps)
3003         applyLin(1./delta,-offset/delta,i);
3004       else
3005         applyLin(1.,-offset,i);
3006     }
3007 }
3008
3009 /*!
3010  * Returns the maximal value and its location within \a this one-dimensional array.
3011  *  \param [out] tupleId - index of the tuple holding the maximal value.
3012  *  \return double - the maximal value among all values of \a this array.
3013  *  \throw If \a this->getNumberOfComponents() != 1
3014  *  \throw If \a this->getNumberOfTuples() < 1
3015  */
3016 double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
3017 {
3018   checkAllocated();
3019   if(getNumberOfComponents()!=1)
3020     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 !");
3021   int nbOfTuples=getNumberOfTuples();
3022   if(nbOfTuples<=0)
3023     throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
3024   const double *vals=getConstPointer();
3025   const double *loc=std::max_element(vals,vals+nbOfTuples);
3026   tupleId=(int)std::distance(vals,loc);
3027   return *loc;
3028 }
3029
3030 /*!
3031  * Returns the maximal value within \a this array that is allowed to have more than
3032  *  one component.
3033  *  \return double - the maximal value among all values of \a this array.
3034  *  \throw If \a this is not allocated.
3035  */
3036 double DataArrayDouble::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
3037 {
3038   checkAllocated();
3039   const double *loc=std::max_element(begin(),end());
3040   return *loc;
3041 }
3042
3043 /*!
3044  * Returns the maximal value and all its locations within \a this one-dimensional array.
3045  *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
3046  *               tuples holding the maximal value. The caller is to delete it using
3047  *               decrRef() as it is no more needed.
3048  *  \return double - the maximal value among all values of \a this array.
3049  *  \throw If \a this->getNumberOfComponents() != 1
3050  *  \throw If \a this->getNumberOfTuples() < 1
3051  */
3052 double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
3053 {
3054   int tmp;
3055   tupleIds=0;
3056   double ret=getMaxValue(tmp);
3057   tupleIds=getIdsInRange(ret,ret);
3058   return ret;
3059 }
3060
3061 /*!
3062  * Returns the minimal value and its location within \a this one-dimensional array.
3063  *  \param [out] tupleId - index of the tuple holding the minimal value.
3064  *  \return double - the minimal value among all values of \a this array.
3065  *  \throw If \a this->getNumberOfComponents() != 1
3066  *  \throw If \a this->getNumberOfTuples() < 1
3067  */
3068 double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
3069 {
3070   checkAllocated();
3071   if(getNumberOfComponents()!=1)
3072     throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
3073   int nbOfTuples=getNumberOfTuples();
3074   if(nbOfTuples<=0)
3075     throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
3076   const double *vals=getConstPointer();
3077   const double *loc=std::min_element(vals,vals+nbOfTuples);
3078   tupleId=(int)std::distance(vals,loc);
3079   return *loc;
3080 }
3081
3082 /*!
3083  * Returns the minimal value within \a this array that is allowed to have more than
3084  *  one component.
3085  *  \return double - the minimal value among all values of \a this array.
3086  *  \throw If \a this is not allocated.
3087  */
3088 double DataArrayDouble::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
3089 {
3090   checkAllocated();
3091   const double *loc=std::min_element(begin(),end());
3092   return *loc;
3093 }
3094
3095 /*!
3096  * Returns the minimal value and all its locations within \a this one-dimensional array.
3097  *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
3098  *               tuples holding the minimal value. The caller is to delete it using
3099  *               decrRef() as it is no more needed.
3100  *  \return double - the minimal value among all values of \a this array.
3101  *  \throw If \a this->getNumberOfComponents() != 1
3102  *  \throw If \a this->getNumberOfTuples() < 1
3103  */
3104 double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
3105 {
3106   int tmp;
3107   tupleIds=0;
3108   double ret=getMinValue(tmp);
3109   tupleIds=getIdsInRange(ret,ret);
3110   return ret;
3111 }
3112
3113 /*!
3114  * This method returns the number of values in \a this that are equals ( within an absolute precision of \a eps ) to input parameter \a value.
3115  * This method only works for single component array.
3116  *
3117  * \return a value in [ 0, \c this->getNumberOfTuples() )
3118  *
3119  * \throw If \a this is not allocated
3120  *
3121  */
3122 int DataArrayDouble::count(double value, double eps) const throw(INTERP_KERNEL::Exception)
3123 {
3124   int ret=0;
3125   checkAllocated();
3126   if(getNumberOfComponents()!=1)
3127     throw INTERP_KERNEL::Exception("DataArrayDouble::count : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
3128   const double *vals=begin();
3129   int nbOfTuples=getNumberOfTuples();
3130   for(int i=0;i<nbOfTuples;i++,vals++)
3131     if(fabs(*vals-value)<=eps)
3132       ret++;
3133   return ret;
3134 }
3135
3136 /*!
3137  * Returns the average value of \a this one-dimensional array.
3138  *  \return double - the average value over all values of \a this array.
3139  *  \throw If \a this->getNumberOfComponents() != 1
3140  *  \throw If \a this->getNumberOfTuples() < 1
3141  */
3142 double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
3143 {
3144   if(getNumberOfComponents()!=1)
3145     throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
3146   int nbOfTuples=getNumberOfTuples();
3147   if(nbOfTuples<=0)
3148     throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !");
3149   const double *vals=getConstPointer();
3150   double ret=std::accumulate(vals,vals+nbOfTuples,0.);
3151   return ret/nbOfTuples;
3152 }
3153
3154 /*!
3155  * Returns the Euclidean norm of the vector defined by \a this array.
3156  *  \return double - the value of the Euclidean norm, i.e.
3157  *          the square root of the inner product of vector.
3158  *  \throw If \a this is not allocated.
3159  */
3160 double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
3161 {
3162   checkAllocated();
3163   double ret=0.;
3164   std::size_t nbOfElems=getNbOfElems();
3165   const double *pt=getConstPointer();
3166   for(std::size_t i=0;i<nbOfElems;i++,pt++)
3167     ret+=(*pt)*(*pt);
3168   return sqrt(ret);
3169 }
3170
3171 /*!
3172  * Returns the maximum norm of the vector defined by \a this array.
3173  *  \return double - the value of the maximum norm, i.e.
3174  *          the maximal absolute value among values of \a this array.
3175  *  \throw If \a this is not allocated.
3176  */
3177 double DataArrayDouble::normMax() const throw(INTERP_KERNEL::Exception)
3178 {
3179   checkAllocated();
3180   double ret=-1.;
3181   std::size_t nbOfElems=getNbOfElems();
3182   const double *pt=getConstPointer();
3183   for(std::size_t i=0;i<nbOfElems;i++,pt++)
3184     {
3185       double val=std::abs(*pt);
3186       if(val>ret)
3187         ret=val;
3188     }
3189   return ret;
3190 }
3191
3192 /*!
3193  * Accumulates values of each component of \a this array.
3194  *  \param [out] res - an array of length \a this->getNumberOfComponents(), allocated 
3195  *         by the caller, that is filled by this method with sum value for each
3196  *         component.
3197  *  \throw If \a this is not allocated.
3198  */
3199 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
3200 {
3201   checkAllocated();
3202   const double *ptr=getConstPointer();
3203   int nbTuple=getNumberOfTuples();
3204   int nbComps=getNumberOfComponents();
3205   std::fill(res,res+nbComps,0.);
3206   for(int i=0;i<nbTuple;i++)
3207     std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
3208 }
3209
3210 /*!
3211  * This method returns the min distance from an external tuple defined by [ \a tupleBg , \a tupleEnd ) to \a this and
3212  * the first tuple in \a this that matches the returned distance. If there is no tuples in \a this an exception will be thrown.
3213  *
3214  *
3215  * \a this is expected to be allocated and expected to have a number of components equal to the distance from \a tupleBg to
3216  * \a tupleEnd. If not an exception will be thrown.
3217  *
3218  * \param [in] tupleBg start pointer (included) of input external tuple
3219  * \param [in] tupleEnd end pointer (not included) of input external tuple
3220  * \param [out] tupleId the tuple id in \a this that matches the min of distance between \a this and input external tuple
3221  * \return the min distance.
3222  * \sa MEDCouplingUMesh::distanceToPoint
3223  */
3224 double DataArrayDouble::distanceToTuple(const double *tupleBg, const double *tupleEnd, int& tupleId) const throw(INTERP_KERNEL::Exception)
3225 {
3226   checkAllocated();
3227   int nbTuple=getNumberOfTuples();
3228   int nbComps=getNumberOfComponents();
3229   if(nbComps!=(int)std::distance(tupleBg,tupleEnd))
3230     { 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()); }
3231   if(nbTuple==0)
3232     throw INTERP_KERNEL::Exception("DataArrayDouble::distanceToTuple : no tuple in this ! No distance to compute !");
3233   double ret0=std::numeric_limits<double>::max();
3234   tupleId=-1;
3235   const double *work=getConstPointer();
3236   for(int i=0;i<nbTuple;i++)
3237     {
3238       double val=0.;
3239       for(int j=0;j<nbComps;j++,work++) 
3240         val+=(*work-tupleBg[j])*((*work-tupleBg[j]));
3241       if(val>=ret0)
3242         continue;
3243       else
3244         { ret0=val; tupleId=i; }
3245     }
3246   return sqrt(ret0);
3247 }
3248
3249 /*!
3250  * Accumulate values of the given component of \a this array.
3251  *  \param [in] compId - the index of the component of interest.
3252  *  \return double - a sum value of \a compId-th component.
3253  *  \throw If \a this is not allocated.
3254  *  \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
3255  *         not respected.
3256  */
3257 double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
3258 {
3259   checkAllocated();
3260   const double *ptr=getConstPointer();
3261   int nbTuple=getNumberOfTuples();
3262   int nbComps=getNumberOfComponents();
3263   if(compId<0 || compId>=nbComps)
3264     throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !");
3265   double ret=0.;
3266   for(int i=0;i<nbTuple;i++)
3267     ret+=ptr[i*nbComps+compId];
3268   return ret;
3269 }
3270
3271 /*!
3272  * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
3273  * The returned array will have same number of components than \a this and number of tuples equal to
3274  * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
3275  *
3276  * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
3277  * This method is quite useful for users that need to put a field on cells to field on nodes on the same mesh without a need of conservation.
3278  *
3279  * \param [in] bgOfIndex - begin (included) of the input index array.
3280  * \param [in] endOfIndex - end (excluded) of the input index array.
3281  * \return DataArrayDouble * - the new instance having the same number of components than \a this.
3282  * 
3283  * \throw If bgOfIndex or end is NULL.
3284  * \throw If input index array is not ascendingly sorted.
3285  * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
3286  * \throw If std::distance(bgOfIndex,endOfIndex)==0.
3287  */
3288 DataArrayDouble *DataArrayDouble::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const throw(INTERP_KERNEL::Exception)
3289 {
3290   if(!bgOfIndex || !endOfIndex)
3291     throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : input pointer NULL !");
3292   checkAllocated();
3293   int nbCompo=getNumberOfComponents();
3294   int nbOfTuples=getNumberOfTuples();
3295   int sz=(int)std::distance(bgOfIndex,endOfIndex);
3296   if(sz<1)
3297     throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : invalid size of input index array !");
3298   sz--;
3299   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(sz,nbCompo);
3300   const int *w=bgOfIndex;
3301   if(*w<0 || *w>=nbOfTuples)
3302     throw INTERP_KERNEL::Exception("DataArrayDouble::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
3303   const double *srcPt=begin()+(*w)*nbCompo;
3304   double *tmp=ret->getPointer();
3305   for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
3306     {
3307       std::fill(tmp,tmp+nbCompo,0.);
3308       if(w[1]>=w[0])
3309         {
3310           for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
3311             {
3312               if(j>=0 && j<nbOfTuples)
3313                 std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<double>());
3314               else
3315                 {
3316                   std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
3317                   throw INTERP_KERNEL::Exception(oss.str().c_str());
3318                 }
3319             }
3320         }
3321       else
3322         {
3323           std::ostringstream oss; oss << "DataArrayDouble::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
3324           throw INTERP_KERNEL::Exception(oss.str().c_str());
3325         }
3326     }
3327   ret->copyStringInfoFrom(*this);
3328   return ret.retn();
3329 }
3330
3331 /*!
3332  * Converts each 2D point defined by the tuple of \a this array from the Polar to the
3333  * Cartesian coordinate system. The two components of the tuple of \a this array are 
3334  * considered to contain (1) radius and (2) angle of the point in the Polar CS.
3335  *  \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3336  *          contains X and Y coordinates of the point in the Cartesian CS. The caller
3337  *          is to delete this array using decrRef() as it is no more needed. The array
3338  *          does not contain any textual info on components.
3339  *  \throw If \a this->getNumberOfComponents() != 2.
3340  */
3341 DataArrayDouble *DataArrayDouble::fromPolarToCart() const throw(INTERP_KERNEL::Exception)
3342 {
3343   checkAllocated();
3344   int nbOfComp=getNumberOfComponents();
3345   if(nbOfComp!=2)
3346     throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !");
3347   int nbOfTuple=getNumberOfTuples();
3348   DataArrayDouble *ret=DataArrayDouble::New();
3349   ret->alloc(nbOfTuple,2);
3350   double *w=ret->getPointer();
3351   const double *wIn=getConstPointer();
3352   for(int i=0;i<nbOfTuple;i++,w+=2,wIn+=2)
3353     {
3354       w[0]=wIn[0]*cos(wIn[1]);
3355       w[1]=wIn[0]*sin(wIn[1]);
3356     }
3357   return ret;
3358 }
3359
3360 /*!
3361  * Converts each 3D point defined by the tuple of \a this array from the Cylindrical to
3362  * the Cartesian coordinate system. The three components of the tuple of \a this array 
3363  * are considered to contain (1) radius, (2) azimuth and (3) altitude of the point in
3364  * the Cylindrical CS.
3365  *  \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3366  *          contains X, Y and Z coordinates of the point in the Cartesian CS. The info
3367  *          on the third component is copied from \a this array. The caller
3368  *          is to delete this array using decrRef() as it is no more needed. 
3369  *  \throw If \a this->getNumberOfComponents() != 3.
3370  */
3371 DataArrayDouble *DataArrayDouble::fromCylToCart() const throw(INTERP_KERNEL::Exception)
3372 {
3373   checkAllocated();
3374   int nbOfComp=getNumberOfComponents();
3375   if(nbOfComp!=3)
3376     throw INTERP_KERNEL::Exception("DataArrayDouble::fromCylToCart : must be an array with exactly 3 components !");
3377   int nbOfTuple=getNumberOfTuples();
3378   DataArrayDouble *ret=DataArrayDouble::New();
3379   ret->alloc(getNumberOfTuples(),3);
3380   double *w=ret->getPointer();
3381   const double *wIn=getConstPointer();
3382   for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
3383     {
3384       w[0]=wIn[0]*cos(wIn[1]);
3385       w[1]=wIn[0]*sin(wIn[1]);
3386       w[2]=wIn[2];
3387     }
3388   ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str());
3389   return ret;
3390 }
3391
3392 /*!
3393  * Converts each 3D point defined by the tuple of \a this array from the Spherical to
3394  * the Cartesian coordinate system. The three components of the tuple of \a this array 
3395  * are considered to contain (1) radius, (2) polar angle and (3) azimuthal angle of the
3396  * point in the Cylindrical CS.
3397  *  \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3398  *          contains X, Y and Z coordinates of the point in the Cartesian CS. The info
3399  *          on the third component is copied from \a this array. The caller
3400  *          is to delete this array using decrRef() as it is no more needed.
3401  *  \throw If \a this->getNumberOfComponents() != 3.
3402  */
3403 DataArrayDouble *DataArrayDouble::fromSpherToCart() const throw(INTERP_KERNEL::Exception)
3404 {
3405   checkAllocated();
3406   int nbOfComp=getNumberOfComponents();
3407   if(nbOfComp!=3)
3408     throw INTERP_KERNEL::Exception("DataArrayDouble::fromSpherToCart : must be an array with exactly 3 components !");
3409   int nbOfTuple=getNumberOfTuples();
3410   DataArrayDouble *ret=DataArrayDouble::New();
3411   ret->alloc(getNumberOfTuples(),3);
3412   double *w=ret->getPointer();
3413   const double *wIn=getConstPointer();
3414   for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
3415     {
3416       w[0]=wIn[0]*cos(wIn[2])*sin(wIn[1]);
3417       w[1]=wIn[0]*sin(wIn[2])*sin(wIn[1]);
3418       w[2]=wIn[0]*cos(wIn[1]);
3419     }
3420   return ret;
3421 }
3422
3423 /*!
3424  * Computes the doubly contracted product of every tensor defined by the tuple of \a this
3425  * array contating 6 components.
3426  *  \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3427  *          is calculated from the tuple <em>(t)</em> of \a this array as follows:
3428  *          \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
3429  *         The caller is to delete this result array using decrRef() as it is no more needed. 
3430  *  \throw If \a this->getNumberOfComponents() != 6.
3431  */
3432 DataArrayDouble *DataArrayDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
3433 {
3434   checkAllocated();
3435   int nbOfComp=getNumberOfComponents();
3436   if(nbOfComp!=6)
3437     throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !");
3438   DataArrayDouble *ret=DataArrayDouble::New();
3439   int nbOfTuple=getNumberOfTuples();
3440   ret->alloc(nbOfTuple,1);
3441   const double *src=getConstPointer();
3442   double *dest=ret->getPointer();
3443   for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
3444     *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];
3445   return ret;
3446 }
3447
3448 /*!
3449  * Computes the determinant of every square matrix defined by the tuple of \a this
3450  * array, which contains either 4, 6 or 9 components. The case of 6 components
3451  * corresponds to that of the upper triangular matrix.
3452  *  \return DataArrayDouble * - the new instance of DataArrayDouble, whose each tuple
3453  *          is the determinant of matrix of the corresponding tuple of \a this array.
3454  *          The caller is to delete this result array using decrRef() as it is no more
3455  *          needed. 
3456  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3457  */
3458 DataArrayDouble *DataArrayDouble::determinant() const throw(INTERP_KERNEL::Exception)
3459 {
3460   checkAllocated();
3461   DataArrayDouble *ret=DataArrayDouble::New();
3462   int nbOfTuple=getNumberOfTuples();
3463   ret->alloc(nbOfTuple,1);
3464   const double *src=getConstPointer();
3465   double *dest=ret->getPointer();
3466   switch(getNumberOfComponents())
3467     {
3468     case 6:
3469       for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
3470         *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];
3471       return ret;
3472     case 4:
3473       for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
3474         *dest=src[0]*src[3]-src[1]*src[2];
3475       return ret;
3476     case 9:
3477       for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
3478         *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];
3479       return ret;
3480     default:
3481       ret->decrRef();
3482       throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
3483     }
3484 }
3485
3486 /*!
3487  * Computes 3 eigenvalues of every upper triangular matrix defined by the tuple of
3488  * \a this array, which contains 6 components.
3489  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing 3
3490  *          components, whose each tuple contains the eigenvalues of the matrix of
3491  *          corresponding tuple of \a this array. 
3492  *          The caller is to delete this result array using decrRef() as it is no more
3493  *          needed. 
3494  *  \throw If \a this->getNumberOfComponents() != 6.
3495  */
3496 DataArrayDouble *DataArrayDouble::eigenValues() const throw(INTERP_KERNEL::Exception)
3497 {
3498   checkAllocated();
3499   int nbOfComp=getNumberOfComponents();
3500   if(nbOfComp!=6)
3501     throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !");
3502   DataArrayDouble *ret=DataArrayDouble::New();
3503   int nbOfTuple=getNumberOfTuples();
3504   ret->alloc(nbOfTuple,3);
3505   const double *src=getConstPointer();
3506   double *dest=ret->getPointer();
3507   for(int i=0;i<nbOfTuple;i++,dest+=3,src+=6)
3508     INTERP_KERNEL::computeEigenValues6(src,dest);
3509   return ret;
3510 }
3511
3512 /*!
3513  * Computes 3 eigenvectors of every upper triangular matrix defined by the tuple of
3514  * \a this array, which contains 6 components.
3515  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing 9
3516  *          components, whose each tuple contains 3 eigenvectors of the matrix of
3517  *          corresponding tuple of \a this array.
3518  *          The caller is to delete this result array using decrRef() as it is no more
3519  *          needed.
3520  *  \throw If \a this->getNumberOfComponents() != 6.
3521  */
3522 DataArrayDouble *DataArrayDouble::eigenVectors() const throw(INTERP_KERNEL::Exception)
3523 {
3524   checkAllocated();
3525   int nbOfComp=getNumberOfComponents();
3526   if(nbOfComp!=6)
3527     throw INTERP_KERNEL::Exception("DataArrayDouble::eigenVectors : must be an array with exactly 6 components !");
3528   DataArrayDouble *ret=DataArrayDouble::New();
3529   int nbOfTuple=getNumberOfTuples();
3530   ret->alloc(nbOfTuple,9);
3531   const double *src=getConstPointer();
3532   double *dest=ret->getPointer();
3533   for(int i=0;i<nbOfTuple;i++,src+=6)
3534     {
3535       double tmp[3];
3536       INTERP_KERNEL::computeEigenValues6(src,tmp);
3537       for(int j=0;j<3;j++,dest+=3)
3538         INTERP_KERNEL::computeEigenVectorForEigenValue6(src,tmp[j],1e-12,dest);
3539     }
3540   return ret;
3541 }
3542
3543 /*!
3544  * Computes the inverse matrix of every matrix defined by the tuple of \a this
3545  * array, which contains either 4, 6 or 9 components. The case of 6 components
3546  * corresponds to that of the upper triangular matrix.
3547  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3548  *          same number of components as \a this one, whose each tuple is the inverse
3549  *          matrix of the matrix of corresponding tuple of \a this array. 
3550  *          The caller is to delete this result array using decrRef() as it is no more
3551  *          needed. 
3552  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3553  */
3554 DataArrayDouble *DataArrayDouble::inverse() const throw(INTERP_KERNEL::Exception)
3555 {
3556   checkAllocated();
3557   int nbOfComp=getNumberOfComponents();
3558   if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
3559     throw INTERP_KERNEL::Exception("DataArrayDouble::inversion : must be an array with 4,6 or 9 components !");
3560   DataArrayDouble *ret=DataArrayDouble::New();
3561   int nbOfTuple=getNumberOfTuples();
3562   ret->alloc(nbOfTuple,nbOfComp);
3563   const double *src=getConstPointer();
3564   double *dest=ret->getPointer();
3565 if(nbOfComp==6)
3566     for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
3567       {
3568         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];
3569         dest[0]=(src[1]*src[2]-src[4]*src[4])/det;
3570         dest[1]=(src[0]*src[2]-src[5]*src[5])/det;
3571         dest[2]=(src[0]*src[1]-src[3]*src[3])/det;
3572         dest[3]=(src[5]*src[4]-src[3]*src[2])/det;
3573         dest[4]=(src[5]*src[3]-src[0]*src[4])/det;
3574         dest[5]=(src[3]*src[4]-src[1]*src[5])/det;
3575       }
3576   else if(nbOfComp==4)
3577     for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
3578       {
3579         double det=src[0]*src[3]-src[1]*src[2];
3580         dest[0]=src[3]/det;
3581         dest[1]=-src[1]/det;
3582         dest[2]=-src[2]/det;
3583         dest[3]=src[0]/det;
3584       }
3585   else
3586     for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
3587       {
3588         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];
3589         dest[0]=(src[4]*src[8]-src[7]*src[5])/det;
3590         dest[1]=(src[7]*src[2]-src[1]*src[8])/det;
3591         dest[2]=(src[1]*src[5]-src[4]*src[2])/det;
3592         dest[3]=(src[6]*src[5]-src[3]*src[8])/det;
3593         dest[4]=(src[0]*src[8]-src[6]*src[2])/det;
3594         dest[5]=(src[2]*src[3]-src[0]*src[5])/det;
3595         dest[6]=(src[3]*src[7]-src[6]*src[4])/det;
3596         dest[7]=(src[6]*src[1]-src[0]*src[7])/det;
3597         dest[8]=(src[0]*src[4]-src[1]*src[3])/det;
3598       }
3599   return ret;
3600 }
3601
3602 /*!
3603  * Computes the trace of every matrix defined by the tuple of \a this
3604  * array, which contains either 4, 6 or 9 components. The case of 6 components
3605  * corresponds to that of the upper triangular matrix.
3606  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing 
3607  *          1 component, whose each tuple is the trace of
3608  *          the matrix of corresponding tuple of \a this array. 
3609  *          The caller is to delete this result array using decrRef() as it is no more
3610  *          needed. 
3611  *  \throw If \a this->getNumberOfComponents() is not in [4,6,9].
3612  */
3613 DataArrayDouble *DataArrayDouble::trace() const throw(INTERP_KERNEL::Exception)
3614 {
3615   checkAllocated();
3616   int nbOfComp=getNumberOfComponents();
3617   if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
3618     throw INTERP_KERNEL::Exception("DataArrayDouble::trace : must be an array with 4,6 or 9 components !");
3619   DataArrayDouble *ret=DataArrayDouble::New();
3620   int nbOfTuple=getNumberOfTuples();
3621   ret->alloc(nbOfTuple,1);
3622   const double *src=getConstPointer();
3623   double *dest=ret->getPointer();
3624   if(nbOfComp==6)
3625     for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
3626       *dest=src[0]+src[1]+src[2];
3627   else if(nbOfComp==4)
3628     for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
3629       *dest=src[0]+src[3];
3630   else
3631     for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
3632       *dest=src[0]+src[4]+src[8];
3633   return ret;
3634 }
3635
3636 /*!
3637  * Computes the stress deviator tensor of every stress tensor defined by the tuple of
3638  * \a this array, which contains 6 components.
3639  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3640  *          same number of components and tuples as \a this array.
3641  *          The caller is to delete this result array using decrRef() as it is no more
3642  *          needed.
3643  *  \throw If \a this->getNumberOfComponents() != 6.
3644  */
3645 DataArrayDouble *DataArrayDouble::deviator() const throw(INTERP_KERNEL::Exception)
3646 {
3647   checkAllocated();
3648   int nbOfComp=getNumberOfComponents();
3649   if(nbOfComp!=6)
3650     throw INTERP_KERNEL::Exception("DataArrayDouble::deviator : must be an array with exactly 6 components !");
3651   DataArrayDouble *ret=DataArrayDouble::New();
3652   int nbOfTuple=getNumberOfTuples();
3653   ret->alloc(nbOfTuple,6);
3654   const double *src=getConstPointer();
3655   double *dest=ret->getPointer();
3656   for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
3657     {
3658       double tr=(src[0]+src[1]+src[2])/3.;
3659       dest[0]=src[0]-tr;
3660       dest[1]=src[1]-tr;
3661       dest[2]=src[2]-tr;
3662       dest[3]=src[3];
3663       dest[4]=src[4];
3664       dest[5]=src[5];
3665     }
3666   return ret;
3667 }
3668
3669 /*!
3670  * Computes the magnitude of every vector defined by the tuple of
3671  * \a this array.
3672  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3673  *          same number of tuples as \a this array and one component.
3674  *          The caller is to delete this result array using decrRef() as it is no more
3675  *          needed.
3676  *  \throw If \a this is not allocated.
3677  */
3678 DataArrayDouble *DataArrayDouble::magnitude() const throw(INTERP_KERNEL::Exception)
3679 {
3680   checkAllocated();
3681   int nbOfComp=getNumberOfComponents();
3682   DataArrayDouble *ret=DataArrayDouble::New();
3683   int nbOfTuple=getNumberOfTuples();
3684   ret->alloc(nbOfTuple,1);
3685   const double *src=getConstPointer();
3686   double *dest=ret->getPointer();
3687   for(int i=0;i<nbOfTuple;i++,dest++)
3688     {
3689       double sum=0.;
3690       for(int j=0;j<nbOfComp;j++,src++)
3691         sum+=(*src)*(*src);
3692       *dest=sqrt(sum);
3693     }
3694   return ret;
3695 }
3696
3697 /*!
3698  * Computes the maximal value within every tuple of \a this array.
3699  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3700  *          same number of tuples as \a this array and one component.
3701  *          The caller is to delete this result array using decrRef() as it is no more
3702  *          needed.
3703  *  \throw If \a this is not allocated.
3704  *  \sa DataArrayDouble::maxPerTupleWithCompoId
3705  */
3706 DataArrayDouble *DataArrayDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
3707 {
3708   checkAllocated();
3709   int nbOfComp=getNumberOfComponents();
3710   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3711   int nbOfTuple=getNumberOfTuples();
3712   ret->alloc(nbOfTuple,1);
3713   const double *src=getConstPointer();
3714   double *dest=ret->getPointer();
3715   for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
3716     *dest=*std::max_element(src,src+nbOfComp);
3717   return ret.retn();
3718 }
3719
3720 /*!
3721  * Computes the maximal value within every tuple of \a this array and it returns the first component
3722  * id for each tuple that corresponds to the maximal value within the tuple.
3723  * 
3724  *  \param [out] compoIdOfMaxPerTuple - the new new instance of DataArrayInt containing the
3725  *          same number of tuples and only one component.
3726  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3727  *          same number of tuples as \a this array and one component.
3728  *          The caller is to delete this result array using decrRef() as it is no more
3729  *          needed.
3730  *  \throw If \a this is not allocated.
3731  *  \sa DataArrayDouble::maxPerTuple
3732  */
3733 DataArrayDouble *DataArrayDouble::maxPerTupleWithCompoId(DataArrayInt* &compoIdOfMaxPerTuple) const throw(INTERP_KERNEL::Exception)
3734 {
3735   checkAllocated();
3736   int nbOfComp=getNumberOfComponents();
3737   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret0=DataArrayDouble::New();
3738   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
3739   int nbOfTuple=getNumberOfTuples();
3740   ret0->alloc(nbOfTuple,1); ret1->alloc(nbOfTuple,1);
3741   const double *src=getConstPointer();
3742   double *dest=ret0->getPointer(); int *dest1=ret1->getPointer();
3743   for(int i=0;i<nbOfTuple;i++,dest++,dest1++,src+=nbOfComp)
3744     {
3745       const double *loc=std::max_element(src,src+nbOfComp);
3746       *dest=*loc;
3747       *dest1=(int)std::distance(src,loc);
3748     }
3749   compoIdOfMaxPerTuple=ret1.retn();
3750   return ret0.retn();
3751 }
3752
3753 /*!
3754  * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c this->getNumberOfTuples() tuples.
3755  * \n This returned array contains the euclidian distance for each tuple in \a this. 
3756  * \n So the returned array can be seen as a dense symmetrical matrix whose diagonal elements are equal to 0.
3757  * \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)
3758  *
3759  * \warning use this method with care because it can leads to big amount of consumed memory !
3760  * 
3761  * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
3762  *
3763  * \throw If \a this is not allocated.
3764  *
3765  * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrixWith
3766  */
3767 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception)
3768 {
3769   checkAllocated();
3770   int nbOfComp=getNumberOfComponents();
3771   int nbOfTuples=getNumberOfTuples();
3772   const double *inData=getConstPointer();
3773   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3774   ret->alloc(nbOfTuples*nbOfTuples,1);
3775   double *outData=ret->getPointer();
3776   for(int i=0;i<nbOfTuples;i++)
3777     {
3778       outData[i*nbOfTuples+i]=0.;
3779       for(int j=i+1;j<nbOfTuples;j++)
3780         {
3781           double dist=0.;
3782           for(int k=0;k<nbOfComp;k++)
3783             { double delta=inData[i*nbOfComp+k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
3784           dist=sqrt(dist);
3785           outData[i*nbOfTuples+j]=dist;
3786           outData[j*nbOfTuples+i]=dist;
3787         }
3788     }
3789   return ret.retn();
3790 }
3791
3792 /*!
3793  * This method returns a newly allocated DataArrayDouble instance having one component and \c this->getNumberOfTuples() * \c other->getNumberOfTuples() tuples.
3794  * \n This returned array contains the euclidian distance for each tuple in \a other with each tuple in \a this. 
3795  * \n So the returned array can be seen as a dense rectangular matrix with \c other->getNumberOfTuples() rows and \c this->getNumberOfTuples() columns.
3796  * \n Output rectangular matrix is sorted along rows.
3797  * \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)
3798  *
3799  * \warning use this method with care because it can leads to big amount of consumed memory !
3800  * 
3801  * \param [in] other DataArrayDouble instance having same number of components than \a this.
3802  * \return A newly allocated (huge) ParaMEDMEM::DataArrayDouble instance that the caller should deal with.
3803  *
3804  * \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.
3805  *
3806  * \sa DataArrayDouble::buildEuclidianDistanceDenseMatrix
3807  */
3808 DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception)
3809 {
3810   if(!other)
3811     throw INTERP_KERNEL::Exception("DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : input parameter is null !");
3812   checkAllocated();
3813   other->checkAllocated();
3814   int nbOfComp=getNumberOfComponents();
3815   int otherNbOfComp=other->getNumberOfComponents();
3816   if(nbOfComp!=otherNbOfComp)
3817     {
3818       std::ostringstream oss; oss << "DataArrayDouble::buildEuclidianDistanceDenseMatrixWith : this nb of compo=" << nbOfComp << " and other nb of compo=" << otherNbOfComp << ". It should match !";
3819       throw INTERP_KERNEL::Exception(oss.str().c_str());
3820     }
3821   int nbOfTuples=getNumberOfTuples();
3822   int otherNbOfTuples=other->getNumberOfTuples();
3823   const double *inData=getConstPointer();
3824   const double *inDataOther=other->getConstPointer();
3825   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
3826   ret->alloc(otherNbOfTuples*nbOfTuples,1);
3827   double *outData=ret->getPointer();
3828   for(int i=0;i<otherNbOfTuples;i++,inDataOther+=nbOfComp)
3829     {
3830       for(int j=0;j<nbOfTuples;j++)
3831         {
3832           double dist=0.;
3833           for(int k=0;k<nbOfComp;k++)
3834             { double delta=inDataOther[k]-inData[j*nbOfComp+k]; dist+=delta*delta; }
3835           dist=sqrt(dist);
3836           outData[i*nbOfTuples+j]=dist;
3837         }
3838     }
3839   return ret.retn();
3840 }
3841
3842 /*!
3843  * Sorts value within every tuple of \a this array.
3844  *  \param [in] asc - if \a true, the values are sorted in ascending order, else,
3845  *              in descending order.
3846  *  \throw If \a this is not allocated.
3847  */
3848 void DataArrayDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
3849 {
3850   checkAllocated();
3851   double *pt=getPointer();
3852   int nbOfTuple=getNumberOfTuples();
3853   int nbOfComp=getNumberOfComponents();
3854   if(asc)
3855     for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
3856       std::sort(pt,pt+nbOfComp);
3857   else
3858     for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
3859       std::sort(pt,pt+nbOfComp,std::greater<double>());
3860   declareAsNew();
3861 }
3862
3863 /*!
3864  * Converts every value of \a this array to its absolute value.
3865  *  \throw If \a this is not allocated.
3866  */
3867 void DataArrayDouble::abs() throw(INTERP_KERNEL::Exception)
3868 {
3869   checkAllocated();
3870   double *ptr=getPointer();
3871   std::size_t nbOfElems=getNbOfElems();
3872   std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
3873   declareAsNew();
3874 }
3875
3876 /*!
3877  * Apply a liner function to a given component of \a this array, so that
3878  * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
3879  *  \param [in] a - the first coefficient of the function.
3880  *  \param [in] b - the second coefficient of the function.
3881  *  \param [in] compoId - the index of component to modify.
3882  *  \throw If \a this is not allocated.
3883  */
3884 void DataArrayDouble::applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception)
3885 {
3886   checkAllocated();
3887   double *ptr=getPointer()+compoId;
3888   int nbOfComp=getNumberOfComponents();
3889   int nbOfTuple=getNumberOfTuples();
3890   for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
3891     *ptr=a*(*ptr)+b;
3892   declareAsNew();
3893 }
3894
3895 /*!
3896  * Apply a liner function to all elements of \a this array, so that
3897  * an element _x_ becomes \f$ a * x + b \f$.
3898  *  \param [in] a - the first coefficient of the function.
3899  *  \param [in] b - the second coefficient of the function.
3900  *  \throw If \a this is not allocated.
3901  */
3902 void DataArrayDouble::applyLin(double a, double b) throw(INTERP_KERNEL::Exception)
3903 {
3904   checkAllocated();
3905   double *ptr=getPointer();
3906   std::size_t nbOfElems=getNbOfElems();
3907   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3908     *ptr=a*(*ptr)+b;
3909   declareAsNew();
3910 }
3911
3912 /*!
3913  * Modify all elements of \a this array, so that
3914  * an element _x_ becomes \f$ numerator / x \f$.
3915  *  \warning If an exception is thrown because of presence of 0.0 element in \a this 
3916  *           array, all elements processed before detection of the zero element remain
3917  *           modified.
3918  *  \param [in] numerator - the numerator used to modify array elements.
3919  *  \throw If \a this is not allocated.
3920  *  \throw If there is an element equal to 0.0 in \a this array.
3921  */
3922 void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception)
3923 {
3924   checkAllocated();
3925   double *ptr=getPointer();
3926   std::size_t nbOfElems=getNbOfElems();
3927   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3928     {
3929       if(std::abs(*ptr)>std::numeric_limits<double>::min())
3930         {
3931           *ptr=numerator/(*ptr);
3932         }
3933       else
3934         {
3935           std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
3936           oss << " !";
3937           throw INTERP_KERNEL::Exception(oss.str().c_str());
3938         }
3939     }
3940   declareAsNew();
3941 }
3942
3943 /*!
3944  * Returns a full copy of \a this array except that sign of all elements is reversed.
3945  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
3946  *          same number of tuples and component as \a this array.
3947  *          The caller is to delete this result array using decrRef() as it is no more
3948  *          needed.
3949  *  \throw If \a this is not allocated.
3950  */
3951 DataArrayDouble *DataArrayDouble::negate() const throw(INTERP_KERNEL::Exception)
3952 {
3953   checkAllocated();
3954   DataArrayDouble *newArr=DataArrayDouble::New();
3955   int nbOfTuples=getNumberOfTuples();
3956   int nbOfComp=getNumberOfComponents();
3957   newArr->alloc(nbOfTuples,nbOfComp);
3958   const double *cptr=getConstPointer();
3959   std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
3960   newArr->copyStringInfoFrom(*this);
3961   return newArr;
3962 }
3963
3964 /*!
3965  * Modify all elements of \a this array, so that
3966  * an element _x_ becomes <em> val ^ x </em>. Contrary to DataArrayInt::applyPow
3967  * all values in \a this have to be >= 0 if val is \b not integer.
3968  *  \param [in] val - the value used to apply pow on all array elements.
3969  *  \throw If \a this is not allocated.
3970  *  \warning If an exception is thrown because of presence of 0 element in \a this 
3971  *           array and \a val is \b not integer, all elements processed before detection of the zero element remain
3972  *           modified.
3973  */
3974 void DataArrayDouble::applyPow(double val) throw(INTERP_KERNEL::Exception)
3975 {
3976   checkAllocated();
3977   double *ptr=getPointer();
3978   std::size_t nbOfElems=getNbOfElems();
3979   int val2=(int)val;
3980   bool isInt=((double)val2)==val;
3981   if(!isInt)
3982     {
3983       for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3984         {
3985           if(*ptr>=0)
3986             *ptr=pow(*ptr,val);
3987           else
3988             {
3989               std::ostringstream oss; oss << "DataArrayDouble::applyPow (double) : At elem # " << i << " value is " << *ptr << " ! must be >=0. !";
3990               throw INTERP_KERNEL::Exception(oss.str().c_str());
3991             }
3992         }
3993     }
3994   else
3995     {
3996       for(std::size_t i=0;i<nbOfElems;i++,ptr++)
3997         *ptr=pow(*ptr,val2);
3998     }
3999   declareAsNew();
4000 }
4001
4002 /*!
4003  * Modify all elements of \a this array, so that
4004  * an element _x_ becomes \f$ val ^ x \f$.
4005  *  \param [in] val - the value used to apply pow on all array elements.
4006  *  \throw If \a this is not allocated.
4007  *  \throw If \a val < 0.
4008  *  \warning If an exception is thrown because of presence of 0 element in \a this 
4009  *           array, all elements processed before detection of the zero element remain
4010  *           modified.
4011  */
4012 void DataArrayDouble::applyRPow(double val) throw(INTERP_KERNEL::Exception)
4013 {
4014   checkAllocated();
4015   if(val<0.)
4016     throw INTERP_KERNEL::Exception("DataArrayDouble::applyRPow : the input value has to be >= 0 !");
4017   double *ptr=getPointer();
4018   std::size_t nbOfElems=getNbOfElems();
4019   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
4020     *ptr=pow(val,*ptr);
4021   declareAsNew();
4022 }
4023
4024 /*!
4025  * Returns a new DataArrayDouble created from \a this one by applying \a
4026  * FunctionToEvaluate to every tuple of \a this array. Textual data is not copied.
4027  * For more info see \ref MEDCouplingArrayApplyFunc
4028  *  \param [in] nbOfComp - number of components in the result array.
4029  *  \param [in] func - the \a FunctionToEvaluate declared as 
4030  *              \c bool (*\a func)(\c const \c double *\a pos, \c double *\a res), 
4031  *              where \a pos points to the first component of a tuple of \a this array
4032  *              and \a res points to the first component of a tuple of the result array.
4033  *              Note that length (number of components) of \a pos can differ from
4034  *              that of \a res.
4035  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
4036  *          same number of tuples as \a this array.
4037  *          The caller is to delete this result array using decrRef() as it is no more
4038  *          needed.
4039  *  \throw If \a this is not allocated.
4040  *  \throw If \a func returns \a false.
4041  */
4042 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
4043 {
4044   checkAllocated();
4045   DataArrayDouble *newArr=DataArrayDouble::New();
4046   int nbOfTuples=getNumberOfTuples();
4047   int oldNbOfComp=getNumberOfComponents();
4048   newArr->alloc(nbOfTuples,nbOfComp);
4049   const double *ptr=getConstPointer();
4050   double *ptrToFill=newArr->getPointer();
4051   for(int i=0;i<nbOfTuples;i++)
4052     {
4053       if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
4054         {
4055           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
4056           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
4057           oss << ") : Evaluation of function failed !";
4058           newArr->decrRef();
4059           throw INTERP_KERNEL::Exception(oss.str().c_str());
4060         }
4061     }
4062   return newArr;
4063 }
4064
4065 /*!
4066  * Returns a new DataArrayDouble created from \a this one by applying a function to every
4067  * tuple of \a this array. Textual data is not copied.
4068  * For more info see \ref MEDCouplingArrayApplyFunc1.
4069  *  \param [in] nbOfComp - number of components in the result array.
4070  *  \param [in] func - the expression defining how to transform a tuple of \a this array.
4071  *              Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
4072  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
4073  *          same number of tuples as \a this array and \a nbOfComp components.
4074  *          The caller is to delete this result array using decrRef() as it is no more
4075  *          needed.
4076  *  \throw If \a this is not allocated.
4077  *  \throw If computing \a func fails.
4078  */
4079 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
4080 {
4081   checkAllocated();
4082   INTERP_KERNEL::ExprParser expr(func);
4083   expr.parse();
4084   std::set<std::string> vars;
4085   expr.getTrueSetOfVars(vars);
4086   int oldNbOfComp=getNumberOfComponents();
4087   if((int)vars.size()>oldNbOfComp)
4088     {
4089       std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
4090       oss << vars.size() << " variables : ";
4091       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
4092       throw INTERP_KERNEL::Exception(oss.str().c_str());
4093     }
4094   std::vector<std::string> varsV(vars.begin(),vars.end());
4095   expr.prepareExprEvaluation(varsV,oldNbOfComp,nbOfComp);
4096   //
4097   DataArrayDouble *newArr=DataArrayDouble::New();
4098   int nbOfTuples=getNumberOfTuples();
4099   newArr->alloc(nbOfTuples,nbOfComp);
4100   const double *ptr=getConstPointer();
4101   double *ptrToFill=newArr->getPointer();
4102   for(int i=0;i<nbOfTuples;i++)
4103     {
4104       try
4105         {
4106           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
4107         }
4108       catch(INTERP_KERNEL::Exception& e)
4109         {
4110           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
4111           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
4112           oss << ") : Evaluation of function failed !" << e.what();
4113           newArr->decrRef();
4114           throw INTERP_KERNEL::Exception(oss.str().c_str());
4115         }
4116     }
4117   return newArr;
4118 }
4119
4120 /*!
4121  * Returns a new DataArrayDouble created from \a this one by applying a function to every
4122  * tuple of \a this array. Textual data is not copied.
4123  * For more info see \ref MEDCouplingArrayApplyFunc0.
4124  *  \param [in] func - the expression defining how to transform a tuple of \a this array.
4125  *              Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
4126  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
4127  *          same number of tuples and components as \a this array.
4128  *          The caller is to delete this result array using decrRef() as it is no more
4129  *          needed.
4130  *  \throw If \a this is not allocated.
4131  *  \throw If computing \a func fails.
4132  */
4133 DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const throw(INTERP_KERNEL::Exception)
4134 {
4135   checkAllocated();
4136   INTERP_KERNEL::ExprParser expr(func);
4137   expr.parse();
4138   expr.prepareExprEvaluationVec();
4139   //
4140   DataArrayDouble *newArr=DataArrayDouble::New();
4141   int nbOfTuples=getNumberOfTuples();
4142   int nbOfComp=getNumberOfComponents();
4143   newArr->alloc(nbOfTuples,nbOfComp);
4144   const double *ptr=getConstPointer();
4145   double *ptrToFill=newArr->getPointer();
4146   for(int i=0;i<nbOfTuples;i++)
4147     {
4148       try
4149         {
4150           expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
4151         }
4152       catch(INTERP_KERNEL::Exception& e)
4153         {
4154           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
4155           std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
4156           oss << ") : Evaluation of function failed ! " << e.what();
4157           newArr->decrRef();
4158           throw INTERP_KERNEL::Exception(oss.str().c_str());
4159         }
4160     }
4161   return newArr;
4162 }
4163
4164 /*!
4165  * Returns a new DataArrayDouble created from \a this one by applying a function to every
4166  * tuple of \a this array. Textual data is not copied.
4167  * For more info see \ref MEDCouplingArrayApplyFunc2.
4168  *  \param [in] nbOfComp - number of components in the result array.
4169  *  \param [in] func - the expression defining how to transform a tuple of \a this array.
4170  *              Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
4171  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
4172  *          same number of tuples as \a this array.
4173  *          The caller is to delete this result array using decrRef() as it is no more
4174  *          needed.
4175  *  \throw If \a this is not allocated.
4176  *  \throw If \a func contains vars that are not in \a this->getInfoOnComponent().
4177  *  \throw If computing \a func fails.
4178  */
4179 DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
4180 {
4181   checkAllocated();
4182   INTERP_KERNEL::ExprParser expr(func);
4183   expr.parse();
4184   std::set<std::string> vars;
4185   expr.getTrueSetOfVars(vars);
4186   int oldNbOfComp=getNumberOfComponents();
4187   if((int)vars.size()>oldNbOfComp)
4188     {
4189       std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
4190       oss << vars.size() << " variables : ";
4191       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
4192       throw INTERP_KERNEL::Exception(oss.str().c_str());
4193     }
4194   expr.prepareExprEvaluation(getVarsOnComponent(),oldNbOfComp,nbOfComp);
4195   //
4196   DataArrayDouble *newArr=DataArrayDouble::New();
4197   int nbOfTuples=getNumberOfTuples();
4198   newArr->alloc(nbOfTuples,nbOfComp);
4199   const double *ptr=getConstPointer();
4200   double *ptrToFill=newArr->getPointer();
4201   for(int i=0;i<nbOfTuples;i++)
4202     {
4203       try
4204         {
4205           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
4206         }
4207       catch(INTERP_KERNEL::Exception& e)
4208         {
4209           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
4210           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
4211           oss << ") : Evaluation of function failed !" << e.what();
4212           newArr->decrRef();
4213           throw INTERP_KERNEL::Exception(oss.str().c_str());
4214         }
4215     }
4216   return newArr;
4217 }
4218
4219 /*!
4220  * Returns a new DataArrayDouble created from \a this one by applying a function to every
4221  * tuple of \a this array. Textual data is not copied.
4222  * For more info see \ref MEDCouplingArrayApplyFunc3.
4223  *  \param [in] nbOfComp - number of components in the result array.
4224  *  \param [in] varsOrder - sequence of vars defining their order.
4225  *  \param [in] func - the expression defining how to transform a tuple of \a this array.
4226  *              Supported expressions are described \ref MEDCouplingArrayApplyFuncExpr "here".
4227  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
4228  *          same number of tuples as \a this array.
4229  *          The caller is to delete this result array using decrRef() as it is no more
4230  *          needed.
4231  *  \throw If \a this is not allocated.
4232  *  \throw If \a func contains vars not in \a varsOrder.
4233  *  \throw If computing \a func fails.
4234  */
4235 DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception)
4236 {
4237   checkAllocated();
4238   INTERP_KERNEL::ExprParser expr(func);
4239   expr.parse();
4240   std::set<std::string> vars;
4241   expr.getTrueSetOfVars(vars);
4242   int oldNbOfComp=getNumberOfComponents();
4243   if((int)vars.size()>oldNbOfComp)
4244     {
4245       std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
4246       oss << vars.size() << " variables : ";
4247       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
4248       throw INTERP_KERNEL::Exception(oss.str().c_str());
4249     }
4250   expr.prepareExprEvaluation(varsOrder,oldNbOfComp,nbOfComp);
4251   //
4252   DataArrayDouble *newArr=DataArrayDouble::New();
4253   int nbOfTuples=getNumberOfTuples();
4254   newArr->alloc(nbOfTuples,nbOfComp);
4255   const double *ptr=getConstPointer();
4256   double *ptrToFill=newArr->getPointer();
4257   for(int i=0;i<nbOfTuples;i++)
4258     {
4259       try
4260         {
4261           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
4262         }
4263       catch(INTERP_KERNEL::Exception& e)
4264         {
4265           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
4266           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
4267           oss << ") : Evaluation of function failed !" << e.what();
4268           newArr->decrRef();
4269           throw INTERP_KERNEL::Exception(oss.str().c_str());
4270         }
4271     }
4272   return newArr;
4273 }
4274
4275 void DataArrayDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
4276 {
4277   checkAllocated();
4278   INTERP_KERNEL::ExprParser expr(func);
4279   expr.parse();
4280   char *funcStr=expr.compileX86();
4281   MYFUNCPTR funcPtr;
4282   *((void **)&funcPtr)=funcStr;//he he...
4283   //
4284   double *ptr=getPointer();
4285   int nbOfComp=getNumberOfComponents();
4286   int nbOfTuples=getNumberOfTuples();
4287   int nbOfElems=nbOfTuples*nbOfComp;
4288   for(int i=0;i<nbOfElems;i++,ptr++)
4289     *ptr=funcPtr(*ptr);
4290   declareAsNew();
4291 }
4292
4293 void DataArrayDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
4294 {
4295   checkAllocated();
4296   INTERP_KERNEL::ExprParser expr(func);
4297   expr.parse();
4298   char *funcStr=expr.compileX86_64();
4299   MYFUNCPTR funcPtr;
4300   *((void **)&funcPtr)=funcStr;//he he...
4301   //
4302   double *ptr=getPointer();
4303   int nbOfComp=getNumberOfComponents();
4304   int nbOfTuples=getNumberOfTuples();
4305   int nbOfElems=nbOfTuples*nbOfComp;
4306   for(int i=0;i<nbOfElems;i++,ptr++)
4307     *ptr=funcPtr(*ptr);
4308   declareAsNew();
4309 }
4310
4311 DataArrayDoubleIterator *DataArrayDouble::iterator() throw(INTERP_KERNEL::Exception)
4312 {
4313   return new DataArrayDoubleIterator(this);
4314 }
4315
4316 /*!
4317  * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
4318  * array whose values are within a given range. Textual data is not copied.
4319  *  \param [in] vmin - a lowest acceptable value (included).
4320  *  \param [in] vmax - a greatest acceptable value (included).
4321  *  \return DataArrayInt * - the new instance of DataArrayInt.
4322  *          The caller is to delete this result array using decrRef() as it is no more
4323  *          needed.
4324  *  \throw If \a this->getNumberOfComponents() != 1.
4325  *
4326  *  \ref cpp_mcdataarraydouble_getidsinrange "Here is a C++ example".<br>
4327  *  \ref py_mcdataarraydouble_getidsinrange "Here is a Python example".
4328  */
4329 DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
4330 {
4331   checkAllocated();
4332   if(getNumberOfComponents()!=1)
4333     throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !");
4334   const double *cptr=getConstPointer();
4335   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
4336   int nbOfTuples=getNumberOfTuples();
4337   for(int i=0;i<nbOfTuples;i++,cptr++)
4338     if(*cptr>=vmin && *cptr<=vmax)
4339       ret->pushBackSilent(i);
4340   return ret.retn();
4341 }
4342
4343 /*!
4344  * Returns a new DataArrayDouble by concatenating two given arrays, so that (1) the number
4345  * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
4346  * the number of component in the result array is same as that of each of given arrays.
4347  * Info on components is copied from the first of the given arrays. Number of components
4348  * in the given arrays must be  the same.
4349  *  \param [in] a1 - an array to include in the result array.
4350  *  \param [in] a2 - another array to include in the result array.
4351  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4352  *          The caller is to delete this result array using decrRef() as it is no more
4353  *          needed.
4354  *  \throw If both \a a1 and \a a2 are NULL.
4355  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
4356  */
4357 DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4358 {
4359   std::vector<const DataArrayDouble *> tmp(2);
4360   tmp[0]=a1; tmp[1]=a2;
4361   return Aggregate(tmp);
4362 }
4363
4364 /*!
4365  * Returns a new DataArrayDouble by concatenating all given arrays, so that (1) the number
4366  * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
4367  * the number of component in the result array is same as that of each of given arrays.
4368  * Info on components is copied from the first of the given arrays. Number of components
4369  * in the given arrays must be  the same.
4370  *  \param [in] arr - a sequence of arrays to include in the result array.
4371  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4372  *          The caller is to delete this result array using decrRef() as it is no more
4373  *          needed.
4374  *  \throw If all arrays within \a arr are NULL.
4375  *  \throw If getNumberOfComponents() of arrays within \a arr.
4376  */
4377 DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
4378 {
4379   std::vector<const DataArrayDouble *> a;
4380   for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4381     if(*it4)
4382       a.push_back(*it4);
4383   if(a.empty())
4384     throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must contain at least one NON EMPTY DataArrayDouble !");
4385   std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
4386   int nbOfComp=(*it)->getNumberOfComponents();
4387   int nbt=(*it++)->getNumberOfTuples();
4388   for(int i=1;it!=a.end();it++,i++)
4389     {
4390       if((*it)->getNumberOfComponents()!=nbOfComp)
4391         throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
4392       nbt+=(*it)->getNumberOfTuples();
4393     }
4394   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4395   ret->alloc(nbt,nbOfComp);
4396   double *pt=ret->getPointer();
4397   for(it=a.begin();it!=a.end();it++)
4398     pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
4399   ret->copyStringInfoFrom(*(a[0]));
4400   return ret.retn();
4401 }
4402
4403 /*!
4404  * Returns a new DataArrayDouble by aggregating two given arrays, so that (1) the number
4405  * of components in the result array is a sum of the number of components of given arrays
4406  * and (2) the number of tuples in the result array is same as that of each of given
4407  * arrays. In other words the i-th tuple of result array includes all components of
4408  * i-th tuples of all given arrays.
4409  * Number of tuples in the given arrays must be  the same.
4410  *  \param [in] a1 - an array to include in the result array.
4411  *  \param [in] a2 - another array to include in the result array.
4412  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4413  *          The caller is to delete this result array using decrRef() as it is no more
4414  *          needed.
4415  *  \throw If both \a a1 and \a a2 are NULL.
4416  *  \throw If any given array is not allocated.
4417  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4418  */
4419 DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4420 {
4421   std::vector<const DataArrayDouble *> arr(2);
4422   arr[0]=a1; arr[1]=a2;
4423   return Meld(arr);
4424 }
4425
4426 /*!
4427  * Returns a new DataArrayDouble by aggregating all given arrays, so that (1) the number
4428  * of components in the result array is a sum of the number of components of given arrays
4429  * and (2) the number of tuples in the result array is same as that of each of given
4430  * arrays. In other words the i-th tuple of result array includes all components of
4431  * i-th tuples of all given arrays.
4432  * Number of tuples in the given arrays must be  the same.
4433  *  \param [in] arr - a sequence of arrays to include in the result array.
4434  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4435  *          The caller is to delete this result array using decrRef() as it is no more
4436  *          needed.
4437  *  \throw If all arrays within \a arr are NULL.
4438  *  \throw If any given array is not allocated.
4439  *  \throw If getNumberOfTuples() of arrays within \a arr is different.
4440  */
4441 DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& arr) throw(INTERP_KERNEL::Exception)
4442 {
4443   std::vector<const DataArrayDouble *> a;
4444   for(std::vector<const DataArrayDouble *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
4445     if(*it4)
4446       a.push_back(*it4);
4447   if(a.empty())
4448     throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : input list must contain at least one NON EMPTY DataArrayDouble !");
4449   std::vector<const DataArrayDouble *>::const_iterator it;
4450   for(it=a.begin();it!=a.end();it++)
4451     (*it)->checkAllocated();
4452   it=a.begin();
4453   int nbOfTuples=(*it)->getNumberOfTuples();
4454   std::vector<int> nbc(a.size());
4455   std::vector<const double *> pts(a.size());
4456   nbc[0]=(*it)->getNumberOfComponents();
4457   pts[0]=(*it++)->getConstPointer();
4458   for(int i=1;it!=a.end();it++,i++)
4459     {
4460       if(nbOfTuples!=(*it)->getNumberOfTuples())
4461         throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
4462       nbc[i]=(*it)->getNumberOfComponents();
4463       pts[i]=(*it)->getConstPointer();
4464     }
4465   int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
4466   DataArrayDouble *ret=DataArrayDouble::New();
4467   ret->alloc(nbOfTuples,totalNbOfComp);
4468   double *retPtr=ret->getPointer();
4469   for(int i=0;i<nbOfTuples;i++)
4470     for(int j=0;j<(int)a.size();j++)
4471       {
4472         retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
4473         pts[j]+=nbc[j];
4474       }
4475   int k=0;
4476   for(int i=0;i<(int)a.size();i++)
4477     for(int j=0;j<nbc[i];j++,k++)
4478       ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
4479   return ret;
4480 }
4481
4482 /*!
4483  * Returns a new DataArrayDouble containing a dot product of two given arrays, so that
4484  * the i-th tuple of the result array is a sum of products of j-th components of i-th
4485  * tuples of given arrays (\f$ a_i = \sum_{j=1}^n a1_j * a2_j \f$).
4486  * Info on components and name is copied from the first of the given arrays.
4487  * Number of tuples and components in the given arrays must be the same.
4488  *  \param [in] a1 - a given array.
4489  *  \param [in] a2 - another given array.
4490  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4491  *          The caller is to delete this result array using decrRef() as it is no more
4492  *          needed.
4493  *  \throw If either \a a1 or \a a2 is NULL.
4494  *  \throw If any given array is not allocated.
4495  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4496  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
4497  */
4498 DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4499 {
4500   if(!a1 || !a2)
4501     throw INTERP_KERNEL::Exception("DataArrayDouble::Dot : input DataArrayDouble instance is NULL !");
4502   a1->checkAllocated();
4503   a2->checkAllocated();
4504   int nbOfComp=a1->getNumberOfComponents();
4505   if(nbOfComp!=a2->getNumberOfComponents())
4506     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
4507   int nbOfTuple=a1->getNumberOfTuples();
4508   if(nbOfTuple!=a2->getNumberOfTuples())
4509     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
4510   DataArrayDouble *ret=DataArrayDouble::New();
4511   ret->alloc(nbOfTuple,1);
4512   double *retPtr=ret->getPointer();
4513   const double *a1Ptr=a1->getConstPointer();
4514   const double *a2Ptr=a2->getConstPointer();
4515   for(int i=0;i<nbOfTuple;i++)
4516     {
4517       double sum=0.;
4518       for(int j=0;j<nbOfComp;j++)
4519         sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
4520       retPtr[i]=sum;
4521     }
4522   ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str());
4523   ret->setName(a1->getName().c_str());
4524   return ret;
4525 }
4526
4527 /*!
4528  * Returns a new DataArrayDouble containing a cross product of two given arrays, so that
4529  * the i-th tuple of the result array contains 3 components of a vector which is a cross
4530  * product of two vectors defined by the i-th tuples of given arrays.
4531  * Info on components is copied from the first of the given arrays.
4532  * Number of tuples in the given arrays must be the same.
4533  * Number of components in the given arrays must be 3.
4534  *  \param [in] a1 - a given array.
4535  *  \param [in] a2 - another given array.
4536  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4537  *          The caller is to delete this result array using decrRef() as it is no more
4538  *          needed.
4539  *  \throw If either \a a1 or \a a2 is NULL.
4540  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4541  *  \throw If \a a1->getNumberOfComponents() != 3
4542  *  \throw If \a a2->getNumberOfComponents() != 3
4543  */
4544 DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4545 {
4546   if(!a1 || !a2)
4547     throw INTERP_KERNEL::Exception("DataArrayDouble::CrossProduct : input DataArrayDouble instance is NULL !");
4548   int nbOfComp=a1->getNumberOfComponents();
4549   if(nbOfComp!=a2->getNumberOfComponents())
4550     throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
4551   if(nbOfComp!=3)
4552     throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
4553   int nbOfTuple=a1->getNumberOfTuples();
4554   if(nbOfTuple!=a2->getNumberOfTuples())
4555     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
4556   DataArrayDouble *ret=DataArrayDouble::New();
4557   ret->alloc(nbOfTuple,3);
4558   double *retPtr=ret->getPointer();
4559   const double *a1Ptr=a1->getConstPointer();
4560   const double *a2Ptr=a2->getConstPointer();
4561   for(int i=0;i<nbOfTuple;i++)
4562     {
4563       retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
4564       retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
4565       retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
4566     }
4567   ret->copyStringInfoFrom(*a1);
4568   return ret;
4569 }
4570
4571 /*!
4572  * Returns a new DataArrayDouble containing maximal values of two given arrays.
4573  * Info on components is copied from the first of the given arrays.
4574  * Number of tuples and components in the given arrays must be the same.
4575  *  \param [in] a1 - an array to compare values with another one.
4576  *  \param [in] a2 - another array to compare values with the first one.
4577  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4578  *          The caller is to delete this result array using decrRef() as it is no more
4579  *          needed.
4580  *  \throw If either \a a1 or \a a2 is NULL.
4581  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4582  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
4583  */
4584 DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4585 {
4586   if(!a1 || !a2)
4587     throw INTERP_KERNEL::Exception("DataArrayDouble::Max : input DataArrayDouble instance is NULL !");
4588   int nbOfComp=a1->getNumberOfComponents();
4589   if(nbOfComp!=a2->getNumberOfComponents())
4590     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
4591   int nbOfTuple=a1->getNumberOfTuples();
4592   if(nbOfTuple!=a2->getNumberOfTuples())
4593     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
4594   DataArrayDouble *ret=DataArrayDouble::New();
4595   ret->alloc(nbOfTuple,nbOfComp);
4596   double *retPtr=ret->getPointer();
4597   const double *a1Ptr=a1->getConstPointer();
4598   const double *a2Ptr=a2->getConstPointer();
4599   int nbElem=nbOfTuple*nbOfComp;
4600   for(int i=0;i<nbElem;i++)
4601     retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
4602   ret->copyStringInfoFrom(*a1);
4603   return ret;
4604 }
4605
4606 /*!
4607  * Returns a new DataArrayDouble containing minimal values of two given arrays.
4608  * Info on components is copied from the first of the given arrays.
4609  * Number of tuples and components in the given arrays must be the same.
4610  *  \param [in] a1 - an array to compare values with another one.
4611  *  \param [in] a2 - another array to compare values with the first one.
4612  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4613  *          The caller is to delete this result array using decrRef() as it is no more
4614  *          needed.
4615  *  \throw If either \a a1 or \a a2 is NULL.
4616  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
4617  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents()
4618  */
4619 DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4620 {
4621   if(!a1 || !a2)
4622     throw INTERP_KERNEL::Exception("DataArrayDouble::Min : input DataArrayDouble instance is NULL !");
4623   int nbOfComp=a1->getNumberOfComponents();
4624   if(nbOfComp!=a2->getNumberOfComponents())
4625     throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
4626   int nbOfTuple=a1->getNumberOfTuples();
4627   if(nbOfTuple!=a2->getNumberOfTuples())
4628     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
4629   DataArrayDouble *ret=DataArrayDouble::New();
4630   ret->alloc(nbOfTuple,nbOfComp);
4631   double *retPtr=ret->getPointer();
4632   const double *a1Ptr=a1->getConstPointer();
4633   const double *a2Ptr=a2->getConstPointer();
4634   int nbElem=nbOfTuple*nbOfComp;
4635   for(int i=0;i<nbElem;i++)
4636     retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
4637   ret->copyStringInfoFrom(*a1);
4638   return ret;
4639 }
4640
4641 /*!
4642  * Returns a new DataArrayDouble that is a sum of two given arrays. There are 3
4643  * valid cases.
4644  * 1.  The arrays have same number of tuples and components. Then each value of
4645  *   the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
4646  *   i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
4647  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
4648  *   component. Then
4649  *   _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
4650  * 3.  The arrays have same number of components and one array, say _a2_, has one
4651  *   tuple. Then
4652  *   _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
4653  *
4654  * Info on components is copied either from the first array (in the first case) or from
4655  * the array with maximal number of elements (getNbOfElems()).
4656  *  \param [in] a1 - an array to sum up.
4657  *  \param [in] a2 - another array to sum up.
4658  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4659  *          The caller is to delete this result array using decrRef() as it is no more
4660  *          needed.
4661  *  \throw If either \a a1 or \a a2 is NULL.
4662  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4663  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4664  *         none of them has number of tuples or components equal to 1.
4665  */
4666 DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4667 {
4668   if(!a1 || !a2)
4669     throw INTERP_KERNEL::Exception("DataArrayDouble::Add : input DataArrayDouble instance is NULL !");
4670   int nbOfTuple=a1->getNumberOfTuples();
4671   int nbOfTuple2=a2->getNumberOfTuples();
4672   int nbOfComp=a1->getNumberOfComponents();
4673   int nbOfComp2=a2->getNumberOfComponents();
4674   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
4675   if(nbOfTuple==nbOfTuple2)
4676     {
4677       if(nbOfComp==nbOfComp2)
4678         {
4679           ret=DataArrayDouble::New();
4680           ret->alloc(nbOfTuple,nbOfComp);
4681           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
4682           ret->copyStringInfoFrom(*a1);
4683         }
4684       else
4685         {
4686           int nbOfCompMin,nbOfCompMax;
4687           const DataArrayDouble *aMin, *aMax;
4688           if(nbOfComp>nbOfComp2)
4689             {
4690               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
4691               aMin=a2; aMax=a1;
4692             }
4693           else
4694             {
4695               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
4696               aMin=a1; aMax=a2;
4697             }
4698           if(nbOfCompMin==1)
4699             {
4700               ret=DataArrayDouble::New();
4701               ret->alloc(nbOfTuple,nbOfCompMax);
4702               const double *aMinPtr=aMin->getConstPointer();
4703               const double *aMaxPtr=aMax->getConstPointer();
4704               double *res=ret->getPointer();
4705               for(int i=0;i<nbOfTuple;i++)
4706                 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
4707               ret->copyStringInfoFrom(*aMax);
4708             }
4709           else
4710             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
4711         }
4712     }
4713   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
4714     {
4715       if(nbOfComp==nbOfComp2)
4716         {
4717           int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
4718           const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
4719           const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
4720           const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
4721           ret=DataArrayDouble::New();
4722           ret->alloc(nbOfTupleMax,nbOfComp);
4723           double *res=ret->getPointer();
4724           for(int i=0;i<nbOfTupleMax;i++)
4725             res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<double>());
4726           ret->copyStringInfoFrom(*aMax);
4727         }
4728       else
4729         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
4730     }
4731   else
4732     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
4733   return ret.retn();
4734 }
4735
4736 /*!
4737  * Adds values of another DataArrayDouble to values of \a this one. There are 3
4738  * valid cases.
4739  * 1.  The arrays have same number of tuples and components. Then each value of
4740  *   \a other array is added to the corresponding value of \a this array, i.e.:
4741  *   _a_ [ i, j ] += _other_ [ i, j ].
4742  * 2.  The arrays have same number of tuples and \a other array has one component. Then
4743  *   _a_ [ i, j ] += _other_ [ i, 0 ].
4744  * 3.  The arrays have same number of components and \a other array has one tuple. Then
4745  *   _a_ [ i, j ] += _a2_ [ 0, j ].
4746  *
4747  *  \param [in] other - an array to add to \a this one.
4748  *  \throw If \a other is NULL.
4749  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
4750  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
4751  *         \a other has number of both tuples and components not equal to 1.
4752  */
4753 void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4754 {
4755   if(!other)
4756     throw INTERP_KERNEL::Exception("DataArrayDouble::addEqual : input DataArrayDouble instance is NULL !");
4757   const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual  !";
4758   checkAllocated();
4759   other->checkAllocated();
4760   int nbOfTuple=getNumberOfTuples();
4761   int nbOfTuple2=other->getNumberOfTuples();
4762   int nbOfComp=getNumberOfComponents();
4763   int nbOfComp2=other->getNumberOfComponents();
4764   if(nbOfTuple==nbOfTuple2)
4765     {
4766       if(nbOfComp==nbOfComp2)
4767         {
4768           std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
4769         }
4770       else if(nbOfComp2==1)
4771         {
4772           double *ptr=getPointer();
4773           const double *ptrc=other->getConstPointer();
4774           for(int i=0;i<nbOfTuple;i++)
4775             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
4776         }
4777       else
4778         throw INTERP_KERNEL::Exception(msg);
4779     }
4780   else if(nbOfTuple2==1)
4781     {
4782       if(nbOfComp2==nbOfComp)
4783         {
4784           double *ptr=getPointer();
4785           const double *ptrc=other->getConstPointer();
4786           for(int i=0;i<nbOfTuple;i++)
4787             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
4788         }
4789       else
4790         throw INTERP_KERNEL::Exception(msg);
4791     }
4792   else
4793     throw INTERP_KERNEL::Exception(msg);
4794   declareAsNew();
4795 }
4796
4797 /*!
4798  * Returns a new DataArrayDouble that is a subtraction of two given arrays. There are 3
4799  * valid cases.
4800  * 1.  The arrays have same number of tuples and components. Then each value of
4801  *   the result array (_a_) is a subtraction of the corresponding values of \a a1 and
4802  *   \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
4803  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
4804  *   component. Then
4805  *   _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
4806  * 3.  The arrays have same number of components and one array, say _a2_, has one
4807  *   tuple. Then
4808  *   _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
4809  *
4810  * Info on components is copied either from the first array (in the first case) or from
4811  * the array with maximal number of elements (getNbOfElems()).
4812  *  \param [in] a1 - an array to subtract from.
4813  *  \param [in] a2 - an array to subtract.
4814  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4815  *          The caller is to delete this result array using decrRef() as it is no more
4816  *          needed.
4817  *  \throw If either \a a1 or \a a2 is NULL.
4818  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4819  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4820  *         none of them has number of tuples or components equal to 1.
4821  */
4822 DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4823 {
4824   if(!a1 || !a2)
4825     throw INTERP_KERNEL::Exception("DataArrayDouble::Substract : input DataArrayDouble instance is NULL !");
4826   int nbOfTuple1=a1->getNumberOfTuples();
4827   int nbOfTuple2=a2->getNumberOfTuples();
4828   int nbOfComp1=a1->getNumberOfComponents();
4829   int nbOfComp2=a2->getNumberOfComponents();
4830   if(nbOfTuple2==nbOfTuple1)
4831     {
4832       if(nbOfComp1==nbOfComp2)
4833         {
4834           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4835           ret->alloc(nbOfTuple2,nbOfComp1);
4836           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
4837           ret->copyStringInfoFrom(*a1);
4838           return ret.retn();
4839         }
4840       else if(nbOfComp2==1)
4841         {
4842           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4843           ret->alloc(nbOfTuple1,nbOfComp1);
4844           const double *a2Ptr=a2->getConstPointer();
4845           const double *a1Ptr=a1->getConstPointer();
4846           double *res=ret->getPointer();
4847           for(int i=0;i<nbOfTuple1;i++)
4848             res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<double>(),a2Ptr[i]));
4849           ret->copyStringInfoFrom(*a1);
4850           return ret.retn();
4851         }
4852       else
4853         {
4854           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
4855           return 0;
4856         }
4857     }
4858   else if(nbOfTuple2==1)
4859     {
4860       a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
4861       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
4862       ret->alloc(nbOfTuple1,nbOfComp1);
4863       const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
4864       double *pt=ret->getPointer();
4865       for(int i=0;i<nbOfTuple1;i++)
4866         pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<double>());
4867       ret->copyStringInfoFrom(*a1);
4868       return ret.retn();
4869     }
4870   else
4871     {
4872       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
4873       return 0;
4874     }
4875 }
4876
4877 /*!
4878  * Subtract values of another DataArrayDouble from values of \a this one. There are 3
4879  * valid cases.
4880  * 1.  The arrays have same number of tuples and components. Then each value of
4881  *   \a other array is subtracted from the corresponding value of \a this array, i.e.:
4882  *   _a_ [ i, j ] -= _other_ [ i, j ].
4883  * 2.  The arrays have same number of tuples and \a other array has one component. Then
4884  *   _a_ [ i, j ] -= _other_ [ i, 0 ].
4885  * 3.  The arrays have same number of components and \a other array has one tuple. Then
4886  *   _a_ [ i, j ] -= _a2_ [ 0, j ].
4887  *
4888  *  \param [in] other - an array to subtract from \a this one.
4889  *  \throw If \a other is NULL.
4890  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
4891  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
4892  *         \a other has number of both tuples and components not equal to 1.
4893  */
4894 void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
4895 {
4896   if(!other)
4897     throw INTERP_KERNEL::Exception("DataArrayDouble::substractEqual : input DataArrayDouble instance is NULL !");
4898   const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual  !";
4899   checkAllocated();
4900   other->checkAllocated();
4901   int nbOfTuple=getNumberOfTuples();
4902   int nbOfTuple2=other->getNumberOfTuples();
4903   int nbOfComp=getNumberOfComponents();
4904   int nbOfComp2=other->getNumberOfComponents();
4905   if(nbOfTuple==nbOfTuple2)
4906     {
4907       if(nbOfComp==nbOfComp2)
4908         {
4909           std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
4910         }
4911       else if(nbOfComp2==1)
4912         {
4913           double *ptr=getPointer();
4914           const double *ptrc=other->getConstPointer();
4915           for(int i=0;i<nbOfTuple;i++)
4916             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*ptrc++)); 
4917         }
4918       else
4919         throw INTERP_KERNEL::Exception(msg);
4920     }
4921   else if(nbOfTuple2==1)
4922     {
4923       if(nbOfComp2==nbOfComp)
4924         {
4925           double *ptr=getPointer();
4926           const double *ptrc=other->getConstPointer();
4927           for(int i=0;i<nbOfTuple;i++)
4928             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
4929         }
4930       else
4931         throw INTERP_KERNEL::Exception(msg);
4932     }
4933   else
4934     throw INTERP_KERNEL::Exception(msg);
4935   declareAsNew();
4936 }
4937
4938 /*!
4939  * Returns a new DataArrayDouble that is a product of two given arrays. There are 3
4940  * valid cases.
4941  * 1.  The arrays have same number of tuples and components. Then each value of
4942  *   the result array (_a_) is a product of the corresponding values of \a a1 and
4943  *   \a a2, i.e. _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
4944  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
4945  *   component. Then
4946  *   _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
4947  * 3.  The arrays have same number of components and one array, say _a2_, has one
4948  *   tuple. Then
4949  *   _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
4950  *
4951  * Info on components is copied either from the first array (in the first case) or from
4952  * the array with maximal number of elements (getNbOfElems()).
4953  *  \param [in] a1 - a factor array.
4954  *  \param [in] a2 - another factor array.
4955  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
4956  *          The caller is to delete this result array using decrRef() as it is no more
4957  *          needed.
4958  *  \throw If either \a a1 or \a a2 is NULL.
4959  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
4960  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
4961  *         none of them has number of tuples or components equal to 1.
4962  */
4963 DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
4964 {
4965   if(!a1 || !a2)
4966     throw INTERP_KERNEL::Exception("DataArrayDouble::Multiply : input DataArrayDouble instance is NULL !");
4967   int nbOfTuple=a1->getNumberOfTuples();
4968   int nbOfTuple2=a2->getNumberOfTuples();
4969   int nbOfComp=a1->getNumberOfComponents();
4970   int nbOfComp2=a2->getNumberOfComponents();
4971   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=0;
4972   if(nbOfTuple==nbOfTuple2)
4973     {
4974       if(nbOfComp==nbOfComp2)
4975         {
4976           ret=DataArrayDouble::New();
4977           ret->alloc(nbOfTuple,nbOfComp);
4978           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<double>());
4979           ret->copyStringInfoFrom(*a1);
4980         }
4981       else
4982         {
4983           int nbOfCompMin,nbOfCompMax;
4984           const DataArrayDouble *aMin, *aMax;
4985           if(nbOfComp>nbOfComp2)
4986             {
4987               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
4988               aMin=a2; aMax=a1;
4989             }
4990           else
4991             {
4992               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
4993               aMin=a1; aMax=a2;
4994             }
4995           if(nbOfCompMin==1)
4996             {
4997               ret=DataArrayDouble::New();
4998               ret->alloc(nbOfTuple,nbOfCompMax);
4999               const double *aMinPtr=aMin->getConstPointer();
5000               const double *aMaxPtr=aMax->getConstPointer();
5001               double *res=ret->getPointer();
5002               for(int i=0;i<nbOfTuple;i++)
5003                 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
5004               ret->copyStringInfoFrom(*aMax);
5005             }
5006           else
5007             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
5008         }
5009     }
5010   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
5011     {
5012       if(nbOfComp==nbOfComp2)
5013         {
5014           int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
5015           const DataArrayDouble *aMin=nbOfTuple>nbOfTuple2?a2:a1;
5016           const DataArrayDouble *aMax=nbOfTuple>nbOfTuple2?a1:a2;
5017           const double *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
5018           ret=DataArrayDouble::New();
5019           ret->alloc(nbOfTupleMax,nbOfComp);
5020           double *res=ret->getPointer();
5021           for(int i=0;i<nbOfTupleMax;i++)
5022             res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<double>());
5023           ret->copyStringInfoFrom(*aMax);
5024         }
5025       else
5026         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
5027     }
5028   else
5029     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
5030   return ret.retn();
5031 }
5032
5033 /*!
5034  * Multiply values of another DataArrayDouble to values of \a this one. There are 3
5035  * valid cases.
5036  * 1.  The arrays have same number of tuples and components. Then each value of
5037  *   \a other array is multiplied to the corresponding value of \a this array, i.e.
5038  *   _this_ [ i, j ] *= _other_ [ i, j ].
5039  * 2.  The arrays have same number of tuples and \a other array has one component. Then
5040  *   _this_ [ i, j ] *= _other_ [ i, 0 ].
5041  * 3.  The arrays have same number of components and \a other array has one tuple. Then
5042  *   _this_ [ i, j ] *= _a2_ [ 0, j ].
5043  *
5044  *  \param [in] other - an array to multiply to \a this one.
5045  *  \throw If \a other is NULL.
5046  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
5047  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
5048  *         \a other has number of both tuples and components not equal to 1.
5049  */
5050 void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
5051 {
5052   if(!other)
5053     throw INTERP_KERNEL::Exception("DataArrayDouble::multiplyEqual : input DataArrayDouble instance is NULL !");
5054   const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
5055   checkAllocated();
5056   other->checkAllocated();
5057   int nbOfTuple=getNumberOfTuples();
5058   int nbOfTuple2=other->getNumberOfTuples();
5059   int nbOfComp=getNumberOfComponents();
5060   int nbOfComp2=other->getNumberOfComponents();
5061   if(nbOfTuple==nbOfTuple2)
5062     {
5063       if(nbOfComp==nbOfComp2)
5064         {
5065           std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
5066         }
5067       else if(nbOfComp2==1)
5068         {
5069           double *ptr=getPointer();
5070           const double *ptrc=other->getConstPointer();
5071           for(int i=0;i<nbOfTuple;i++)
5072             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<double>(),*ptrc++));
5073         }
5074       else
5075         throw INTERP_KERNEL::Exception(msg);
5076     }
5077   else if(nbOfTuple2==1)
5078     {
5079       if(nbOfComp2==nbOfComp)
5080         {
5081           double *ptr=getPointer();
5082           const double *ptrc=other->getConstPointer();
5083           for(int i=0;i<nbOfTuple;i++)
5084             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<double>());
5085         }
5086       else
5087         throw INTERP_KERNEL::Exception(msg);
5088     }
5089   else
5090     throw INTERP_KERNEL::Exception(msg);
5091   declareAsNew();
5092 }
5093
5094 /*!
5095  * Returns a new DataArrayDouble that is a division of two given arrays. There are 3
5096  * valid cases.
5097  * 1.  The arrays have same number of tuples and components. Then each value of
5098  *   the result array (_a_) is a division of the corresponding values of \a a1 and
5099  *   \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
5100  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
5101  *   component. Then
5102  *   _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
5103  * 3.  The arrays have same number of components and one array, say _a2_, has one
5104  *   tuple. Then
5105  *   _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
5106  *
5107  * Info on components is copied either from the first array (in the first case) or from
5108  * the array with maximal number of elements (getNbOfElems()).
5109  *  \warning No check of division by zero is performed!
5110  *  \param [in] a1 - a numerator array.
5111  *  \param [in] a2 - a denominator array.
5112  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
5113  *          The caller is to delete this result array using decrRef() as it is no more
5114  *          needed.
5115  *  \throw If either \a a1 or \a a2 is NULL.
5116  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
5117  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
5118  *         none of them has number of tuples or components equal to 1.
5119  */
5120 DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
5121 {
5122   if(!a1 || !a2)
5123     throw INTERP_KERNEL::Exception("DataArrayDouble::Divide : input DataArrayDouble instance is NULL !");
5124   int nbOfTuple1=a1->getNumberOfTuples();
5125   int nbOfTuple2=a2->getNumberOfTuples();
5126   int nbOfComp1=a1->getNumberOfComponents();
5127   int nbOfComp2=a2->getNumberOfComponents();
5128   if(nbOfTuple2==nbOfTuple1)
5129     {
5130       if(nbOfComp1==nbOfComp2)
5131         {
5132           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
5133           ret->alloc(nbOfTuple2,nbOfComp1);
5134           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
5135           ret->copyStringInfoFrom(*a1);
5136           return ret.retn();
5137         }
5138       else if(nbOfComp2==1)
5139         {
5140           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
5141           ret->alloc(nbOfTuple1,nbOfComp1);
5142           const double *a2Ptr=a2->getConstPointer();
5143           const double *a1Ptr=a1->getConstPointer();
5144           double *res=ret->getPointer();
5145           for(int i=0;i<nbOfTuple1;i++)
5146             res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
5147           ret->copyStringInfoFrom(*a1);
5148           return ret.retn();
5149         }
5150       else
5151         {
5152           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
5153           return 0;
5154         }
5155     }
5156   else if(nbOfTuple2==1)
5157     {
5158       a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
5159       MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
5160       ret->alloc(nbOfTuple1,nbOfComp1);
5161       const double *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
5162       double *pt=ret->getPointer();
5163       for(int i=0;i<nbOfTuple1;i++)
5164         pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<double>());
5165       ret->copyStringInfoFrom(*a1);
5166       return ret.retn();
5167     }
5168   else
5169     {
5170       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
5171       return 0;
5172     }
5173 }
5174
5175 /*!
5176  * Divide values of \a this array by values of another DataArrayDouble. There are 3
5177  * valid cases.
5178  * 1.  The arrays have same number of tuples and components. Then each value of
5179  *    \a this array is divided by the corresponding value of \a other one, i.e.:
5180  *   _a_ [ i, j ] /= _other_ [ i, j ].
5181  * 2.  The arrays have same number of tuples and \a other array has one component. Then
5182  *   _a_ [ i, j ] /= _other_ [ i, 0 ].
5183  * 3.  The arrays have same number of components and \a other array has one tuple. Then
5184  *   _a_ [ i, j ] /= _a2_ [ 0, j ].
5185  *
5186  *  \warning No check of division by zero is performed!
5187  *  \param [in] other - an array to divide \a this one by.
5188  *  \throw If \a other is NULL.
5189  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
5190  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
5191  *         \a other has number of both tuples and components not equal to 1.
5192  */
5193 void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
5194 {
5195   if(!other)
5196     throw INTERP_KERNEL::Exception("DataArrayDouble::divideEqual : input DataArrayDouble instance is NULL !");
5197   const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
5198   checkAllocated();
5199   other->checkAllocated();
5200   int nbOfTuple=getNumberOfTuples();
5201   int nbOfTuple2=other->getNumberOfTuples();
5202   int nbOfComp=getNumberOfComponents();
5203   int nbOfComp2=other->getNumberOfComponents();
5204   if(nbOfTuple==nbOfTuple2)
5205     {
5206       if(nbOfComp==nbOfComp2)
5207         {
5208           std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
5209         }
5210       else if(nbOfComp2==1)
5211         {
5212           double *ptr=getPointer();
5213           const double *ptrc=other->getConstPointer();
5214           for(int i=0;i<nbOfTuple;i++)
5215             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
5216         }
5217       else
5218         throw INTERP_KERNEL::Exception(msg);
5219     }
5220   else if(nbOfTuple2==1)
5221     {
5222       if(nbOfComp2==nbOfComp)
5223         {
5224           double *ptr=getPointer();
5225           const double *ptrc=other->getConstPointer();
5226           for(int i=0;i<nbOfTuple;i++)
5227             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
5228         }
5229       else
5230         throw INTERP_KERNEL::Exception(msg);
5231     }
5232   else
5233     throw INTERP_KERNEL::Exception(msg);
5234   declareAsNew();
5235 }
5236
5237 /*!
5238  * Returns a new DataArrayDouble that is the result of pow of two given arrays. There are 3
5239  * valid cases.
5240  *
5241  *  \param [in] a1 - an array to pow up.
5242  *  \param [in] a2 - another array to sum up.
5243  *  \return DataArrayDouble * - the new instance of DataArrayDouble.
5244  *          The caller is to delete this result array using decrRef() as it is no more
5245  *          needed.
5246  *  \throw If either \a a1 or \a a2 is NULL.
5247  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
5248  *  \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
5249  *  \throw If there is a negative value in \a a1.
5250  */
5251 DataArrayDouble *DataArrayDouble::Pow(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
5252 {
5253   if(!a1 || !a2)
5254     throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : at least one of input instances is null !");
5255   int nbOfTuple=a1->getNumberOfTuples();
5256   int nbOfTuple2=a2->getNumberOfTuples();
5257   int nbOfComp=a1->getNumberOfComponents();
5258   int nbOfComp2=a2->getNumberOfComponents();
5259   if(nbOfTuple!=nbOfTuple2)
5260     throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of tuples mismatches !");
5261   if(nbOfComp!=1 || nbOfComp2!=1)
5262     throw INTERP_KERNEL::Exception("DataArrayDouble::Pow : number of components of both arrays must be equal to 1 !");
5263   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbOfTuple,1);
5264   const double *ptr1(a1->begin()),*ptr2(a2->begin());
5265   double *ptr=ret->getPointer();
5266   for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
5267     {
5268       if(*ptr1>=0)
5269         {
5270           *ptr=pow(*ptr1,*ptr2);
5271         }
5272       else
5273         {
5274           std::ostringstream oss; oss << "DataArrayDouble::Pow : on tuple #" << i << " of a1 value is < 0 (" << *ptr1 << ") !";
5275           throw INTERP_KERNEL::Exception(oss.str().c_str());
5276         }
5277     }
5278   return ret.retn();
5279 }
5280
5281 /*!
5282  * Apply pow on values of another DataArrayDouble to values of \a this one.
5283  *
5284  *  \param [in] other - an array to pow to \a this one.
5285  *  \throw If \a other is NULL.
5286  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
5287  *  \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
5288  *  \throw If there is a negative value in \a this.
5289  */
5290 void DataArrayDouble::powEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
5291 {
5292   if(!other)
5293     throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : input instance is null !");
5294   int nbOfTuple=getNumberOfTuples();
5295   int nbOfTuple2=other->getNumberOfTuples();
5296   int nbOfComp=getNumberOfComponents();
5297   int nbOfComp2=other->getNumberOfComponents();
5298   if(nbOfTuple!=nbOfTuple2)
5299     throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of tuples mismatches !");
5300   if(nbOfComp!=1 || nbOfComp2!=1)
5301     throw INTERP_KERNEL::Exception("DataArrayDouble::powEqual : number of components of both arrays must be equal to 1 !");
5302   double *ptr=getPointer();
5303   const double *ptrc=other->begin();
5304   for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
5305     {
5306       if(*ptr>=0)
5307         *ptr=pow(*ptr,*ptrc);
5308       else
5309         {
5310           std::ostringstream oss; oss << "DataArrayDouble::powEqual : on tuple #" << i << " of this value is < 0 (" << *ptr << ") !";
5311           throw INTERP_KERNEL::Exception(oss.str().c_str());
5312         }
5313     }
5314   declareAsNew();
5315 }
5316
5317 /*!
5318  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5319  * Server side.
5320  */
5321 void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
5322 {
5323   tinyInfo.resize(2);
5324   if(isAllocated())
5325     {
5326       tinyInfo[0]=getNumberOfTuples();
5327       tinyInfo[1]=getNumberOfComponents();
5328     }
5329   else
5330     {
5331       tinyInfo[0]=-1;
5332       tinyInfo[1]=-1;
5333     }
5334 }
5335
5336 /*!
5337  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5338  * Server side.
5339  */
5340 void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
5341 {
5342   if(isAllocated())
5343     {
5344       int nbOfCompo=getNumberOfComponents();
5345       tinyInfo.resize(nbOfCompo+1);
5346       tinyInfo[0]=getName();
5347       for(int i=0;i<nbOfCompo;i++)
5348         tinyInfo[i+1]=getInfoOnComponent(i);
5349     }
5350   else
5351     {
5352       tinyInfo.resize(1);
5353       tinyInfo[0]=getName();
5354     }
5355 }
5356
5357 /*!
5358  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5359  * This method returns if a feeding is needed.
5360  */
5361 bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
5362 {
5363   int nbOfTuple=tinyInfoI[0];
5364   int nbOfComp=tinyInfoI[1];
5365   if(nbOfTuple!=-1 || nbOfComp!=-1)
5366     {
5367       alloc(nbOfTuple,nbOfComp);
5368       return true;
5369     }
5370   return false;
5371 }
5372
5373 /*!
5374  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
5375  */
5376 void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
5377 {
5378   setName(tinyInfoS[0].c_str());
5379   if(isAllocated())
5380     {
5381       int nbOfCompo=getNumberOfComponents();
5382       for(int i=0;i<nbOfCompo;i++)
5383         setInfoOnComponent(i,tinyInfoS[i+1].c_str());
5384     }
5385 }
5386
5387 DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
5388 {
5389   if(_da)
5390     {
5391       _da->incrRef();
5392       if(_da->isAllocated())
5393         {
5394           _nb_comp=da->getNumberOfComponents();
5395           _nb_tuple=da->getNumberOfTuples();
5396           _pt=da->getPointer();
5397         }
5398     }
5399 }
5400
5401 DataArrayDoubleIterator::~DataArrayDoubleIterator()
5402 {
5403   if(_da)
5404     _da->decrRef();
5405 }
5406
5407 DataArrayDoubleTuple *DataArrayDoubleIterator::nextt() throw(INTERP_KERNEL::Exception)
5408 {
5409   if(_tuple_id<_nb_tuple)
5410     {
5411       _tuple_id++;
5412       DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
5413       _pt+=_nb_comp;
5414       return ret;
5415     }
5416   else
5417     return 0;
5418 }
5419
5420 DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
5421 {
5422 }
5423
5424
5425 std::string DataArrayDoubleTuple::repr() const throw(INTERP_KERNEL::Exception)
5426 {
5427   std::ostringstream oss; oss.precision(17); oss << "(";
5428   for(int i=0;i<_nb_of_compo-1;i++)
5429     oss << _pt[i] << ", ";
5430   oss << _pt[_nb_of_compo-1] << ")";
5431   return oss.str();
5432 }
5433
5434 double DataArrayDoubleTuple::doubleValue() const throw(INTERP_KERNEL::Exception)
5435 {
5436   if(_nb_of_compo==1)
5437     return *_pt;
5438   throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
5439 }
5440
5441 /*!
5442  * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayDouble::decrRef.
5443  * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayDouble::useArray with ownership set to \b false.
5444  * 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
5445  * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
5446  */
5447 DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
5448 {
5449   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
5450     {
5451       DataArrayDouble *ret=DataArrayDouble::New();
5452       ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
5453       return ret;
5454     }
5455   else
5456     {
5457       std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
5458       oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
5459       throw INTERP_KERNEL::Exception(oss.str().c_str());
5460     }
5461 }
5462
5463 /*!
5464  * Returns a new instance of DataArrayInt. The caller is to delete this array
5465  * using decrRef() as it is no more needed. 
5466  */
5467 DataArrayInt *DataArrayInt::New()
5468 {
5469   return new DataArrayInt;
5470 }
5471
5472 /*!
5473  * Checks if raw data is allocated. Read more on the raw data
5474  * in \ref MEDCouplingArrayBasicsTuplesAndCompo "DataArrays infos" for more information.
5475  *  \return bool - \a true if the raw data is allocated, \a false else.
5476  */
5477 bool DataArrayInt::isAllocated() const throw(INTERP_KERNEL::Exception)
5478 {
5479   return getConstPointer()!=0;
5480 }
5481
5482 /*!
5483  * Checks if raw data is allocated and throws an exception if it is not the case.
5484  *  \throw If the raw data is not allocated.
5485  */
5486 void DataArrayInt::checkAllocated() const throw(INTERP_KERNEL::Exception)
5487 {
5488   if(!isAllocated())
5489     throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
5490 }
5491
5492 /*!
5493  * This method desallocated \a this without modification of informations relative to the components.
5494  * After call of this method, DataArrayInt::isAllocated will return false.
5495  * If \a this is already not allocated, \a this is let unchanged.
5496  */
5497 void DataArrayInt::desallocate() throw(INTERP_KERNEL::Exception)
5498 {
5499   _mem.destroy();
5500 }
5501
5502 std::size_t DataArrayInt::getHeapMemorySize() const
5503 {
5504   std::size_t sz=_mem.getNbOfElemAllocated();
5505   sz*=sizeof(int);
5506   return DataArray::getHeapMemorySize()+sz;
5507 }
5508
5509 /*!
5510  * Returns the only one value in \a this, if and only if number of elements
5511  * (nb of tuples * nb of components) is equal to 1, and that \a this is allocated.
5512  *  \return double - the sole value stored in \a this array.
5513  *  \throw If at least one of conditions stated above is not fulfilled.
5514  */
5515 int DataArrayInt::intValue() const throw(INTERP_KERNEL::Exception)
5516 {
5517   if(isAllocated())
5518     {
5519       if(getNbOfElems()==1)
5520         {
5521           return *getConstPointer();
5522         }
5523       else
5524         throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is allocated but number of elements is not equal to 1 !");
5525     }
5526   else
5527     throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
5528 }
5529
5530 /*!
5531  * Returns an integer value characterizing \a this array, which is useful for a quick
5532  * comparison of many instances of DataArrayInt.
5533  *  \return int - the hash value.
5534  *  \throw If \a this is not allocated.
5535  */
5536 int DataArrayInt::getHashCode() const throw(INTERP_KERNEL::Exception)
5537 {
5538   checkAllocated();
5539   std::size_t nbOfElems=getNbOfElems();
5540   int ret=nbOfElems*65536;
5541   int delta=3;
5542   if(nbOfElems>48)
5543     delta=nbOfElems/8;
5544   int ret0=0;
5545   const int *pt=begin();
5546   for(std::size_t i=0;i<nbOfElems;i+=delta)
5547     ret0+=pt[i] & 0x1FFF;
5548   return ret+ret0;
5549 }
5550
5551 /*!
5552  * Checks the number of tuples.
5553  *  \return bool - \a true if getNumberOfTuples() == 0, \a false else.
5554  *  \throw If \a this is not allocated.
5555  */
5556 bool DataArrayInt::empty() const throw(INTERP_KERNEL::Exception)
5557 {
5558   checkAllocated();
5559   return getNumberOfTuples()==0;
5560 }
5561
5562 /*!
5563  * Returns a full copy of \a this. For more info on copying data arrays see
5564  * \ref MEDCouplingArrayBasicsCopyDeep.
5565  *  \return DataArrayInt * - a new instance of DataArrayInt.
5566  */
5567 DataArrayInt *DataArrayInt::deepCpy() const throw(INTERP_KERNEL::Exception)
5568 {
5569   return new DataArrayInt(*this);
5570 }
5571
5572 /*!
5573  * Returns either a \a deep or \a shallow copy of this array. For more info see
5574  * \ref MEDCouplingArrayBasicsCopyDeep and \ref MEDCouplingArrayBasicsCopyShallow.
5575  *  \param [in] dCpy - if \a true, a deep copy is returned, else, a shallow one.
5576  *  \return DataArrayInt * - either a new instance of DataArrayInt (if \a dCpy
5577  *          == \a true) or \a this instance (if \a dCpy == \a false).
5578  */
5579 DataArrayInt *DataArrayInt::performCpy(bool dCpy) const throw(INTERP_KERNEL::Exception)
5580 {
5581   if(dCpy)
5582     return deepCpy();
5583   else
5584     {
5585       incrRef();
5586       return const_cast<DataArrayInt *>(this);
5587     }
5588 }
5589
5590 /*!
5591  * Copies all the data from another DataArrayInt. For more info see
5592  * \ref MEDCouplingArrayBasicsCopyDeepAssign.
5593  *  \param [in] other - another instance of DataArrayInt to copy data from.
5594  *  \throw If the \a other is not allocated.
5595  */
5596 void DataArrayInt::cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception)
5597 {
5598   other.checkAllocated();
5599   int nbOfTuples=other.getNumberOfTuples();
5600   int nbOfComp=other.getNumberOfComponents();
5601   allocIfNecessary(nbOfTuples,nbOfComp);
5602   std::size_t nbOfElems=(std::size_t)nbOfTuples*nbOfComp;
5603   int *pt=getPointer();
5604   const int *ptI=other.getConstPointer();
5605   for(std::size_t i=0;i<nbOfElems;i++)
5606     pt[i]=ptI[i];
5607   copyStringInfoFrom(other);
5608 }
5609
5610 /*!
5611  * This method reserve nbOfElems elements in memory ( nbOfElems*4 bytes ) \b without impacting the number of tuples in \a this.
5612  * 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.
5613  * If \a this has not already been allocated, number of components is set to one.
5614  * This method allows to reduce number of reallocations on invokation of DataArrayInt::pushBackSilent and DataArrayInt::pushBackValsSilent on \a this.
5615  * 
5616  * \sa DataArrayInt::pack, DataArrayInt::pushBackSilent, DataArrayInt::pushBackValsSilent
5617  */
5618 void DataArrayInt::reserve(std::size_t nbOfElems) throw(INTERP_KERNEL::Exception)
5619 {
5620   int nbCompo=getNumberOfComponents();
5621   if(nbCompo==1)
5622     {
5623       _mem.reserve(nbOfElems);
5624     }
5625   else if(nbCompo==0)
5626     {
5627       _mem.reserve(nbOfElems);
5628       _info_on_compo.resize(1);
5629     }
5630   else
5631     throw INTERP_KERNEL::Exception("DataArrayInt::reserve : not available for DataArrayInt with number of components different than 1 !");
5632 }
5633
5634 /*!
5635  * 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
5636  * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
5637  *
5638  * \param [in] val the value to be added in \a this
5639  * \throw If \a this has already been allocated with number of components different from one.
5640  * \sa DataArrayInt::pushBackValsSilent
5641  */
5642 void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception)
5643 {
5644   int nbCompo=getNumberOfComponents();
5645   if(nbCompo==1)
5646     _mem.pushBack(val);
5647   else if(nbCompo==0)
5648     {
5649       _info_on_compo.resize(1);
5650       _mem.pushBack(val);
5651     }
5652   else
5653     throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !");
5654 }
5655
5656 /*!
5657  * 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
5658  * of counter. So the caller is expected to call TimeLabel::declareAsNew on \a this at the end of the push session.
5659  *
5660  *  \param [in] valsBg - an array of values to push at the end of \this.
5661  *  \param [in] valsEnd - specifies the end of the array \a valsBg, so that
5662  *              the last value of \a valsBg is \a valsEnd[ -1 ].
5663  * \throw If \a this has already been allocated with number of components different from one.
5664  * \sa DataArrayInt::pushBackSilent
5665  */
5666 void DataArrayInt::pushBackValsSilent(const int *valsBg, const int *valsEnd) throw(INTERP_KERNEL::Exception)
5667 {
5668   int nbCompo=getNumberOfComponents();
5669   if(nbCompo==1)
5670     _mem.insertAtTheEnd(valsBg,valsEnd);
5671   else if(nbCompo==0)
5672     {
5673       _info_on_compo.resize(1);
5674       _mem.insertAtTheEnd(valsBg,valsEnd);
5675     }
5676   else
5677     throw INTERP_KERNEL::Exception("DataArrayInt::pushBackValsSilent : not available for DataArrayInt with number of components different than 1 !");
5678 }
5679
5680 /*!
5681  * This method returns silently ( without updating time label in \a this ) the last value, if any and suppress it.
5682  * \throw If \a this is already empty.
5683  * \throw If \a this has number of components different from one.
5684  */
5685 int DataArrayInt::popBackSilent() throw(INTERP_KERNEL::Exception)
5686 {
5687   if(getNumberOfComponents()==1)
5688     return _mem.popBack();
5689   else
5690     throw INTERP_KERNEL::Exception("DataArrayInt::popBackSilent : not available for DataArrayInt with number of components different than 1 !");
5691 }
5692
5693 /*!
5694  * 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.
5695  *
5696  * \sa DataArrayInt::getHeapMemorySize, DataArrayInt::reserve
5697  */
5698 void DataArrayInt::pack() const throw(INTERP_KERNEL::Exception)
5699 {
5700   _mem.pack();
5701 }
5702
5703 /*!
5704  * Allocates the raw data in memory. If exactly as same memory as needed already
5705  * allocated, it is not re-allocated.
5706  *  \param [in] nbOfTuple - number of tuples of data to allocate.
5707  *  \param [in] nbOfCompo - number of components of data to allocate.
5708  *  \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
5709  */
5710 void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
5711 {
5712   if(isAllocated())
5713     {
5714       if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
5715         alloc(nbOfTuple,nbOfCompo);
5716     }
5717   else
5718     alloc(nbOfTuple,nbOfCompo);
5719 }
5720
5721 /*!
5722  * Allocates the raw data in memory. If the memory was already allocated, then it is
5723  * freed and re-allocated. See an example of this method use
5724  * \ref MEDCouplingArraySteps1WC "here".
5725  *  \param [in] nbOfTuple - number of tuples of data to allocate.
5726  *  \param [in] nbOfCompo - number of components of data to allocate.
5727  *  \throw If \a nbOfTuple < 0 or \a nbOfCompo < 0.
5728  */
5729 void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
5730 {
5731   if(nbOfTuple<0 || nbOfCompo<0)
5732     throw INTERP_KERNEL::Exception("DataArrayInt::alloc : request for negative length of data !");
5733   _info_on_compo.resize(nbOfCompo);
5734   _mem.alloc(nbOfCompo*(std::size_t)nbOfTuple);
5735   declareAsNew();
5736 }
5737
5738 /*!
5739  * Assign zero to all values in \a this array. To know more on filling arrays see
5740  * \ref MEDCouplingArrayFill.
5741  * \throw If \a this is not allocated.
5742  */
5743 void DataArrayInt::fillWithZero() throw(INTERP_KERNEL::Exception)
5744 {
5745   checkAllocated();
5746   _mem.fillWithValue(0);
5747   declareAsNew();
5748 }
5749
5750 /*!
5751  * Assign \a val to all values in \a this array. To know more on filling arrays see
5752  * \ref MEDCouplingArrayFill.
5753  *  \param [in] val - the value to fill with.
5754  *  \throw If \a this is not allocated.
5755  */
5756 void DataArrayInt::fillWithValue(int val) throw(INTERP_KERNEL::Exception)
5757 {
5758   checkAllocated();
5759   _mem.fillWithValue(val);
5760   declareAsNew();
5761 }
5762
5763 /*!
5764  * Set all values in \a this array so that the i-th element equals to \a init + i
5765  * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
5766  *  \param [in] init - value to assign to the first element of array.
5767  *  \throw If \a this->getNumberOfComponents() != 1
5768  *  \throw If \a this is not allocated.
5769  */
5770 void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception)
5771 {
5772   checkAllocated();
5773   if(getNumberOfComponents()!=1)
5774     throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
5775   int *ptr=getPointer();
5776   int ntuples=getNumberOfTuples();
5777   for(int i=0;i<ntuples;i++)
5778     ptr[i]=init+i;
5779   declareAsNew();
5780 }
5781
5782 /*!
5783  * Returns a textual and human readable representation of \a this instance of
5784  * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
5785  *  \return std::string - text describing \a this DataArrayInt.
5786  */
5787 std::string DataArrayInt::repr() const throw(INTERP_KERNEL::Exception)
5788 {
5789   std::ostringstream ret;
5790   reprStream(ret);
5791   return ret.str();
5792 }
5793
5794 std::string DataArrayInt::reprZip() const throw(INTERP_KERNEL::Exception)
5795 {
5796   std::ostringstream ret;
5797   reprZipStream(ret);
5798   return ret.str();
5799 }
5800
5801 void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
5802 {
5803   checkAllocated();
5804   std::string idt(indent,' ');
5805   ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
5806   ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
5807   std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
5808   ofs << std::endl << idt << "</DataArray>\n";
5809 }
5810
5811 void DataArrayInt::reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5812 {
5813   stream << "Name of int array : \"" << _name << "\"\n";
5814   reprWithoutNameStream(stream);
5815 }
5816
5817 void DataArrayInt::reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5818 {
5819   stream << "Name of int array : \"" << _name << "\"\n";
5820   reprZipWithoutNameStream(stream);
5821 }
5822
5823 void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5824 {
5825   DataArray::reprWithoutNameStream(stream);
5826   _mem.repr(getNumberOfComponents(),stream);
5827 }
5828
5829 void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5830 {
5831   DataArray::reprWithoutNameStream(stream);
5832   _mem.reprZip(getNumberOfComponents(),stream);
5833 }
5834
5835 void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5836 {
5837   int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
5838   const int *data=getConstPointer();
5839   stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl;
5840   if(nbTuples*nbComp>=1)
5841     {
5842       stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={";
5843       std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<int>(stream,","));
5844       stream << data[nbTuples*nbComp-1] << "};" << std::endl;
5845       stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
5846     }
5847   else
5848     stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
5849   stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
5850 }
5851
5852 /*!
5853  * Method that gives a quick overvien of \a this for python.
5854  */
5855 void DataArrayInt::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
5856 {
5857   static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
5858   stream << "DataArrayInt C++ instance at " << this << ". ";
5859   if(isAllocated())
5860     {
5861       int nbOfCompo=(int)_info_on_compo.size();
5862       if(nbOfCompo>=1)
5863         {
5864           int nbOfTuples=getNumberOfTuples();
5865           stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
5866           reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
5867         }
5868       else
5869         stream << "Number of components : 0.";
5870     }
5871   else
5872     stream << "*** No data allocated ****";
5873 }
5874
5875 void DataArrayInt::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const throw(INTERP_KERNEL::Exception)
5876 {
5877   const int *data=begin();
5878   int nbOfTuples=getNumberOfTuples();
5879   int nbOfCompo=(int)_info_on_compo.size();
5880   std::ostringstream oss2; oss2 << "[";
5881   std::string oss2Str(oss2.str());
5882   bool isFinished=true;
5883   for(int i=0;i<nbOfTuples && isFinished;i++)
5884     {
5885       if(nbOfCompo>1)
5886         {
5887           oss2 << "(";
5888           for(int j=0;j<nbOfCompo;j++,data++)
5889             {
5890               oss2 << *data;
5891               if(j!=nbOfCompo-1) oss2 << ", ";
5892             }
5893           oss2 << ")";
5894         }
5895       else
5896         oss2 << *data++;
5897       if(i!=nbOfTuples-1) oss2 << ", ";
5898       std::string oss3Str(oss2.str());
5899       if(oss3Str.length()<maxNbOfByteInRepr)
5900         oss2Str=oss3Str;
5901       else
5902         isFinished=false;
5903     }
5904   stream << oss2Str;
5905   if(!isFinished)
5906     stream << "... ";
5907   stream << "]";
5908 }
5909
5910 /*!
5911  * Modifies \a this one-dimensional array so that each value \a v = \a indArrBg[ \a v ],
5912  * i.e. a current value is used as in index to get a new value from \a indArrBg.
5913  *  \param [in] indArrBg - pointer to the first element of array of new values to assign
5914  *         to \a this array.
5915  *  \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
5916  *              the last value of \a indArrBg is \a indArrEnd[ -1 ].
5917  *  \throw If \a this->getNumberOfComponents() != 1
5918  *  \throw If any value of \a this can't be used as a valid index for 
5919  *         [\a indArrBg, \a indArrEnd).
5920  */
5921 void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception)
5922 {
5923   checkAllocated();
5924   if(getNumberOfComponents()!=1)
5925     throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
5926   int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
5927   int nbOfTuples=getNumberOfTuples();
5928   int *pt=getPointer();
5929   for(int i=0;i<nbOfTuples;i++,pt++)
5930     {
5931       if(*pt>=0 && *pt<nbElemsIn)
5932         *pt=indArrBg[*pt];
5933       else
5934         {
5935           std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
5936           throw INTERP_KERNEL::Exception(oss.str().c_str());
5937         }
5938     }
5939   declareAsNew();
5940 }
5941
5942 /*!
5943  * Computes distribution of values of \a this one-dimensional array between given value
5944  * ranges (casts). This method is typically useful for entity number spliting by types,
5945  * for example. 
5946  *  \warning The values contained in \a arrBg should be sorted ascendently. No
5947  *           check of this is be done. If not, the result is not warranted. 
5948  *  \param [in] arrBg - the array of ascending values defining the value ranges. The i-th
5949  *         value of \a arrBg (\a arrBg[ i ]) gives the lowest value of the i-th range,
5950  *         and the greatest value of the i-th range equals to \a arrBg[ i+1 ] - 1. \a
5951  *         arrBg containing \a n values defines \a n-1 ranges. The last value of \a arrBg
5952  *         should be more than every value in \a this array.
5953  *  \param [in] arrEnd - specifies the end of the array \a arrBg, so that
5954  *              the last value of \a arrBg is \a arrEnd[ -1 ].
5955  *  \param [out] castArr - a new instance of DataArrayInt, of same size as \a this array
5956  *         (same number of tuples and components), the caller is to delete 
5957  *         using decrRef() as it is no more needed.
5958  *         This array contains indices of ranges for every value of \a this array. I.e.
5959  *         the i-th value of \a castArr gives the index of range the i-th value of \a this
5960  *         belongs to. Or, in other words, this parameter contains for each tuple in \a
5961  *         this in which cast it holds.
5962  *  \param [out] rankInsideCast - a new instance of DataArrayInt, of same size as \a this
5963  *         array, the caller is to delete using decrRef() as it is no more needed.
5964  *         This array contains ranks of values of \a this array within ranges
5965  *         they belongs to. I.e. the i-th value of \a rankInsideCast gives the rank of
5966  *         the i-th value of \a this array within the \a castArr[ i ]-th range, to which
5967  *         the i-th value of \a this belongs to. Or, in other words, this param contains 
5968  *         for each tuple its rank inside its cast. The rank is computed as difference
5969  *         between the value and the lowest value of range.
5970  *  \param [out] castsPresent - a new instance of DataArrayInt, containing indices of
5971  *         ranges (casts) to which at least one value of \a this array belongs.
5972  *         Or, in other words, this param contains the casts that \a this contains.
5973  *         The caller is to delete this array using decrRef() as it is no more needed.
5974  *
5975  * \b Example: If \a this contains [6,5,0,3,2,7,8,1,4] and \a arrBg contains [0,4,9] then
5976  *            the output of this method will be : 
5977  * - \a castArr       : [1,1,0,0,0,1,1,0,1]
5978  * - \a rankInsideCast: [2,1,0,3,2,3,4,1,0]
5979  * - \a castsPresent  : [0,1]
5980  *
5981  * I.e. values of \a this array belong to 2 ranges: #0 and #1. Value 6 belongs to the
5982  * range #1 and its rank within this range is 2; etc.
5983  *
5984  *  \throw If \a this->getNumberOfComponents() != 1.
5985  *  \throw If \a arrEnd - arrBg < 2.
5986  *  \throw If any value of \a this is not less than \a arrEnd[-1].
5987  */
5988 void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
5989                                      DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception)
5990 {
5991   checkAllocated();
5992   if(getNumberOfComponents()!=1)
5993     throw INTERP_KERNEL::Exception("Call splitByValueRange  method on DataArrayInt with only one component, you can call 'rearrange' method before !");
5994   int nbOfTuples=getNumberOfTuples();
5995   std::size_t nbOfCast=std::distance(arrBg,arrEnd);
5996   if(nbOfCast<2)
5997     throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !");
5998   nbOfCast--;
5999   const int *work=getConstPointer();
6000   typedef std::reverse_iterator<const int *> rintstart;
6001   rintstart bg(arrEnd);//OK no problem because size of 'arr' is greater or equal 2
6002   rintstart end2(arrBg);
6003   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
6004   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=DataArrayInt::New();
6005   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret3=DataArrayInt::New();
6006   ret1->alloc(nbOfTuples,1);
6007   ret2->alloc(nbOfTuples,1);
6008   int *ret1Ptr=ret1->getPointer();
6009   int *ret2Ptr=ret2->getPointer();
6010   std::set<std::size_t> castsDetected;
6011   for(int i=0;i<nbOfTuples;i++)
6012     {
6013       rintstart res=std::find_if(bg,end2,std::bind2nd(std::less_equal<int>(), work[i]));
6014       std::size_t pos=std::distance(bg,res);
6015       std::size_t pos2=nbOfCast-pos;
6016       if(pos2<nbOfCast)
6017         {
6018           ret1Ptr[i]=(int)pos2;
6019           ret2Ptr[i]=work[i]-arrBg[pos2];
6020           castsDetected.insert(pos2);
6021         }
6022       else
6023         {
6024           std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " should be in [0," << *bg << ") !";
6025           throw INTERP_KERNEL::Exception(oss.str().c_str());
6026         }
6027     }
6028   ret3->alloc((int)castsDetected.size(),1);
6029   std::copy(castsDetected.begin(),castsDetected.end(),ret3->getPointer());
6030   castArr=ret1.retn();
6031   rankInsideCast=ret2.retn();
6032   castsPresent=ret3.retn();
6033 }
6034
6035 /*!
6036  * Creates a one-dimensional DataArrayInt (\a res) whose contents are computed from 
6037  * values of \a this (\a a) and the given (\a indArr) arrays as follows:
6038  * \a res[ \a indArr[ \a a[ i ]]] = i. I.e. for each value in place i \a v = \a a[ i ],
6039  * new value in place \a indArr[ \a v ] is i.
6040  *  \param [in] indArrBg - the array holding indices within the result array to assign
6041  *         indices of values of \a this array pointing to values of \a indArrBg.
6042  *  \param [in] indArrEnd - specifies the end of the array \a indArrBg, so that
6043  *              the last value of \a indArrBg is \a indArrEnd[ -1 ].
6044  *  \return DataArrayInt * - the new instance of DataArrayInt.
6045  *          The caller is to delete this result array using decrRef() as it is no more
6046  *          needed.
6047  *  \throw If \a this->getNumberOfComponents() != 1.
6048  *  \throw If any value of \a this array is not a valid index for \a indArrBg array.
6049  *  \throw If any value of \a indArrBg is not a valid index for \a this array.
6050  */
6051 DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception)
6052 {
6053   checkAllocated();
6054   if(getNumberOfComponents()!=1)
6055     throw INTERP_KERNEL::Exception("Call transformWithIndArrR method on DataArrayInt with only one component, you can call 'rearrange' method before !");
6056   int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
6057   int nbOfTuples=getNumberOfTuples();
6058   const int *pt=getConstPointer();
6059   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6060   ret->alloc(nbOfTuples,1);
6061   ret->fillWithValue(-1);
6062   int *tmp=ret->getPointer();
6063   for(int i=0;i<nbOfTuples;i++,pt++)
6064     {
6065       if(*pt>=0 && *pt<nbElemsIn)
6066         {
6067           int pos=indArrBg[*pt];
6068           if(pos>=0 && pos<nbOfTuples)
6069             tmp[pos]=i;
6070           else
6071             {
6072               std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value of new pos is " << pos << " ( indArrBg[" << *pt << "]) ! Should be in [0," << nbOfTuples << ") !";
6073               throw INTERP_KERNEL::Exception(oss.str().c_str());
6074             }
6075         }
6076       else
6077         {
6078           std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn << " !";
6079           throw INTERP_KERNEL::Exception(oss.str().c_str());
6080         }
6081     }
6082   return ret.retn();
6083 }
6084
6085 /*!
6086  * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
6087  * from values of \a this array, which is supposed to contain a renumbering map in 
6088  * "Old to New" mode. The result array contains a renumbering map in "New to Old" mode.
6089  * To know how to use the renumbering maps see \ref MEDCouplingArrayRenumbering.
6090  *  \param [in] newNbOfElem - the number of tuples in the result array.
6091  *  \return DataArrayInt * - the new instance of DataArrayInt.
6092  *          The caller is to delete this result array using decrRef() as it is no more
6093  *          needed.
6094  * 
6095  *  \ref cpp_mcdataarrayint_invertarrayo2n2n2o "Here is a C++ example".<br>
6096  *  \ref py_mcdataarrayint_invertarrayo2n2n2o  "Here is a Python example".
6097  */
6098 DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
6099 {
6100   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6101   ret->alloc(newNbOfElem,1);
6102   int nbOfOldNodes=getNumberOfTuples();
6103   const int *old2New=getConstPointer();
6104   int *pt=ret->getPointer();
6105   for(int i=0;i!=nbOfOldNodes;i++)
6106     if(old2New[i]!=-1)
6107       pt[old2New[i]]=i;
6108   return ret.retn();
6109 }
6110
6111 /*!
6112  * This method is similar to DataArrayInt::invertArrayO2N2N2O except that 
6113  * 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]
6114  */
6115 DataArrayInt *DataArrayInt::invertArrayO2N2N2OBis(int newNbOfElem) const throw(INTERP_KERNEL::Exception)
6116 {
6117   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6118   ret->alloc(newNbOfElem,1);
6119   int nbOfOldNodes=getNumberOfTuples();
6120   const int *old2New=getConstPointer();
6121   int *pt=ret->getPointer();
6122   for(int i=nbOfOldNodes-1;i>=0;i--)
6123     if(old2New[i]!=-1)
6124       pt[old2New[i]]=i;
6125   return ret.retn();
6126 }
6127
6128 /*!
6129  * Creates a one-dimensional DataArrayInt of given length, whose contents are computed
6130  * from values of \a this array, which is supposed to contain a renumbering map in 
6131  * "New to Old" mode. The result array contains a renumbering map in "Old to New" mode.
6132  * To know how to use the renumbering maps see \ref MEDCouplingArrayRenumbering.
6133  *  \param [in] newNbOfElem - the number of tuples in the result array.
6134  *  \return DataArrayInt * - the new instance of DataArrayInt.
6135  *          The caller is to delete this result array using decrRef() as it is no more
6136  *          needed.
6137  * 
6138  *  \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
6139  *
6140  *  \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
6141  */
6142 DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
6143 {
6144   checkAllocated();
6145   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6146   ret->alloc(oldNbOfElem,1);
6147   const int *new2Old=getConstPointer();
6148   int *pt=ret->getPointer();
6149   std::fill(pt,pt+oldNbOfElem,-1);
6150   int nbOfNewElems=getNumberOfTuples();
6151   for(int i=0;i<nbOfNewElems;i++)
6152     {
6153       int v(new2Old[i]);
6154       if(v>=0 && v<oldNbOfElem)
6155          pt[v]=i;
6156       else
6157         {
6158           std::ostringstream oss; oss << "DataArrayInt::invertArrayN2O2O2N : in new id #" << i << " old value is " << v << " expected to be in [0," << oldNbOfElem << ") !";
6159           throw INTERP_KERNEL::Exception(oss.str().c_str());
6160         }
6161     }
6162   return ret.retn();
6163 }
6164
6165 /*!
6166  * Equivalent to DataArrayInt::isEqual except that if false the reason of
6167  * mismatch is given.
6168  * 
6169  * \param [in] other the instance to be compared with \a this
6170  * \param [out] reason In case of inequality returns the reason.
6171  * \sa DataArrayInt::isEqual
6172  */
6173 bool DataArrayInt::isEqualIfNotWhy(const DataArrayInt& other, std::string& reason) const throw(INTERP_KERNEL::Exception)
6174 {
6175   if(!areInfoEqualsIfNotWhy(other,reason))
6176     return false;
6177   return _mem.isEqual(other._mem,0,reason);
6178 }
6179
6180 /*!
6181  * Checks if \a this and another DataArrayInt are fully equal. For more info see
6182  * \ref MEDCouplingArrayBasicsCompare.
6183  *  \param [in] other - an instance of DataArrayInt to compare with \a this one.
6184  *  \return bool - \a true if the two arrays are equal, \a false else.
6185  */
6186 bool DataArrayInt::isEqual(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
6187 {
6188   std::string tmp;
6189   return isEqualIfNotWhy(other,tmp);
6190 }
6191
6192 /*!
6193  * Checks if values of \a this and another DataArrayInt are equal. For more info see
6194  * \ref MEDCouplingArrayBasicsCompare.
6195  *  \param [in] other - an instance of DataArrayInt to compare with \a this one.
6196  *  \return bool - \a true if the values of two arrays are equal, \a false else.
6197  */
6198 bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
6199 {
6200   std::string tmp;
6201   return _mem.isEqual(other._mem,0,tmp);
6202 }
6203
6204 /*!
6205  * Checks if values of \a this and another DataArrayInt are equal. Comparison is
6206  * performed on sorted value sequences.
6207  * For more info see\ref MEDCouplingArrayBasicsCompare.
6208  *  \param [in] other - an instance of DataArrayInt to compare with \a this one.
6209  *  \return bool - \a true if the sorted values of two arrays are equal, \a false else.
6210  */
6211 bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
6212 {
6213   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a=deepCpy();
6214   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> b=other.deepCpy();
6215   a->sort();
6216   b->sort();
6217   return a->isEqualWithoutConsideringStr(*b);
6218 }
6219
6220 /*!
6221  * This method compares content of input vector \a v and \a this.
6222  * If for each id in \a this v[id]==True and for all other ids id2 not in \a this v[id2]==False, true is returned.
6223  * For performance reasons \a this is expected to be sorted ascendingly. If not an exception will be thrown.
6224  *
6225  * \param [in] v - the vector of 'flags' to be compared with \a this.
6226  *
6227  * \throw If \a this is not sorted ascendingly.
6228  * \throw If \a this has not exactly one component.
6229  * \throw If \a this is not allocated.
6230  */
6231 bool DataArrayInt::isFittingWith(const std::vector<bool>& v) const throw(INTERP_KERNEL::Exception)
6232 {
6233   checkAllocated();
6234   if(getNumberOfComponents()!=1)
6235     throw INTERP_KERNEL::Exception("DataArrayInt::isFittingWith : number of components of this should be equal to one !");
6236   int nbOfTuples(getNumberOfTuples());
6237   const int *w(begin()),*end2(end());
6238   int refVal=-std::numeric_limits<int>::max();
6239   int i=0;
6240   std::vector<bool>::const_iterator it(v.begin());
6241   for(;it!=v.end();it++,i++)
6242     {
6243       if(*it)
6244         {
6245           if(w!=end2)
6246             {
6247               if(*w++==i)
6248                 {
6249                   if(i>refVal)
6250                     refVal=i;
6251                   else
6252                     {
6253                       std::ostringstream oss; oss << "DataArrayInt::isFittingWith : At pos #" << std::distance(begin(),w-1) << " this is not sorted ascendingly !";
6254                       throw INTERP_KERNEL::Exception(oss.str().c_str());
6255                     }
6256                 }
6257               else
6258                 return false;
6259             }
6260           else
6261             return false;
6262         }
6263     }
6264   return w==end2;
6265 }
6266
6267 /*!
6268  * Sorts values of the array.
6269  *  \param [in] asc - \a true means ascending order, \a false, descending.
6270  *  \throw If \a this is not allocated.
6271  *  \throw If \a this->getNumberOfComponents() != 1.
6272  */
6273 void DataArrayInt::sort(bool asc) throw(INTERP_KERNEL::Exception)
6274 {
6275   checkAllocated();
6276   if(getNumberOfComponents()!=1)
6277     throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !");
6278   _mem.sort(asc);
6279   declareAsNew();
6280 }
6281
6282 /*!
6283  * Reverse the array values.
6284  *  \throw If \a this->getNumberOfComponents() < 1.
6285  *  \throw If \a this is not allocated.
6286  */
6287 void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception)
6288 {
6289   checkAllocated();
6290   _mem.reverse(getNumberOfComponents());
6291   declareAsNew();
6292 }
6293
6294 /*!
6295  * Checks that \a this array is consistently **increasing** or **decreasing** in value.
6296  * If not an exception is thrown.
6297  *  \param [in] increasing - if \a true, the array values should be increasing.
6298  *  \throw If sequence of values is not strictly monotonic in agreement with \a
6299  *         increasing arg.
6300  *  \throw If \a this->getNumberOfComponents() != 1.
6301  *  \throw If \a this is not allocated.
6302  */
6303 void DataArrayInt::checkMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6304 {
6305   if(!isMonotonic(increasing))
6306     {
6307       if (increasing)
6308         throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
6309       else
6310         throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
6311     }
6312 }
6313
6314 /*!
6315  * Checks that \a this array is consistently **increasing** or **decreasing** in value.
6316  *  \param [in] increasing - if \a true, array values should be increasing.
6317  *  \return bool - \a true if values change in accordance with \a increasing arg.
6318  *  \throw If \a this->getNumberOfComponents() != 1.
6319  *  \throw If \a this is not allocated.
6320  */
6321 bool DataArrayInt::isMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6322 {
6323   checkAllocated();
6324   if(getNumberOfComponents()!=1)
6325     throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !");
6326   int nbOfElements=getNumberOfTuples();
6327   const int *ptr=getConstPointer();
6328   if(nbOfElements==0)
6329     return true;
6330   int ref=ptr[0];
6331   if(increasing)
6332     {
6333       for(int i=1;i<nbOfElements;i++)
6334         {
6335           if(ptr[i]>=ref)
6336             ref=ptr[i];
6337           else
6338             return false;
6339         }
6340     }
6341   else
6342     {
6343       for(int i=1;i<nbOfElements;i++)
6344         {
6345           if(ptr[i]<=ref)
6346             ref=ptr[i];
6347           else
6348             return false;
6349         }
6350     }
6351   return true;
6352 }
6353
6354 /*!
6355  * This method check that array consistently INCREASING or DECREASING in value.
6356  */
6357 bool DataArrayInt::isStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6358 {
6359   checkAllocated();
6360   if(getNumberOfComponents()!=1)
6361     throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !");
6362   int nbOfElements=getNumberOfTuples();
6363   const int *ptr=getConstPointer();
6364   if(nbOfElements==0)
6365     return true;
6366   int ref=ptr[0];
6367   if(increasing)
6368     {
6369       for(int i=1;i<nbOfElements;i++)
6370         {
6371           if(ptr[i]>ref)
6372             ref=ptr[i];
6373           else
6374             return false;
6375         }
6376     }
6377   else
6378     {
6379       for(int i=1;i<nbOfElements;i++)
6380         {
6381           if(ptr[i]<ref)
6382             ref=ptr[i];
6383           else
6384             return false;
6385         }
6386     }
6387   return true;
6388 }
6389
6390 /*!
6391  * This method check that array consistently INCREASING or DECREASING in value.
6392  */
6393 void DataArrayInt::checkStrictlyMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception)
6394 {
6395   if(!isStrictlyMonotonic(increasing))
6396     {
6397       if (increasing)
6398         throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
6399       else
6400         throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
6401     }
6402 }
6403
6404 /*!
6405  * Creates a new one-dimensional DataArrayInt of the same size as \a this and a given
6406  * one-dimensional arrays that must be of the same length. The result array describes
6407  * correspondence between \a this and \a other arrays, so that 
6408  * <em> other.getIJ(i,0) == this->getIJ(ret->getIJ(i),0)</em>. If such a permutation is
6409  * not possible because some element in \a other is not in \a this, an exception is thrown.
6410  *  \param [in] other - an array to compute permutation to.
6411  *  \return DataArrayInt * - a new instance of DataArrayInt, which is a permutation array
6412  * from \a this to \a other. The caller is to delete this array using decrRef() as it is
6413  * no more needed.
6414  *  \throw If \a this->getNumberOfComponents() != 1.
6415  *  \throw If \a other->getNumberOfComponents() != 1.
6416  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples().
6417  *  \throw If \a other includes a value which is not in \a this array.
6418  * 
6419  *  \ref cpp_mcdataarrayint_buildpermutationarr "Here is a C++ example".
6420  *
6421  *  \ref py_mcdataarrayint_buildpermutationarr "Here is a Python example".
6422  */
6423 DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
6424 {
6425   checkAllocated();
6426   if(getNumberOfComponents()!=1 || other.getNumberOfComponents()!=1)
6427     throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' have to have exactly ONE component !");
6428   int nbTuple=getNumberOfTuples();
6429   other.checkAllocated();
6430   if(nbTuple!=other.getNumberOfTuples())
6431     throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' must have the same number of tuple !");
6432   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6433   ret->alloc(nbTuple,1);
6434   ret->fillWithValue(-1);
6435   const int *pt=getConstPointer();
6436   std::map<int,int> mm;
6437   for(int i=0;i<nbTuple;i++)
6438     mm[pt[i]]=i;
6439   pt=other.getConstPointer();
6440   int *retToFill=ret->getPointer();
6441   for(int i=0;i<nbTuple;i++)
6442     {
6443       std::map<int,int>::const_iterator it=mm.find(pt[i]);
6444       if(it==mm.end())
6445         {
6446           std::ostringstream oss; oss << "DataArrayInt::buildPermutationArr : Arrays mismatch : element (" << pt[i] << ") in 'other' not findable in 'this' !";
6447           throw INTERP_KERNEL::Exception(oss.str().c_str());
6448         }
6449       retToFill[i]=(*it).second;
6450     }
6451   return ret.retn();
6452 }
6453
6454 /*!
6455  * Sets a C array to be used as raw data of \a this. The previously set info
6456  *  of components is retained and re-sized. 
6457  * For more info see \ref MEDCouplingArraySteps1.
6458  *  \param [in] array - the C array to be used as raw data of \a this.
6459  *  \param [in] ownership - if \a true, \a array will be deallocated at destruction of \a this.
6460  *  \param [in] type - specifies how to deallocate \a array. If \a type == ParaMEDMEM::CPP_DEALLOC,
6461  *                     \c delete [] \c array; will be called. If \a type == ParaMEDMEM::C_DEALLOC,
6462  *                     \c free(\c array ) will be called.
6463  *  \param [in] nbOfTuple - new number of tuples in \a this.
6464  *  \param [in] nbOfCompo - new number of components in \a this.
6465  */
6466 void DataArrayInt::useArray(const int *array, bool ownership,  DeallocType type, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
6467 {
6468   _info_on_compo.resize(nbOfCompo);
6469   _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
6470   declareAsNew();
6471 }
6472
6473 void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
6474 {
6475   _info_on_compo.resize(nbOfCompo);
6476   _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
6477   declareAsNew();
6478 }
6479
6480 /*!
6481  * Returns a new DataArrayInt holding the same values as \a this array but differently
6482  * arranged in memory. If \a this array holds 2 components of 3 values:
6483  * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
6484  * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
6485  *  \warning Do not confuse this method with transpose()!
6486  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6487  *          is to delete using decrRef() as it is no more needed.
6488  *  \throw If \a this is not allocated.
6489  */
6490 DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
6491 {
6492   checkAllocated();
6493   if(_mem.isNull())
6494     throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
6495   int *tab=_mem.fromNoInterlace(getNumberOfComponents());
6496   DataArrayInt *ret=DataArrayInt::New();
6497   ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
6498   return ret;
6499 }
6500
6501 /*!
6502  * Returns a new DataArrayInt holding the same values as \a this array but differently
6503  * arranged in memory. If \a this array holds 2 components of 3 values:
6504  * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
6505  * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
6506  *  \warning Do not confuse this method with transpose()!
6507  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6508  *          is to delete using decrRef() as it is no more needed.
6509  *  \throw If \a this is not allocated.
6510  */
6511 DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception)
6512 {
6513   checkAllocated();
6514   if(_mem.isNull())
6515     throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
6516   int *tab=_mem.toNoInterlace(getNumberOfComponents());
6517   DataArrayInt *ret=DataArrayInt::New();
6518   ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
6519   return ret;
6520 }
6521
6522 /*!
6523  * Permutes values of \a this array as required by \a old2New array. The values are
6524  * permuted so that \c new[ \a old2New[ i ]] = \c old[ i ]. Number of tuples remains
6525  * the same as in \this one.
6526  * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
6527  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6528  *  \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
6529  *     giving a new position for i-th old value.
6530  */
6531 void DataArrayInt::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::Exception)
6532 {
6533   checkAllocated();
6534   int nbTuples=getNumberOfTuples();
6535   int nbOfCompo=getNumberOfComponents();
6536   int *tmp=new int[nbTuples*nbOfCompo];
6537   const int *iptr=getConstPointer();
6538   for(int i=0;i<nbTuples;i++)
6539     {
6540       int v=old2New[i];
6541       if(v>=0 && v<nbTuples)
6542         std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*v);
6543       else
6544         {
6545           std::ostringstream oss; oss << "DataArrayInt::renumberInPlace : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
6546           throw INTERP_KERNEL::Exception(oss.str().c_str());
6547         }
6548     }
6549   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
6550   delete [] tmp;
6551   declareAsNew();
6552 }
6553
6554 /*!
6555  * Permutes values of \a this array as required by \a new2Old array. The values are
6556  * permuted so that \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of tuples remains
6557  * the same as in \this one.
6558  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6559  *  \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
6560  *     giving a previous position of i-th new value.
6561  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6562  *          is to delete using decrRef() as it is no more needed.
6563  */
6564 void DataArrayInt::renumberInPlaceR(const int *new2Old) throw(INTERP_KERNEL::Exception)
6565 {
6566   checkAllocated();
6567   int nbTuples=getNumberOfTuples();
6568   int nbOfCompo=getNumberOfComponents();
6569   int *tmp=new int[nbTuples*nbOfCompo];
6570   const int *iptr=getConstPointer();
6571   for(int i=0;i<nbTuples;i++)
6572     {
6573       int v=new2Old[i];
6574       if(v>=0 && v<nbTuples)
6575         std::copy(iptr+nbOfCompo*v,iptr+nbOfCompo*(v+1),tmp+nbOfCompo*i);
6576       else
6577         {
6578           std::ostringstream oss; oss << "DataArrayInt::renumberInPlaceR : At place #" << i << " value is " << v << " ! Should be in [0," << nbTuples << ") !";
6579           throw INTERP_KERNEL::Exception(oss.str().c_str());
6580         }
6581     }
6582   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
6583   delete [] tmp;
6584   declareAsNew();
6585 }
6586
6587 /*!
6588  * Returns a copy of \a this array with values permuted as required by \a old2New array.
6589  * The values are permuted so that  \c new[ \a old2New[ i ]] = \c old[ i ].
6590  * Number of tuples in the result array remains the same as in \this one.
6591  * If a permutation reduction is needed, renumberAndReduce() should be used.
6592  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6593  *  \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
6594  *          giving a new position for i-th old value.
6595  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6596  *          is to delete using decrRef() as it is no more needed.
6597  *  \throw If \a this is not allocated.
6598  */
6599 DataArrayInt *DataArrayInt::renumber(const int *old2New) const throw(INTERP_KERNEL::Exception)
6600 {
6601   checkAllocated();
6602   int nbTuples=getNumberOfTuples();
6603   int nbOfCompo=getNumberOfComponents();
6604   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6605   ret->alloc(nbTuples,nbOfCompo);
6606   ret->copyStringInfoFrom(*this);
6607   const int *iptr=getConstPointer();
6608   int *optr=ret->getPointer();
6609   for(int i=0;i<nbTuples;i++)
6610     std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
6611   ret->copyStringInfoFrom(*this);
6612   return ret.retn();
6613 }
6614
6615 /*!
6616  * Returns a copy of \a this array with values permuted as required by \a new2Old array.
6617  * The values are permuted so that  \c new[ i ] = \c old[ \a new2Old[ i ]]. Number of
6618  * tuples in the result array remains the same as in \this one.
6619  * If a permutation reduction is needed, substr() or selectByTupleId() should be used.
6620  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6621  *  \param [in] new2Old - C array of length equal to \a this->getNumberOfTuples()
6622  *     giving a previous position of i-th new value.
6623  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6624  *          is to delete using decrRef() as it is no more needed.
6625  */
6626 DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception)
6627 {
6628   checkAllocated();
6629   int nbTuples=getNumberOfTuples();
6630   int nbOfCompo=getNumberOfComponents();
6631   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6632   ret->alloc(nbTuples,nbOfCompo);
6633   ret->copyStringInfoFrom(*this);
6634   const int *iptr=getConstPointer();
6635   int *optr=ret->getPointer();
6636   for(int i=0;i<nbTuples;i++)
6637     std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+nbOfCompo*i);
6638   ret->copyStringInfoFrom(*this);
6639   return ret.retn();
6640 }
6641
6642 /*!
6643  * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
6644  * of size \a newNbOfTuple and it's values are permuted as required by \a old2New array.
6645  * The values are permuted so that  \c new[ \a old2New[ i ]] = \c old[ i ] for all
6646  * \a old2New[ i ] >= 0. In other words every i-th tuple in \a this array, for which 
6647  * \a old2New[ i ] is negative, is missing from the result array.
6648  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6649  *  \param [in] old2New - C array of length equal to \a this->getNumberOfTuples()
6650  *     giving a new position for i-th old tuple and giving negative position for
6651  *     for i-th old tuple that should be omitted.
6652  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6653  *          is to delete using decrRef() as it is no more needed.
6654  */
6655 DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const throw(INTERP_KERNEL::Exception)
6656 {
6657   checkAllocated();
6658   int nbTuples=getNumberOfTuples();
6659   int nbOfCompo=getNumberOfComponents();
6660   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6661   ret->alloc(newNbOfTuple,nbOfCompo);
6662   const int *iptr=getConstPointer();
6663   int *optr=ret->getPointer();
6664   for(int i=0;i<nbTuples;i++)
6665     {
6666       int w=old2New[i];
6667       if(w>=0)
6668         std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
6669     }
6670   ret->copyStringInfoFrom(*this);
6671   return ret.retn();
6672 }
6673
6674 /*!
6675  * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
6676  * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
6677  * \a new2OldBg array.
6678  * The values are permuted so that  \c new[ i ] = \c old[ \a new2OldBg[ i ]].
6679  * This method is equivalent to renumberAndReduce() except that convention in input is
6680  * \c new2old and \b not \c old2new.
6681  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6682  *  \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
6683  *              tuple index in \a this array to fill the i-th tuple in the new array.
6684  *  \param [in] new2OldEnd - specifies the end of the permutation array that starts at
6685  *              \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
6686  *              \a new2OldBg <= \a pi < \a new2OldEnd.
6687  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6688  *          is to delete using decrRef() as it is no more needed.
6689  */
6690 DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
6691 {
6692   checkAllocated();
6693   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6694   int nbComp=getNumberOfComponents();
6695   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
6696   ret->copyStringInfoFrom(*this);
6697   int *pt=ret->getPointer();
6698   const int *srcPt=getConstPointer();
6699   int i=0;
6700   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
6701     std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
6702   ret->copyStringInfoFrom(*this);
6703   return ret.retn();
6704 }
6705
6706 /*!
6707  * Returns a shorten and permuted copy of \a this array. The new DataArrayInt is
6708  * of size \a new2OldEnd - \a new2OldBg and it's values are permuted as required by
6709  * \a new2OldBg array.
6710  * The values are permuted so that  \c new[ i ] = \c old[ \a new2OldBg[ i ]].
6711  * This method is equivalent to renumberAndReduce() except that convention in input is
6712  * \c new2old and \b not \c old2new.
6713  * This method is equivalent to selectByTupleId() except that it prevents coping data
6714  * from behind the end of \a this array.
6715  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6716  *  \param [in] new2OldBg - pointer to the beginning of a permutation array that gives a
6717  *              tuple index in \a this array to fill the i-th tuple in the new array.
6718  *  \param [in] new2OldEnd - specifies the end of the permutation array that starts at
6719  *              \a new2OldBg, so that pointer to a tuple index (\a pi) varies as this:
6720  *              \a new2OldBg <= \a pi < \a new2OldEnd.
6721  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6722  *          is to delete using decrRef() as it is no more needed.
6723  *  \throw If \a new2OldEnd - \a new2OldBg > \a this->getNumberOfTuples().
6724  */
6725 DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
6726 {
6727   checkAllocated();
6728   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6729   int nbComp=getNumberOfComponents();
6730   int oldNbOfTuples=getNumberOfTuples();
6731   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
6732   ret->copyStringInfoFrom(*this);
6733   int *pt=ret->getPointer();
6734   const int *srcPt=getConstPointer();
6735   int i=0;
6736   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
6737     if(*w>=0 && *w<oldNbOfTuples)
6738       std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
6739     else
6740       throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
6741   ret->copyStringInfoFrom(*this);
6742   return ret.retn();
6743 }
6744
6745 /*!
6746  * Returns a shorten copy of \a this array. The new DataArrayInt contains every
6747  * (\a bg + \c i * \a step)-th tuple of \a this array located before the \a end2-th
6748  * tuple. Indices of the selected tuples are the same as ones returned by the Python
6749  * command \c range( \a bg, \a end2, \a step ).
6750  * This method is equivalent to selectByTupleIdSafe() except that the input array is
6751  * not constructed explicitly.
6752  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6753  *  \param [in] bg - index of the first tuple to copy from \a this array.
6754  *  \param [in] end2 - index of the tuple before which the tuples to copy are located.
6755  *  \param [in] step - index increment to get index of the next tuple to copy.
6756  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6757  *          is to delete using decrRef() as it is no more needed.
6758  *  \sa DataArrayInt::substr.
6759  */
6760 DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
6761 {
6762   checkAllocated();
6763   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6764   int nbComp=getNumberOfComponents();
6765   int newNbOfTuples=GetNumberOfItemGivenBESRelative(bg,end2,step,"DataArrayInt::selectByTupleId2 : ");
6766   ret->alloc(newNbOfTuples,nbComp);
6767   int *pt=ret->getPointer();
6768   const int *srcPt=getConstPointer()+bg*nbComp;
6769   for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
6770     std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
6771   ret->copyStringInfoFrom(*this);
6772   return ret.retn();
6773 }
6774
6775 /*!
6776  * Returns a shorten copy of \a this array. The new DataArrayInt contains ranges
6777  * of tuples specified by \a ranges parameter.
6778  * For more info on renumbering see \ref MEDCouplingArrayRenumbering.
6779  *  \param [in] ranges - std::vector of std::pair's each of which defines a range
6780  *              of tuples in [\c begin,\c end) format.
6781  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
6782  *          is to delete using decrRef() as it is no more needed.
6783  *  \throw If \a end < \a begin.
6784  *  \throw If \a end > \a this->getNumberOfTuples().
6785  *  \throw If \a this is not allocated.
6786  */
6787 DataArray *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
6788 {
6789   checkAllocated();
6790   int nbOfComp=getNumberOfComponents();
6791   int nbOfTuplesThis=getNumberOfTuples();
6792   if(ranges.empty())
6793     {
6794       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6795       ret->alloc(0,nbOfComp);
6796       ret->copyStringInfoFrom(*this);
6797       return ret.retn();
6798     }
6799   int ref=ranges.front().first;
6800   int nbOfTuples=0;
6801   bool isIncreasing=true;
6802   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
6803     {
6804       if((*it).first<=(*it).second)
6805         {
6806           if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
6807             {
6808               nbOfTuples+=(*it).second-(*it).first;
6809               if(isIncreasing)
6810                 isIncreasing=ref<=(*it).first;
6811               ref=(*it).second;
6812             }
6813           else
6814             {
6815               std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
6816               oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
6817               throw INTERP_KERNEL::Exception(oss.str().c_str());
6818             }
6819         }
6820       else
6821         {
6822           std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
6823           oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
6824           throw INTERP_KERNEL::Exception(oss.str().c_str());
6825         }
6826     }
6827   if(isIncreasing && nbOfTuplesThis==nbOfTuples)
6828     return deepCpy();
6829   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
6830   ret->alloc(nbOfTuples,nbOfComp);
6831   ret->copyStringInfoFrom(*this);
6832   const int *src=getConstPointer();
6833   int *work=ret->getPointer();
6834   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
6835     work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
6836   return ret.retn();
6837 }
6838
6839 /*!
6840  * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode.
6841  * This map, if applied to \a this array, would make it sorted. For example, if
6842  * \a this array contents are [9,10,0,6,4,11,3,7] then the contents of the result array
6843  * are [5,6,0,3,2,7,1,4]; if this result array (\a res) is used as an argument in call
6844  * \a this->renumber(\a res) then the returned array contains [0,3,4,6,7,9,10,11].
6845  * This method is useful for renumbering (in MED file for example). For more info
6846  * on renumbering see \ref MEDCouplingArrayRenumbering.
6847  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
6848  *          array using decrRef() as it is no more needed.
6849  *  \throw If \a this is not allocated.
6850  *  \throw If \a this->getNumberOfComponents() != 1.
6851  *  \throw If there are equal values in \a this array.
6852  */
6853 DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception)
6854 {
6855   checkAllocated();
6856   if(getNumberOfComponents()!=1)
6857     throw INTERP_KERNEL::Exception("DataArrayInt::checkAndPreparePermutation : number of components must == 1 !");
6858   int nbTuples=getNumberOfTuples();
6859   const int *pt=getConstPointer();
6860   int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
6861   DataArrayInt *ret=DataArrayInt::New();
6862   ret->useArray(pt2,true,C_DEALLOC,nbTuples,1);
6863   return ret;
6864 }
6865
6866 /*!
6867  * This method tries to find the permutation to apply to the first input \a ids1 to obtain the same array (without considering strings informations) the second
6868  * input array \a ids2.
6869  * \a ids1 and \a ids2 are expected to be both a list of ids (both with number of components equal to one) not sorted and with values that can be negative.
6870  * This method will throw an exception is no such permutation array can be obtained. It is typically the case if there is some ids in \a ids1 not in \a ids2 or
6871  * inversely.
6872  * In case of success (no throw) : \c ids1->renumber(ret)->isEqual(ids2) where \a ret is the return of this method.
6873  *
6874  * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
6875  *          array using decrRef() as it is no more needed.
6876  * \throw If either ids1 or ids2 is null not allocated or not with one components.
6877  * 
6878  */
6879 DataArrayInt *DataArrayInt::FindPermutationFromFirstToSecond(const DataArrayInt *ids1, const DataArrayInt *ids2) throw(INTERP_KERNEL::Exception)
6880 {
6881   if(!ids1 || !ids2)
6882     throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two input arrays must be not null !");
6883   if(!ids1->isAllocated() || !ids2->isAllocated())
6884     throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two input arrays must be allocated !");
6885   if(ids1->getNumberOfComponents()!=1 || ids2->getNumberOfComponents()!=1)
6886     throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two input arrays have exactly one component !");
6887   if(ids1->getNumberOfTuples()!=ids2->getNumberOfTuples())
6888     {
6889       std::ostringstream oss; oss << "DataArrayInt::FindPermutationFromFirstToSecond : first array has " << ids1->getNumberOfTuples() << " tuples and the second one " << ids2->getNumberOfTuples() << " tuples ! No chance to find a permutation between the 2 arrays !";
6890       throw INTERP_KERNEL::Exception(oss.str().c_str());
6891     }
6892   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(ids1->deepCpy());
6893   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(ids2->deepCpy());
6894   p1->sort(true); p2->sort(true);
6895   if(!p1->isEqualWithoutConsideringStr(*p2))
6896     throw INTERP_KERNEL::Exception("DataArrayInt::FindPermutationFromFirstToSecond : the two arrays are not lying on same ids ! Impossible to find a permutation betwenn the 2 arrays !");
6897   p1=ids1->checkAndPreparePermutation();
6898   p2=ids2->checkAndPreparePermutation();
6899   p2=p2->invertArrayO2N2N2O(p2->getNumberOfTuples());
6900   p2=p2->selectByTupleIdSafe(p1->begin(),p1->end());
6901   return p2.retn();
6902 }
6903
6904 /*!
6905  * Returns two arrays describing a surjective mapping from \a this set of values (\a A)
6906  * onto a set of values of size \a targetNb (\a B). The surjective function is 
6907  * \a B[ \a A[ i ]] = i. That is to say that for each \a id in [0,\a targetNb), where \a
6908  * targetNb < \a this->getNumberOfTuples(), there exists at least one tupleId (\a tid) so
6909  * that <em> this->getIJ( tid, 0 ) == id</em>. <br>
6910  * The first of out arrays returns indices of elements of \a this array, grouped by their
6911  * place in the set \a B. The second out array is the index of the first one; it shows how
6912  * many elements of \a A are mapped into each element of \a B. <br>
6913  * For more info on
6914  * mapping and its usage in renumbering see \ref MEDCouplingArrayRenumbering. <br>
6915  * \b Example:
6916  * - \a this: [0,3,2,3,2,2,1,2]
6917  * - \a targetNb: 4
6918  * - \a arr:  [0,  6,  2,4,5,7,  1,3]
6919  * - \a arrI: [0,1,2,6,8]
6920  *
6921  * This result means: <br>
6922  * the element of \a B 0 encounters within \a A once (\a arrI[ 0+1 ] - \a arrI[ 0 ]) and
6923  * its index within \a A is 0 ( \a arr[ 0:1 ] == \a arr[ \a arrI[ 0 ] : \a arrI[ 0+1 ]]);<br>
6924  * the element of \a B 2 encounters within \a A 4 times (\a arrI[ 2+1 ] - \a arrI[ 2 ]) and
6925  * its indices within \a A are [2,4,5,7] ( \a arr[ 2:6 ] == \a arr[ \a arrI[ 2 ] : 
6926  * \a arrI[ 2+1 ]]); <br> etc.
6927  *  \param [in] targetNb - the size of the set \a B. \a targetNb must be equal or more
6928  *         than the maximal value of \a A.
6929  *  \param [out] arr - a new instance of DataArrayInt returning indices of
6930  *         elements of \a this, grouped by their place in the set \a B. The caller is to delete
6931  *         this array using decrRef() as it is no more needed.
6932  *  \param [out] arrI - a new instance of DataArrayInt returning size of groups of equal
6933  *         elements of \a this. The caller is to delete this array using decrRef() as it
6934  *         is no more needed.
6935  *  \throw If \a this is not allocated.
6936  *  \throw If \a this->getNumberOfComponents() != 1.
6937  *  \throw If any value in \a this is more or equal to \a targetNb.
6938  */
6939 void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception)
6940 {
6941   checkAllocated();
6942   if(getNumberOfComponents()!=1)
6943     throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : number of components must == 1 !");
6944   int nbOfTuples=getNumberOfTuples();
6945   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
6946   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retI(DataArrayInt::New());
6947   retI->alloc(targetNb+1,1);
6948   const int *input=getConstPointer();
6949   std::vector< std::vector<int> > tmp(targetNb);
6950   for(int i=0;i<nbOfTuples;i++)
6951     {
6952       int tmp2=input[i];
6953       if(tmp2>=0 && tmp2<targetNb)
6954         tmp[tmp2].push_back(i);
6955       else
6956         {
6957           std::ostringstream oss; oss << "DataArrayInt::changeSurjectiveFormat : At pos " << i << " presence of element " << tmp2 << " ! should be in [0," << targetNb << ") !";
6958           throw INTERP_KERNEL::Exception(oss.str().c_str());
6959         }
6960     }
6961   int *retIPtr=retI->getPointer();
6962   *retIPtr=0;
6963   for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++,retIPtr++)
6964     retIPtr[1]=retIPtr[0]+(int)((*it1).size());
6965   if(nbOfTuples!=retI->getIJ(targetNb,0))
6966     throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : big problem should never happen !");
6967   ret->alloc(nbOfTuples,1);
6968   int *retPtr=ret->getPointer();
6969   for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++)
6970     retPtr=std::copy((*it1).begin(),(*it1).end(),retPtr);
6971   arr=ret.retn();
6972   arrI=retI.retn();
6973 }
6974
6975
6976 /*!
6977  * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode computed
6978  * from a zip representation of a surjective format (returned e.g. by
6979  * \ref ParaMEDMEM::DataArrayDouble::findCommonTuples() "DataArrayDouble::findCommonTuples()"
6980  * for example). The result array minimizes the permutation. <br>
6981  * For more info on renumbering see \ref MEDCouplingArrayRenumbering. <br>
6982  * \b Example: <br>
6983  * - \a nbOfOldTuples: 10 
6984  * - \a arr          : [0,3, 5,7,9]
6985  * - \a arrIBg       : [0,2,5]
6986  * - \a newNbOfTuples: 7
6987  * - result array    : [0,1,2,0,3,4,5,4,6,4]
6988  *
6989  *  \param [in] nbOfOldTuples - number of tuples in the initial array \a arr.
6990  *  \param [in] arr - the array of tuple indices grouped by \a arrIBg array.
6991  *  \param [in] arrIBg - the array dividing all indices stored in \a arr into groups of
6992  *         (indices of) equal values. Its every element (except the last one) points to
6993  *         the first element of a group of equal values.
6994  *  \param [in] arrIEnd - specifies the end of \a arrIBg, so that the last element of \a
6995  *          arrIBg is \a arrIEnd[ -1 ].
6996  *  \param [out] newNbOfTuples - number of tuples after surjection application.
6997  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
6998  *          array using decrRef() as it is no more needed.
6999  *  \throw If any value of \a arr breaks condition ( 0 <= \a arr[ i ] < \a nbOfOldTuples ).
7000  */
7001 DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
7002 {
7003   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
7004   ret->alloc(nbOfOldTuples,1);
7005   int *pt=ret->getPointer();
7006   std::fill(pt,pt+nbOfOldTuples,-1);
7007   int nbOfGrps=((int)std::distance(arrIBg,arrIEnd))-1;
7008   const int *cIPtr=arrIBg;
7009   for(int i=0;i<nbOfGrps;i++)
7010     pt[arr[cIPtr[i]]]=-(i+2);
7011   int newNb=0;
7012   for(int iNode=0;iNode<nbOfOldTuples;iNode++)
7013     {
7014       if(pt[iNode]<0)
7015         {
7016           if(pt[iNode]==-1)
7017             pt[iNode]=newNb++;
7018           else
7019             {
7020               int grpId=-(pt[iNode]+2);
7021               for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
7022                 {
7023                   if(arr[j]>=0 && arr[j]<nbOfOldTuples)
7024                     pt[arr[j]]=newNb;
7025                   else
7026                     {
7027                       std::ostringstream oss; oss << "DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : With element #" << j << " value is " << arr[j] << " should be in [0," << nbOfOldTuples << ") !";
7028                       throw INTERP_KERNEL::Exception(oss.str().c_str());
7029                     }
7030                 }
7031               newNb++;
7032             }
7033         }
7034     }
7035   newNbOfTuples=newNb;
7036   return ret.retn();
7037 }
7038
7039 /*!
7040  * Returns a new DataArrayInt containing a renumbering map in "New to Old" mode,
7041  * which if applied to \a this array would make it sorted ascendingly.
7042  * For more info on renumbering see \ref MEDCouplingArrayRenumbering. <br>
7043  * \b Example: <br>
7044  * - \a this: [2,0,1,1,0,1,2,0,1,1,0,0]
7045  * - result: [10,0,5,6,1,7,11,2,8,9,3,4]
7046  * - after applying result to \a this: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2] 
7047  *
7048  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
7049  *          array using decrRef() as it is no more needed.
7050  *  \throw If \a this is not allocated.
7051  *  \throw If \a this->getNumberOfComponents() != 1.
7052  */
7053 DataArrayInt *DataArrayInt::buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception)
7054 {
7055   checkAllocated();
7056   if(getNumberOfComponents()!=1)
7057     throw INTERP_KERNEL::Exception("DataArrayInt::buildPermArrPerLevel : number of components must == 1 !");
7058   int nbOfTuples=getNumberOfTuples();
7059   const int *pt=getConstPointer();
7060   std::map<int,int> m;
7061   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
7062   ret->alloc(nbOfTuples,1);
7063   int *opt=ret->getPointer();
7064   for(int i=0;i<nbOfTuples;i++,pt++,opt++)
7065     {
7066       int val=*pt;
7067       std::map<int,int>::iterator it=m.find(val);
7068       if(it!=m.end())
7069         {
7070           *opt=(*it).second;
7071           (*it).second++;
7072         }
7073       else
7074         {
7075           *opt=0;
7076           m.insert(std::pair<int,int>(val,1));
7077         }
7078     }
7079   int sum=0;
7080   for(std::map<int,int>::iterator it=m.begin();it!=m.end();it++)
7081     {
7082       int vt=(*it).second;
7083       (*it).second=sum;
7084       sum+=vt;
7085     }
7086   pt=getConstPointer();
7087   opt=ret->getPointer();
7088   for(int i=0;i<nbOfTuples;i++,pt++,opt++)
7089     *opt+=m[*pt];
7090   //
7091   return ret.retn();
7092 }
7093
7094 /*!
7095  * Checks if contents of \a this array are equal to that of an array filled with
7096  * iota(). This method is particularly useful for DataArrayInt instances that represent
7097  * a renumbering array to check the real need in renumbering. 
7098  *  \return bool - \a true if \a this array contents == \a range( \a this->getNumberOfTuples())
7099  *  \throw If \a this is not allocated.
7100  *  \throw If \a this->getNumberOfComponents() != 1.
7101  */
7102 bool DataArrayInt::isIdentity() const throw(INTERP_KERNEL::Exception)
7103 {
7104   checkAllocated();
7105   if(getNumberOfComponents()!=1)
7106     return false;
7107   int nbOfTuples=getNumberOfTuples();
7108   const int *pt=getConstPointer();
7109   for(int i=0;i<nbOfTuples;i++,pt++)
7110     if(*pt!=i)
7111       return false;
7112   return true;
7113 }
7114
7115 /*!
7116  * Checks if all values in \a this array are equal to \a val.
7117  *  \param [in] val - value to check equality of array values to.
7118  *  \return bool - \a true if all values are \a val.
7119  *  \throw If \a this is not allocated.
7120  *  \throw If \a this->getNumberOfComponents() != 1
7121  */
7122 bool DataArrayInt::isUniform(int val) const throw(INTERP_KERNEL::Exception)
7123 {
7124   checkAllocated();
7125   if(getNumberOfComponents()!=1)
7126     throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
7127   int nbOfTuples=getNumberOfTuples();
7128   const int *w=getConstPointer();
7129   const int *end2=w+nbOfTuples;
7130   for(;w!=end2;w++)
7131     if(*w!=val)
7132       return false;
7133   return true;
7134 }
7135
7136 /*!
7137  * Creates a new DataArrayDouble and assigns all (textual and numerical) data of \a this
7138  * array to the new one.
7139  *  \return DataArrayDouble * - the new instance of DataArrayInt.
7140  */
7141 DataArrayDouble *DataArrayInt::convertToDblArr() const
7142 {
7143   checkAllocated();
7144   DataArrayDouble *ret=DataArrayDouble::New();
7145   ret->alloc(getNumberOfTuples(),getNumberOfComponents());
7146   std::size_t nbOfVals=getNbOfElems();
7147   const int *src=getConstPointer();
7148   double *dest=ret->getPointer();
7149   std::copy(src,src+nbOfVals,dest);
7150   ret->copyStringInfoFrom(*this);
7151   return ret;
7152 }
7153
7154 /*!
7155  * Returns a shorten copy of \a this array. The new DataArrayInt contains all
7156  * tuples starting from the \a tupleIdBg-th tuple and including all tuples located before
7157  * the \a tupleIdEnd-th one. This methods has a similar behavior as std::string::substr().
7158  * This method is a specialization of selectByTupleId2().
7159  *  \param [in] tupleIdBg - index of the first tuple to copy from \a this array.
7160  *  \param [in] tupleIdEnd - index of the tuple before which the tuples to copy are located.
7161  *          If \a tupleIdEnd == -1, all the tuples till the end of \a this array are copied.
7162  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
7163  *          is to delete using decrRef() as it is no more needed.
7164  *  \throw If \a tupleIdBg < 0.
7165  *  \throw If \a tupleIdBg > \a this->getNumberOfTuples().
7166     \throw If \a tupleIdEnd != -1 && \a tupleIdEnd < \a this->getNumberOfTuples().
7167  *  \sa DataArrayInt::selectByTupleId2
7168  */
7169 DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
7170 {
7171   checkAllocated();
7172   int nbt=getNumberOfTuples();
7173   if(tupleIdBg<0)
7174     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
7175   if(tupleIdBg>nbt)
7176     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
7177   int trueEnd=tupleIdEnd;
7178   if(tupleIdEnd!=-1)
7179     {
7180       if(tupleIdEnd>nbt)
7181         throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
7182     }
7183   else
7184     trueEnd=nbt;
7185   int nbComp=getNumberOfComponents();
7186   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
7187   ret->alloc(trueEnd-tupleIdBg,nbComp);
7188   ret->copyStringInfoFrom(*this);
7189   std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
7190   return ret.retn();
7191 }
7192
7193 /*!
7194  * Changes the number of components within \a this array so that its raw data **does
7195  * not** change, instead splitting this data into tuples changes.
7196  *  \warning This method erases all (name and unit) component info set before!
7197  *  \param [in] newNbOfComp - number of components for \a this array to have.
7198  *  \throw If \a this is not allocated
7199  *  \throw If getNbOfElems() % \a newNbOfCompo != 0.
7200  *  \throw If \a newNbOfCompo is lower than 1.
7201  *  \throw If the rearrange method would lead to a number of tuples higher than 2147483647 (maximal capacity of int32 !).
7202  *  \warning This method erases all (name and unit) component info set before!
7203  */
7204 void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
7205 {
7206   checkAllocated();
7207   if(newNbOfCompo<1)
7208     throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : input newNbOfCompo must be > 0 !");
7209   std::size_t nbOfElems=getNbOfElems();
7210   if(nbOfElems%newNbOfCompo!=0)
7211     throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
7212   if(nbOfElems/newNbOfCompo>(std::size_t)std::numeric_limits<int>::max())
7213     throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : the rearrangement leads to too high number of tuples (> 2147483647) !");
7214   _info_on_compo.clear();
7215   _info_on_compo.resize(newNbOfCompo);
7216   declareAsNew();
7217 }
7218
7219 /*!
7220  * Changes the number of components within \a this array to be equal to its number
7221  * of tuples, and inversely its number of tuples to become equal to its number of 
7222  * components. So that its raw data **does not** change, instead splitting this
7223  * data into tuples changes.
7224  *  \warning This method erases all (name and unit) component info set before!
7225  *  \warning Do not confuse this method with fromNoInterlace() and toNoInterlace()!
7226  *  \throw If \a this is not allocated.
7227  *  \sa rearrange()
7228  */
7229 void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception)
7230 {
7231   checkAllocated();
7232   int nbOfTuples=getNumberOfTuples();
7233   rearrange(nbOfTuples);
7234 }
7235
7236 /*!
7237  * Returns a shorten or extended copy of \a this array. If \a newNbOfComp is less
7238  * than \a this->getNumberOfComponents() then the result array is shorten as each tuple
7239  * is truncated to have \a newNbOfComp components, keeping first components. If \a
7240  * newNbOfComp is more than \a this->getNumberOfComponents() then the result array is
7241  * expanded as each tuple is populated with \a dftValue to have \a newNbOfComp
7242  * components.  
7243  *  \param [in] newNbOfComp - number of components for the new array to have.
7244  *  \param [in] dftValue - value assigned to new values added to the new array.
7245  *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
7246  *          is to delete using decrRef() as it is no more needed.
7247  *  \throw If \a this is not allocated.
7248  */
7249 DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception)
7250 {
7251   checkAllocated();
7252   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
7253   ret->alloc(getNumberOfTuples(),newNbOfComp);
7254   const int *oldc=getConstPointer();
7255   int *nc=ret->getPointer();
7256   int nbOfTuples=getNumberOfTuples();
7257   int oldNbOfComp=getNumberOfComponents();
7258   int dim=std::min(oldNbOfComp,newNbOfComp);
7259   for(int i=0;i<nbOfTuples;i++)
7260     {
7261       int j=0;
7262       for(;j<dim;j++)
7263         nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
7264       for(;j<newNbOfComp;j++)
7265         nc[newNbOfComp*i+j]=dftValue;
7266     }
7267   ret->setName(getName().c_str());
7268   for(int i=0;i<dim;i++)
7269     ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
7270   ret->setName(getName().c_str());
7271   return ret.retn();
7272 }
7273
7274 /*!
7275  * Changes number of tuples in the array. If the new number of tuples is smaller
7276  * than the current number the array is truncated, otherwise the array is extended.
7277  *  \param [in] nbOfTuples - new number of tuples. 
7278  *  \throw If \a this is not allocated.
7279  *  \throw If \a nbOfTuples is negative.
7280  */
7281 void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
7282 {
7283   if(nbOfTuples<0)
7284     throw INTERP_KERNEL::Exception("DataArrayInt::reAlloc : input new number of tuples should be >=0 !");
7285   checkAllocated();
7286   _mem.reAlloc(getNumberOfComponents()*(std::size_t)nbOfTuples);
7287   declareAsNew();
7288 }
7289
7290
7291 /*!
7292  * Returns a copy of \a this array composed of selected components.
7293  * The new DataArrayInt has the same number of tuples but includes components
7294  * specified by \a compoIds parameter. So that getNbOfElems() of the result array
7295  * can be either less, same or more than \a this->getNbOfElems().
7296  *  \param [in] compoIds - sequence of zero based indices of components to include
7297  *              into the new array.
7298  *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
7299  *          is to delete using decrRef() as it is no more needed.
7300  *  \throw If \a this is not allocated.
7301  *  \throw If a component index (\a i) is not valid: 
7302  *         \a i < 0 || \a i >= \a this->getNumberOfComponents().
7303  *
7304  *  \ref py_mcdataarrayint_keepselectedcomponents "Here is a Python example".
7305  */
7306 DataArray *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
7307 {
7308   checkAllocated();
7309   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
7310   int newNbOfCompo=(int)compoIds.size();
7311   int oldNbOfCompo=getNumberOfComponents();
7312   for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
7313     DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
7314   int nbOfTuples=getNumberOfTuples();
7315   ret->alloc(nbOfTuples,newNbOfCompo);
7316   ret->copyPartOfStringInfoFrom(*this,compoIds);
7317   const int *oldc=getConstPointer();
7318   int *nc=ret->getPointer();
7319   for(int i=0;i<nbOfTuples;i++)
7320     for(int j=0;j<newNbOfCompo;j++,nc++)
7321       *nc=oldc[i*oldNbOfCompo+compoIds[j]];
7322   return ret.retn();
7323 }
7324
7325 /*!
7326  * Appends components of another array to components of \a this one, tuple by tuple.
7327  * So that the number of tuples of \a this array remains the same and the number of 
7328  * components increases.
7329  *  \param [in] other - the DataArrayInt to append to \a this one.
7330  *  \throw If \a this is not allocated.
7331  *  \throw If \a this and \a other arrays have different number of tuples.
7332  *
7333  *  \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
7334  *
7335  *  \ref py_mcdataarrayint_meldwith "Here is a Python example".
7336  */
7337 void DataArrayInt::meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
7338 {
7339   if(!other)
7340     throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
7341   checkAllocated();
7342   other->checkAllocated();
7343   int nbOfTuples=getNumberOfTuples();
7344   if(nbOfTuples!=other->getNumberOfTuples())
7345     throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
7346   int nbOfComp1=getNumberOfComponents();
7347   int nbOfComp2=other->getNumberOfComponents();
7348   int *newArr=(int *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(int));
7349   int *w=newArr;
7350   const int *inp1=getConstPointer();
7351   const int *inp2=other->getConstPointer();
7352   for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
7353     {
7354       w=std::copy(inp1,inp1+nbOfComp1,w);
7355       w=std::copy(inp2,inp2+nbOfComp2,w);
7356     }
7357   useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
7358   std::vector<int> compIds(nbOfComp2);
7359   for(int i=0;i<nbOfComp2;i++)
7360     compIds[i]=nbOfComp1+i;
7361   copyPartOfStringInfoFrom2(compIds,*other);
7362 }
7363
7364 /*!
7365  * Copy all components in a specified order from another DataArrayInt.
7366  * The specified components become the first ones in \a this array.
7367  * Both numerical and textual data is copied. The number of tuples in \a this and
7368  * the other array can be different.
7369  *  \param [in] a - the array to copy data from.
7370  *  \param [in] compoIds - sequence of zero based indices of components, data of which is
7371  *              to be copied.
7372  *  \throw If \a a is NULL.
7373  *  \throw If \a compoIds.size() != \a a->getNumberOfComponents().
7374  *  \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
7375  *
7376  *  \ref py_mcdataarrayint_setselectedcomponents "Here is a Python example".
7377  */
7378 void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
7379 {
7380   if(!a)
7381     throw INTERP_KERNEL::Exception("DataArrayInt::setSelectedComponents : input DataArrayInt is NULL !");
7382   checkAllocated();
7383   a->checkAllocated();
7384   copyPartOfStringInfoFrom2(compoIds,*a);
7385   std::size_t partOfCompoSz=compoIds.size();
7386   int nbOfCompo=getNumberOfComponents();
7387   int nbOfTuples=std::min(getNumberOfTuples(),a->getNumberOfTuples());
7388   const int *ac=a->getConstPointer();
7389   int *nc=getPointer();
7390   for(int i=0;i<nbOfTuples;i++)
7391     for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
7392       nc[nbOfCompo*i+compoIds[j]]=*ac;
7393 }
7394
7395 /*!
7396  * Copy all values from another DataArrayInt into specified tuples and components
7397  * of \a this array. Textual data is not copied.
7398  * The tree parameters defining set of indices of tuples and components are similar to
7399  * the tree parameters of the Python function \c range(\c start,\c stop,\c step).
7400  *  \param [in] a - the array to copy values from.
7401  *  \param [in] bgTuples - index of the first tuple of \a this array to assign values to.
7402  *  \param [in] endTuples - index of the tuple before which the tuples to assign to
7403  *              are located.
7404  *  \param [in] stepTuples - index increment to get index of the next tuple to assign to.
7405  *  \param [in] bgComp - index of the first component of \a this array to assign values to.
7406  *  \param [in] endComp - index of the component before which the components to assign
7407  *              to are located.
7408  *  \param [in] stepComp - index increment to get index of the next component to assign to.
7409  *  \param [in] strictCompoCompare - if \a true (by default), then \a a->getNumberOfComponents() 
7410  *              must be equal to the number of columns to assign to, else an
7411  *              exception is thrown; if \a false, then it is only required that \a
7412  *              a->getNbOfElems() equals to number of values to assign to (this condition
7413  *              must be respected even if \a strictCompoCompare is \a true). The number of 
7414  *              values to assign to is given by following Python expression:
7415  *              \a nbTargetValues = 
7416  *              \c len(\c range(\a bgTuples,\a endTuples,\a stepTuples)) *
7417  *              \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
7418  *  \throw If \a a is NULL.
7419  *  \throw If \a a is not allocated.
7420  *  \throw If \a this is not allocated.
7421  *  \throw If parameters specifying tuples and components to assign to do not give a
7422  *            non-empty range of increasing indices.
7423  *  \throw If \a a->getNbOfElems() != \a nbTargetValues.
7424  *  \throw If \a strictCompoCompare == \a true && \a a->getNumberOfComponents() !=
7425  *            \c len(\c range(\a bgComp,\a endComp,\a stepComp)).
7426  *
7427  *  \ref py_mcdataarrayint_setpartofvalues1 "Here is a Python example".
7428  */
7429 void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7430 {
7431   if(!a)
7432     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues1 : DataArrayInt pointer in input is NULL !");
7433   const char msg[]="DataArrayInt::setPartOfValues1";
7434   checkAllocated();
7435   a->checkAllocated();
7436   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7437   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7438   int nbComp=getNumberOfComponents();
7439   int nbOfTuples=getNumberOfTuples();
7440   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7441   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7442   bool assignTech=true;
7443   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7444     {
7445       if(strictCompoCompare)
7446         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7447     }
7448   else
7449     {
7450       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7451       assignTech=false;
7452     }
7453   int *pt=getPointer()+bgTuples*nbComp+bgComp;
7454   const int *srcPt=a->getConstPointer();
7455   if(assignTech)
7456     {
7457       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7458         for(int j=0;j<newNbOfComp;j++,srcPt++)
7459           pt[j*stepComp]=*srcPt;
7460     }
7461   else
7462     {
7463       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7464         {
7465           const int *srcPt2=srcPt;
7466           for(int j=0;j<newNbOfComp;j++,srcPt2++)
7467             pt[j*stepComp]=*srcPt2;
7468         }
7469     }
7470 }
7471
7472 /*!
7473  * Assign a given value to values at specified tuples and components of \a this array.
7474  * The tree parameters defining set of indices of tuples and components are similar to
7475  * the tree parameters of the Python function \c range(\c start,\c stop,\c step)..
7476  *  \param [in] a - the value to assign.
7477  *  \param [in] bgTuples - index of the first tuple of \a this array to assign to.
7478  *  \param [in] endTuples - index of the tuple before which the tuples to assign to
7479  *              are located.
7480  *  \param [in] stepTuples - index increment to get index of the next tuple to assign to.
7481  *  \param [in] bgComp - index of the first component of \a this array to assign to.
7482  *  \param [in] endComp - index of the component before which the components to assign
7483  *              to are located.
7484  *  \param [in] stepComp - index increment to get index of the next component to assign to.
7485  *  \throw If \a this is not allocated.
7486  *  \throw If parameters specifying tuples and components to assign to, do not give a
7487  *            non-empty range of increasing indices or indices are out of a valid range
7488  *            for \this array.
7489  *
7490  *  \ref py_mcdataarrayint_setpartofvaluessimple1 "Here is a Python example".
7491  */
7492 void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
7493 {
7494   const char msg[]="DataArrayInt::setPartOfValuesSimple1";
7495   checkAllocated();
7496   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7497   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7498   int nbComp=getNumberOfComponents();
7499   int nbOfTuples=getNumberOfTuples();
7500   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7501   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7502   int *pt=getPointer()+bgTuples*nbComp+bgComp;
7503   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7504     for(int j=0;j<newNbOfComp;j++)
7505       pt[j*stepComp]=a;
7506 }
7507
7508
7509 /*!
7510  * Copy all values from another DataArrayInt (\a a) into specified tuples and 
7511  * components of \a this array. Textual data is not copied.
7512  * The tuples and components to assign to are defined by C arrays of indices.
7513  * There are two *modes of usage*:
7514  * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
7515  *   of \a a is assigned to its own location within \a this array. 
7516  * - If \a a includes one tuple, then all values of \a a are assigned to the specified
7517  *   components of every specified tuple of \a this array. In this mode it is required
7518  *   that \a a->getNumberOfComponents() equals to the number of specified components.
7519  * 
7520  *  \param [in] a - the array to copy values from.
7521  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7522  *              assign values of \a a to.
7523  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7524  *              pointer to a tuple index <em>(pi)</em> varies as this: 
7525  *              \a bgTuples <= \a pi < \a endTuples.
7526  *  \param [in] bgComp - pointer to an array of component indices of \a this array to
7527  *              assign values of \a a to.
7528  *  \param [in] endComp - specifies the end of the array \a bgTuples, so that
7529  *              pointer to a component index <em>(pi)</em> varies as this: 
7530  *              \a bgComp <= \a pi < \a endComp.
7531  *  \param [in] strictCompoCompare - this parameter is checked only if the
7532  *               *mode of usage* is the first; if it is \a true (default), 
7533  *               then \a a->getNumberOfComponents() must be equal 
7534  *               to the number of specified columns, else this is not required.
7535  *  \throw If \a a is NULL.
7536  *  \throw If \a a is not allocated.
7537  *  \throw If \a this is not allocated.
7538  *  \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
7539  *         out of a valid range for \a this array.
7540  *  \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
7541  *         if <em> a->getNumberOfComponents() != (endComp - bgComp) </em>.
7542  *  \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
7543  *         <em> a->getNumberOfComponents() != (endComp - bgComp)</em>.
7544  *
7545  *  \ref py_mcdataarrayint_setpartofvalues2 "Here is a Python example".
7546  */
7547 void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7548 {
7549   if(!a)
7550     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues2 : DataArrayInt pointer in input is NULL !");
7551   const char msg[]="DataArrayInt::setPartOfValues2";
7552   checkAllocated();
7553   a->checkAllocated();
7554   int nbComp=getNumberOfComponents();
7555   int nbOfTuples=getNumberOfTuples();
7556   for(const int *z=bgComp;z!=endComp;z++)
7557     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7558   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
7559   int newNbOfComp=(int)std::distance(bgComp,endComp);
7560   bool assignTech=true;
7561   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7562     {
7563       if(strictCompoCompare)
7564         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7565     }
7566   else
7567     {
7568       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7569       assignTech=false;
7570     }
7571   int *pt=getPointer();
7572   const int *srcPt=a->getConstPointer();
7573   if(assignTech)
7574     {    
7575       for(const int *w=bgTuples;w!=endTuples;w++)
7576         {
7577           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7578           for(const int *z=bgComp;z!=endComp;z++,srcPt++)
7579             {    
7580               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt;
7581             }
7582         }
7583     }
7584   else
7585     {
7586       for(const int *w=bgTuples;w!=endTuples;w++)
7587         {
7588           const int *srcPt2=srcPt;
7589           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7590           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
7591             {    
7592               pt[(std::size_t)(*w)*nbComp+(*z)]=*srcPt2;
7593             }
7594         }
7595     }
7596 }
7597
7598 /*!
7599  * Assign a given value to values at specified tuples and components of \a this array.
7600  * The tuples and components to assign to are defined by C arrays of indices.
7601  *  \param [in] a - the value to assign.
7602  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7603  *              assign \a a to.
7604  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7605  *              pointer to a tuple index (\a pi) varies as this: 
7606  *              \a bgTuples <= \a pi < \a endTuples.
7607  *  \param [in] bgComp - pointer to an array of component indices of \a this array to
7608  *              assign \a a to.
7609  *  \param [in] endComp - specifies the end of the array \a bgTuples, so that
7610  *              pointer to a component index (\a pi) varies as this: 
7611  *              \a bgComp <= \a pi < \a endComp.
7612  *  \throw If \a this is not allocated.
7613  *  \throw If any index of tuple/component given by <em>bgTuples / bgComp</em> is
7614  *         out of a valid range for \a this array.
7615  *
7616  *  \ref py_mcdataarrayint_setpartofvaluessimple2 "Here is a Python example".
7617  */
7618 void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
7619 {
7620   checkAllocated();
7621   int nbComp=getNumberOfComponents();
7622   int nbOfTuples=getNumberOfTuples();
7623   for(const int *z=bgComp;z!=endComp;z++)
7624     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7625   int *pt=getPointer();
7626   for(const int *w=bgTuples;w!=endTuples;w++)
7627     for(const int *z=bgComp;z!=endComp;z++)
7628       {
7629         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7630         pt[(std::size_t)(*w)*nbComp+(*z)]=a;
7631       }
7632 }
7633
7634 /*!
7635  * Copy all values from another DataArrayInt (\a a) into specified tuples and 
7636  * components of \a this array. Textual data is not copied.
7637  * The tuples to assign to are defined by a C array of indices.
7638  * The components to assign to are defined by three values similar to parameters of
7639  * the Python function \c range(\c start,\c stop,\c step).
7640  * There are two *modes of usage*:
7641  * - If \a a->getNbOfElems() equals to number of values to assign to, then every value
7642  *   of \a a is assigned to its own location within \a this array. 
7643  * - If \a a includes one tuple, then all values of \a a are assigned to the specified
7644  *   components of every specified tuple of \a this array. In this mode it is required
7645  *   that \a a->getNumberOfComponents() equals to the number of specified components.
7646  *
7647  *  \param [in] a - the array to copy values from.
7648  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7649  *              assign values of \a a to.
7650  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7651  *              pointer to a tuple index <em>(pi)</em> varies as this: 
7652  *              \a bgTuples <= \a pi < \a endTuples.
7653  *  \param [in] bgComp - index of the first component of \a this array to assign to.
7654  *  \param [in] endComp - index of the component before which the components to assign
7655  *              to are located.
7656  *  \param [in] stepComp - index increment to get index of the next component to assign to.
7657  *  \param [in] strictCompoCompare - this parameter is checked only in the first
7658  *               *mode of usage*; if \a strictCompoCompare is \a true (default), 
7659  *               then \a a->getNumberOfComponents() must be equal 
7660  *               to the number of specified columns, else this is not required.
7661  *  \throw If \a a is NULL.
7662  *  \throw If \a a is not allocated.
7663  *  \throw If \a this is not allocated.
7664  *  \throw If any index of tuple given by \a bgTuples is out of a valid range for 
7665  *         \a this array.
7666  *  \throw In the first *mode of usage*, if <em>strictCompoCompare == true </em> and
7667  *         if <em> a->getNumberOfComponents()</em> is unequal to the number of components
7668  *         defined by <em>(bgComp,endComp,stepComp)</em>.
7669  *  \throw In the second *mode of usage*, if \a a->getNumberOfTuples() != 1 or
7670  *         <em> a->getNumberOfComponents()</em> is unequal to the number of components
7671  *         defined by <em>(bgComp,endComp,stepComp)</em>.
7672  *  \throw If parameters specifying components to assign to, do not give a
7673  *            non-empty range of increasing indices or indices are out of a valid range
7674  *            for \this array.
7675  *
7676  *  \ref py_mcdataarrayint_setpartofvalues3 "Here is a Python example".
7677  */
7678 void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7679 {
7680   if(!a)
7681     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues3 : DataArrayInt pointer in input is NULL !");
7682   const char msg[]="DataArrayInt::setPartOfValues3";
7683   checkAllocated();
7684   a->checkAllocated();
7685   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7686   int nbComp=getNumberOfComponents();
7687   int nbOfTuples=getNumberOfTuples();
7688   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7689   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
7690   bool assignTech=true;
7691   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7692     {
7693       if(strictCompoCompare)
7694         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7695     }
7696   else
7697     {
7698       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7699       assignTech=false;
7700     }
7701   int *pt=getPointer()+bgComp;
7702   const int *srcPt=a->getConstPointer();
7703   if(assignTech)
7704     {
7705       for(const int *w=bgTuples;w!=endTuples;w++)
7706         for(int j=0;j<newNbOfComp;j++,srcPt++)
7707           {
7708             DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7709             pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt;
7710           }
7711     }
7712   else
7713     {
7714       for(const int *w=bgTuples;w!=endTuples;w++)
7715         {
7716           const int *srcPt2=srcPt;
7717           for(int j=0;j<newNbOfComp;j++,srcPt2++)
7718             {
7719               DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7720               pt[(std::size_t)(*w)*nbComp+j*stepComp]=*srcPt2;
7721             }
7722         }
7723     }
7724 }
7725
7726 /*!
7727  * Assign a given value to values at specified tuples and components of \a this array.
7728  * The tuples to assign to are defined by a C array of indices.
7729  * The components to assign to are defined by three values similar to parameters of
7730  * the Python function \c range(\c start,\c stop,\c step).
7731  *  \param [in] a - the value to assign.
7732  *  \param [in] bgTuples - pointer to an array of tuple indices of \a this array to
7733  *              assign \a a to.
7734  *  \param [in] endTuples - specifies the end of the array \a bgTuples, so that
7735  *              pointer to a tuple index <em>(pi)</em> varies as this: 
7736  *              \a bgTuples <= \a pi < \a endTuples.
7737  *  \param [in] bgComp - index of the first component of \a this array to assign to.
7738  *  \param [in] endComp - index of the component before which the components to assign
7739  *              to are located.
7740  *  \param [in] stepComp - index increment to get index of the next component to assign to.
7741  *  \throw If \a this is not allocated.
7742  *  \throw If any index of tuple given by \a bgTuples is out of a valid range for 
7743  *         \a this array.
7744  *  \throw If parameters specifying components to assign to, do not give a
7745  *            non-empty range of increasing indices or indices are out of a valid range
7746  *            for \this array.
7747  *
7748  *  \ref py_mcdataarrayint_setpartofvaluessimple3 "Here is a Python example".
7749  */
7750 void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
7751 {
7752   const char msg[]="DataArrayInt::setPartOfValuesSimple3";
7753   checkAllocated();
7754   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
7755   int nbComp=getNumberOfComponents();
7756   int nbOfTuples=getNumberOfTuples();
7757   DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value");
7758   int *pt=getPointer()+bgComp;
7759   for(const int *w=bgTuples;w!=endTuples;w++)
7760     for(int j=0;j<newNbOfComp;j++)
7761       {
7762         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
7763         pt[(std::size_t)(*w)*nbComp+j*stepComp]=a;
7764       }
7765 }
7766
7767 void DataArrayInt::setPartOfValues4(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
7768 {
7769   if(!a)
7770     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValues4 : input DataArrayInt is NULL !");
7771   const char msg[]="DataArrayInt::setPartOfValues4";
7772   checkAllocated();
7773   a->checkAllocated();
7774   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7775   int newNbOfComp=(int)std::distance(bgComp,endComp);
7776   int nbComp=getNumberOfComponents();
7777   for(const int *z=bgComp;z!=endComp;z++)
7778     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7779   int nbOfTuples=getNumberOfTuples();
7780   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7781   bool assignTech=true;
7782   if(a->getNbOfElems()==(std::size_t)newNbOfTuples*newNbOfComp)
7783     {
7784       if(strictCompoCompare)
7785         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
7786     }
7787   else
7788     {
7789       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
7790       assignTech=false;
7791     }
7792   const int *srcPt=a->getConstPointer();
7793   int *pt=getPointer()+bgTuples*nbComp;
7794   if(assignTech)
7795     {
7796       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7797         for(const int *z=bgComp;z!=endComp;z++,srcPt++)
7798           pt[*z]=*srcPt;
7799     }
7800   else
7801     {
7802       for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7803         {
7804           const int *srcPt2=srcPt;
7805           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
7806             pt[*z]=*srcPt2;
7807         }
7808     }
7809 }
7810
7811 void DataArrayInt::setPartOfValuesSimple4(int a, int bgTuples, int endTuples, int stepTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
7812 {
7813   const char msg[]="DataArrayInt::setPartOfValuesSimple4";
7814   checkAllocated();
7815   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
7816   int nbComp=getNumberOfComponents();
7817   for(const int *z=bgComp;z!=endComp;z++)
7818     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
7819   int nbOfTuples=getNumberOfTuples();
7820   DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value");
7821   int *pt=getPointer()+bgTuples*nbComp;
7822   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
7823     for(const int *z=bgComp;z!=endComp;z++)
7824       pt[*z]=a;
7825 }
7826
7827 /*!
7828  * Copy some tuples from another DataArrayInt into specified tuples
7829  * of \a this array. Textual data is not copied. Both arrays must have equal number of
7830  * components.
7831  * Both the tuples to assign and the tuples to assign to are defined by a DataArrayInt.
7832  * All components of selected tuples are copied.
7833  *  \param [in] a - the array to copy values from.
7834  *  \param [in] tuplesSelec - the array specifying both source tuples of \a a and
7835  *              target tuples of \a this. \a tuplesSelec has two components, and the
7836  *              first component specifies index of the source tuple and the second
7837  *              one specifies index of the target tuple.
7838  *  \throw If \a this is not allocated.
7839  *  \throw If \a a is NULL.
7840  *  \throw If \a a is not allocated.
7841  *  \throw If \a tuplesSelec is NULL.
7842  *  \throw If \a tuplesSelec is not allocated.
7843  *  \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
7844  *  \throw If \a tuplesSelec->getNumberOfComponents() != 2.
7845  *  \throw If any tuple index given by \a tuplesSelec is out of a valid range for 
7846  *         the corresponding (\a this or \a a) array.
7847  */
7848 void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
7849 {
7850   if(!a || !tuplesSelec)
7851     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : DataArrayInt pointer in input is NULL !");
7852   checkAllocated();
7853   a->checkAllocated();
7854   tuplesSelec->checkAllocated();
7855   int nbOfComp=getNumberOfComponents();
7856   if(nbOfComp!=a->getNumberOfComponents())
7857     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : This and a do not have the same number of components !");
7858   if(tuplesSelec->getNumberOfComponents()!=2)
7859     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
7860   int thisNt=getNumberOfTuples();
7861   int aNt=a->getNumberOfTuples();
7862   int *valsToSet=getPointer();
7863   const int *valsSrc=a->getConstPointer();
7864   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
7865     {
7866       if(tuple[1]>=0 && tuple[1]<aNt)
7867         {
7868           if(tuple[0]>=0 && tuple[0]<thisNt)
7869             std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
7870           else
7871             {
7872               std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
7873               oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
7874               throw INTERP_KERNEL::Exception(oss.str().c_str());
7875             }
7876         }
7877       else
7878         {
7879           std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
7880           oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
7881           throw INTERP_KERNEL::Exception(oss.str().c_str());
7882         }
7883     }
7884 }
7885
7886 /*!
7887  * Copy some tuples from another DataArrayInt (\a a) into contiguous tuples
7888  * of \a this array. Textual data is not copied. Both arrays must have equal number of
7889  * components.
7890  * The tuples to assign to are defined by index of the first tuple, and
7891  * their number is defined by \a tuplesSelec->getNumberOfTuples().
7892  * The tuples to copy are defined by values of a DataArrayInt.
7893  * All components of selected tuples are copied.
7894  *  \param [in] tupleIdStart - index of the first tuple of \a this array to assign
7895  *              values to.
7896  *  \param [in] a - the array to copy values from.
7897  *  \param [in] tuplesSelec - the array specifying tuples of \a a to copy.
7898  *  \throw If \a this is not allocated.
7899  *  \throw If \a a is NULL.
7900  *  \throw If \a a is not allocated.
7901  *  \throw If \a tuplesSelec is NULL.
7902  *  \throw If \a tuplesSelec is not allocated.
7903  *  \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
7904  *  \throw If \a tuplesSelec->getNumberOfComponents() != 1.
7905  *  \throw If <em>tupleIdStart + tuplesSelec->getNumberOfTuples() > this->getNumberOfTuples().</em>
7906  *  \throw If any tuple index given by \a tuplesSelec is out of a valid range for 
7907  *         \a a array.
7908  */
7909 void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArray *aBase, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
7910 {
7911   if(!aBase || !tuplesSelec)
7912     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : input DataArray is NULL !");
7913   const DataArrayInt *a=dynamic_cast<const DataArrayInt *>(aBase);
7914   if(!a)
7915     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : input DataArray aBase is not a DataArrayInt !");
7916   checkAllocated();
7917   a->checkAllocated();
7918   tuplesSelec->checkAllocated();
7919   int nbOfComp=getNumberOfComponents();
7920   if(nbOfComp!=a->getNumberOfComponents())
7921     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : This and a do not have the same number of components !");
7922   if(tuplesSelec->getNumberOfComponents()!=1)
7923     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
7924   int thisNt=getNumberOfTuples();
7925   int aNt=a->getNumberOfTuples();
7926   int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
7927   int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
7928   if(tupleIdStart+nbOfTupleToWrite>thisNt)
7929     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : invalid number range of values to write !");
7930   const int *valsSrc=a->getConstPointer();
7931   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
7932     {
7933       if(*tuple>=0 && *tuple<aNt)
7934         {
7935           std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
7936         }
7937       else
7938         {
7939           std::ostringstream oss; oss << "DataArrayInt::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
7940           oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
7941           throw INTERP_KERNEL::Exception(oss.str().c_str());
7942         }
7943     }
7944 }
7945
7946 /*!
7947  * Copy some tuples from another DataArrayInt (\a a) into contiguous tuples
7948  * of \a this array. Textual data is not copied. Both arrays must have equal number of
7949  * components.
7950  * The tuples to copy are defined by three values similar to parameters of
7951  * the Python function \c range(\c start,\c stop,\c step).
7952  * The tuples to assign to are defined by index of the first tuple, and
7953  * their number is defined by number of tuples to copy.
7954  * All components of selected tuples are copied.
7955  *  \param [in] tupleIdStart - index of the first tuple of \a this array to assign
7956  *              values to.
7957  *  \param [in] a - the array to copy values from.
7958  *  \param [in] bg - index of the first tuple to copy of the array \a a.
7959  *  \param [in] end2 - index of the tuple of \a a before which the tuples to copy
7960  *              are located.
7961  *  \param [in] step - index increment to get index of the next tuple to copy.
7962  *  \throw If \a this is not allocated.
7963  *  \throw If \a a is NULL.
7964  *  \throw If \a a is not allocated.
7965  *  \throw If <em>this->getNumberOfComponents() != a->getNumberOfComponents()</em>.
7966  *  \throw If <em>tupleIdStart + len(range(bg,end2,step)) > this->getNumberOfTuples().</em>
7967  *  \throw If parameters specifying tuples to copy, do not give a
7968  *            non-empty range of increasing indices or indices are out of a valid range
7969  *            for the array \a a.
7970  */
7971 void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArray *aBase, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
7972 {
7973   if(!aBase)
7974     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : input DataArray is NULL !");
7975   const DataArrayInt *a=dynamic_cast<const DataArrayInt *>(aBase);
7976   if(!a)
7977     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : input DataArray aBase is not a DataArrayInt !");
7978   checkAllocated();
7979   a->checkAllocated();
7980   int nbOfComp=getNumberOfComponents();
7981   const char msg[]="DataArrayInt::setContigPartOfSelectedValues2";
7982   int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
7983   if(nbOfComp!=a->getNumberOfComponents())
7984     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
7985   int thisNt=getNumberOfTuples();
7986   int aNt=a->getNumberOfTuples();
7987   int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
7988   if(tupleIdStart+nbOfTupleToWrite>thisNt)
7989     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid number range of values to write !");
7990   if(end2>aNt)
7991     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid range of values to read !");
7992   const int *valsSrc=a->getConstPointer()+bg*nbOfComp;
7993   for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
7994     {
7995       std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
7996     }
7997 }
7998
7999 /*!
8000  * Returns a value located at specified tuple and component.
8001  * This method is equivalent to DataArrayInt::getIJ() except that validity of
8002  * parameters is checked. So this method is safe but expensive if used to go through
8003  * all values of \a this.
8004  *  \param [in] tupleId - index of tuple of interest.
8005  *  \param [in] compoId - index of component of interest.
8006  *  \return double - value located by \a tupleId and \a compoId.
8007  *  \throw If \a this is not allocated.
8008  *  \throw If condition <em>( 0 <= tupleId < this->getNumberOfTuples() )</em> is violated.
8009  *  \throw If condition <em>( 0 <= compoId < this->getNumberOfComponents() )</em> is violated.
8010  */
8011 int DataArrayInt::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
8012 {
8013   checkAllocated();
8014   if(tupleId<0 || tupleId>=getNumberOfTuples())
8015     {
8016       std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
8017       throw INTERP_KERNEL::Exception(oss.str().c_str());
8018     }
8019   if(compoId<0 || compoId>=getNumberOfComponents())
8020     {
8021       std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
8022       throw INTERP_KERNEL::Exception(oss.str().c_str());
8023     }
8024   return _mem[tupleId*_info_on_compo.size()+compoId];
8025 }
8026
8027 /*!
8028  * Returns the first value of \a this. 
8029  *  \return int - the last value of \a this array.
8030  *  \throw If \a this is not allocated.
8031  *  \throw If \a this->getNumberOfComponents() != 1.
8032  *  \throw If \a this->getNumberOfTuples() < 1.
8033  */
8034 int DataArrayInt::front() const throw(INTERP_KERNEL::Exception)
8035 {
8036   checkAllocated();
8037   if(getNumberOfComponents()!=1)
8038     throw INTERP_KERNEL::Exception("DataArrayInt::front : number of components not equal to one !");
8039   int nbOfTuples=getNumberOfTuples();
8040   if(nbOfTuples<1)
8041     throw INTERP_KERNEL::Exception("DataArrayInt::front : number of tuples must be >= 1 !");
8042   return *(getConstPointer());
8043 }
8044
8045 /*!
8046  * Returns the last value of \a this. 
8047  *  \return int - the last value of \a this array.
8048  *  \throw If \a this is not allocated.
8049  *  \throw If \a this->getNumberOfComponents() != 1.
8050  *  \throw If \a this->getNumberOfTuples() < 1.
8051  */
8052 int DataArrayInt::back() const throw(INTERP_KERNEL::Exception)
8053 {
8054   checkAllocated();
8055   if(getNumberOfComponents()!=1)
8056     throw INTERP_KERNEL::Exception("DataArrayInt::back : number of components not equal to one !");
8057   int nbOfTuples=getNumberOfTuples();
8058   if(nbOfTuples<1)
8059     throw INTERP_KERNEL::Exception("DataArrayInt::back : number of tuples must be >= 1 !");
8060   return *(getConstPointer()+nbOfTuples-1);
8061 }
8062
8063 /*!
8064  * Assign pointer to one array to a pointer to another appay. Reference counter of
8065  * \a arrayToSet is incremented / decremented.
8066  *  \param [in] newArray - the pointer to array to assign to \a arrayToSet.
8067  *  \param [in,out] arrayToSet - the pointer to array to assign to.
8068  */
8069 void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
8070 {
8071   if(newArray!=arrayToSet)
8072     {
8073       if(arrayToSet)
8074         arrayToSet->decrRef();
8075       arrayToSet=newArray;
8076       if(arrayToSet)
8077         arrayToSet->incrRef();
8078     }
8079 }
8080
8081 DataArrayIntIterator *DataArrayInt::iterator() throw(INTERP_KERNEL::Exception)
8082 {
8083   return new DataArrayIntIterator(this);
8084 }
8085
8086 /*!
8087  * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to a
8088  * given one.
8089  *  \param [in] val - the value to find within \a this.
8090  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8091  *          array using decrRef() as it is no more needed.
8092  *  \throw If \a this is not allocated.
8093  *  \throw If \a this->getNumberOfComponents() != 1.
8094  */
8095 DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception)
8096 {
8097   checkAllocated();
8098   if(getNumberOfComponents()!=1)
8099     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
8100   const int *cptr=getConstPointer();
8101   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
8102   int nbOfTuples=getNumberOfTuples();
8103   for(int i=0;i<nbOfTuples;i++,cptr++)
8104     if(*cptr==val)
8105       ret->pushBackSilent(i);
8106   return ret.retn();
8107 }
8108
8109 /*!
8110  * Creates a new DataArrayInt containing IDs (indices) of tuples holding value \b not
8111  * equal to a given one. 
8112  *  \param [in] val - the value to ignore within \a this.
8113  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8114  *          array using decrRef() as it is no more needed.
8115  *  \throw If \a this is not allocated.
8116  *  \throw If \a this->getNumberOfComponents() != 1.
8117  */
8118 DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception)
8119 {
8120   checkAllocated();
8121   if(getNumberOfComponents()!=1)
8122     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !");
8123   const int *cptr=getConstPointer();
8124   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
8125   int nbOfTuples=getNumberOfTuples();
8126   for(int i=0;i<nbOfTuples;i++,cptr++)
8127     if(*cptr!=val)
8128       ret->pushBackSilent(i);
8129   return ret.retn();
8130 }
8131
8132
8133 /*!
8134  * Assigns \a newValue to all elements holding \a oldValue within \a this
8135  * one-dimensional array.
8136  *  \param [in] oldValue - the value to replace.
8137  *  \param [in] newValue - the value to assign.
8138  *  \return int - number of replacements performed.
8139  *  \throw If \a this is not allocated.
8140  *  \throw If \a this->getNumberOfComponents() != 1.
8141  */
8142 int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception)
8143 {
8144   checkAllocated();
8145   if(getNumberOfComponents()!=1)
8146     throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !");
8147   int *start=getPointer();
8148   int *end2=start+getNbOfElems();
8149   int ret=0;
8150   for(int *val=start;val!=end2;val++)
8151     {
8152       if(*val==oldValue)
8153         {
8154           *val=newValue;
8155           ret++;
8156         }
8157     }
8158   return ret;
8159 }
8160
8161 /*!
8162  * Creates a new DataArrayInt containing IDs (indices) of tuples holding value equal to
8163  * one of given values.
8164  *  \param [in] valsBg - an array of values to find within \a this array.
8165  *  \param [in] valsEnd - specifies the end of the array \a valsBg, so that
8166  *              the last value of \a valsBg is \a valsEnd[ -1 ].
8167  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8168  *          array using decrRef() as it is no more needed.
8169  *  \throw If \a this->getNumberOfComponents() != 1.
8170  */
8171 DataArrayInt *DataArrayInt::getIdsEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
8172 {
8173   if(getNumberOfComponents()!=1)
8174     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component, you can call 'rearrange' method before !");
8175   std::set<int> vals2(valsBg,valsEnd);
8176   const int *cptr=getConstPointer();
8177   std::vector<int> res;
8178   int nbOfTuples=getNumberOfTuples();
8179   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
8180   for(int i=0;i<nbOfTuples;i++,cptr++)
8181     if(vals2.find(*cptr)!=vals2.end())
8182       ret->pushBackSilent(i);
8183   return ret.retn();
8184 }
8185
8186 /*!
8187  * Creates a new DataArrayInt containing IDs (indices) of tuples holding values \b not
8188  * equal to any of given values.
8189  *  \param [in] valsBg - an array of values to ignore within \a this array.
8190  *  \param [in] valsEnd - specifies the end of the array \a valsBg, so that
8191  *              the last value of \a valsBg is \a valsEnd[ -1 ].
8192  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
8193  *          array using decrRef() as it is no more needed.
8194  *  \throw If \a this->getNumberOfComponents() != 1.
8195  */
8196 DataArrayInt *DataArrayInt::getIdsNotEqualList(const int *valsBg, const int *valsEnd) const throw(INTERP_KERNEL::Exception)
8197 {
8198   if(getNumberOfComponents()!=1)
8199     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : the array must have only one component, you can call 'rearrange' method before !");
8200   std::set<int> vals2(valsBg,valsEnd);
8201   const int *cptr=getConstPointer();
8202   std::vector<int> res;
8203   int nbOfTuples=getNumberOfTuples();
8204   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
8205   for(int i=0;i<nbOfTuples;i++,cptr++)
8206     if(vals2.find(*cptr)==vals2.end())
8207       ret->pushBackSilent(i);
8208   return ret.retn();
8209 }
8210
8211 /*!
8212  * This method is an extension of DataArrayInt::locateValue method because this method works for DataArrayInt with
8213  * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
8214  * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
8215  * If any the tuple id is returned. If not -1 is returned.
8216  * 
8217  * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
8218  * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
8219  *
8220  * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this.
8221  * \sa DataArrayInt::search, DataArrayInt::presenceOfTuple.
8222  */
8223 int DataArrayInt::locateTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
8224 {
8225   checkAllocated();
8226   int nbOfCompo=getNumberOfComponents();
8227   if(nbOfCompo==0)
8228     throw INTERP_KERNEL::Exception("DataArrayInt::locateTuple : 0 components in 'this' !");
8229   if(nbOfCompo!=(int)tupl.size())
8230     {
8231       std::ostringstream oss; oss << "DataArrayInt::locateTuple : 'this' contains " << nbOfCompo << " components and searching for a tuple of length " << tupl.size() << " !";
8232       throw INTERP_KERNEL::Exception(oss.str().c_str());
8233     }
8234   const int *cptr=getConstPointer();
8235   std::size_t nbOfVals=getNbOfElems();
8236   for(const int *work=cptr;work!=cptr+nbOfVals;)
8237     {
8238       work=std::search(work,cptr+nbOfVals,tupl.begin(),tupl.end());
8239       if(work!=cptr+nbOfVals)
8240         {
8241           if(std::distance(cptr,work)%nbOfCompo!=0)
8242             work++;
8243           else
8244             return std::distance(cptr,work)/nbOfCompo;
8245         }
8246     }
8247   return -1;
8248 }
8249
8250 /*!
8251  * This method searches the sequence specified in input parameter \b vals in \b this.
8252  * This works only for DataArrayInt having number of components equal to one (if not an INTERP_KERNEL::Exception will be thrown).
8253  * This method differs from DataArrayInt::locateTuple in that the position is internal raw data is not considered here contrary to DataArrayInt::locateTuple.
8254  * \sa DataArrayInt::locateTuple
8255  */
8256 int DataArrayInt::search(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
8257 {
8258   checkAllocated();
8259   int nbOfCompo=getNumberOfComponents();
8260   if(nbOfCompo!=1)
8261     throw INTERP_KERNEL::Exception("DataArrayInt::search : works only for DataArrayInt instance with one component !");
8262   const int *cptr=getConstPointer();
8263   std::size_t nbOfVals=getNbOfElems();
8264   const int *loc=std::search(cptr,cptr+nbOfVals,vals.begin(),vals.end());
8265   if(loc!=cptr+nbOfVals)
8266     return std::distance(cptr,loc);
8267   return -1;
8268 }
8269
8270 /*!
8271  * This method expects to be called when number of components of this is equal to one.
8272  * This method returns the tuple id, if it exists, of the first tuple equal to \b value.
8273  * If not any tuple contains \b value -1 is returned.
8274  * \sa DataArrayInt::presenceOfValue
8275  */
8276 int DataArrayInt::locateValue(int value) const throw(INTERP_KERNEL::Exception)
8277 {
8278   checkAllocated();
8279   if(getNumberOfComponents()!=1)
8280     throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
8281   const int *cptr=getConstPointer();
8282   int nbOfTuples=getNumberOfTuples();
8283   const int *ret=std::find(cptr,cptr+nbOfTuples,value);
8284   if(ret!=cptr+nbOfTuples)
8285     return std::distance(cptr,ret);
8286   return -1;
8287 }
8288
8289 /*!
8290  * This method expects to be called when number of components of this is equal to one.
8291  * This method returns the tuple id, if it exists, of the first tuple so that the value is contained in \b vals.
8292  * If not any tuple contains one of the values contained in 'vals' false is returned.
8293  * \sa DataArrayInt::presenceOfValue
8294  */
8295 int DataArrayInt::locateValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
8296 {
8297   checkAllocated();
8298   if(getNumberOfComponents()!=1)
8299     throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
8300   std::set<int> vals2(vals.begin(),vals.end());
8301   const int *cptr=getConstPointer();
8302   int nbOfTuples=getNumberOfTuples();
8303   for(const int *w=cptr;w!=cptr+nbOfTuples;w++)
8304     if(vals2.find(*w)!=vals2.end())
8305       return std::distance(cptr,w);
8306   return -1;
8307 }
8308
8309 /*!
8310  * This method returns the number of values in \a this that are equals to input parameter \a value.
8311  * This method only works for single component array.
8312  *
8313  * \return a value in [ 0, \c this->getNumberOfTuples() )
8314  *
8315  * \throw If \a this is not allocated
8316  *
8317  */
8318 int DataArrayInt::count(int value) const throw(INTERP_KERNEL::Exception)
8319 {
8320   int ret=0;
8321   checkAllocated();
8322   if(getNumberOfComponents()!=1)
8323     throw INTERP_KERNEL::Exception("DataArrayInt::count : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
8324   const int *vals=begin();
8325   int nbOfTuples=getNumberOfTuples();
8326   for(int i=0;i<nbOfTuples;i++,vals++)
8327     if(*vals==value)
8328       ret++;
8329   return ret;
8330 }
8331
8332 /*!
8333  * This method is an extension of DataArrayInt::presenceOfValue method because this method works for DataArrayInt with
8334  * any number of components excepted 0 (an INTERP_KERNEL::Exception is thrown in this case).
8335  * This method searches in \b this is there is a tuple that matched the input parameter \b tupl.
8336  * This method throws an INTERP_KERNEL::Exception if the number of components in \b this mismatches with the size of
8337  * the input vector. An INTERP_KERNEL::Exception is thrown too if \b this is not allocated.
8338  * \sa DataArrayInt::locateTuple
8339  */
8340 bool DataArrayInt::presenceOfTuple(const std::vector<int>& tupl) const throw(INTERP_KERNEL::Exception)
8341 {
8342   return locateTuple(tupl)!=-1;
8343 }
8344
8345
8346 /*!
8347  * Returns \a true if a given value is present within \a this one-dimensional array.
8348  *  \param [in] value - the value to find within \a this array.
8349  *  \return bool - \a true in case if \a value is present within \a this array.
8350  *  \throw If \a this is not allocated.
8351  *  \throw If \a this->getNumberOfComponents() != 1.
8352  *  \sa locateValue()
8353  */
8354 bool DataArrayInt::presenceOfValue(int value) const throw(INTERP_KERNEL::Exception)
8355 {
8356   return locateValue(value)!=-1;
8357 }
8358
8359 /*!
8360  * This method expects to be called when number of components of this is equal to one.
8361  * This method returns true if it exists a tuple so that the value is contained in \b vals.
8362  * If not any tuple contains one of the values contained in 'vals' false is returned.
8363  * \sa DataArrayInt::locateValue
8364  */
8365 bool DataArrayInt::presenceOfValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
8366 {
8367   return locateValue(vals)!=-1;
8368 }
8369
8370 /*!
8371  * Accumulates values of each component of \a this array.
8372  *  \param [out] res - an array of length \a this->getNumberOfComponents(), allocated 
8373  *         by the caller, that is filled by this method with sum value for each
8374  *         component.
8375  *  \throw If \a this is not allocated.
8376  */
8377 void DataArrayInt::accumulate(int *res) const throw(INTERP_KERNEL::Exception)
8378 {
8379   checkAllocated();
8380   const int *ptr=getConstPointer();
8381   int nbTuple=getNumberOfTuples();
8382   int nbComps=getNumberOfComponents();
8383   std::fill(res,res+nbComps,0);
8384   for(int i=0;i<nbTuple;i++)
8385     std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<int>());
8386 }
8387
8388 int DataArrayInt::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
8389 {
8390   checkAllocated();
8391   const int *ptr=getConstPointer();
8392   int nbTuple=getNumberOfTuples();
8393   int nbComps=getNumberOfComponents();
8394   if(compId<0 || compId>=nbComps)
8395     throw INTERP_KERNEL::Exception("DataArrayInt::accumulate : Invalid compId specified : No such nb of components !");
8396   int ret=0;
8397   for(int i=0;i<nbTuple;i++)
8398     ret+=ptr[i*nbComps+compId];
8399   return ret;
8400 }
8401
8402 /*!
8403  * This method accumulate using addition tuples in \a this using input index array [ \a bgOfIndex, \a endOfIndex ).
8404  * The returned array will have same number of components than \a this and number of tuples equal to
8405  * \c std::distance(bgOfIndex,endOfIndex) \b minus \b one.
8406  *
8407  * The input index array is expected to be ascendingly sorted in which the all referenced ids should be in [0, \c this->getNumberOfTuples).
8408  *
8409  * \param [in] bgOfIndex - begin (included) of the input index array.
8410  * \param [in] endOfIndex - end (excluded) of the input index array.
8411  * \return DataArrayInt * - the new instance having the same number of components than \a this.
8412  * 
8413  * \throw If bgOfIndex or end is NULL.
8414  * \throw If input index array is not ascendingly sorted.
8415  * \throw If there is an id in [ \a bgOfIndex, \a endOfIndex ) not in [0, \c this->getNumberOfTuples).
8416  * \throw If std::distance(bgOfIndex,endOfIndex)==0.
8417  */
8418 DataArrayInt *DataArrayInt::accumulatePerChunck(const int *bgOfIndex, const int *endOfIndex) const throw(INTERP_KERNEL::Exception)
8419 {
8420   if(!bgOfIndex || !endOfIndex)
8421     throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : input pointer NULL !");
8422   checkAllocated();
8423   int nbCompo=getNumberOfComponents();
8424   int nbOfTuples=getNumberOfTuples();
8425   int sz=(int)std::distance(bgOfIndex,endOfIndex);
8426   if(sz<1)
8427     throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : invalid size of input index array !");
8428   sz--;
8429   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(sz,nbCompo);
8430   const int *w=bgOfIndex;
8431   if(*w<0 || *w>=nbOfTuples)
8432     throw INTERP_KERNEL::Exception("DataArrayInt::accumulatePerChunck : The first element of the input index not in [0,nbOfTuples) !");
8433   const int *srcPt=begin()+(*w)*nbCompo;
8434   int *tmp=ret->getPointer();
8435   for(int i=0;i<sz;i++,tmp+=nbCompo,w++)
8436     {
8437       std::fill(tmp,tmp+nbCompo,0.);
8438       if(w[1]>=w[0])
8439         {
8440           for(int j=w[0];j<w[1];j++,srcPt+=nbCompo)
8441             {
8442               if(j>=0 && j<nbOfTuples)
8443                 std::transform(srcPt,srcPt+nbCompo,tmp,tmp,std::plus<int>());
8444               else
8445                 {
8446                   std::ostringstream oss; oss << "DataArrayInt::accumulatePerChunck : At rank #" << i << " the input index array points to id " << j << " should be in [0," << nbOfTuples << ") !";
8447                   throw INTERP_KERNEL::Exception(oss.str().c_str());
8448                 }
8449             }
8450         }
8451       else
8452         {
8453           std::ostringstream oss; oss << "DataArrayInt::accumulatePerChunck : At rank #" << i << " the input index array is not in ascendingly sorted.";
8454           throw INTERP_KERNEL::Exception(oss.str().c_str());
8455         }
8456     }
8457   ret->copyStringInfoFrom(*this);
8458   return ret.retn();
8459 }
8460
8461 /*!
8462  * Returns a new DataArrayInt by concatenating two given arrays, so that (1) the number
8463  * of tuples in the result array is <em> a1->getNumberOfTuples() + a2->getNumberOfTuples() -
8464  * offsetA2</em> and (2)
8465  * the number of component in the result array is same as that of each of given arrays.
8466  * First \a offsetA2 tuples of \a a2 are skipped and thus are missing from the result array.
8467  * Info on components is copied from the first of the given arrays. Number of components
8468  * in the given arrays must be the same.
8469  *  \param [in] a1 - an array to include in the result array.
8470  *  \param [in] a2 - another array to include in the result array.
8471  *  \param [in] offsetA2 - number of tuples of \a a2 to skip.
8472  *  \return DataArrayInt * - the new instance of DataArrayInt.
8473  *          The caller is to delete this result array using decrRef() as it is no more
8474  *          needed.
8475  *  \throw If either \a a1 or \a a2 is NULL.
8476  *  \throw If \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents().
8477  */
8478 DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
8479 {
8480   if(!a1 || !a2)
8481     throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input DataArrayInt instance is NULL !");
8482   int nbOfComp=a1->getNumberOfComponents();
8483   if(nbOfComp!=a2->getNumberOfComponents())
8484     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
8485   int nbOfTuple1=a1->getNumberOfTuples();
8486   int nbOfTuple2=a2->getNumberOfTuples();
8487   DataArrayInt *ret=DataArrayInt::New();
8488   ret->alloc(nbOfTuple1+nbOfTuple2-offsetA2,nbOfComp);
8489   int *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer());
8490   std::copy(a2->getConstPointer()+offsetA2*nbOfComp,a2->getConstPointer()+nbOfTuple2*nbOfComp,pt);
8491   ret->copyStringInfoFrom(*a1);
8492   return ret;
8493 }
8494
8495 /*!
8496  * Returns a new DataArrayInt by concatenating all given arrays, so that (1) the number
8497  * of tuples in the result array is a sum of the number of tuples of given arrays and (2)
8498  * the number of component in the result array is same as that of each of given arrays.
8499  * Info on components is copied from the first of the given arrays. Number of components
8500  * in the given arrays must be  the same.
8501  *  \param [in] arr - a sequence of arrays to include in the result array.
8502  *  \return DataArrayInt * - the new instance of DataArrayInt.
8503  *          The caller is to delete this result array using decrRef() as it is no more
8504  *          needed.
8505  *  \throw If all arrays within \a arr are NULL.
8506  *  \throw If getNumberOfComponents() of arrays within \a arr.
8507  */
8508 DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8509 {
8510   std::vector<const DataArrayInt *> a;
8511   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8512     if(*it4)
8513       a.push_back(*it4);
8514   if(a.empty())
8515     throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
8516   std::vector<const DataArrayInt *>::const_iterator it=a.begin();
8517   int nbOfComp=(*it)->getNumberOfComponents();
8518   int nbt=(*it++)->getNumberOfTuples();
8519   for(int i=1;it!=a.end();it++,i++)
8520     {
8521       if((*it)->getNumberOfComponents()!=nbOfComp)
8522         throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !");
8523       nbt+=(*it)->getNumberOfTuples();
8524     }
8525   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8526   ret->alloc(nbt,nbOfComp);
8527   int *pt=ret->getPointer();
8528   for(it=a.begin();it!=a.end();it++)
8529     pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
8530   ret->copyStringInfoFrom(*(a[0]));
8531   return ret.retn();
8532 }
8533
8534 /*!
8535  * This method takes as input a list of DataArrayInt instances \a arrs that represent each a packed index arrays.
8536  * A packed index array is an allocated array with one component, and at least one tuple. The first element
8537  * of each array in \a arrs must be 0. Each array in \a arrs is expected to be increasingly monotonic.
8538  * This method is useful for users that want to aggregate a pair of DataArrayInt representing an indexed data (typically nodal connectivity index in unstructured meshes.
8539  * 
8540  * \return DataArrayInt * - a new object to be managed by the caller.
8541  */
8542 DataArrayInt *DataArrayInt::AggregateIndexes(const std::vector<const DataArrayInt *>& arrs) throw(INTERP_KERNEL::Exception)
8543 {
8544   int retSz=1;
8545   for(std::vector<const DataArrayInt *>::const_iterator it4=arrs.begin();it4!=arrs.end();it4++)
8546     {
8547       if(*it4)
8548         {
8549           (*it4)->checkAllocated();
8550           if((*it4)->getNumberOfComponents()!=1)
8551             {
8552               std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with nb of compo != 1 at pos " << std::distance(arrs.begin(),it4) << " !";
8553               throw INTERP_KERNEL::Exception(oss.str().c_str());
8554             }
8555           int nbTupl=(*it4)->getNumberOfTuples();
8556           if(nbTupl<1)
8557             {
8558               std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with nb of tuples < 1 at pos " << std::distance(arrs.begin(),it4) << " !";
8559               throw INTERP_KERNEL::Exception(oss.str().c_str());
8560             }
8561           if((*it4)->front()!=0)
8562             {
8563               std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a DataArrayInt instance with front value != 0 at pos " << std::distance(arrs.begin(),it4) << " !";
8564               throw INTERP_KERNEL::Exception(oss.str().c_str());
8565             }
8566           retSz+=nbTupl-1;
8567         }
8568       else
8569         {
8570           std::ostringstream oss; oss << "DataArrayInt::AggregateIndexes : presence of a null instance at pos " << std::distance(arrs.begin(),it4) << " !";
8571           throw INTERP_KERNEL::Exception(oss.str().c_str());
8572         }
8573     }
8574   if(arrs.empty())
8575     throw INTERP_KERNEL::Exception("DataArrayInt::AggregateIndexes : input list must be NON EMPTY !");
8576   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
8577   ret->alloc(retSz,1);
8578   int *pt=ret->getPointer(); *pt++=0;
8579   for(std::vector<const DataArrayInt *>::const_iterator it=arrs.begin();it!=arrs.end();it++)
8580     pt=std::transform((*it)->begin()+1,(*it)->end(),pt,std::bind2nd(std::plus<int>(),pt[-1]));
8581   ret->copyStringInfoFrom(*(arrs[0]));
8582   return ret.retn();
8583 }
8584
8585 /*!
8586  * Returns the maximal value and its location within \a this one-dimensional array.
8587  *  \param [out] tupleId - index of the tuple holding the maximal value.
8588  *  \return int - the maximal value among all values of \a this array.
8589  *  \throw If \a this->getNumberOfComponents() != 1
8590  *  \throw If \a this->getNumberOfTuples() < 1
8591  */
8592 int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
8593 {
8594   checkAllocated();
8595   if(getNumberOfComponents()!=1)
8596     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
8597   int nbOfTuples=getNumberOfTuples();
8598   if(nbOfTuples<=0)
8599     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
8600   const int *vals=getConstPointer();
8601   const int *loc=std::max_element(vals,vals+nbOfTuples);
8602   tupleId=(int)std::distance(vals,loc);
8603   return *loc;
8604 }
8605
8606 /*!
8607  * Returns the maximal value within \a this array that is allowed to have more than
8608  *  one component.
8609  *  \return int - the maximal value among all values of \a this array.
8610  *  \throw If \a this is not allocated.
8611  */
8612 int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
8613 {
8614   checkAllocated();
8615   const int *loc=std::max_element(begin(),end());
8616   return *loc;
8617 }
8618
8619 /*!
8620  * Returns the minimal value and its location within \a this one-dimensional array.
8621  *  \param [out] tupleId - index of the tuple holding the minimal value.
8622  *  \return int - the minimal value among all values of \a this array.
8623  *  \throw If \a this->getNumberOfComponents() != 1
8624  *  \throw If \a this->getNumberOfTuples() < 1
8625  */
8626 int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
8627 {
8628   checkAllocated();
8629   if(getNumberOfComponents()!=1)
8630     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
8631   int nbOfTuples=getNumberOfTuples();
8632   if(nbOfTuples<=0)
8633     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
8634   const int *vals=getConstPointer();
8635   const int *loc=std::min_element(vals,vals+nbOfTuples);
8636   tupleId=(int)std::distance(vals,loc);
8637   return *loc;
8638 }
8639
8640 /*!
8641  * Returns the minimal value within \a this array that is allowed to have more than
8642  *  one component.
8643  *  \return int - the minimal value among all values of \a this array.
8644  *  \throw If \a this is not allocated.
8645  */
8646 int DataArrayInt::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
8647 {
8648   checkAllocated();
8649   const int *loc=std::min_element(begin(),end());
8650   return *loc;
8651 }
8652
8653 /*!
8654  * Converts every value of \a this array to its absolute value.
8655  *  \throw If \a this is not allocated.
8656  */
8657 void DataArrayInt::abs() throw(INTERP_KERNEL::Exception)
8658 {
8659   checkAllocated();
8660   int *ptr=getPointer();
8661   std::size_t nbOfElems=getNbOfElems();
8662   std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
8663   declareAsNew();
8664 }
8665
8666 /*!
8667  * Apply a liner function to a given component of \a this array, so that
8668  * an array element <em>(x)</em> becomes \f$ a * x + b \f$.
8669  *  \param [in] a - the first coefficient of the function.
8670  *  \param [in] b - the second coefficient of the function.
8671  *  \param [in] compoId - the index of component to modify.
8672  *  \throw If \a this is not allocated.
8673  */
8674 void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception)
8675 {
8676   checkAllocated();
8677   int *ptr=getPointer()+compoId;
8678   int nbOfComp=getNumberOfComponents();
8679   int nbOfTuple=getNumberOfTuples();
8680   for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
8681     *ptr=a*(*ptr)+b;
8682   declareAsNew();
8683 }
8684
8685 /*!
8686  * Apply a liner function to all elements of \a this array, so that
8687  * an element _x_ becomes \f$ a * x + b \f$.
8688  *  \param [in] a - the first coefficient of the function.
8689  *  \param [in] b - the second coefficient of the function.
8690  *  \throw If \a this is not allocated.
8691  */
8692 void DataArrayInt::applyLin(int a, int b) throw(INTERP_KERNEL::Exception)
8693 {
8694   checkAllocated();
8695   int *ptr=getPointer();
8696   std::size_t nbOfElems=getNbOfElems();
8697   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8698     *ptr=a*(*ptr)+b;
8699   declareAsNew();
8700 }
8701
8702 /*!
8703  * Returns a full copy of \a this array except that sign of all elements is reversed.
8704  *  \return DataArrayInt * - the new instance of DataArrayInt containing the
8705  *          same number of tuples and component as \a this array.
8706  *          The caller is to delete this result array using decrRef() as it is no more
8707  *          needed.
8708  *  \throw If \a this is not allocated.
8709  */
8710 DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception)
8711 {
8712   checkAllocated();
8713   DataArrayInt *newArr=DataArrayInt::New();
8714   int nbOfTuples=getNumberOfTuples();
8715   int nbOfComp=getNumberOfComponents();
8716   newArr->alloc(nbOfTuples,nbOfComp);
8717   const int *cptr=getConstPointer();
8718   std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
8719   newArr->copyStringInfoFrom(*this);
8720   return newArr;
8721 }
8722
8723 /*!
8724  * Modify all elements of \a this array, so that
8725  * an element _x_ becomes \f$ numerator / x \f$.
8726  *  \warning If an exception is thrown because of presence of 0 element in \a this 
8727  *           array, all elements processed before detection of the zero element remain
8728  *           modified.
8729  *  \param [in] numerator - the numerator used to modify array elements.
8730  *  \throw If \a this is not allocated.
8731  *  \throw If there is an element equal to 0 in \a this array.
8732  */
8733 void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception)
8734 {
8735   checkAllocated();
8736   int *ptr=getPointer();
8737   std::size_t nbOfElems=getNbOfElems();
8738   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8739     {
8740       if(*ptr!=0)
8741         {
8742           *ptr=numerator/(*ptr);
8743         }
8744       else
8745         {
8746           std::ostringstream oss; oss << "DataArrayInt::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8747           oss << " !";
8748           throw INTERP_KERNEL::Exception(oss.str().c_str());
8749         }
8750     }
8751   declareAsNew();
8752 }
8753
8754 /*!
8755  * Modify all elements of \a this array, so that
8756  * an element _x_ becomes \f$ x / val \f$.
8757  *  \param [in] val - the denominator used to modify array elements.
8758  *  \throw If \a this is not allocated.
8759  *  \throw If \a val == 0.
8760  */
8761 void DataArrayInt::applyDivideBy(int val) throw(INTERP_KERNEL::Exception)
8762 {
8763   if(val==0)
8764     throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to divide by 0 !");
8765   checkAllocated();
8766   int *ptr=getPointer();
8767   std::size_t nbOfElems=getNbOfElems();
8768   std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides<int>(),val));
8769   declareAsNew();
8770 }
8771
8772 /*!
8773  * Modify all elements of \a this array, so that
8774  * an element _x_ becomes  <em> x % val </em>.
8775  *  \param [in] val - the divisor used to modify array elements.
8776  *  \throw If \a this is not allocated.
8777  *  \throw If \a val <= 0.
8778  */
8779 void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception)
8780 {
8781   if(val<=0)
8782     throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !");
8783   checkAllocated();
8784   int *ptr=getPointer();
8785   std::size_t nbOfElems=getNbOfElems();
8786   std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus<int>(),val));
8787   declareAsNew();
8788 }
8789
8790 /*!
8791  * This method works only on data array with one component.
8792  * This method returns a newly allocated array storing stored ascendantly tuple ids in \b this so that
8793  * this[*id] in [\b vmin,\b vmax)
8794  * 
8795  * \param [in] vmin begin of range. This value is included in range (included).
8796  * \param [in] vmax end of range. This value is \b not included in range (excluded).
8797  * \return a newly allocated data array that the caller should deal with.
8798  */
8799 DataArrayInt *DataArrayInt::getIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
8800 {
8801   checkAllocated();
8802   if(getNumberOfComponents()!=1)
8803     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsInRange : this must have exactly one component !");
8804   const int *cptr=getConstPointer();
8805   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(0,1);
8806   int nbOfTuples=getNumberOfTuples();
8807   for(int i=0;i<nbOfTuples;i++,cptr++)
8808     if(*cptr>=vmin && *cptr<vmax)
8809       ret->pushBackSilent(i);
8810   return ret.retn();
8811 }
8812
8813 /*!
8814  * This method works only on data array with one component.
8815  * This method checks that all ids in \b this are in [ \b vmin, \b vmax ). If there is at least one element in \a this not in [ \b vmin, \b vmax ) an exception will be thrown.
8816  * 
8817  * \param [in] vmin begin of range. This value is included in range (included).
8818  * \param [in] vmax end of range. This value is \b not included in range (excluded).
8819  * \return if all ids in \a this are so that (*this)[i]==i for all i in [ 0, \c this->getNumberOfTuples() ).
8820  */
8821 bool DataArrayInt::checkAllIdsInRange(int vmin, int vmax) const throw(INTERP_KERNEL::Exception)
8822 {
8823   checkAllocated();
8824   if(getNumberOfComponents()!=1)
8825     throw INTERP_KERNEL::Exception("DataArrayInt::checkAllIdsInRange : this must have exactly one component !");
8826   int nbOfTuples=getNumberOfTuples();
8827   bool ret=true;
8828   const int *cptr=getConstPointer();
8829   for(int i=0;i<nbOfTuples;i++,cptr++)
8830     {
8831       if(*cptr>=vmin && *cptr<vmax)
8832         { ret=ret && *cptr==i; }
8833       else
8834         {
8835           std::ostringstream oss; oss << "DataArrayInt::checkAllIdsInRange : tuple #" << i << " has value " << *cptr << " should be in [" << vmin << "," << vmax << ") !";
8836           throw INTERP_KERNEL::Exception(oss.str().c_str());
8837         }
8838     }
8839   return ret;
8840 }
8841
8842 /*!
8843  * Modify all elements of \a this array, so that
8844  * an element _x_ becomes <em> val % x </em>.
8845  *  \warning If an exception is thrown because of presence of an element <= 0 in \a this 
8846  *           array, all elements processed before detection of the zero element remain
8847  *           modified.
8848  *  \param [in] val - the divident used to modify array elements.
8849  *  \throw If \a this is not allocated.
8850  *  \throw If there is an element equal to or less than 0 in \a this array.
8851  */
8852 void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception)
8853 {
8854   checkAllocated();
8855   int *ptr=getPointer();
8856   std::size_t nbOfElems=getNbOfElems();
8857   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8858     {
8859       if(*ptr>0)
8860         {
8861           *ptr=val%(*ptr);
8862         }
8863       else
8864         {
8865           std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8866           oss << " !";
8867           throw INTERP_KERNEL::Exception(oss.str().c_str());
8868         }
8869     }
8870   declareAsNew();
8871 }
8872
8873 /*!
8874  * Modify all elements of \a this array, so that
8875  * an element _x_ becomes <em> val ^ x </em>.
8876  *  \param [in] val - the value used to apply pow on all array elements.
8877  *  \throw If \a this is not allocated.
8878  *  \throw If \a val < 0.
8879  */
8880 void DataArrayInt::applyPow(int val) throw(INTERP_KERNEL::Exception)
8881 {
8882   checkAllocated();
8883   if(val<0)
8884     throw INTERP_KERNEL::Exception("DataArrayInt::applyPow : input pow in < 0 !");
8885   int *ptr=getPointer();
8886   std::size_t nbOfElems=getNbOfElems();
8887   if(val==0)
8888     {
8889       std::fill(ptr,ptr+nbOfElems,1.);
8890       return ;
8891     }
8892   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8893     {
8894       int tmp=1;
8895       for(int j=0;j<val;j++)
8896         tmp*=*ptr;
8897       *ptr=tmp;
8898     }
8899   declareAsNew();
8900 }
8901
8902 /*!
8903  * Modify all elements of \a this array, so that
8904  * an element _x_ becomes \f$ val ^ x \f$.
8905  *  \param [in] val - the value used to apply pow on all array elements.
8906  *  \throw If \a this is not allocated.
8907  *  \throw If there is an element < 0 in \a this array.
8908  *  \warning If an exception is thrown because of presence of 0 element in \a this 
8909  *           array, all elements processed before detection of the zero element remain
8910  *           modified.
8911  */
8912 void DataArrayInt::applyRPow(int val) throw(INTERP_KERNEL::Exception)
8913 {
8914   checkAllocated();
8915   int *ptr=getPointer();
8916   std::size_t nbOfElems=getNbOfElems();
8917   for(std::size_t i=0;i<nbOfElems;i++,ptr++)
8918     {
8919       if(*ptr>=0)
8920         {
8921           int tmp=1;
8922           for(int j=0;j<*ptr;j++)
8923             tmp*=val;
8924           *ptr=tmp;
8925         }
8926       else
8927         {
8928           std::ostringstream oss; oss << "DataArrayInt::applyRPow : presence of negative value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
8929           oss << " !";
8930           throw INTERP_KERNEL::Exception(oss.str().c_str());
8931         }
8932     }
8933   declareAsNew();
8934 }
8935
8936 /*!
8937  * Returns a new DataArrayInt by aggregating two given arrays, so that (1) the number
8938  * of components in the result array is a sum of the number of components of given arrays
8939  * and (2) the number of tuples in the result array is same as that of each of given
8940  * arrays. In other words the i-th tuple of result array includes all components of
8941  * i-th tuples of all given arrays.
8942  * Number of tuples in the given arrays must be the same.
8943  *  \param [in] a1 - an array to include in the result array.
8944  *  \param [in] a2 - another array to include in the result array.
8945  *  \return DataArrayInt * - the new instance of DataArrayInt.
8946  *          The caller is to delete this result array using decrRef() as it is no more
8947  *          needed.
8948  *  \throw If both \a a1 and \a a2 are NULL.
8949  *  \throw If any given array is not allocated.
8950  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
8951  */
8952 DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
8953 {
8954   std::vector<const DataArrayInt *> arr(2);
8955   arr[0]=a1; arr[1]=a2;
8956   return Meld(arr);
8957 }
8958
8959 /*!
8960  * Returns a new DataArrayInt by aggregating all given arrays, so that (1) the number
8961  * of components in the result array is a sum of the number of components of given arrays
8962  * and (2) the number of tuples in the result array is same as that of each of given
8963  * arrays. In other words the i-th tuple of result array includes all components of
8964  * i-th tuples of all given arrays.
8965  * Number of tuples in the given arrays must be  the same.
8966  *  \param [in] arr - a sequence of arrays to include in the result array.
8967  *  \return DataArrayInt * - the new instance of DataArrayInt.
8968  *          The caller is to delete this result array using decrRef() as it is no more
8969  *          needed.
8970  *  \throw If all arrays within \a arr are NULL.
8971  *  \throw If any given array is not allocated.
8972  *  \throw If getNumberOfTuples() of arrays within \a arr is different.
8973  */
8974 DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
8975 {
8976   std::vector<const DataArrayInt *> a;
8977   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
8978     if(*it4)
8979       a.push_back(*it4);
8980   if(a.empty())
8981     throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !");
8982   std::vector<const DataArrayInt *>::const_iterator it;
8983   for(it=a.begin();it!=a.end();it++)
8984     (*it)->checkAllocated();
8985   it=a.begin();
8986   int nbOfTuples=(*it)->getNumberOfTuples();
8987   std::vector<int> nbc(a.size());
8988   std::vector<const int *> pts(a.size());
8989   nbc[0]=(*it)->getNumberOfComponents();
8990   pts[0]=(*it++)->getConstPointer();
8991   for(int i=1;it!=a.end();it++,i++)
8992     {
8993       if(nbOfTuples!=(*it)->getNumberOfTuples())
8994         throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !");
8995       nbc[i]=(*it)->getNumberOfComponents();
8996       pts[i]=(*it)->getConstPointer();
8997     }
8998   int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
8999   DataArrayInt *ret=DataArrayInt::New();
9000   ret->alloc(nbOfTuples,totalNbOfComp);
9001   int *retPtr=ret->getPointer();
9002   for(int i=0;i<nbOfTuples;i++)
9003     for(int j=0;j<(int)a.size();j++)
9004       {
9005         retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
9006         pts[j]+=nbc[j];
9007       }
9008   int k=0;
9009   for(int i=0;i<(int)a.size();i++)
9010     for(int j=0;j<nbc[i];j++,k++)
9011       ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
9012   return ret;
9013 }
9014
9015 /*!
9016  * Returns a new DataArrayInt which is a minimal partition of elements of \a groups.
9017  * The i-th item of the result array is an ID of a set of elements belonging to a
9018  * unique set of groups, which the i-th element is a part of. This set of elements
9019  * belonging to a unique set of groups is called \a family, so the result array contains
9020  * IDs of families each element belongs to.
9021  *
9022  * \b Example: if we have two groups of elements: \a group1 [0,4] and \a group2 [ 0,1,2 ],
9023  * then there are 3 families:
9024  * - \a family1 (with ID 1) contains element [0] belonging to ( \a group1 + \a group2 ),
9025  * - \a family2 (with ID 2) contains elements [4] belonging to ( \a group1 ),
9026  * - \a family3 (with ID 3) contains element [1,2] belonging to ( \a group2 ), <br>
9027  * and the result array contains IDs of families [ 1,3,3,0,2 ]. <br> Note a family ID 0 which
9028  * stands for the element #3 which is in none of groups.
9029  *
9030  *  \param [in] groups - sequence of groups of element IDs.
9031  *  \param [in] newNb - total number of elements; it must be more than max ID of element
9032  *         in \a groups.
9033  *  \param [out] fidsOfGroups - IDs of families the elements of each group belong to.
9034  *  \return DataArrayInt * - a new instance of DataArrayInt containing IDs of families
9035  *         each element with ID from range [0, \a newNb ) belongs to. The caller is to
9036  *         delete this array using decrRef() as it is no more needed.
9037  *  \throw If any element ID in \a groups violates condition ( 0 <= ID < \a newNb ).
9038  */
9039 DataArrayInt *DataArrayInt::MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups) throw(INTERP_KERNEL::Exception)
9040 {
9041   std::vector<const DataArrayInt *> groups2;
9042   for(std::vector<const DataArrayInt *>::const_iterator it4=groups.begin();it4!=groups.end();it4++)
9043     if(*it4)
9044       groups2.push_back(*it4);
9045   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9046   ret->alloc(newNb,1);
9047   int *retPtr=ret->getPointer();
9048   std::fill(retPtr,retPtr+newNb,0);
9049   int fid=1;
9050   for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++)
9051     {
9052       const int *ptr=(*iter)->getConstPointer();
9053       std::size_t nbOfElem=(*iter)->getNbOfElems();
9054       int sfid=fid;
9055       for(int j=0;j<sfid;j++)
9056         {
9057           bool found=false;
9058           for(std::size_t i=0;i<nbOfElem;i++)
9059             {
9060               if(ptr[i]>=0 && ptr[i]<newNb)
9061                 {
9062                   if(retPtr[ptr[i]]==j)
9063                     {
9064                       retPtr[ptr[i]]=fid;
9065                       found=true;
9066                     }
9067                 }
9068               else
9069                 {
9070                   std::ostringstream oss; oss << "DataArrayInt::MakePartition : In group \"" << (*iter)->getName() << "\" in tuple #" << i << " value = " << ptr[i] << " ! Should be in [0," << newNb;
9071                   oss << ") !";
9072                   throw INTERP_KERNEL::Exception(oss.str().c_str());
9073                 }
9074             }
9075           if(found)
9076             fid++;
9077         }
9078     }
9079   fidsOfGroups.clear();
9080   fidsOfGroups.resize(groups2.size());
9081   int grId=0;
9082   for(std::vector<const DataArrayInt *>::const_iterator iter=groups2.begin();iter!=groups2.end();iter++,grId++)
9083     {
9084       std::set<int> tmp;
9085       const int *ptr=(*iter)->getConstPointer();
9086       std::size_t nbOfElem=(*iter)->getNbOfElems();
9087       for(const int *p=ptr;p!=ptr+nbOfElem;p++)
9088         tmp.insert(retPtr[*p]);
9089       fidsOfGroups[grId].insert(fidsOfGroups[grId].end(),tmp.begin(),tmp.end());
9090     }
9091   return ret.retn();
9092 }
9093
9094 /*!
9095  * Returns a new DataArrayInt which contains all elements of given one-dimensional
9096  * arrays. The result array does not contain any duplicates and its values
9097  * are sorted in ascending order.
9098  *  \param [in] arr - sequence of DataArrayInt's to unite.
9099  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
9100  *         array using decrRef() as it is no more needed.
9101  *  \throw If any \a arr[i] is not allocated.
9102  *  \throw If \a arr[i]->getNumberOfComponents() != 1.
9103  */
9104 DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
9105 {
9106   std::vector<const DataArrayInt *> a;
9107   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
9108     if(*it4)
9109       a.push_back(*it4);
9110   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
9111     {
9112       (*it)->checkAllocated();
9113       if((*it)->getNumberOfComponents()!=1)
9114         throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
9115     }
9116   //
9117   std::set<int> r;
9118   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
9119     {
9120       const int *pt=(*it)->getConstPointer();
9121       int nbOfTuples=(*it)->getNumberOfTuples();
9122       r.insert(pt,pt+nbOfTuples);
9123     }
9124   DataArrayInt *ret=DataArrayInt::New();
9125   ret->alloc((int)r.size(),1);
9126   std::copy(r.begin(),r.end(),ret->getPointer());
9127   return ret;
9128 }
9129
9130 /*!
9131  * Returns a new DataArrayInt which contains elements present in each of given one-dimensional
9132  * arrays. The result array does not contain any duplicates and its values
9133  * are sorted in ascending order.
9134  *  \param [in] arr - sequence of DataArrayInt's to intersect.
9135  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
9136  *         array using decrRef() as it is no more needed.
9137  *  \throw If any \a arr[i] is not allocated.
9138  *  \throw If \a arr[i]->getNumberOfComponents() != 1.
9139  */
9140 DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& arr) throw(INTERP_KERNEL::Exception)
9141 {
9142   std::vector<const DataArrayInt *> a;
9143   for(std::vector<const DataArrayInt *>::const_iterator it4=arr.begin();it4!=arr.end();it4++)
9144     if(*it4)
9145       a.push_back(*it4);
9146   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
9147     {
9148       (*it)->checkAllocated();
9149       if((*it)->getNumberOfComponents()!=1)
9150         throw INTERP_KERNEL::Exception("DataArrayInt::BuildIntersection : only single component allowed !");
9151     }
9152   //
9153   std::set<int> r;
9154   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
9155     {
9156       const int *pt=(*it)->getConstPointer();
9157       int nbOfTuples=(*it)->getNumberOfTuples();
9158       std::set<int> s1(pt,pt+nbOfTuples);
9159       if(it!=a.begin())
9160         {
9161           std::set<int> r2;
9162           std::set_intersection(r.begin(),r.end(),s1.begin(),s1.end(),inserter(r2,r2.end()));
9163           r=r2;
9164         }
9165       else
9166         r=s1;
9167     }
9168   DataArrayInt *ret=DataArrayInt::New();
9169   ret->alloc((int)r.size(),1);
9170   std::copy(r.begin(),r.end(),ret->getPointer());
9171   return ret;
9172 }
9173
9174 /*!
9175  * Returns a new DataArrayInt which contains a complement of elements of \a this
9176  * one-dimensional array. I.e. the result array contains all elements from the range [0,
9177  * \a nbOfElement) not present in \a this array.
9178  *  \param [in] nbOfElement - maximal size of the result array.
9179  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
9180  *         array using decrRef() as it is no more needed.
9181  *  \throw If \a this is not allocated.
9182  *  \throw If \a this->getNumberOfComponents() != 1.
9183  *  \throw If any element \a x of \a this array violates condition ( 0 <= \a x < \a
9184  *         nbOfElement ).
9185  */
9186 DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception)
9187 {
9188    checkAllocated();
9189    if(getNumberOfComponents()!=1)
9190      throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : only single component allowed !");
9191    std::vector<bool> tmp(nbOfElement);
9192    const int *pt=getConstPointer();
9193    int nbOfTuples=getNumberOfTuples();
9194    for(const int *w=pt;w!=pt+nbOfTuples;w++)
9195      if(*w>=0 && *w<nbOfElement)
9196        tmp[*w]=true;
9197      else
9198        throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : an element is not in valid range : [0,nbOfElement) !");
9199    int nbOfRetVal=(int)std::count(tmp.begin(),tmp.end(),false);
9200    DataArrayInt *ret=DataArrayInt::New();
9201    ret->alloc(nbOfRetVal,1);
9202    int j=0;
9203    int *retPtr=ret->getPointer();
9204    for(int i=0;i<nbOfElement;i++)
9205      if(!tmp[i])
9206        retPtr[j++]=i;
9207    return ret;
9208 }
9209
9210 /*!
9211  * Returns a new DataArrayInt containing elements of \a this one-dimensional missing
9212  * from an \a other one-dimensional array.
9213  *  \param [in] other - a DataArrayInt containing elements not to include in the result array.
9214  *  \return DataArrayInt * - a new instance of DataArrayInt with one component. The
9215  *         caller is to delete this array using decrRef() as it is no more needed.
9216  *  \throw If \a other is NULL.
9217  *  \throw If \a other is not allocated.
9218  *  \throw If \a other->getNumberOfComponents() != 1.
9219  *  \throw If \a this is not allocated.
9220  *  \throw If \a this->getNumberOfComponents() != 1.
9221  *  \sa DataArrayInt::buildSubstractionOptimized()
9222  */
9223 DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
9224 {
9225   if(!other)
9226     throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : DataArrayInt pointer in input is NULL !");
9227   checkAllocated();
9228   other->checkAllocated();
9229   if(getNumberOfComponents()!=1)
9230      throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !");
9231   if(other->getNumberOfComponents()!=1)
9232      throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !");
9233   const int *pt=getConstPointer();
9234   int nbOfTuples=getNumberOfTuples();
9235   std::set<int> s1(pt,pt+nbOfTuples);
9236   pt=other->getConstPointer();
9237   nbOfTuples=other->getNumberOfTuples();
9238   std::set<int> s2(pt,pt+nbOfTuples);
9239   std::vector<int> r;
9240   std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<int> >(r));
9241   DataArrayInt *ret=DataArrayInt::New();
9242   ret->alloc((int)r.size(),1);
9243   std::copy(r.begin(),r.end(),ret->getPointer());
9244   return ret;
9245 }
9246
9247 /*!
9248  * \a this is expected to have one component and to be sorted ascendingly (as for \a other).
9249  * \a other is expected to be a part of \a this. If not DataArrayInt::buildSubstraction should be called instead.
9250  * 
9251  * \param [in] other an array with one component and expected to be sorted ascendingly.
9252  * \ret list of ids in \a this but not in \a other.
9253  * \sa DataArrayInt::buildSubstraction
9254  */
9255 DataArrayInt *DataArrayInt::buildSubstractionOptimized(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
9256 {
9257   static const char *MSG="DataArrayInt::buildSubstractionOptimized : only single component allowed !";
9258   if(!other) throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstractionOptimized : NULL input array !");
9259   checkAllocated(); other->checkAllocated();
9260   if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
9261   if(other->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception(MSG);
9262   const int *pt1Bg(begin()),*pt1End(end()),*pt2Bg(other->begin()),*pt2End(other->end()),*work1(pt1Bg),*work2(pt2Bg);
9263   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(0,1);
9264   for(;work1!=pt1End;work1++)
9265     {
9266       if(work2!=pt2End && *work1==*work2)
9267         work2++;
9268       else
9269         ret->pushBackSilent(*work1);
9270     }
9271   return ret.retn();
9272 }
9273
9274
9275 /*!
9276  * Returns a new DataArrayInt which contains all elements of \a this and a given
9277  * one-dimensional arrays. The result array does not contain any duplicates
9278  * and its values are sorted in ascending order.
9279  *  \param [in] other - an array to unite with \a this one.
9280  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
9281  *         array using decrRef() as it is no more needed.
9282  *  \throw If \a this or \a other is not allocated.
9283  *  \throw If \a this->getNumberOfComponents() != 1.
9284  *  \throw If \a other->getNumberOfComponents() != 1.
9285  */
9286 DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
9287 {
9288   std::vector<const DataArrayInt *>arrs(2);
9289   arrs[0]=this; arrs[1]=other;
9290   return BuildUnion(arrs);
9291 }
9292
9293
9294 /*!
9295  * Returns a new DataArrayInt which contains elements present in both \a this and a given
9296  * one-dimensional arrays. The result array does not contain any duplicates
9297  * and its values are sorted in ascending order.
9298  *  \param [in] other - an array to intersect with \a this one.
9299  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
9300  *         array using decrRef() as it is no more needed.
9301  *  \throw If \a this or \a other is not allocated.
9302  *  \throw If \a this->getNumberOfComponents() != 1.
9303  *  \throw If \a other->getNumberOfComponents() != 1.
9304  */
9305 DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
9306 {
9307   std::vector<const DataArrayInt *>arrs(2);
9308   arrs[0]=this; arrs[1]=other;
9309   return BuildIntersection(arrs);
9310 }
9311
9312 /*!
9313  * This method can be applied on allocated with one component DataArrayInt instance.
9314  * This method is typically relevant for sorted arrays. All consecutive duplicated items in \a this will appear only once in returned DataArrayInt instance.
9315  * 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]
9316  * 
9317  * \return a newly allocated array that contain the result of the unique operation applied on \a this.
9318  * \throw if \a this is not allocated or if \a this has not exactly one component.
9319  */
9320 DataArrayInt *DataArrayInt::buildUnique() const throw(INTERP_KERNEL::Exception)
9321 {
9322   checkAllocated();
9323   if(getNumberOfComponents()!=1)
9324      throw INTERP_KERNEL::Exception("DataArrayInt::buildUnique : only single component allowed !");
9325   int nbOfTuples=getNumberOfTuples();
9326   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=deepCpy();
9327   int *data=tmp->getPointer();
9328   int *last=std::unique(data,data+nbOfTuples);
9329   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9330   ret->alloc(std::distance(data,last),1);
9331   std::copy(data,last,ret->getPointer());
9332   return ret.retn();
9333 }
9334
9335 /*!
9336  * Returns a new DataArrayInt which contains size of every of groups described by \a this
9337  * "index" array. Such "index" array is returned for example by 
9338  * \ref ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity
9339  * "MEDCouplingUMesh::buildDescendingConnectivity" and
9340  * \ref ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex
9341  * "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
9342  * This method preforms the reverse operation of DataArrayInt::computeOffsets2.
9343  *  \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
9344  *          equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
9345  *          The caller is to delete this array using decrRef() as it is no more needed. 
9346  *  \throw If \a this is not allocated.
9347  *  \throw If \a this->getNumberOfComponents() != 1.
9348  *  \throw If \a this->getNumberOfTuples() < 2.
9349  *
9350  *  \b Example: <br> 
9351  *         - this contains [1,3,6,7,7,9,15]
9352  *         - result array contains [2,3,1,0,2,6],
9353  *          where 2 = 3 - 1, 3 = 6 - 3, 1 = 7 - 6 etc.
9354  *
9355  * \sa DataArrayInt::computeOffsets2
9356  */
9357 DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
9358 {
9359   checkAllocated();
9360   if(getNumberOfComponents()!=1)
9361      throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
9362   int nbOfTuples=getNumberOfTuples();
9363   if(nbOfTuples<2)
9364     throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
9365   const int *ptr=getConstPointer();
9366   DataArrayInt *ret=DataArrayInt::New();
9367   ret->alloc(nbOfTuples-1,1);
9368   int *out=ret->getPointer();
9369   std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
9370   return ret;
9371 }
9372
9373 /*!
9374  * Modifies \a this one-dimensional array so that value of each element \a x
9375  * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
9376  * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number of tuples
9377  * and components remains the same.<br>
9378  * This method is useful for allToAllV in MPI with contiguous policy. This method
9379  * differs from computeOffsets2() in that the number of tuples is \b not changed by
9380  * this one.
9381  *  \throw If \a this is not allocated.
9382  *  \throw If \a this->getNumberOfComponents() != 1.
9383  *
9384  *  \b Example: <br>
9385  *          - Before \a this contains [3,5,1,2,0,8]
9386  *          - After \a this contains  [0,3,8,9,11,11]<br>
9387  *          Note that the last element 19 = 11 + 8 is missing because size of \a this
9388  *          array is retained and thus there is no space to store the last element.
9389  */
9390 void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception)
9391 {
9392   checkAllocated();
9393   if(getNumberOfComponents()!=1)
9394      throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
9395   int nbOfTuples=getNumberOfTuples();
9396   if(nbOfTuples==0)
9397     return ;
9398   int *work=getPointer();
9399   int tmp=work[0];
9400   work[0]=0;
9401   for(int i=1;i<nbOfTuples;i++)
9402     {
9403       int tmp2=work[i];
9404       work[i]=work[i-1]+tmp;
9405       tmp=tmp2;
9406     }
9407   declareAsNew();
9408 }
9409
9410
9411 /*!
9412  * Modifies \a this one-dimensional array so that value of each element \a x
9413  * of \a this array (\a a) is computed as \f$ x_i = \sum_{j=0}^{i-1} a[ j ] \f$.
9414  * Or: for each i>0 new[i]=new[i-1]+old[i-1] for i==0 new[i]=0. Number
9415  * components remains the same and number of tuples is inceamented by one.<br>
9416  * This method is useful for allToAllV in MPI with contiguous policy. This method
9417  * differs from computeOffsets() in that the number of tuples is changed by this one.
9418  * This method preforms the reverse operation of DataArrayInt::deltaShiftIndex.
9419  *  \throw If \a this is not allocated.
9420  *  \throw If \a this->getNumberOfComponents() != 1.
9421  *
9422  *  \b Example: <br>
9423  *          - Before \a this contains [3,5,1,2,0,8]
9424  *          - After \a this contains  [0,3,8,9,11,11,19]<br>
9425  * \sa DataArrayInt::deltaShiftIndex
9426  */
9427 void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
9428 {
9429   checkAllocated();
9430   if(getNumberOfComponents()!=1)
9431     throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !");
9432   int nbOfTuples=getNumberOfTuples();
9433   int *ret=(int *)malloc((nbOfTuples+1)*sizeof(int));
9434   if(nbOfTuples==0)
9435     return ;
9436   const int *work=getConstPointer();
9437   ret[0]=0;
9438   for(int i=0;i<nbOfTuples;i++)
9439     ret[i+1]=work[i]+ret[i];
9440   useArray(ret,true,C_DEALLOC,nbOfTuples+1,1);
9441   declareAsNew();
9442 }
9443
9444 /*!
9445  * Returns two new DataArrayInt instances whose contents is computed from that of \a this and \a listOfIds arrays as follows.
9446  * \a this is expected to be an offset format ( as returned by DataArrayInt::computeOffsets2 ) that is to say with one component
9447  * and ** sorted strictly increasingly **. \a listOfIds is expected to be sorted ascendingly (not strictly needed for \a listOfIds).
9448  * This methods searches in \a this, considered as a set of contiguous \c this->getNumberOfComponents() ranges, all ids in \a listOfIds
9449  * filling completely one of the ranges in \a this.
9450  *
9451  * \param [in] listOfIds a list of ids that has to be sorted ascendingly.
9452  * \param [out] rangeIdsFetched the range ids fetched
9453  * \param [out] idsInInputListThatFetch contains the list of ids in \a listOfIds that are \b fully included in a range in \a this. So
9454  *              \a idsInInputListThatFetch is a part of input \a listOfIds.
9455  *
9456  * \sa DataArrayInt::computeOffsets2
9457  *
9458  *  \b Example: <br>
9459  *          - \a this : [0,3,7,9,15,18]
9460  *          - \a listOfIds contains  [0,1,2,3,7,8,15,16,17]
9461  *          - \a rangeIdsFetched result array: [0,2,4]
9462  *          - \a idsInInputListThatFetch result array: [0,1,2,7,8,15,16,17]
9463  * In this example id 3 in input \a listOfIds is alone so it do not appear in output \a idsInInputListThatFetch.
9464  * <br>
9465  */
9466 void DataArrayInt::searchRangesInListOfIds(const DataArrayInt *listOfIds, DataArrayInt *& rangeIdsFetched, DataArrayInt *& idsInInputListThatFetch) const throw(INTERP_KERNEL::Exception)
9467 {
9468   if(!listOfIds)
9469     throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids is null !");
9470   listOfIds->checkAllocated(); checkAllocated();
9471   if(listOfIds->getNumberOfComponents()!=1)
9472     throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : input list of ids must have exactly one component !");
9473   if(getNumberOfComponents()!=1)
9474     throw INTERP_KERNEL::Exception("DataArrayInt::searchRangesInListOfIds : this must have exactly one component !");
9475   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret0=DataArrayInt::New(); ret0->alloc(0,1);
9476   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New(); ret1->alloc(0,1);
9477   const int *tupEnd(listOfIds->end()),*offBg(begin()),*offEnd(end()-1);
9478   const int *tupPtr(listOfIds->begin()),*offPtr(offBg);
9479   while(tupPtr!=tupEnd && offPtr!=offEnd)
9480     {
9481       if(*tupPtr==*offPtr)
9482         {
9483           int i=offPtr[0];
9484           while(i<offPtr[1] && *tupPtr==i && tupPtr!=tupEnd) { i++; tupPtr++; }
9485           if(i==offPtr[1])
9486             {
9487               ret0->pushBackSilent((int)std::distance(offBg,offPtr));
9488               ret1->pushBackValsSilent(tupPtr-(offPtr[1]-offPtr[0]),tupPtr);
9489               offPtr++;
9490             }
9491         }
9492       else
9493         { if(*tupPtr<*offPtr) tupPtr++; else offPtr++; }
9494     }
9495   rangeIdsFetched=ret0.retn();
9496   idsInInputListThatFetch=ret1.retn();
9497 }
9498
9499 /*!
9500  * Returns a new DataArrayInt whose contents is computed from that of \a this and \a
9501  * offsets arrays as follows. \a offsets is a one-dimensional array considered as an
9502  * "index" array of a "iota" array, thus, whose each element gives an index of a group
9503  * beginning within the "iota" array. And \a this is a one-dimensional array
9504  * considered as a selector of groups described by \a offsets to include into the result array.
9505  *  \throw If \a offsets is NULL.
9506  *  \throw If \a offsets is not allocated.
9507  *  \throw If \a offsets->getNumberOfComponents() != 1.
9508  *  \throw If \a offsets is not monotonically increasing.
9509  *  \throw If \a this is not allocated.
9510  *  \throw If \a this->getNumberOfComponents() != 1.
9511  *  \throw If any element of \a this is not a valid index for \a offsets array.
9512  *
9513  *  \b Example: <br>
9514  *          - \a this: [0,2,3]
9515  *          - \a offsets: [0,3,6,10,14,20]
9516  *          - result array: [0,1,2,6,7,8,9,10,11,12,13] == <br>
9517  *            \c range(0,3) + \c range(6,10) + \c range(10,14) ==<br>
9518  *            \c range( \a offsets[ \a this[0] ], offsets[ \a this[0]+1 ]) + 
9519  *            \c range( \a offsets[ \a this[1] ], offsets[ \a this[1]+1 ]) + 
9520  *            \c range( \a offsets[ \a this[2] ], offsets[ \a this[2]+1 ])
9521  */
9522 DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception)
9523 {
9524   if(!offsets)
9525     throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : DataArrayInt pointer in input is NULL !");
9526   checkAllocated();
9527   if(getNumberOfComponents()!=1)
9528      throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
9529   offsets->checkAllocated();
9530   if(offsets->getNumberOfComponents()!=1)
9531      throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
9532   int othNbTuples=offsets->getNumberOfTuples()-1;
9533   int nbOfTuples=getNumberOfTuples();
9534   int retNbOftuples=0;
9535   const int *work=getConstPointer();
9536   const int *offPtr=offsets->getConstPointer();
9537   for(int i=0;i<nbOfTuples;i++)
9538     {
9539       int val=work[i];
9540       if(val>=0 && val<othNbTuples)
9541         {
9542           int delta=offPtr[val+1]-offPtr[val];
9543           if(delta>=0)
9544             retNbOftuples+=delta;
9545           else
9546             {
9547               std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
9548               throw INTERP_KERNEL::Exception(oss.str().c_str());
9549             }
9550         }
9551       else
9552         {
9553           std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
9554           oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
9555           throw INTERP_KERNEL::Exception(oss.str().c_str());
9556         }
9557     }
9558   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9559   ret->alloc(retNbOftuples,1);
9560   int *retPtr=ret->getPointer();
9561   for(int i=0;i<nbOfTuples;i++)
9562     {
9563       int val=work[i];
9564       int start=offPtr[val];
9565       int off=offPtr[val+1]-start;
9566       for(int j=0;j<off;j++,retPtr++)
9567         *retPtr=start+j;
9568     }
9569   return ret.retn();
9570 }
9571
9572 /*!
9573  * 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.
9574  * 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
9575  * in tuple **i** of returned DataArrayInt.
9576  * If ranges overlapped (in theory it should not) this method do not detect it and always returns the first range.
9577  *
9578  * 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)]
9579  * The return DataArrayInt will contain : **[0,4,1,2,2,3]**
9580  * 
9581  * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
9582  *             for lower value included and 2nd component is the upper value of corresponding range **excluded**.
9583  * \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
9584  *        is thrown if no ranges in \a ranges contains value in \a this.
9585  * 
9586  * \sa DataArrayInt::findIdInRangeForEachTuple
9587  */
9588 DataArrayInt *DataArrayInt::findRangeIdForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
9589 {
9590   if(!ranges)
9591     throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : null input pointer !");
9592   if(ranges->getNumberOfComponents()!=2)
9593     throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : input DataArrayInt instance should have 2 components !");
9594   checkAllocated();
9595   if(getNumberOfComponents()!=1)
9596     throw INTERP_KERNEL::Exception("DataArrayInt::findRangeIdForEachTuple : this should have only one component !");
9597   int nbTuples=getNumberOfTuples();
9598   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
9599   int nbOfRanges=ranges->getNumberOfTuples();
9600   const int *rangesPtr=ranges->getConstPointer();
9601   int *retPtr=ret->getPointer();
9602   const int *inPtr=getConstPointer();
9603   for(int i=0;i<nbTuples;i++,retPtr++)
9604     {
9605       int val=inPtr[i];
9606       bool found=false;
9607       for(int j=0;j<nbOfRanges && !found;j++)
9608         if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
9609           { *retPtr=j; found=true; }
9610       if(found)
9611         continue;
9612       else
9613         {
9614           std::ostringstream oss; oss << "DataArrayInt::findRangeIdForEachTuple : tuple #" << i << " not found by any ranges !";
9615           throw INTERP_KERNEL::Exception(oss.str().c_str());
9616         }
9617     }
9618   return ret.retn();
9619 }
9620
9621 /*!
9622  * 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.
9623  * 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
9624  * in tuple **i** of returned DataArrayInt.
9625  * If ranges overlapped (in theory it should not) this method do not detect it and always returns the sub position of the first range.
9626  *
9627  * 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)]
9628  * The return DataArrayInt will contain : **[1,2,4,0,2,2]**
9629  * This method is often called in pair with DataArrayInt::findRangeIdForEachTuple method.
9630  * 
9631  * \param [in] ranges typically come from output of MEDCouplingUMesh::ComputeRangesFromTypeDistribution. Each range is specified like this : 1st component is
9632  *             for lower value included and 2nd component is the upper value of corresponding range **excluded**.
9633  * \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
9634  *        is thrown if no ranges in \a ranges contains value in \a this.
9635  * \sa DataArrayInt::findRangeIdForEachTuple
9636  */
9637 DataArrayInt *DataArrayInt::findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception)
9638 {
9639   if(!ranges)
9640     throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : null input pointer !");
9641   if(ranges->getNumberOfComponents()!=2)
9642     throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : input DataArrayInt instance should have 2 components !");
9643   checkAllocated();
9644   if(getNumberOfComponents()!=1)
9645     throw INTERP_KERNEL::Exception("DataArrayInt::findIdInRangeForEachTuple : this should have only one component !");
9646   int nbTuples=getNumberOfTuples();
9647   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTuples,1);
9648   int nbOfRanges=ranges->getNumberOfTuples();
9649   const int *rangesPtr=ranges->getConstPointer();
9650   int *retPtr=ret->getPointer();
9651   const int *inPtr=getConstPointer();
9652   for(int i=0;i<nbTuples;i++,retPtr++)
9653     {
9654       int val=inPtr[i];
9655       bool found=false;
9656       for(int j=0;j<nbOfRanges && !found;j++)
9657         if(val>=rangesPtr[2*j] && val<rangesPtr[2*j+1])
9658           { *retPtr=val-rangesPtr[2*j]; found=true; }
9659       if(found)
9660         continue;
9661       else
9662         {
9663           std::ostringstream oss; oss << "DataArrayInt::findIdInRangeForEachTuple : tuple #" << i << " not found by any ranges !";
9664           throw INTERP_KERNEL::Exception(oss.str().c_str());
9665         }
9666     }
9667   return ret.retn();
9668 }
9669
9670 /*!
9671  * 
9672  * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
9673  *             \a nbTimes  should be at least equal to 1.
9674  * \return a newly allocated DataArrayInt having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
9675  * \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.
9676  */
9677 DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception)
9678 {
9679   checkAllocated();
9680   if(getNumberOfComponents()!=1)
9681     throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !");
9682   if(nbTimes<1)
9683     throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : nb times should be >= 1 !");
9684   int nbTuples=getNumberOfTuples();
9685   const int *inPtr=getConstPointer();
9686   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTimes*nbTuples,1);
9687   int *retPtr=ret->getPointer();
9688   for(int i=0;i<nbTuples;i++,inPtr++)
9689     {
9690       int val=*inPtr;
9691       for(int j=0;j<nbTimes;j++,retPtr++)
9692         *retPtr=val;
9693     }
9694   ret->copyStringInfoFrom(*this);
9695   return ret.retn();
9696 }
9697
9698 /*!
9699  * This method returns all different values found in \a this. This method throws if \a this has not been allocated.
9700  * But the number of components can be different from one.
9701  * \return a newly allocated array (that should be dealt by the caller) containing different values in \a this.
9702  */
9703 DataArrayInt *DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception)
9704 {
9705   checkAllocated();
9706   std::set<int> ret;
9707   ret.insert(begin(),end());
9708   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=DataArrayInt::New(); ret2->alloc((int)ret.size(),1);
9709   std::copy(ret.begin(),ret.end(),ret2->getPointer());
9710   return ret2.retn();
9711 }
9712
9713 /*!
9714  * This method is a refinement of DataArrayInt::getDifferentValues because it returns not only different values in \a this but also, for each of
9715  * them it tells which tuple id have this id.
9716  * This method works only on arrays with one component (if it is not the case call DataArrayInt::rearrange(1) ).
9717  * This method returns two arrays having same size.
9718  * 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.
9719  * 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]]
9720  */
9721 std::vector<DataArrayInt *> DataArrayInt::partitionByDifferentValues(std::vector<int>& differentIds) const throw(INTERP_KERNEL::Exception)
9722 {
9723   checkAllocated();
9724   if(getNumberOfComponents()!=1)
9725     throw INTERP_KERNEL::Exception("DataArrayInt::partitionByDifferentValues : this should have only one component !");
9726   int id=0;
9727   std::map<int,int> m,m2,m3;
9728   for(const int *w=begin();w!=end();w++)
9729     m[*w]++;
9730   differentIds.resize(m.size());
9731   std::vector<DataArrayInt *> ret(m.size());
9732   std::vector<int *> retPtr(m.size());
9733   for(std::map<int,int>::const_iterator it=m.begin();it!=m.end();it++,id++)
9734     {
9735       m2[(*it).first]=id;
9736       ret[id]=DataArrayInt::New();
9737       ret[id]->alloc((*it).second,1);
9738       retPtr[id]=ret[id]->getPointer();
9739       differentIds[id]=(*it).first;
9740     }
9741   id=0;
9742   for(const int *w=begin();w!=end();w++,id++)
9743     {
9744       retPtr[m2[*w]][m3[*w]++]=id;
9745     }
9746   return ret;
9747 }
9748
9749 /*!
9750  * Returns a new DataArrayInt that is a sum of two given arrays. There are 3
9751  * valid cases.
9752  * 1.  The arrays have same number of tuples and components. Then each value of
9753  *   the result array (_a_) is a sum of the corresponding values of \a a1 and \a a2,
9754  *   i.e.: _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, j ].
9755  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
9756  *   component. Then
9757  *   _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ i, 0 ].
9758  * 3.  The arrays have same number of components and one array, say _a2_, has one
9759  *   tuple. Then
9760  *   _a_ [ i, j ] = _a1_ [ i, j ] + _a2_ [ 0, j ].
9761  *
9762  * Info on components is copied either from the first array (in the first case) or from
9763  * the array with maximal number of elements (getNbOfElems()).
9764  *  \param [in] a1 - an array to sum up.
9765  *  \param [in] a2 - another array to sum up.
9766  *  \return DataArrayInt * - the new instance of DataArrayInt.
9767  *          The caller is to delete this result array using decrRef() as it is no more
9768  *          needed.
9769  *  \throw If either \a a1 or \a a2 is NULL.
9770  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9771  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9772  *         none of them has number of tuples or components equal to 1.
9773  */
9774 DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9775 {
9776   if(!a1 || !a2)
9777     throw INTERP_KERNEL::Exception("DataArrayInt::Add : input DataArrayInt instance is NULL !");
9778   int nbOfTuple=a1->getNumberOfTuples();
9779   int nbOfTuple2=a2->getNumberOfTuples();
9780   int nbOfComp=a1->getNumberOfComponents();
9781   int nbOfComp2=a2->getNumberOfComponents();
9782   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=0;
9783   if(nbOfTuple==nbOfTuple2)
9784     {
9785       if(nbOfComp==nbOfComp2)
9786         {
9787           ret=DataArrayInt::New();
9788           ret->alloc(nbOfTuple,nbOfComp);
9789           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<int>());
9790           ret->copyStringInfoFrom(*a1);
9791         }
9792       else
9793         {
9794           int nbOfCompMin,nbOfCompMax;
9795           const DataArrayInt *aMin, *aMax;
9796           if(nbOfComp>nbOfComp2)
9797             {
9798               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
9799               aMin=a2; aMax=a1;
9800             }
9801           else
9802             {
9803               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
9804               aMin=a1; aMax=a2;
9805             }
9806           if(nbOfCompMin==1)
9807             {
9808               ret=DataArrayInt::New();
9809               ret->alloc(nbOfTuple,nbOfCompMax);
9810               const int *aMinPtr=aMin->getConstPointer();
9811               const int *aMaxPtr=aMax->getConstPointer();
9812               int *res=ret->getPointer();
9813               for(int i=0;i<nbOfTuple;i++)
9814                 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<int>(),aMinPtr[i]));
9815               ret->copyStringInfoFrom(*aMax);
9816             }
9817           else
9818             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
9819         }
9820     }
9821   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
9822     {
9823       if(nbOfComp==nbOfComp2)
9824         {
9825           int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
9826           const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
9827           const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
9828           const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
9829           ret=DataArrayInt::New();
9830           ret->alloc(nbOfTupleMax,nbOfComp);
9831           int *res=ret->getPointer();
9832           for(int i=0;i<nbOfTupleMax;i++)
9833             res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::plus<int>());
9834           ret->copyStringInfoFrom(*aMax);
9835         }
9836       else
9837         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
9838     }
9839   else
9840     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
9841   return ret.retn();
9842 }
9843
9844 /*!
9845  * Adds values of another DataArrayInt to values of \a this one. There are 3
9846  * valid cases.
9847  * 1.  The arrays have same number of tuples and components. Then each value of
9848  *   \a other array is added to the corresponding value of \a this array, i.e.:
9849  *   _a_ [ i, j ] += _other_ [ i, j ].
9850  * 2.  The arrays have same number of tuples and \a other array has one component. Then
9851  *   _a_ [ i, j ] += _other_ [ i, 0 ].
9852  * 3.  The arrays have same number of components and \a other array has one tuple. Then
9853  *   _a_ [ i, j ] += _a2_ [ 0, j ].
9854  *
9855  *  \param [in] other - an array to add to \a this one.
9856  *  \throw If \a other is NULL.
9857  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9858  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9859  *         \a other has number of both tuples and components not equal to 1.
9860  */
9861 void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
9862 {
9863   if(!other)
9864     throw INTERP_KERNEL::Exception("DataArrayInt::addEqual : input DataArrayInt instance is NULL !");
9865   const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual  !";
9866   checkAllocated(); other->checkAllocated();
9867   int nbOfTuple=getNumberOfTuples();
9868   int nbOfTuple2=other->getNumberOfTuples();
9869   int nbOfComp=getNumberOfComponents();
9870   int nbOfComp2=other->getNumberOfComponents();
9871   if(nbOfTuple==nbOfTuple2)
9872     {
9873       if(nbOfComp==nbOfComp2)
9874         {
9875           std::transform(begin(),end(),other->begin(),getPointer(),std::plus<int>());
9876         }
9877       else if(nbOfComp2==1)
9878         {
9879           int *ptr=getPointer();
9880           const int *ptrc=other->getConstPointer();
9881           for(int i=0;i<nbOfTuple;i++)
9882             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<int>(),*ptrc++));
9883         }
9884       else
9885         throw INTERP_KERNEL::Exception(msg);
9886     }
9887   else if(nbOfTuple2==1)
9888     {
9889       if(nbOfComp2==nbOfComp)
9890         {
9891           int *ptr=getPointer();
9892           const int *ptrc=other->getConstPointer();
9893           for(int i=0;i<nbOfTuple;i++)
9894             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<int>());
9895         }
9896       else
9897         throw INTERP_KERNEL::Exception(msg);
9898     }
9899   else
9900     throw INTERP_KERNEL::Exception(msg);
9901   declareAsNew();
9902 }
9903
9904 /*!
9905  * Returns a new DataArrayInt that is a subtraction of two given arrays. There are 3
9906  * valid cases.
9907  * 1.  The arrays have same number of tuples and components. Then each value of
9908  *   the result array (_a_) is a subtraction of the corresponding values of \a a1 and
9909  *   \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, j ].
9910  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
9911  *   component. Then
9912  *   _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ i, 0 ].
9913  * 3.  The arrays have same number of components and one array, say _a2_, has one
9914  *   tuple. Then
9915  *   _a_ [ i, j ] = _a1_ [ i, j ] - _a2_ [ 0, j ].
9916  *
9917  * Info on components is copied either from the first array (in the first case) or from
9918  * the array with maximal number of elements (getNbOfElems()).
9919  *  \param [in] a1 - an array to subtract from.
9920  *  \param [in] a2 - an array to subtract.
9921  *  \return DataArrayInt * - the new instance of DataArrayInt.
9922  *          The caller is to delete this result array using decrRef() as it is no more
9923  *          needed.
9924  *  \throw If either \a a1 or \a a2 is NULL.
9925  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
9926  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
9927  *         none of them has number of tuples or components equal to 1.
9928  */
9929 DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
9930 {
9931   if(!a1 || !a2)
9932     throw INTERP_KERNEL::Exception("DataArrayInt::Substract : input DataArrayInt instance is NULL !");
9933   int nbOfTuple1=a1->getNumberOfTuples();
9934   int nbOfTuple2=a2->getNumberOfTuples();
9935   int nbOfComp1=a1->getNumberOfComponents();
9936   int nbOfComp2=a2->getNumberOfComponents();
9937   if(nbOfTuple2==nbOfTuple1)
9938     {
9939       if(nbOfComp1==nbOfComp2)
9940         {
9941           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9942           ret->alloc(nbOfTuple2,nbOfComp1);
9943           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<int>());
9944           ret->copyStringInfoFrom(*a1);
9945           return ret.retn();
9946         }
9947       else if(nbOfComp2==1)
9948         {
9949           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9950           ret->alloc(nbOfTuple1,nbOfComp1);
9951           const int *a2Ptr=a2->getConstPointer();
9952           const int *a1Ptr=a1->getConstPointer();
9953           int *res=ret->getPointer();
9954           for(int i=0;i<nbOfTuple1;i++)
9955             res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::minus<int>(),a2Ptr[i]));
9956           ret->copyStringInfoFrom(*a1);
9957           return ret.retn();
9958         }
9959       else
9960         {
9961           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
9962           return 0;
9963         }
9964     }
9965   else if(nbOfTuple2==1)
9966     {
9967       a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Substract !");
9968       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
9969       ret->alloc(nbOfTuple1,nbOfComp1);
9970       const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
9971       int *pt=ret->getPointer();
9972       for(int i=0;i<nbOfTuple1;i++)
9973         pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::minus<int>());
9974       ret->copyStringInfoFrom(*a1);
9975       return ret.retn();
9976     }
9977   else
9978     {
9979       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Substract !");//will always throw an exception
9980       return 0;
9981     }
9982 }
9983
9984 /*!
9985  * Subtract values of another DataArrayInt from values of \a this one. There are 3
9986  * valid cases.
9987  * 1.  The arrays have same number of tuples and components. Then each value of
9988  *   \a other array is subtracted from the corresponding value of \a this array, i.e.:
9989  *   _a_ [ i, j ] -= _other_ [ i, j ].
9990  * 2.  The arrays have same number of tuples and \a other array has one component. Then
9991  *   _a_ [ i, j ] -= _other_ [ i, 0 ].
9992  * 3.  The arrays have same number of components and \a other array has one tuple. Then
9993  *   _a_ [ i, j ] -= _a2_ [ 0, j ].
9994  *
9995  *  \param [in] other - an array to subtract from \a this one.
9996  *  \throw If \a other is NULL.
9997  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
9998  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
9999  *         \a other has number of both tuples and components not equal to 1.
10000  */
10001 void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
10002 {
10003   if(!other)
10004     throw INTERP_KERNEL::Exception("DataArrayInt::substractEqual : input DataArrayInt instance is NULL !");
10005   const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual  !";
10006   checkAllocated(); other->checkAllocated();
10007   int nbOfTuple=getNumberOfTuples();
10008   int nbOfTuple2=other->getNumberOfTuples();
10009   int nbOfComp=getNumberOfComponents();
10010   int nbOfComp2=other->getNumberOfComponents();
10011   if(nbOfTuple==nbOfTuple2)
10012     {
10013       if(nbOfComp==nbOfComp2)
10014         {
10015           std::transform(begin(),end(),other->begin(),getPointer(),std::minus<int>());
10016         }
10017       else if(nbOfComp2==1)
10018         {
10019           int *ptr=getPointer();
10020           const int *ptrc=other->getConstPointer();
10021           for(int i=0;i<nbOfTuple;i++)
10022             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<int>(),*ptrc++));
10023         }
10024       else
10025         throw INTERP_KERNEL::Exception(msg);
10026     }
10027   else if(nbOfTuple2==1)
10028     {
10029       int *ptr=getPointer();
10030       const int *ptrc=other->getConstPointer();
10031       for(int i=0;i<nbOfTuple;i++)
10032         std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<int>());
10033     }
10034   else
10035     throw INTERP_KERNEL::Exception(msg);
10036   declareAsNew();
10037 }
10038
10039 /*!
10040  * Returns a new DataArrayInt that is a product of two given arrays. There are 3
10041  * valid cases.
10042  * 1.  The arrays have same number of tuples and components. Then each value of
10043  *   the result array (_a_) is a product of the corresponding values of \a a1 and
10044  *   \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, j ].
10045  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
10046  *   component. Then
10047  *   _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ i, 0 ].
10048  * 3.  The arrays have same number of components and one array, say _a2_, has one
10049  *   tuple. Then
10050  *   _a_ [ i, j ] = _a1_ [ i, j ] * _a2_ [ 0, j ].
10051  *
10052  * Info on components is copied either from the first array (in the first case) or from
10053  * the array with maximal number of elements (getNbOfElems()).
10054  *  \param [in] a1 - a factor array.
10055  *  \param [in] a2 - another factor array.
10056  *  \return DataArrayInt * - the new instance of DataArrayInt.
10057  *          The caller is to delete this result array using decrRef() as it is no more
10058  *          needed.
10059  *  \throw If either \a a1 or \a a2 is NULL.
10060  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
10061  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
10062  *         none of them has number of tuples or components equal to 1.
10063  */
10064 DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
10065 {
10066   if(!a1 || !a2)
10067     throw INTERP_KERNEL::Exception("DataArrayInt::Multiply : input DataArrayInt instance is NULL !");
10068   int nbOfTuple=a1->getNumberOfTuples();
10069   int nbOfTuple2=a2->getNumberOfTuples();
10070   int nbOfComp=a1->getNumberOfComponents();
10071   int nbOfComp2=a2->getNumberOfComponents();
10072   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=0;
10073   if(nbOfTuple==nbOfTuple2)
10074     {
10075       if(nbOfComp==nbOfComp2)
10076         {
10077           ret=DataArrayInt::New();
10078           ret->alloc(nbOfTuple,nbOfComp);
10079           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<int>());
10080           ret->copyStringInfoFrom(*a1);
10081         }
10082       else
10083         {
10084           int nbOfCompMin,nbOfCompMax;
10085           const DataArrayInt *aMin, *aMax;
10086           if(nbOfComp>nbOfComp2)
10087             {
10088               nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
10089               aMin=a2; aMax=a1;
10090             }
10091           else
10092             {
10093               nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
10094               aMin=a1; aMax=a2;
10095             }
10096           if(nbOfCompMin==1)
10097             {
10098               ret=DataArrayInt::New();
10099               ret->alloc(nbOfTuple,nbOfCompMax);
10100               const int *aMinPtr=aMin->getConstPointer();
10101               const int *aMaxPtr=aMax->getConstPointer();
10102               int *res=ret->getPointer();
10103               for(int i=0;i<nbOfTuple;i++)
10104                 res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<int>(),aMinPtr[i]));
10105               ret->copyStringInfoFrom(*aMax);
10106             }
10107           else
10108             throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
10109         }
10110     }
10111   else if((nbOfTuple==1 && nbOfTuple2>1) || (nbOfTuple>1 && nbOfTuple2==1))
10112     {
10113       if(nbOfComp==nbOfComp2)
10114         {
10115           int nbOfTupleMax=std::max(nbOfTuple,nbOfTuple2);
10116           const DataArrayInt *aMin=nbOfTuple>nbOfTuple2?a2:a1;
10117           const DataArrayInt *aMax=nbOfTuple>nbOfTuple2?a1:a2;
10118           const int *aMinPtr=aMin->getConstPointer(),*aMaxPtr=aMax->getConstPointer();
10119           ret=DataArrayInt::New();
10120           ret->alloc(nbOfTupleMax,nbOfComp);
10121           int *res=ret->getPointer();
10122           for(int i=0;i<nbOfTupleMax;i++)
10123             res=std::transform(aMaxPtr+i*nbOfComp,aMaxPtr+(i+1)*nbOfComp,aMinPtr,res,std::multiplies<int>());
10124           ret->copyStringInfoFrom(*aMax);
10125         }
10126       else
10127         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
10128     }
10129   else
10130     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
10131   return ret.retn();
10132 }
10133
10134
10135 /*!
10136  * Multiply values of another DataArrayInt to values of \a this one. There are 3
10137  * valid cases.
10138  * 1.  The arrays have same number of tuples and components. Then each value of
10139  *   \a other array is multiplied to the corresponding value of \a this array, i.e.:
10140  *   _a_ [ i, j ] *= _other_ [ i, j ].
10141  * 2.  The arrays have same number of tuples and \a other array has one component. Then
10142  *   _a_ [ i, j ] *= _other_ [ i, 0 ].
10143  * 3.  The arrays have same number of components and \a other array has one tuple. Then
10144  *   _a_ [ i, j ] *= _a2_ [ 0, j ].
10145  *
10146  *  \param [in] other - an array to multiply to \a this one.
10147  *  \throw If \a other is NULL.
10148  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
10149  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
10150  *         \a other has number of both tuples and components not equal to 1.
10151  */
10152 void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
10153 {
10154   if(!other)
10155     throw INTERP_KERNEL::Exception("DataArrayInt::multiplyEqual : input DataArrayInt instance is NULL !");
10156   const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !";
10157   checkAllocated(); other->checkAllocated();
10158   int nbOfTuple=getNumberOfTuples();
10159   int nbOfTuple2=other->getNumberOfTuples();
10160   int nbOfComp=getNumberOfComponents();
10161   int nbOfComp2=other->getNumberOfComponents();
10162   if(nbOfTuple==nbOfTuple2)
10163     {
10164       if(nbOfComp==nbOfComp2)
10165         {
10166           std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<int>());
10167         }
10168       else if(nbOfComp2==1)
10169         {
10170           int *ptr=getPointer();
10171           const int *ptrc=other->getConstPointer();
10172           for(int i=0;i<nbOfTuple;i++)
10173             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<int>(),*ptrc++));    
10174         }
10175       else
10176         throw INTERP_KERNEL::Exception(msg);
10177     }
10178   else if(nbOfTuple2==1)
10179     {
10180       if(nbOfComp2==nbOfComp)
10181         {
10182           int *ptr=getPointer();
10183           const int *ptrc=other->getConstPointer();
10184           for(int i=0;i<nbOfTuple;i++)
10185             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<int>());
10186         }
10187       else
10188         throw INTERP_KERNEL::Exception(msg);
10189     }
10190   else
10191     throw INTERP_KERNEL::Exception(msg);
10192   declareAsNew();
10193 }
10194
10195
10196 /*!
10197  * Returns a new DataArrayInt that is a division of two given arrays. There are 3
10198  * valid cases.
10199  * 1.  The arrays have same number of tuples and components. Then each value of
10200  *   the result array (_a_) is a division of the corresponding values of \a a1 and
10201  *   \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, j ].
10202  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
10203  *   component. Then
10204  *   _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ i, 0 ].
10205  * 3.  The arrays have same number of components and one array, say _a2_, has one
10206  *   tuple. Then
10207  *   _a_ [ i, j ] = _a1_ [ i, j ] / _a2_ [ 0, j ].
10208  *
10209  * Info on components is copied either from the first array (in the first case) or from
10210  * the array with maximal number of elements (getNbOfElems()).
10211  *  \warning No check of division by zero is performed!
10212  *  \param [in] a1 - a numerator array.
10213  *  \param [in] a2 - a denominator array.
10214  *  \return DataArrayInt * - the new instance of DataArrayInt.
10215  *          The caller is to delete this result array using decrRef() as it is no more
10216  *          needed.
10217  *  \throw If either \a a1 or \a a2 is NULL.
10218  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
10219  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
10220  *         none of them has number of tuples or components equal to 1.
10221  */
10222 DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
10223 {
10224   if(!a1 || !a2)
10225     throw INTERP_KERNEL::Exception("DataArrayInt::Divide : input DataArrayInt instance is NULL !");
10226   int nbOfTuple1=a1->getNumberOfTuples();
10227   int nbOfTuple2=a2->getNumberOfTuples();
10228   int nbOfComp1=a1->getNumberOfComponents();
10229   int nbOfComp2=a2->getNumberOfComponents();
10230   if(nbOfTuple2==nbOfTuple1)
10231     {
10232       if(nbOfComp1==nbOfComp2)
10233         {
10234           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10235           ret->alloc(nbOfTuple2,nbOfComp1);
10236           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<int>());
10237           ret->copyStringInfoFrom(*a1);
10238           return ret.retn();
10239         }
10240       else if(nbOfComp2==1)
10241         {
10242           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10243           ret->alloc(nbOfTuple1,nbOfComp1);
10244           const int *a2Ptr=a2->getConstPointer();
10245           const int *a1Ptr=a1->getConstPointer();
10246           int *res=ret->getPointer();
10247           for(int i=0;i<nbOfTuple1;i++)
10248             res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::divides<int>(),a2Ptr[i]));
10249           ret->copyStringInfoFrom(*a1);
10250           return ret.retn();
10251         }
10252       else
10253         {
10254           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
10255           return 0;
10256         }
10257     }
10258   else if(nbOfTuple2==1)
10259     {
10260       a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Divide !");
10261       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10262       ret->alloc(nbOfTuple1,nbOfComp1);
10263       const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
10264       int *pt=ret->getPointer();
10265       for(int i=0;i<nbOfTuple1;i++)
10266         pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::divides<int>());
10267       ret->copyStringInfoFrom(*a1);
10268       return ret.retn();
10269     }
10270   else
10271     {
10272       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Divide !");//will always throw an exception
10273       return 0;
10274     }
10275 }
10276
10277 /*!
10278  * Divide values of \a this array by values of another DataArrayInt. There are 3
10279  * valid cases.
10280  * 1.  The arrays have same number of tuples and components. Then each value of
10281  *    \a this array is divided by the corresponding value of \a other one, i.e.:
10282  *   _a_ [ i, j ] /= _other_ [ i, j ].
10283  * 2.  The arrays have same number of tuples and \a other array has one component. Then
10284  *   _a_ [ i, j ] /= _other_ [ i, 0 ].
10285  * 3.  The arrays have same number of components and \a other array has one tuple. Then
10286  *   _a_ [ i, j ] /= _a2_ [ 0, j ].
10287  *
10288  *  \warning No check of division by zero is performed!
10289  *  \param [in] other - an array to divide \a this one by.
10290  *  \throw If \a other is NULL.
10291  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
10292  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
10293  *         \a other has number of both tuples and components not equal to 1.
10294  */
10295 void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
10296 {
10297   if(!other)
10298     throw INTERP_KERNEL::Exception("DataArrayInt::divideEqual : input DataArrayInt instance is NULL !");
10299   const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !";
10300   checkAllocated(); other->checkAllocated();
10301   int nbOfTuple=getNumberOfTuples();
10302   int nbOfTuple2=other->getNumberOfTuples();
10303   int nbOfComp=getNumberOfComponents();
10304   int nbOfComp2=other->getNumberOfComponents();
10305   if(nbOfTuple==nbOfTuple2)
10306     {
10307       if(nbOfComp==nbOfComp2)
10308         {
10309           std::transform(begin(),end(),other->begin(),getPointer(),std::divides<int>());
10310         }
10311       else if(nbOfComp2==1)
10312         {
10313           int *ptr=getPointer();
10314           const int *ptrc=other->getConstPointer();
10315           for(int i=0;i<nbOfTuple;i++)
10316             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<int>(),*ptrc++));
10317         }
10318       else
10319         throw INTERP_KERNEL::Exception(msg);
10320     }
10321   else if(nbOfTuple2==1)
10322     {
10323       if(nbOfComp2==nbOfComp)
10324         {
10325           int *ptr=getPointer();
10326           const int *ptrc=other->getConstPointer();
10327           for(int i=0;i<nbOfTuple;i++)
10328             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<int>());
10329         }
10330       else
10331         throw INTERP_KERNEL::Exception(msg);
10332     }
10333   else
10334     throw INTERP_KERNEL::Exception(msg);
10335   declareAsNew();
10336 }
10337
10338
10339 /*!
10340  * Returns a new DataArrayInt that is a modulus of two given arrays. There are 3
10341  * valid cases.
10342  * 1.  The arrays have same number of tuples and components. Then each value of
10343  *   the result array (_a_) is a division of the corresponding values of \a a1 and
10344  *   \a a2, i.e.: _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ i, j ].
10345  * 2.  The arrays have same number of tuples and one array, say _a2_, has one
10346  *   component. Then
10347  *   _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ i, 0 ].
10348  * 3.  The arrays have same number of components and one array, say _a2_, has one
10349  *   tuple. Then
10350  *   _a_ [ i, j ] = _a1_ [ i, j ] % _a2_ [ 0, j ].
10351  *
10352  * Info on components is copied either from the first array (in the first case) or from
10353  * the array with maximal number of elements (getNbOfElems()).
10354  *  \warning No check of division by zero is performed!
10355  *  \param [in] a1 - a dividend array.
10356  *  \param [in] a2 - a divisor array.
10357  *  \return DataArrayInt * - the new instance of DataArrayInt.
10358  *          The caller is to delete this result array using decrRef() as it is no more
10359  *          needed.
10360  *  \throw If either \a a1 or \a a2 is NULL.
10361  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples() and
10362  *         \a a1->getNumberOfComponents() != \a a2->getNumberOfComponents() and
10363  *         none of them has number of tuples or components equal to 1.
10364  */
10365 DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
10366 {
10367     if(!a1 || !a2)
10368     throw INTERP_KERNEL::Exception("DataArrayInt::Modulus : input DataArrayInt instance is NULL !");
10369   int nbOfTuple1=a1->getNumberOfTuples();
10370   int nbOfTuple2=a2->getNumberOfTuples();
10371   int nbOfComp1=a1->getNumberOfComponents();
10372   int nbOfComp2=a2->getNumberOfComponents();
10373   if(nbOfTuple2==nbOfTuple1)
10374     {
10375       if(nbOfComp1==nbOfComp2)
10376         {
10377           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10378           ret->alloc(nbOfTuple2,nbOfComp1);
10379           std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::modulus<int>());
10380           ret->copyStringInfoFrom(*a1);
10381           return ret.retn();
10382         }
10383       else if(nbOfComp2==1)
10384         {
10385           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10386           ret->alloc(nbOfTuple1,nbOfComp1);
10387           const int *a2Ptr=a2->getConstPointer();
10388           const int *a1Ptr=a1->getConstPointer();
10389           int *res=ret->getPointer();
10390           for(int i=0;i<nbOfTuple1;i++)
10391             res=std::transform(a1Ptr+i*nbOfComp1,a1Ptr+(i+1)*nbOfComp1,res,std::bind2nd(std::modulus<int>(),a2Ptr[i]));
10392           ret->copyStringInfoFrom(*a1);
10393           return ret.retn();
10394         }
10395       else
10396         {
10397           a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
10398           return 0;
10399         }
10400     }
10401   else if(nbOfTuple2==1)
10402     {
10403       a1->checkNbOfComps(nbOfComp2,"Nb of components mismatch for array Modulus !");
10404       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10405       ret->alloc(nbOfTuple1,nbOfComp1);
10406       const int *a1ptr=a1->getConstPointer(),*a2ptr=a2->getConstPointer();
10407       int *pt=ret->getPointer();
10408       for(int i=0;i<nbOfTuple1;i++)
10409         pt=std::transform(a1ptr+i*nbOfComp1,a1ptr+(i+1)*nbOfComp1,a2ptr,pt,std::modulus<int>());
10410       ret->copyStringInfoFrom(*a1);
10411       return ret.retn();
10412     }
10413   else
10414     {
10415       a1->checkNbOfTuples(nbOfTuple2,"Nb of tuples mismatch for array Modulus !");//will always throw an exception
10416       return 0;
10417     }
10418 }
10419
10420 /*!
10421  * Modify \a this array so that each value becomes a modulus of division of this value by
10422  * a value of another DataArrayInt. There are 3 valid cases.
10423  * 1.  The arrays have same number of tuples and components. Then each value of
10424  *    \a this array is divided by the corresponding value of \a other one, i.e.:
10425  *   _a_ [ i, j ] %= _other_ [ i, j ].
10426  * 2.  The arrays have same number of tuples and \a other array has one component. Then
10427  *   _a_ [ i, j ] %= _other_ [ i, 0 ].
10428  * 3.  The arrays have same number of components and \a other array has one tuple. Then
10429  *   _a_ [ i, j ] %= _a2_ [ 0, j ].
10430  *
10431  *  \warning No check of division by zero is performed!
10432  *  \param [in] other - a divisor array.
10433  *  \throw If \a other is NULL.
10434  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples() and
10435  *         \a this->getNumberOfComponents() != \a other->getNumberOfComponents() and
10436  *         \a other has number of both tuples and components not equal to 1.
10437  */
10438 void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
10439 {
10440   if(!other)
10441     throw INTERP_KERNEL::Exception("DataArrayInt::modulusEqual : input DataArrayInt instance is NULL !");
10442   const char *msg="Nb of tuples mismatch for DataArrayInt::modulusEqual !";
10443   checkAllocated(); other->checkAllocated();
10444   int nbOfTuple=getNumberOfTuples();
10445   int nbOfTuple2=other->getNumberOfTuples();
10446   int nbOfComp=getNumberOfComponents();
10447   int nbOfComp2=other->getNumberOfComponents();
10448   if(nbOfTuple==nbOfTuple2)
10449     {
10450       if(nbOfComp==nbOfComp2)
10451         {
10452           std::transform(begin(),end(),other->begin(),getPointer(),std::modulus<int>());
10453         }
10454       else if(nbOfComp2==1)
10455         {
10456           if(nbOfComp2==nbOfComp)
10457             {
10458               int *ptr=getPointer();
10459               const int *ptrc=other->getConstPointer();
10460               for(int i=0;i<nbOfTuple;i++)
10461                 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::modulus<int>(),*ptrc++));
10462             }
10463           else
10464             throw INTERP_KERNEL::Exception(msg);
10465         }
10466       else
10467         throw INTERP_KERNEL::Exception(msg);
10468     }
10469   else if(nbOfTuple2==1)
10470     {
10471       int *ptr=getPointer();
10472       const int *ptrc=other->getConstPointer();
10473       for(int i=0;i<nbOfTuple;i++)
10474         std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::modulus<int>());
10475     }
10476   else
10477     throw INTERP_KERNEL::Exception(msg);
10478   declareAsNew();
10479 }
10480
10481 /*!
10482  * Returns a new DataArrayInt that is the result of pow of two given arrays. There are 3
10483  * valid cases.
10484  *
10485  *  \param [in] a1 - an array to pow up.
10486  *  \param [in] a2 - another array to sum up.
10487  *  \return DataArrayInt * - the new instance of DataArrayInt.
10488  *          The caller is to delete this result array using decrRef() as it is no more
10489  *          needed.
10490  *  \throw If either \a a1 or \a a2 is NULL.
10491  *  \throw If \a a1->getNumberOfTuples() != \a a2->getNumberOfTuples()
10492  *  \throw If \a a1->getNumberOfComponents() != 1 or \a a2->getNumberOfComponents() != 1.
10493  *  \throw If there is a negative value in \a a2.
10494  */
10495 DataArrayInt *DataArrayInt::Pow(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
10496 {
10497   if(!a1 || !a2)
10498     throw INTERP_KERNEL::Exception("DataArrayInt::Pow : at least one of input instances is null !");
10499   int nbOfTuple=a1->getNumberOfTuples();
10500   int nbOfTuple2=a2->getNumberOfTuples();
10501   int nbOfComp=a1->getNumberOfComponents();
10502   int nbOfComp2=a2->getNumberOfComponents();
10503   if(nbOfTuple!=nbOfTuple2)
10504     throw INTERP_KERNEL::Exception("DataArrayInt::Pow : number of tuples mismatches !");
10505   if(nbOfComp!=1 || nbOfComp2!=1)
10506     throw INTERP_KERNEL::Exception("DataArrayInt::Pow : number of components of both arrays must be equal to 1 !");
10507   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfTuple,1);
10508   const int *ptr1(a1->begin()),*ptr2(a2->begin());
10509   int *ptr=ret->getPointer();
10510   for(int i=0;i<nbOfTuple;i++,ptr1++,ptr2++,ptr++)
10511     {
10512       if(*ptr2>=0)
10513         {
10514           int tmp=1;
10515           for(int j=0;j<*ptr2;j++)
10516             tmp*=*ptr1;
10517           *ptr=tmp;
10518         }
10519       else
10520         {
10521           std::ostringstream oss; oss << "DataArrayInt::Pow : on tuple #" << i << " of a2 value is < 0 (" << *ptr2 << ") !";
10522           throw INTERP_KERNEL::Exception(oss.str().c_str());
10523         }
10524     }
10525   return ret.retn();
10526 }
10527
10528 /*!
10529  * Apply pow on values of another DataArrayInt to values of \a this one.
10530  *
10531  *  \param [in] other - an array to pow to \a this one.
10532  *  \throw If \a other is NULL.
10533  *  \throw If \a this->getNumberOfTuples() != \a other->getNumberOfTuples()
10534  *  \throw If \a this->getNumberOfComponents() != 1 or \a other->getNumberOfComponents() != 1
10535  *  \throw If there is a negative value in \a other.
10536  */
10537 void DataArrayInt::powEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
10538 {
10539   if(!other)
10540     throw INTERP_KERNEL::Exception("DataArrayInt::powEqual : input instance is null !");
10541   int nbOfTuple=getNumberOfTuples();
10542   int nbOfTuple2=other->getNumberOfTuples();
10543   int nbOfComp=getNumberOfComponents();
10544   int nbOfComp2=other->getNumberOfComponents();
10545   if(nbOfTuple!=nbOfTuple2)
10546     throw INTERP_KERNEL::Exception("DataArrayInt::powEqual : number of tuples mismatches !");
10547   if(nbOfComp!=1 || nbOfComp2!=1)
10548     throw INTERP_KERNEL::Exception("DataArrayInt::powEqual : number of components of both arrays must be equal to 1 !");
10549   int *ptr=getPointer();
10550   const int *ptrc=other->begin();
10551   for(int i=0;i<nbOfTuple;i++,ptrc++,ptr++)
10552     {
10553       if(*ptrc>=0)
10554         {
10555           int tmp=1;
10556           for(int j=0;j<*ptrc;j++)
10557             tmp*=*ptr;
10558           *ptr=tmp;
10559         }
10560       else
10561         {
10562           std::ostringstream oss; oss << "DataArrayInt::powEqual : on tuple #" << i << " of other value is < 0 (" << *ptrc << ") !";
10563           throw INTERP_KERNEL::Exception(oss.str().c_str());
10564         }
10565     }
10566   declareAsNew();
10567 }
10568
10569 /*!
10570  * Returns a C array which is a renumbering map in "Old to New" mode for the input array.
10571  * This map, if applied to \a start array, would make it sorted. For example, if
10572  * \a start array contents are [9,10,0,6,4,11,3,7] then the contents of the result array is
10573  * [5,6,0,3,2,7,1,4].
10574  *  \param [in] start - pointer to the first element of the array for which the
10575  *         permutation map is computed.
10576  *  \param [in] end - pointer specifying the end of the array \a start, so that
10577  *         the last value of \a start is \a end[ -1 ].
10578  *  \return int * - the result permutation array that the caller is to delete as it is no
10579  *         more needed.
10580  *  \throw If there are equal values in the input array.
10581  */
10582 int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end)
10583 {
10584   std::size_t sz=std::distance(start,end);
10585   int *ret=(int *)malloc(sz*sizeof(int));
10586   int *work=new int[sz];
10587   std::copy(start,end,work);
10588   std::sort(work,work+sz);
10589   if(std::unique(work,work+sz)!=work+sz)
10590     {
10591       delete [] work;
10592       free(ret);
10593       throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
10594     }
10595   std::map<int,int> m;
10596   for(int *workPt=work;workPt!=work+sz;workPt++)
10597     m[*workPt]=(int)std::distance(work,workPt);
10598   int *iter2=ret;
10599   for(const int *iter=start;iter!=end;iter++,iter2++)
10600     *iter2=m[*iter];
10601   delete [] work;
10602   return ret;
10603 }
10604
10605 /*!
10606  * Returns a new DataArrayInt containing an arithmetic progression
10607  * that is equal to the sequence returned by Python \c range(\a begin,\a  end,\a  step )
10608  * function.
10609  *  \param [in] begin - the start value of the result sequence.
10610  *  \param [in] end - limiting value, so that every value of the result array is less than
10611  *              \a end.
10612  *  \param [in] step - specifies the increment or decrement.
10613  *  \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
10614  *          array using decrRef() as it is no more needed.
10615  *  \throw If \a step == 0.
10616  *  \throw If \a end < \a begin && \a step > 0.
10617  *  \throw If \a end > \a begin && \a step < 0.
10618  */
10619 DataArrayInt *DataArrayInt::Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception)
10620 {
10621   int nbOfTuples=GetNumberOfItemGivenBESRelative(begin,end,step,"DataArrayInt::Range");
10622   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
10623   ret->alloc(nbOfTuples,1);
10624   int *ptr=ret->getPointer();
10625   if(step>0)
10626     {
10627       for(int i=begin;i<end;i+=step,ptr++)
10628         *ptr=i;
10629     }
10630   else
10631     {
10632       for(int i=begin;i>end;i+=step,ptr++)
10633         *ptr=i;
10634     }
10635   return ret.retn();
10636 }
10637
10638 /*!
10639  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10640  * Server side.
10641  */
10642 void DataArrayInt::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
10643 {
10644   tinyInfo.resize(2);
10645   if(isAllocated())
10646     {
10647       tinyInfo[0]=getNumberOfTuples();
10648       tinyInfo[1]=getNumberOfComponents();
10649     }
10650   else
10651     {
10652       tinyInfo[0]=-1;
10653       tinyInfo[1]=-1;
10654     }
10655 }
10656
10657 /*!
10658  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10659  * Server side.
10660  */
10661 void DataArrayInt::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
10662 {
10663   if(isAllocated())
10664     {
10665       int nbOfCompo=getNumberOfComponents();
10666       tinyInfo.resize(nbOfCompo+1);
10667       tinyInfo[0]=getName();
10668       for(int i=0;i<nbOfCompo;i++)
10669         tinyInfo[i+1]=getInfoOnComponent(i);
10670     }
10671   else
10672     {
10673       tinyInfo.resize(1);
10674       tinyInfo[0]=getName();
10675     }
10676 }
10677
10678 /*!
10679  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10680  * This method returns if a feeding is needed.
10681  */
10682 bool DataArrayInt::resizeForUnserialization(const std::vector<int>& tinyInfoI)
10683 {
10684   int nbOfTuple=tinyInfoI[0];
10685   int nbOfComp=tinyInfoI[1];
10686   if(nbOfTuple!=-1 || nbOfComp!=-1)
10687     {
10688       alloc(nbOfTuple,nbOfComp);
10689       return true;
10690     }
10691   return false;
10692 }
10693
10694 /*!
10695  * Useless method for end user. Only for MPI/Corba/File serialsation for multi arrays class.
10696  * This method returns if a feeding is needed.
10697  */
10698 void DataArrayInt::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
10699 {
10700   setName(tinyInfoS[0].c_str());
10701   if(isAllocated())
10702     {
10703       int nbOfCompo=getNumberOfComponents();
10704       for(int i=0;i<nbOfCompo;i++)
10705         setInfoOnComponent(i,tinyInfoS[i+1].c_str());
10706     }
10707 }
10708
10709 DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
10710 {
10711   if(_da)
10712     {
10713       _da->incrRef();
10714       if(_da->isAllocated())
10715         {
10716           _nb_comp=da->getNumberOfComponents();
10717           _nb_tuple=da->getNumberOfTuples();
10718           _pt=da->getPointer();
10719         }
10720     }
10721 }
10722
10723 DataArrayIntIterator::~DataArrayIntIterator()
10724 {
10725   if(_da)
10726     _da->decrRef();
10727 }
10728
10729 DataArrayIntTuple *DataArrayIntIterator::nextt() throw(INTERP_KERNEL::Exception)
10730 {
10731   if(_tuple_id<_nb_tuple)
10732     {
10733       _tuple_id++;
10734       DataArrayIntTuple *ret=new DataArrayIntTuple(_pt,_nb_comp);
10735       _pt+=_nb_comp;
10736       return ret;
10737     }
10738   else
10739     return 0;
10740 }
10741
10742 DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
10743 {
10744 }
10745
10746 std::string DataArrayIntTuple::repr() const throw(INTERP_KERNEL::Exception)
10747 {
10748   std::ostringstream oss; oss << "(";
10749   for(int i=0;i<_nb_of_compo-1;i++)
10750     oss << _pt[i] << ", ";
10751   oss << _pt[_nb_of_compo-1] << ")";
10752   return oss.str();
10753 }
10754
10755 int DataArrayIntTuple::intValue() const throw(INTERP_KERNEL::Exception)
10756 {
10757   if(_nb_of_compo==1)
10758     return *_pt;
10759   throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
10760 }
10761
10762 /*!
10763  * This method returns a newly allocated instance the caller should dealed with by a ParaMEDMEM::DataArrayInt::decrRef.
10764  * This method performs \b no copy of data. The content is only referenced using ParaMEDMEM::DataArrayInt::useArray with ownership set to \b false.
10765  * 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
10766  * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem.
10767  */
10768 DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
10769 {
10770   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
10771     {
10772       DataArrayInt *ret=DataArrayInt::New();
10773       ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
10774       return ret;
10775     }
10776   else
10777     {
10778       std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
10779       oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
10780       throw INTERP_KERNEL::Exception(oss.str().c_str());
10781     }
10782 }