Salome HOME
On the road
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 30 May 2017 21:25:45 +0000 (23:25 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 30 May 2017 21:25:45 +0000 (23:25 +0200)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling/MEDCouplingMemArrayChar.cxx

index 7eb1baf143934d7990dc86bc0097a3a6c2443f1c..566c0797687b55bd7ccf6a474920ee22e46d64ec 100644 (file)
@@ -809,16 +809,6 @@ DataArrayDouble *DataArrayDouble::deepCopy() const
   return new DataArrayDouble(*this);
 }
 
-/*!
- * Assign zero to all values in \a this array. To know more on filling arrays see
- * \ref MEDCouplingArrayFill.
- * \throw If \a this is not allocated.
- */
-void DataArrayDouble::fillWithZero()
-{
-  fillWithValue(0.);
-}
-
 /*!
  * Checks that \a this array is consistently **increasing** or **decreasing** in value,
  * with at least absolute difference value of |\a eps| at each step.
@@ -2405,28 +2395,6 @@ DataArrayDouble *DataArrayDouble::magnitude() const
   return ret;
 }
 
-/*!
- * Computes for each tuple the sum of number of components values in the tuple and return it.
- * 
- * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
- *          same number of tuples as \a this array and one component.
- *          The caller is to delete this result array using decrRef() as it is no more
- *          needed.
- *  \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::sumPerTuple() const
-{
-  checkAllocated();
-  int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
-  MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
-  ret->alloc(nbOfTuple,1);
-  const double *src(getConstPointer());
-  double *dest(ret->getPointer());
-  for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
-    *dest=std::accumulate(src,src+nbOfComp,0.);
-  return ret.retn();
-}
-
 /*!
  * Computes the maximal value within every tuple of \a this array.
  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
@@ -3747,35 +3715,6 @@ DataArrayInt32 *DataArrayInt32::deepCopy() const
   return new DataArrayInt32(*this);
 }
 
-/*!
- * Assign zero to all values in \a this array. To know more on filling arrays see
- * \ref MEDCouplingArrayFill.
- * \throw If \a this is not allocated.
- */
-void DataArrayInt::fillWithZero()
-{
-  fillWithValue(0);
-}
-
-/*!
- * Set all values in \a this array so that the i-th element equals to \a init + i
- * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
- *  \param [in] init - value to assign to the first element of array.
- *  \throw If \a this->getNumberOfComponents() != 1
- *  \throw If \a this is not allocated.
- */
-void DataArrayInt::iota(int init)
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
-  int *ptr=getPointer();
-  int ntuples=getNumberOfTuples();
-  for(int i=0;i<ntuples;i++)
-    ptr[i]=init+i;
-  declareAsNew();
-}
-
 /*!
  * Returns a textual and human readable representation of \a this instance of
  * DataArrayInt. This text is shown when a DataArrayInt is printed in Python.
@@ -4349,180 +4288,6 @@ MCAuto< MapKeyVal<int> > DataArrayInt::invertArrayN2O2O2NOptimized() const
   return ret;
 }
 
-/*!
- * Computes for each tuple the sum of number of components values in the tuple and return it.
- * 
- * \return DataArrayInt * - the new instance of DataArrayInt containing the
- *          same number of tuples as \a this array and one component.
- *          The caller is to delete this result array using decrRef() as it is no more
- *          needed.
- *  \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::sumPerTuple() const
-{
-  checkAllocated();
-  int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
-  MCAuto<DataArrayInt> ret(DataArrayInt::New());
-  ret->alloc(nbOfTuple,1);
-  const int *src(getConstPointer());
-  int *dest(ret->getPointer());
-  for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
-    *dest=std::accumulate(src,src+nbOfComp,0);
-  return ret.retn();
-}
-
-/*!
- * Checks that \a this array is consistently **increasing** or **decreasing** in value.
- * If not an exception is thrown.
- *  \param [in] increasing - if \a true, the array values should be increasing.
- *  \throw If sequence of values is not strictly monotonic in agreement with \a
- *         increasing arg.
- *  \throw If \a this->getNumberOfComponents() != 1.
- *  \throw If \a this is not allocated.
- */
-void DataArrayInt::checkMonotonic(bool increasing) const
-{
-  if(!isMonotonic(increasing))
-    {
-      if (increasing)
-        throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
-      else
-        throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
-    }
-}
-
-/*!
- * Checks that \a this array is consistently **increasing** or **decreasing** in value.
- *  \param [in] increasing - if \a true, array values should be increasing.
- *  \return bool - \a true if values change in accordance with \a increasing arg.
- *  \throw If \a this->getNumberOfComponents() != 1.
- *  \throw If \a this is not allocated.
- */
-bool DataArrayInt::isMonotonic(bool increasing) const
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !");
-  int nbOfElements=getNumberOfTuples();
-  const int *ptr=getConstPointer();
-  if(nbOfElements==0)
-    return true;
-  int ref=ptr[0];
-  if(increasing)
-    {
-      for(int i=1;i<nbOfElements;i++)
-        {
-          if(ptr[i]>=ref)
-            ref=ptr[i];
-          else
-            return false;
-        }
-    }
-  else
-    {
-      for(int i=1;i<nbOfElements;i++)
-        {
-          if(ptr[i]<=ref)
-            ref=ptr[i];
-          else
-            return false;
-        }
-    }
-  return true;
-}
-
-/*!
- * This method check that array consistently INCREASING or DECREASING in value.
- */
-bool DataArrayInt::isStrictlyMonotonic(bool increasing) const
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !");
-  int nbOfElements=getNumberOfTuples();
-  const int *ptr=getConstPointer();
-  if(nbOfElements==0)
-    return true;
-  int ref=ptr[0];
-  if(increasing)
-    {
-      for(int i=1;i<nbOfElements;i++)
-        {
-          if(ptr[i]>ref)
-            ref=ptr[i];
-          else
-            return false;
-        }
-    }
-  else
-    {
-      for(int i=1;i<nbOfElements;i++)
-        {
-          if(ptr[i]<ref)
-            ref=ptr[i];
-          else
-            return false;
-        }
-    }
-  return true;
-}
-
-/*!
- * This method check that array consistently INCREASING or DECREASING in value.
- */
-void DataArrayInt::checkStrictlyMonotonic(bool increasing) const
-{
-  if(!isStrictlyMonotonic(increasing))
-    {
-      if (increasing)
-        throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
-      else
-        throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
-    }
-}
-
-/*!
- * Elements of \a partOfThis are expected to be included in \a this.
- * The returned array \a ret is so that this[ret]==partOfThis
- *
- * For example, if \a this array contents are [9,10,0,6,4,11,3,8] and if \a partOfThis contains [6,0,11,8]
- * the return array will contain [3,2,5,7].
- *
- * \a this is expected to be a 1 compo allocated array.
- * \param [in] partOfThis - A 1 compo allocated array
- * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis.
- * \throw if two same element is present twice in \a this
- * \throw if an element in \a partOfThis is \b NOT in \a this.
- */
-DataArrayInt *DataArrayInt::indicesOfSubPart(const DataArrayInt& partOfThis) const
-{
-  if(getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !");
-  checkAllocated(); partOfThis.checkAllocated();
-  int thisNbTuples(getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples());
-  const int *thisPt(begin()),*pt(partOfThis.begin());
-  MCAuto<DataArrayInt> ret(DataArrayInt::New());
-  ret->alloc(nbTuples,1);
-  int *retPt(ret->getPointer());
-  std::map<int,int> m;
-  for(int i=0;i<thisNbTuples;i++,thisPt++)
-    m[*thisPt]=i;
-  if(m.size()!=thisNbTuples)
-    throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
-  for(int i=0;i<nbTuples;i++,retPt++,pt++)
-    {
-      std::map<int,int>::const_iterator it(m.find(*pt));
-      if(it!=m.end())
-        *retPt=(*it).second;
-      else
-        {
-          std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !";
-          throw INTERP_KERNEL::Exception(oss.str());
-        }
-    }
-  return ret.retn();
-}
-
 /*!
  * Returns a new DataArrayInt containing a renumbering map in "Old to New" mode.
  * This map, if applied to \a this array, would make it sorted. For example, if
index ac91081aae3ae6a60e791ce5b3d285939ed674d4..d2bcc3dea406775ccf24fd435d3faa84861e8ad7 100644 (file)
@@ -292,6 +292,7 @@ namespace MEDCoupling
     void insertAtTheEnd(InputIterator first, InputIterator last);
     MEDCOUPLING_EXPORT static void SetArrayIn(typename Traits<T>::ArrayType *newArray, typename Traits<T>::ArrayType* &arrayToSet);
     MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, T element0, const T *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
+    MEDCOUPLING_EXPORT void fillWithZero();
   public:
     MEDCOUPLING_EXPORT MemArray<T>& accessToMemArray() { return _mem; }
     MEDCOUPLING_EXPORT const MemArray<T>& accessToMemArray() const { return _mem; }
@@ -339,6 +340,8 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT void abs();
     MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *computeAbs() const;
     MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *performCopyOrIncrRef(bool dCpy) const;
+    MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *sumPerTuple() const;
+    MEDCOUPLING_EXPORT void iota(T init=(T)0);
   protected:
     static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
     template<class OP>
@@ -355,7 +358,6 @@ namespace MEDCoupling
   {
   public:
     MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const;
-    MEDCOUPLING_EXPORT void iota(T init=0.);
   };
 }
 
@@ -405,7 +407,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT double doubleValue() const;
     MEDCOUPLING_EXPORT DataArrayDouble *deepCopy() const;
     MEDCOUPLING_EXPORT DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
-    MEDCOUPLING_EXPORT void fillWithZero();
     MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const;
     MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const;
     MEDCOUPLING_EXPORT std::string repr() const;
@@ -471,7 +472,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayDouble *trace() const;
     MEDCOUPLING_EXPORT DataArrayDouble *deviator() const;
     MEDCOUPLING_EXPORT DataArrayDouble *magnitude() const;
-    MEDCOUPLING_EXPORT DataArrayDouble *sumPerTuple() const;
     MEDCOUPLING_EXPORT DataArrayDouble *maxPerTuple() const;
     MEDCOUPLING_EXPORT DataArrayDouble *maxPerTupleWithCompoId(DataArrayInt32* &compoIdOfMaxPerTuple) const;
     MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrix() const;
@@ -533,6 +533,11 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT void switchOnTupleEqualTo(T val, std::vector<bool>& vec) const;
     MEDCOUPLING_EXPORT void switchOnTupleNotEqualTo(T val, std::vector<bool>& vec) const;
     MEDCOUPLING_EXPORT DataArrayIdType *buildPermutationArr(const DataArrayDiscrete<T>& other) const;
+    MEDCOUPLING_EXPORT DataArrayIdType *indicesOfSubPart(const DataArrayDiscrete<T>& partOfThis) const;
+    MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const;
+    MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const;
+    MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const;
+    MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const;
   protected:
     template<class ALG>
     void switchOnTupleAlg(T val, std::vector<bool>& vec, ALG algo) const;
@@ -559,14 +564,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT int getHashCode() const;
     MEDCOUPLING_EXPORT DataArrayInt32 *deepCopy() const;//ok
     MEDCOUPLING_EXPORT DataArrayInt32 *buildNewEmptyInstance() const { return DataArrayInt32::New(); }//ok
-    MEDCOUPLING_EXPORT DataArrayInt32 *indicesOfSubPart(const DataArrayInt32& partOfThis) const;
-    MEDCOUPLING_EXPORT DataArrayInt32 *sumPerTuple() const;
-    MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const;
-    MEDCOUPLING_EXPORT bool isMonotonic(bool increasing) const;
-    MEDCOUPLING_EXPORT void checkStrictlyMonotonic(bool increasing) const;
-    MEDCOUPLING_EXPORT bool isStrictlyMonotonic(bool increasing) const;
-    MEDCOUPLING_EXPORT void fillWithZero();
-    MEDCOUPLING_EXPORT void iota(int init=0);
     MEDCOUPLING_EXPORT std::string repr() const;
     MEDCOUPLING_EXPORT std::string reprZip() const;
     MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
@@ -710,7 +707,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool isEqual(const DataArrayChar& other) const;
     MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const DataArrayChar& other, std::string& reason) const;
     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayChar& other) const;
-    MEDCOUPLING_EXPORT void fillWithZero();
     MEDCOUPLING_EXPORT std::string repr() const;
     MEDCOUPLING_EXPORT std::string reprZip() const;
     MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const;
index 2f05e5cbe29fd995d75c60978b81896c70780568..7813e5417ce7fdff9d91f91fec233bc1c4a69dc4 100644 (file)
@@ -2343,6 +2343,19 @@ namespace MEDCoupling
       }
   }
 
+    /*!
+   * Assign zero to all values in \a this array. To know more on filling arrays see
+   * \ref MEDCouplingArrayFill.
+   * \throw If \a this is not allocated.
+   */
+  template<class T>
+  void DataArrayTemplate<T>::fillWithZero()
+  {
+    fillWithValue((T)0);
+  }
+
+  //////////////////////////////
+
   template<class T>
   template<class U>
   MCAuto< typename Traits<U>::ArrayType > DataArrayTemplateClassic<T>::convertToOtherTypeOfArr() const
@@ -3205,6 +3218,51 @@ struct NotInRange
     const typename Traits<T>::ArrayType *thisC(static_cast<const typename Traits<T>::ArrayType *>(this));
     return DataArrayTemplateClassic<T>::PerformCopyOrIncrRef(dCpy,*thisC);
   }
