Salome HOME
Code Factorization
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 4 May 2017 21:33:35 +0000 (23:33 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 4 May 2017 21:33:35 +0000 (23:33 +0200)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDLoader/Swig/MEDLoaderTest3.py

index 968656cfbde28702fda900b371881def37ab6470..a6e0f23e7e4e51bc4f79ce1163b93e5b908bdf25 100644 (file)
@@ -1123,85 +1123,6 @@ bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other,
   return _mem.isEqual(other._mem,prec,tmp);
 }
 
-/*!
- * Returns a new DataArrayDouble holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
- *  \warning Do not confuse this method with transpose()!
- *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
- *          is to delete using decrRef() as it is no more needed.
- *  \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::fromNoInterlace() const
-{
-  if(_mem.isNull())
-    throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
-  double *tab=_mem.fromNoInterlace(getNumberOfComponents());
-  DataArrayDouble *ret=DataArrayDouble::New();
-  ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
-  return ret;
-}
-
-/*!
- * Returns a new DataArrayDouble holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
- *  \warning Do not confuse this method with transpose()!
- *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
- *          is to delete using decrRef() as it is no more needed.
- *  \throw If \a this is not allocated.
- */
-DataArrayDouble *DataArrayDouble::toNoInterlace() const
-{
-  if(_mem.isNull())
-    throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
-  double *tab=_mem.toNoInterlace(getNumberOfComponents());
-  DataArrayDouble *ret=DataArrayDouble::New();
-  ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
-  return ret;
-}
-
-/*!
- * Appends components of another array to components of \a this one, tuple by tuple.
- * So that the number of tuples of \a this array remains the same and the number of 
- * components increases.
- *  \param [in] other - the DataArrayDouble to append to \a this one.
- *  \throw If \a this is not allocated.
- *  \throw If \a this and \a other arrays have different number of tuples.
- *
- *  \if ENABLE_EXAMPLES
- *  \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
- *
- *  \ref py_mcdataarraydouble_meldwith "Here is a Python example".
- *  \endif
- */
-void DataArrayDouble::meldWith(const DataArrayDouble *other)
-{
-  checkAllocated();
-  other->checkAllocated();
-  int nbOfTuples=getNumberOfTuples();
-  if(nbOfTuples!=other->getNumberOfTuples())
-    throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
-  int nbOfComp1=getNumberOfComponents();
-  int nbOfComp2=other->getNumberOfComponents();
-  double *newArr=(double *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(double));
-  double *w=newArr;
-  const double *inp1=getConstPointer();
-  const double *inp2=other->getConstPointer();
-  for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
-    {
-      w=std::copy(inp1,inp1+nbOfComp1,w);
-      w=std::copy(inp2,inp2+nbOfComp2,w);
-    }
-  useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
-  std::vector<int> compIds(nbOfComp2);
-  for(int i=0;i<nbOfComp2;i++)
-    compIds[i]=nbOfComp1+i;
-  copyPartOfStringInfoFrom2(compIds,*other);
-}
-
 /*!
  * This method checks that all tuples in \a other are in \a this.
  * If true, the output param \a tupleIds contains the tuples ids of \a this that correspond to tupes in \a this.
@@ -1293,34 +1214,6 @@ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayI
   commIndex=cI.retn();
 }
 
-/*!
- * 
- * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
- *             \a nbTimes  should be at least equal to 1.
- * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
- * \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.
- */
-DataArrayDouble *DataArrayDouble::duplicateEachTupleNTimes(int nbTimes) const
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
-  if(nbTimes<1)
-    throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
-  int nbTuples=getNumberOfTuples();
-  const double *inPtr=getConstPointer();
-  MCAuto<DataArrayDouble> ret=DataArrayDouble::New(); ret->alloc(nbTimes*nbTuples,1);
-  double *retPtr=ret->getPointer();
-  for(int i=0;i<nbTuples;i++,inPtr++)
-    {
-      double val=*inPtr;
-      for(int j=0;j<nbTimes;j++,retPtr++)
-        *retPtr=val;
-    }
-  ret->copyStringInfoFrom(*this);
-  return ret.retn();
-}
-
 /*!
  * This methods returns the minimal distance between the two set of points \a this and \a other.
  * So \a this and \a other have to have the same number of components. If not an INTERP_KERNEL::Exception will be thrown.
@@ -1532,27 +1425,6 @@ void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std:
       nc[nbOfCompo*i+compoIds[j]]=*ac;
 }
 
-void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
-{
-  if(newArray!=arrayToSet)
-    {
-      if(arrayToSet)
-        arrayToSet->decrRef();
-      arrayToSet=newArray;
-      if(arrayToSet)
-        arrayToSet->incrRef();
-    }
-}
-
-void DataArrayDouble::aggregate(const DataArrayDouble *other)
-{
-  if(!other)
-    throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !");
-  if(getNumberOfComponents()!=other->getNumberOfComponents())
-    throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !");
-  _mem.insertAtTheEnd(other->begin(),other->end());
-}
-
 /*!
  * Checks if 0.0 value is present in \a this array. If it is the case, an exception
  * is thrown.
@@ -4855,57 +4727,6 @@ DataArrayInt *DataArrayInt::indicesOfSubPart(const DataArrayInt& partOfThis) con
   return ret.retn();
 }
 
-void DataArrayInt::aggregate(const DataArrayInt *other)
-{
-  if(!other)
-    throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : null pointer !");
-  if(getNumberOfComponents()!=other->getNumberOfComponents())
-    throw INTERP_KERNEL::Exception("DataArrayInt::aggregate : mismatch number of components !");
-  _mem.insertAtTheEnd(other->begin(),other->end());
-}
-
-/*!
- * Returns a new DataArrayInt holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
- *  \warning Do not confuse this method with transpose()!
- *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
- *          is to delete using decrRef() as it is no more needed.
- *  \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::fromNoInterlace() const
-{
-  checkAllocated();
-  if(_mem.isNull())
-    throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
-  int *tab=_mem.fromNoInterlace(getNumberOfComponents());
-  DataArrayInt *ret=DataArrayInt::New();
-  ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
-  return ret;
-}
-
-/*!
- * Returns a new DataArrayInt holding the same values as \a this array but differently
- * arranged in memory. If \a this array holds 2 components of 3 values:
- * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
- * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
- *  \warning Do not confuse this method with transpose()!
- *  \return DataArrayInt * - the new instance of DataArrayInt that the caller
- *          is to delete using decrRef() as it is no more needed.
- *  \throw If \a this is not allocated.
- */
-DataArrayInt *DataArrayInt::toNoInterlace() const
-{
-  checkAllocated();
-  if(_mem.isNull())
-    throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
-  int *tab=_mem.toNoInterlace(getNumberOfComponents());
-  DataArrayInt *ret=DataArrayInt::New();
-  ret->useArray(tab,true,C_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
-  return ret;
-}
-
 /*!
  * 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
@@ -5227,47 +5048,6 @@ bool DataArrayInt::hasUniqueValues() const
   return true;
 }
 
-/*!
- * Appends components of another array to components of \a this one, tuple by tuple.
- * So that the number of tuples of \a this array remains the same and the number of 
- * components increases.
- *  \param [in] other - the DataArrayInt to append to \a this one.
- *  \throw If \a this is not allocated.
- *  \throw If \a this and \a other arrays have different number of tuples.
- *
- *  \if ENABLE_EXAMPLES
- *  \ref cpp_mcdataarrayint_meldwith "Here is a C++ example".
- *
- *  \ref py_mcdataarrayint_meldwith "Here is a Python example".
- *  \endif
- */
-void DataArrayInt::meldWith(const DataArrayInt *other)
-{
-  if(!other)
-    throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : DataArrayInt pointer in input is NULL !");
-  checkAllocated();
-  other->checkAllocated();
-  int nbOfTuples=getNumberOfTuples();
-  if(nbOfTuples!=other->getNumberOfTuples())
-    throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
-  int nbOfComp1=getNumberOfComponents();
-  int nbOfComp2=other->getNumberOfComponents();
-  int *newArr=(int *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(int));
-  int *w=newArr;
-  const int *inp1=getConstPointer();
-  const int *inp2=other->getConstPointer();
-  for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
-    {
-      w=std::copy(inp1,inp1+nbOfComp1,w);
-      w=std::copy(inp2,inp2+nbOfComp2,w);
-    }
-  useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
-  std::vector<int> compIds(nbOfComp2);
-  for(int i=0;i<nbOfComp2;i++)
-    compIds[i]=nbOfComp1+i;
-  copyPartOfStringInfoFrom2(compIds,*other);
-}
-
 /*!
  * Copy all components in a specified order from another DataArrayInt.
  * The specified components become the first ones in \a this array.
@@ -5301,24 +5081,6 @@ void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vecto
       nc[nbOfCompo*i+compoIds[j]]=*ac;
 }
 
-/*!
- * Assign pointer to one array to a pointer to another appay. Reference counter of
- * \a arrayToSet is incremented / decremented.
- *  \param [in] newArray - the pointer to array to assign to \a arrayToSet.
- *  \param [in,out] arrayToSet - the pointer to array to assign to.
- */
-void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
-{
-  if(newArray!=arrayToSet)
-    {
-      if(arrayToSet)
-        arrayToSet->decrRef();
-      arrayToSet=newArray;
-      if(arrayToSet)
-        arrayToSet->incrRef();
-    }
-}
-
 DataArrayIntIterator *DataArrayInt::iterator()
 {
   return new DataArrayIntIterator(this);
@@ -7073,34 +6835,6 @@ MCAuto<DataArrayInt> DataArrayInt::fromLinkedListOfPairToList() const
   return ret;
 }
 
-/*!
- * 
- * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayInt instance.
- *             \a nbTimes  should be at least equal to 1.
- * \return a newly allocated DataArrayInt having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
- * \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.
- */
-DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : this should have only one component !");
-  if(nbTimes<1)
-    throw INTERP_KERNEL::Exception("DataArrayInt::duplicateEachTupleNTimes : nb times should be >= 1 !");
-  int nbTuples=getNumberOfTuples();
-  const int *inPtr=getConstPointer();
-  MCAuto<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbTimes*nbTuples,1);
-  int *retPtr=ret->getPointer();
-  for(int i=0;i<nbTuples;i++,inPtr++)
-    {
-      int val=*inPtr;
-      for(int j=0;j<nbTimes;j++,retPtr++)
-        *retPtr=val;
-    }
-  ret->copyStringInfoFrom(*this);
-  return ret.retn();
-}
-
 /*!
  * This method returns all different values found in \a this. This method throws if \a this has not been allocated.
  * But the number of components can be different from one.
index 77ba020ec594f070d443a1e84eaa88a954f2ee7d..81b5784c3bae046e4e918e1ec653712194ec8169 100644 (file)
@@ -283,6 +283,11 @@ namespace MEDCoupling
     T getMaxValueInArray() const;
     T getMinValue(int& tupleId) const;
     T getMinValueInArray() const;
+    MEDCOUPLING_EXPORT void getTuple(int tupleId, T *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
+    template<class InputIterator>
+    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); }
   public:
     MEDCOUPLING_EXPORT MemArray<T>& accessToMemArray() { return _mem; }
     MEDCOUPLING_EXPORT const MemArray<T>& accessToMemArray() const { return _mem; }
@@ -322,6 +327,11 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT MCAuto<DataArrayInt> findIdsLowerOrEqualTo(T val) const;
     MEDCOUPLING_EXPORT MCAuto<DataArrayInt> findIdsLowerThan(T val) const;
     MEDCOUPLING_EXPORT DataArrayInt *findIdsStrictlyNegative() const;
+    MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *fromNoInterlace() const;
+    MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *toNoInterlace() const;
+    MEDCOUPLING_EXPORT void meldWith(const typename Traits<T>::ArrayType *other);
+    MEDCOUPLING_EXPORT typename Traits<T>::ArrayType *duplicateEachTupleNTimes(int nbTimes) const;
+    MEDCOUPLING_EXPORT void aggregate(const typename Traits<T>::ArrayType *other);
   protected:
     static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
     template<class OP>
@@ -409,30 +419,20 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const;
     MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const;
     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const;
-    MEDCOUPLING_EXPORT DataArrayDouble *fromNoInterlace() const;
-    MEDCOUPLING_EXPORT DataArrayDouble *toNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<double>::mySelectByTupleId(new2OldBg,new2OldEnd); }
     MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplateFP<double>::mySelectByTupleId(di); }
     MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<double>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
     MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplateFP<double>::myKeepSelectedComponents(compoIds); }
     MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplateFP<double>::mySelectByTupleIdSafeSlice(bg,end2,step); }
     MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplateFP<double>::mySelectByTupleRanges(ranges); }
-    MEDCOUPLING_EXPORT void meldWith(const DataArrayDouble *other);
     MEDCOUPLING_EXPORT bool areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const;
     MEDCOUPLING_EXPORT void findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const;
     MEDCOUPLING_EXPORT double minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const;
-    MEDCOUPLING_EXPORT DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const;
     MEDCOUPLING_EXPORT DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const;
     MEDCOUPLING_EXPORT DataArrayInt *findClosestTupleId(const DataArrayDouble *other) const;
     MEDCOUPLING_EXPORT DataArrayInt *computeNbOfInteractionsWith(const DataArrayDouble *otherBBoxFrmt, double eps) const;
     MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds);
-    MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
-    MEDCOUPLING_EXPORT static void SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet);
     MEDCOUPLING_EXPORT DataArrayDoubleIterator *iterator();
-    template<class InputIterator>
-    void insertAtTheEnd(InputIterator first, InputIterator last);
-    MEDCOUPLING_EXPORT void aggregate(const DataArrayDouble *other);
-    MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
     MEDCOUPLING_EXPORT void checkNoNullValues() const;
     MEDCOUPLING_EXPORT void getMinMaxPerComponent(double *bounds) const;
     MEDCOUPLING_EXPORT DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const;
@@ -567,8 +567,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2O(int newNbOfElem) const;
     MEDCOUPLING_EXPORT DataArrayInt *invertArrayN2O2O2N(int oldNbOfElem) const;
     MEDCOUPLING_EXPORT DataArrayInt *invertArrayO2N2N2OBis(int newNbOfElem) const;
-    MEDCOUPLING_EXPORT DataArrayInt *fromNoInterlace() const;
-    MEDCOUPLING_EXPORT DataArrayInt *toNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleId(new2OldBg,new2OldEnd); }
     MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate<int>::mySelectByTupleId(di); }
     MEDCOUPLING_EXPORT DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<int>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
@@ -583,10 +581,7 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool isIota(int sizeExpected) const;
     MEDCOUPLING_EXPORT bool isUniform(int val) const;
     MEDCOUPLING_EXPORT bool hasUniqueValues() const;
-    MEDCOUPLING_EXPORT void meldWith(const DataArrayInt *other);
     MEDCOUPLING_EXPORT void setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds);
-    MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
-    MEDCOUPLING_EXPORT static void SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet);
     MEDCOUPLING_EXPORT DataArrayIntIterator *iterator();
     MEDCOUPLING_EXPORT DataArrayInt *findIdsEqual(int val) const;
     MEDCOUPLING_EXPORT DataArrayInt *findIdsNotEqual(int val) const;
@@ -643,14 +638,9 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const;
     MEDCOUPLING_EXPORT void sortEachPairToMakeALinkedList();
     MEDCOUPLING_EXPORT MCAuto<DataArrayInt> fromLinkedListOfPairToList() const;
-    MEDCOUPLING_EXPORT DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const;
     MEDCOUPLING_EXPORT DataArrayInt *getDifferentValues() const;
     MEDCOUPLING_EXPORT std::vector<DataArrayInt *> partitionByDifferentValues(std::vector<int>& differentIds) const;
     MEDCOUPLING_EXPORT std::vector< std::pair<int,int> > splitInBalancedSlices(int nbOfSlices) const;
-    template<class InputIterator>
-    void insertAtTheEnd(InputIterator first, InputIterator last);
-    MEDCOUPLING_EXPORT void aggregate(const DataArrayInt *other);
-    MEDCOUPLING_EXPORT void writeOnPlace(std::size_t id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
     MEDCOUPLING_EXPORT static DataArrayInt *Modulus(const DataArrayInt *a1, const DataArrayInt *a2);
     MEDCOUPLING_EXPORT void modulusEqual(const DataArrayInt *other);
     MEDCOUPLING_EXPORT static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2);
@@ -706,7 +696,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT bool isUniform(char val) const;
     MEDCOUPLING_EXPORT void meldWith(const DataArrayChar *other);
     MEDCOUPLING_EXPORT DataArray *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<char>::mySelectByTupleRanges(ranges); }
-    MEDCOUPLING_EXPORT void getTuple(int tupleId, char *res) const { std::copy(_mem.getConstPointerLoc(tupleId*_info_on_compo.size()),_mem.getConstPointerLoc((tupleId+1)*_info_on_compo.size()),res); }
     MEDCOUPLING_EXPORT DataArrayInt *findIdsEqual(char val) const;
     MEDCOUPLING_EXPORT DataArrayInt *findIdsNotEqual(char val) const;
     MEDCOUPLING_EXPORT int findIdSequence(const std::vector<char>& vals) const;
@@ -721,8 +710,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT static DataArrayChar *Aggregate(const std::vector<const DataArrayChar *>& arr);
     MEDCOUPLING_EXPORT static DataArrayChar *Meld(const DataArrayChar *a1, const DataArrayChar *a2);
     MEDCOUPLING_EXPORT static DataArrayChar *Meld(const std::vector<const DataArrayChar *>& arr);
-    template<class InputIterator>
-    void insertAtTheEnd(InputIterator first, InputIterator last);
     MEDCOUPLING_EXPORT MemArray<char>& accessToMemArray() { return _mem; }
     MEDCOUPLING_EXPORT const MemArray<char>& accessToMemArray() const { return _mem; }
   public:
@@ -955,50 +942,21 @@ namespace MEDCoupling
         pointer[_nb_of_elem++]=*first++;
       }
   }
-  
-  template<class InputIterator>
-  void DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last)
-  {
-    int nbCompo(getNumberOfComponents());
-    if(nbCompo==1)
-      _mem.insertAtTheEnd(first,last);
-    else if(nbCompo==0)
-      {
-        _info_on_compo.resize(1);
-        _mem.insertAtTheEnd(first,last);
-      }
-    else
-      throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");
-  }
-
-  template<class InputIterator>
-  void DataArrayInt::insertAtTheEnd(InputIterator first, InputIterator last)
-  {
-    int nbCompo(getNumberOfComponents());
-    if(nbCompo==1)
-      _mem.insertAtTheEnd(first,last);
-    else if(nbCompo==0)
-      {
-        _info_on_compo.resize(1);
-        _mem.insertAtTheEnd(first,last);
-      }
-    else
-      throw INTERP_KERNEL::Exception("DataArrayInt::insertAtTheEnd : not available for DataArrayInt with number of components different than 1 !");
-  }
 
+  template<class T>
   template<class InputIterator>
-  void DataArrayChar::insertAtTheEnd(InputIterator first, InputIterator last)
+  void DataArrayTemplate<T>::insertAtTheEnd(InputIterator first, InputIterator last)
   {
-    int nbCompo(getNumberOfComponents());
+    int nbCompo(this->getNumberOfComponents());
     if(nbCompo==1)
-      _mem.insertAtTheEnd(first,last);
+      this->_mem.insertAtTheEnd(first,last);
     else if(nbCompo==0)
       {
-        _info_on_compo.resize(1);
-        _mem.insertAtTheEnd(first,last);
+        this->_info_on_compo.resize(1);
+        this->_mem.insertAtTheEnd(first,last);
       }
     else
-      throw INTERP_KERNEL::Exception("DataArrayChar::insertAtTheEnd : not available for DataArrayChar with number of components different than 1 !");
+      throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");
   }
 }
 
index 7643ad169c5cb1e1ff1934ceec2d2c64888d7759..1f45f132546ade6c7fc9669c503b3bb072d74f21 100644 (file)
@@ -2323,6 +2323,25 @@ namespace MEDCoupling
     std::reverse(_info_on_compo.begin(),_info_on_compo.end());
   }
 
+  /*!
+   * Assign pointer to one array to a pointer to another appay. Reference counter of
+   * \a arrayToSet is incremented / decremented.
+   *  \param [in] newArray - the pointer to array to assign to \a arrayToSet.
+   *  \param [in,out] arrayToSet - the pointer to array to assign to.
+   */
+  template<class T>
+  void DataArrayTemplate<T>::SetArrayIn(typename Traits<T>::ArrayType *newArray, typename Traits<T>::ArrayType* &arrayToSet)
+  {
+    if(newArray!=arrayToSet)
+      {
+        if(arrayToSet)
+          arrayToSet->decrRef();
+        arrayToSet=newArray;
+        if(arrayToSet)
+          arrayToSet->incrRef();
+      }
+  }
+
   template<class T>
   template<class U>
   MCAuto< typename Traits<U>::ArrayType > DataArrayTemplateClassic<T>::convertToOtherTypeOfArr() const