+
+  /*!
+   * Computes for each tuple the sum of number of components values in the tuple and return it.
+   * 
+   * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+   *          same number of tuples as \a this array and one component.
+   *          The caller is to delete this result array using decrRef() as it is no more
+   *          needed.
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::sumPerTuple() const
+  {
+    this->checkAllocated();
+    std::size_t nbOfComp(this->getNumberOfComponents()),nbOfTuple(this->getNumberOfTuples());
+    MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+    ret->alloc(nbOfTuple,1);
+    const T *src(this->begin());
+    T *dest(ret->getPointer());
+    for(std::size_t i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
+      *dest=std::accumulate(src,src+nbOfComp,(T)0);
+    return ret.retn();
+  }
+
+  /*!
+   * Set all values in \a this array so that the i-th element equals to \a init + i
+   * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
+   *  \param [in] init - value to assign to the first element of array.
+   *  \throw If \a this->getNumberOfComponents() != 1
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  void DataArrayTemplateClassic<T>::iota(T init)
+  {
+    this->checkAllocated();
+    if(this->getNumberOfComponents()!=1)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
+    T *ptr(this->getPointer());
+    std::size_t ntuples(this->getNumberOfTuples());
+    for(std::size_t i=0;i<ntuples;i++)
+      ptr[i]=init+(T)i;
+    this->declareAsNew();
+  }
+  
+  /////////////////////////////////
   
   /*!
    * Checks if all values in \a this array are equal to \a val at precision \a eps.
@@ -3230,26 +3288,6 @@ struct NotInRange
     return true;
   }
 
-  /*!
-   * Set all values in \a this array so that the i-th element equals to \a init + i
-   * (i starts from zero). To know more on filling arrays see \ref MEDCouplingArrayFill.
-   *  \param [in] init - value to assign to the first element of array.
-   *  \throw If \a this->getNumberOfComponents() != 1
-   *  \throw If \a this is not allocated.
-   */
-  template<class T>
-  void DataArrayTemplateFP<T>::iota(T init)
-  {
-    this->checkAllocated();
-    if(this->getNumberOfComponents()!=1)
-      throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
-    T *ptr(this->getPointer());
-    int ntuples(this->getNumberOfTuples());
-    for(int i=0;i<ntuples;i++)
-      ptr[i]=init+T(i);
-    this->declareAsNew();
-  }
-
   /*!
    * Equivalent to DataArrayInt::isEqual except that if false the reason of
    * mismatch is given.
@@ -3403,6 +3441,165 @@ struct NotInRange
     return ret.retn();
   }
 
+  /*!
+   * Elements of \a partOfThis are expected to be included in \a this.
+   * The returned array \a ret is so that this[ret]==partOfThis
+   *
+   * For example, if \a this array contents are [9,10,0,6,4,11,3,8] and if \a partOfThis contains [6,0,11,8]
+   * the return array will contain [3,2,5,7].
+   *
+   * \a this is expected to be a 1 compo allocated array.
+   * \param [in] partOfThis - A 1 compo allocated array
+   * \return - A newly allocated array to be dealed by caller having the same number of tuples than \a partOfThis.
+   * \throw if two same element is present twice in \a this
+   * \throw if an element in \a partOfThis is \b NOT in \a this.
+   */
+  template<class T>
+  DataArrayIdType *DataArrayDiscrete<T>::indicesOfSubPart(const DataArrayDiscrete<T>& partOfThis) const
+  {
+    if(this->getNumberOfComponents()!=1 || partOfThis.getNumberOfComponents()!=1)
+      throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : this and input array must be one component array !");
+    this->checkAllocated(); partOfThis.checkAllocated();
+    std::size_t thisNbTuples(this->getNumberOfTuples()),nbTuples(partOfThis.getNumberOfTuples());
+    const T *thisPt(this->begin()),*pt(partOfThis.begin());
+    MCAuto<DataArrayIdType> ret(DataArrayIdType::New());
+    ret->alloc(nbTuples,1);
+    T *retPt(ret->getPointer());
+    std::map<int,mcIdType> m;
+    for(mcIdType i=0;i<thisNbTuples;i++,thisPt++)
+      m[*thisPt]=i;
+    if(m.size()!=thisNbTuples)
+      throw INTERP_KERNEL::Exception("DataArrayInt::indicesOfSubPart : some elements appears more than once !");
+    for(mcIdType i=0;i<nbTuples;i++,retPt++,pt++)
+      {
+        std::map<int,mcIdType>::const_iterator it(m.find(*pt));
+        if(it!=m.end())
+          *retPt=(*it).second;
+        else
+          {
+            std::ostringstream oss; oss << "DataArrayInt::indicesOfSubPart : At pos #" << i << " of input array value is " << *pt << " not in this !";
+            throw INTERP_KERNEL::Exception(oss.str());
+          }
+      }
+    return ret.retn();
+  }
+
+  /*!
+   * Checks that \a this array is consistently **increasing** or **decreasing** in value.
+   * If not an exception is thrown.
+   *  \param [in] increasing - if \a true, the array values should be increasing.
+   *  \throw If sequence of values is not strictly monotonic in agreement with \a
+   *         increasing arg.
+   *  \throw If \a this->getNumberOfComponents() != 1.
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  void DataArrayDiscrete<T>::checkMonotonic(bool increasing) const
+  {
+    if(!isMonotonic(increasing))
+      {
+        if (increasing)
+          throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not INCREASING monotonic !");
+        else
+          throw INTERP_KERNEL::Exception("DataArrayInt::checkMonotonic : 'this' is not DECREASING monotonic !");
+      }
+  }
+
+  /*!
+   * Checks that \a this array is consistently **increasing** or **decreasing** in value.
+   *  \param [in] increasing - if \a true, array values should be increasing.
+   *  \return bool - \a true if values change in accordance with \a increasing arg.
+   *  \throw If \a this->getNumberOfComponents() != 1.
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  bool DataArrayDiscrete<T>::isMonotonic(bool increasing) const
+  {
+    this->checkAllocated();
+    if(this->getNumberOfComponents()!=1)
+      throw INTERP_KERNEL::Exception("DataArrayInt::isMonotonic : only supported with 'this' array with ONE component !");
+    std::size_t nbOfElements(this->getNumberOfTuples());
+    const T *ptr(this->begin());
+    if(nbOfElements==0)
+      return true;
+    T ref(ptr[0]);
+    if(increasing)
+      {
+        for(std::size_t i=1;i<nbOfElements;i++)
+          {
+            if(ptr[i]>=ref)
+              ref=ptr[i];
+            else
+              return false;
+          }
+      }
+    else
+      {
+        for(std::size_t i=1;i<nbOfElements;i++)
+          {
+            if(ptr[i]<=ref)
+              ref=ptr[i];
+            else
+              return false;
+          }
+      }
+    return true;
+  }
+
+  /*!
+   * This method check that array consistently INCREASING or DECREASING in value.
+   */
+  template<class T>
+  bool DataArrayDiscrete<T>::isStrictlyMonotonic(bool increasing) const
+  {
+    this->checkAllocated();
+    if(this->getNumberOfComponents()!=1)
+      throw INTERP_KERNEL::Exception("DataArrayInt::isStrictlyMonotonic : only supported with 'this' array with ONE component !");
+    std::size_t nbOfElements(this->getNumberOfTuples());
+    const T *ptr(this->begin());
+    if(nbOfElements==0)
+      return true;
+    T ref(ptr[0]);
+    if(increasing)
+      {
+        for(std::size_t i=1;i<nbOfElements;i++)
+          {
+            if(ptr[i]>ref)
+              ref=ptr[i];
+            else
+              return false;
+          }
+      }
+    else
+      {
+        for(std::size_t i=1;i<nbOfElements;i++)
+          {
+            if(ptr[i]<ref)
+              ref=ptr[i];
+            else
+              return false;
+          }
+      }
+    return true;
+  }
+
+  /*!
+   * This method check that array consistently INCREASING or DECREASING in value.
+   */
+  template<class T>
+  void DataArrayDiscrete<T>::checkStrictlyMonotonic(bool increasing) const
+  {
+    if(!isStrictlyMonotonic(increasing))
+      {
+        if (increasing)
+          throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly INCREASING monotonic !");
+        else
+          throw INTERP_KERNEL::Exception("DataArrayInt::checkStrictlyMonotonic : 'this' is not strictly DECREASING monotonic !");
+      }
+  }
+
+  ////////////////////////////////////
+
   /*!
    * This method compares content of input vector \a v and \a this.
    * 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.
index 590423fdb2bd6b22bac590cdc9ce7bf5df8a447e..07b75d39aeacb7c9e7b9ac9a817f367d43c44503 100644 (file)
@@ -93,16 +93,6 @@ bool DataArrayChar::isEqualWithoutConsideringStr(const DataArrayChar& other) con
   return _mem.isEqual(other._mem,0,tmp);
 }
 
-/*!
- * Assign zero to all values in \a this array. To know more on filling arrays see
- * \ref MEDCouplingArrayFill.
- * \throw If \a this is not allocated.
- */
-void DataArrayChar::fillWithZero()
-{
-  fillWithValue(0);
-}
-
 /*!
  * Returns a textual and human readable representation of \a this instance of
  * DataArrayChar. This text is shown when a DataArrayChar is printed in Python.