@@ -3010,6 +3029,125 @@ struct NotInRange
         ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j));
     return ret;
   }
+
+  /*!
+   * Returns a new DataArrayDouble holding the same values as \a this array but differently
+   * arranged in memory. If \a this array holds 2 components of 3 values:
+   * \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$, then the result array holds these values arranged
+   * as follows: \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$.
+   *  \warning Do not confuse this method with transpose()!
+   *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
+   *          is to delete using decrRef() as it is no more needed.
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::fromNoInterlace() const
+  {
+    if(this->_mem.isNull())
+      throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
+    T *tab(this->_mem.fromNoInterlace(this->getNumberOfComponents()));
+    MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+    ret->useArray(tab,true,C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents());
+    return ret.retn();
+  }
+
+  /*!
+   * Returns a new DataArrayDouble holding the same values as \a this array but differently
+   * arranged in memory. If \a this array holds 2 components of 3 values:
+   * \f$ x_0,y_0,x_1,y_1,x_2,y_2 \f$, then the result array holds these values arranged
+   * as follows: \f$ x_0,x_1,x_2,y_0,y_1,y_2 \f$.
+   *  \warning Do not confuse this method with transpose()!
+   *  \return DataArrayDouble * - the new instance of DataArrayDouble that the caller
+   *          is to delete using decrRef() as it is no more needed.
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::toNoInterlace() const
+  {
+    if(this->_mem.isNull())
+      throw INTERP_KERNEL::Exception("DataArrayDouble::toNoInterlace : Not defined array !");
+    T *tab(this->_mem.toNoInterlace(this->getNumberOfComponents()));
+    MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New());
+    ret->useArray(tab,true,C_DEALLOC,this->getNumberOfTuples(),this->getNumberOfComponents());
+    return ret.retn();
+  }
+  
+  /*!
+   * Appends components of another array to components of \a this one, tuple by tuple.
+   * So that the number of tuples of \a this array remains the same and the number of 
+   * components increases.
+   *  \param [in] other - the DataArrayDouble to append to \a this one.
+   *  \throw If \a this is not allocated.
+   *  \throw If \a this and \a other arrays have different number of tuples.
+   *
+   *  \if ENABLE_EXAMPLES
+   *  \ref cpp_mcdataarraydouble_meldwith "Here is a C++ example".
+   *
+   *  \ref py_mcdataarraydouble_meldwith "Here is a Python example".
+   *  \endif
+   */
+  template<class T>
+  void DataArrayTemplateClassic<T>::meldWith(const typename Traits<T>::ArrayType *other)
+  {
+    this->checkAllocated();
+    other->checkAllocated();
+    int nbOfTuples(this->getNumberOfTuples());
+    if(nbOfTuples!=other->getNumberOfTuples())
+      throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
+    int nbOfComp1(this->getNumberOfComponents()),nbOfComp2(other->getNumberOfComponents());
+    T *newArr=(T *)malloc((nbOfTuples*(nbOfComp1+nbOfComp2))*sizeof(T));
+    T *w=newArr;
+    const T *inp1(this->begin()),*inp2(other->begin());
+    for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
+      {
+        w=std::copy(inp1,inp1+nbOfComp1,w);
+        w=std::copy(inp2,inp2+nbOfComp2,w);
+      }
+    this->useArray(newArr,true,C_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
+    std::vector<int> compIds(nbOfComp2);
+    for(int i=0;i<nbOfComp2;i++)
+      compIds[i]=nbOfComp1+i;
+    this->copyPartOfStringInfoFrom2(compIds,*other);
+  }
+
+  /*!
+   * 
+   * \param [in] nbTimes specifies the nb of times each tuples in \a this will be duplicated contiguouly in returned DataArrayDouble instance.
+   *             \a nbTimes  should be at least equal to 1.
+   * \return a newly allocated DataArrayDouble having one component and number of tuples equal to \a nbTimes * \c this->getNumberOfTuples.
+   * \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.
+   */
+  template<class T>
+  typename Traits<T>::ArrayType *DataArrayTemplateClassic<T>::duplicateEachTupleNTimes(int nbTimes) const
+  {
+    this->checkAllocated();
+    if(this->getNumberOfComponents()!=1)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : this should have only one component !");
+    if(nbTimes<1)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::duplicateEachTupleNTimes : nb times should be >= 1 !");
+    int nbTuples(this->getNumberOfTuples());
+    const T *inPtr(this->begin());
+    MCAuto<typename Traits<T>::ArrayType> ret(Traits<T>::ArrayType::New()); ret->alloc(nbTimes*nbTuples,1);
+    T *retPtr(ret->getPointer());
+    for(int i=0;i<nbTuples;i++,inPtr++)
+      {
+        T val(*inPtr);
+        for(int j=0;j<nbTimes;j++,retPtr++)
+          *retPtr=val;
+      }
+    ret->copyStringInfoFrom(*this);
+    return ret.retn();
+  }
+  
+  template<class T>
+  void DataArrayTemplateClassic<T>::aggregate(const typename Traits<T>::ArrayType *other)
+  {
+    if(!other)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : null pointer !");
+    if(this->getNumberOfComponents()!=other->getNumberOfComponents())
+      throw INTERP_KERNEL::Exception("DataArrayDouble::aggregate : mismatch number of components !");
+    this->_mem.insertAtTheEnd(other->begin(),other->end());
+  }
   
   /*!
    * Checks if all values in \a this array are equal to \a val at precision \a eps.
index 558a8f3a9a21fc08dbde048295fbfa0254a53f6f..55fd117f1498925885467cdc0a8710660c16c6fe 100644 (file)
@@ -3078,7 +3078,7 @@ class MEDLoaderTest3(unittest.TestCase):
         self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
         heap_memory_ref=ff0.getHeapMemorySize()
-        self.assertIn(heap_memory_ref,xrange(182,465+2*strMulFac))
+        self.assertIn(heap_memory_ref,xrange(182,481+2*strMulFac))
         ff0.loadArrays() ##
         arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
@@ -3087,7 +3087,7 @@ class MEDLoaderTest3(unittest.TestCase):
         ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
         heap_memory_ref=ff0.getHeapMemorySize()
-        self.assertIn(heap_memory_ref,xrange(350,520+6*strMulFac))
+        self.assertIn(heap_memory_ref,xrange(350,536+6*strMulFac))
         ff0.loadArrays() ##
         arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
@@ -3105,7 +3105,7 @@ class MEDLoaderTest3(unittest.TestCase):
         self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
         heap_memory_ref=ff0.getHeapMemorySize()
-        self.assertIn(heap_memory_ref,xrange(1100,1384+2*strMulFac))
+        self.assertIn(heap_memory_ref,xrange(1100,1400+2*strMulFac))
         ff0.unloadArrays()
         hmd=ff0.getHeapMemorySize()-heap_memory_ref
         self.assertEqual(hmd,-800) # -50*8*2
@@ -3114,7 +3114,7 @@ class MEDLoaderTest3(unittest.TestCase):
         #
         ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
         heap_memory_ref=ff0.getHeapMemorySize()
-        self.assertIn(heap_memory_ref,xrange(299,520+6*strMulFac))
+        self.assertIn(heap_memory_ref,xrange(299,536+6*strMulFac))
         ff0.loadArrays() ##
         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
@@ -3131,14 +3131,14 @@ class MEDLoaderTest3(unittest.TestCase):
         #
         ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
         heap_memory_ref=ff0.getHeapMemorySize()
-        self.assertIn(heap_memory_ref,xrange(5536,8212+(80+26+1)*strMulFac))
+        self.assertIn(heap_memory_ref,xrange(5536,10242+(80+26+1)*strMulFac))
         ff0.loadArrays()
         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
         del ff0
         #
         ffs=MEDFileFields(fname,False)
         heap_memory_ref=ffs.getHeapMemorySize()
-        self.assertIn(heap_memory_ref,xrange(5335,9031+(80+50+len(ffs))*strMulFac))
+        self.assertIn(heap_memory_ref,xrange(5335,11507+(80+50+len(ffs))*strMulFac))
         ffs.loadArrays()
         self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
         pass