]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
First implementation of DataArrayFloat with corresponding factorization.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 26 Apr 2017 08:01:52 +0000 (10:01 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 26 Apr 2017 12:59:37 +0000 (14:59 +0200)
15 files changed:
src/MEDCoupling/CMakeLists.txt
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling/MEDCouplingMemArrayFloat.cxx [new file with mode: 0644]
src/MEDCoupling/MEDCouplingTraits.cxx
src/MEDCoupling/MEDCouplingTraits.hxx
src/MEDCoupling_Swig/CMakeLists.txt
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx [new file with mode: 0644]
src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i
src/MEDCoupling_Swig/MEDCouplingFieldDiscretization.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i
src/MEDCoupling_Swig/MEDCouplingNumPyTest.py
src/RENUMBER_Swig/MEDRenumberCommon.i

index 34ae94365739c5d7fd0f1fc605174c723d171c06..2c8a580ae5f949a216016101f60048565d6a0c72 100644 (file)
@@ -41,6 +41,7 @@ SET(medcoupling_SOURCES
   MEDCouplingUMesh_intersection.cxx
   MEDCoupling1GTUMesh.cxx
   MEDCouplingMemArray.cxx
+  MEDCouplingMemArrayFloat.cxx
   MEDCouplingMemArrayChar.cxx
   MEDCouplingTraits.cxx
   MEDCouplingTimeLabel.cxx
index 1a53cac8efa5559561bb52f487e04861e955225c..5067c1373dbe12a61bde8103a3da473b1c0c2312 100644 (file)
@@ -40,6 +40,7 @@ template class MEDCoupling::MemArray<int>;
 template class MEDCoupling::MemArray<double>;
 template class MEDCoupling::DataArrayTemplate<int>;
 template class MEDCoupling::DataArrayTemplate<double>;
+template class MEDCoupling::DataArrayTemplateFP<double>;
 
 template<int SPACEDIM>
 void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const
@@ -830,50 +831,6 @@ void DataArrayDouble::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 DataArrayDouble::iota(double init)
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
-  double *ptr=getPointer();
-  int ntuples=getNumberOfTuples();
-  for(int i=0;i<ntuples;i++)
-    ptr[i]=init+double(i);
-  declareAsNew();
-}
-
-/*!
- * Checks if all values in \a this array are equal to \a val at precision \a eps.
- *  \param [in] val - value to check equality of array values to.
- *  \param [in] eps - precision to check the equality.
- *  \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
- *                 \a false else.
- *  \throw If \a this->getNumberOfComponents() != 1
- *  \throw If \a this is not allocated.
- */
-bool DataArrayDouble::isUniform(double val, double eps) const
-{
-  checkAllocated();
-  if(getNumberOfComponents()!=1)
-    throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
-  int nbOfTuples=getNumberOfTuples();
-  const double *w=getConstPointer();
-  const double *end2=w+nbOfTuples;
-  const double vmin=val-eps;
-  const double vmax=val+eps;
-  for(;w!=end2;w++)
-    if(*w<vmin || *w>vmax)
-      return false;
-  return true;
-}
-
 /*!
  * Checks that \a this array is consistently **increasing** or **decreasing** in value,
  * with at least absolute difference value of |\a eps| at each step.
@@ -1051,8 +1008,8 @@ void DataArrayDouble::reprNotTooLongWithoutNameStream(std::ostream& stream) cons
 
 void DataArrayDouble::reprCppStream(const std::string& varName, std::ostream& stream) const
 {
-  int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents();
-  const double *data=getConstPointer();
+  int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
+  const double *data(getConstPointer());
   stream.precision(17);
   stream << "DataArrayDouble *" << varName << "=DataArrayDouble::New();" << std::endl;
   if(nbTuples*nbComp>=1)
index 39ab1cdeaf0c1edf4b4806013f34896cc49f7bef..8a57b8d140fdf044dc7b9e55c045fdb5f763cec5 100644 (file)
@@ -221,6 +221,7 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT std::vector< MCAuto< typename Traits<T>::ArrayTypeCh > > explodeComponents() const;
     //
     std::size_t getHeapMemorySizeWithoutChildren() const;
+    MEDCOUPLING_EXPORT void updateTime() const { }
     //
     MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); }
     MEDCOUPLING_EXPORT std::size_t getNbOfElems() const { return _mem.getNbOfElem(); }
@@ -282,6 +283,9 @@ namespace MEDCoupling
     T getMaxValueInArray() const;
     T getMinValue(int& tupleId) const;
     T getMinValueInArray() const;
+  public:
+    MEDCOUPLING_EXPORT MemArray<T>& accessToMemArray() { return _mem; }
+    MEDCOUPLING_EXPORT const MemArray<T>& accessToMemArray() const { return _mem; }
   protected:
     typename Traits<T>::ArrayType *mySelectByTupleId(const int *new2OldBg, const int *new2OldEnd) const;
     typename Traits<T>::ArrayType *mySelectByTupleId(const DataArrayInt& di) const;
@@ -292,12 +296,54 @@ namespace MEDCoupling
   protected:
     MemArray<T> _mem;
   };
+
+  template<class T>
+  class DataArrayTemplateFP : public DataArrayTemplate<T>
+  {
+  public:
+    MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const;
+    MEDCOUPLING_EXPORT void iota(T init=0.);
+  };
+}
+
+namespace MEDCoupling
+{
+  class DataArrayFloat : public DataArrayTemplateFP<float>
+  {
+  public:
+    MEDCOUPLING_EXPORT static DataArrayFloat *New();
+  public:// abstract method overload
+    MEDCOUPLING_EXPORT DataArrayFloat *deepCopy() const;
+    MEDCOUPLING_EXPORT DataArrayFloat *buildNewEmptyInstance() const { return DataArrayFloat::New(); }
+    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplateFP<float>::mySelectByTupleRanges(ranges); }
+    MEDCOUPLING_EXPORT DataArrayFloat *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplateFP<float>::myKeepSelectedComponents(compoIds); }
+    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<float>::mySelectByTupleId(new2OldBg,new2OldEnd); }
+    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplateFP<float>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
+    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplateFP<float>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+    MEDCOUPLING_EXPORT void reprStream(std::ostream& stream) const;
+    MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const;
+    MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
+    MEDCOUPLING_EXPORT void reprCppStream(const std::string& varName, std::ostream& stream) const;
+    MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const;
+    MEDCOUPLING_EXPORT void reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const;
+  public:
+    MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
+    MEDCOUPLING_EXPORT void reprNotTooLongStream(std::ostream& stream) const;
+    MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
+  public:
+    MEDCOUPLING_EXPORT bool isEqual(const DataArrayFloat& other, float prec) const;
+    MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const;
+    MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const;
+  private:
+    ~DataArrayFloat() { }
+    DataArrayFloat() { }
+  };
 }
 
 namespace MEDCoupling
 {
   class DataArrayDoubleIterator;
-  class DataArrayDouble : public DataArrayTemplate<double>
+  class DataArrayDouble : public DataArrayTemplateFP<double>
   {
   public:
     MEDCOUPLING_EXPORT static DataArrayDouble *New();
@@ -306,8 +352,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayDouble *buildNewEmptyInstance() const { return DataArrayDouble::New(); }
     MEDCOUPLING_EXPORT DataArrayDouble *performCopyOrIncrRef(bool deepCopy) const;
     MEDCOUPLING_EXPORT void fillWithZero();
-    MEDCOUPLING_EXPORT void iota(double init=0.);
-    MEDCOUPLING_EXPORT bool isUniform(double val, double eps) const;
     MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const;
     MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const;
     MEDCOUPLING_EXPORT std::string repr() const;
@@ -329,12 +373,12 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayInt *convertToIntArr() const;
     MEDCOUPLING_EXPORT DataArrayDouble *fromNoInterlace() const;
     MEDCOUPLING_EXPORT DataArrayDouble *toNoInterlace() const;
-    MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<double>::mySelectByTupleId(new2OldBg,new2OldEnd); }
-    MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const DataArrayInt& di) const { return DataArrayTemplate<double>::mySelectByTupleId(di); }
-    MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<double>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
-    MEDCOUPLING_EXPORT DataArrayDouble *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<double>::myKeepSelectedComponents(compoIds); }
-    MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<double>::mySelectByTupleIdSafeSlice(bg,end2,step); }
-    MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const { return DataArrayTemplate<double>::mySelectByTupleRanges(ranges); }
+    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;
@@ -427,9 +471,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT void divideEqual(const DataArrayDouble *other);
     MEDCOUPLING_EXPORT static DataArrayDouble *Pow(const DataArrayDouble *a1, const DataArrayDouble *a2);
     MEDCOUPLING_EXPORT void powEqual(const DataArrayDouble *other);
-    MEDCOUPLING_EXPORT void updateTime() const { }
-    MEDCOUPLING_EXPORT MemArray<double>& accessToMemArray() { return _mem; }
-    MEDCOUPLING_EXPORT const MemArray<double>& accessToMemArray() const { return _mem; }
     MEDCOUPLING_EXPORT std::vector<bool> toVectorOfBool(double eps) const;
     MEDCOUPLING_EXPORT static void Rotate2DAlg(const double *center, double angle, int nbNodes, const double *coordsIn, double *coordsOut);
     MEDCOUPLING_EXPORT static void Rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, const double *coordsIn, double *coordsOut);
@@ -639,7 +680,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT void modulusEqual(const DataArrayInt *other);
     MEDCOUPLING_EXPORT static DataArrayInt *Pow(const DataArrayInt *a1, const DataArrayInt *a2);
     MEDCOUPLING_EXPORT void powEqual(const DataArrayInt *other);
-    MEDCOUPLING_EXPORT void updateTime() const { }
     MEDCOUPLING_EXPORT MemArray<int>& accessToMemArray() { return _mem; }
     MEDCOUPLING_EXPORT const MemArray<int>& accessToMemArray() const { return _mem; }
   public:
@@ -742,7 +782,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT static DataArrayChar *Meld(const std::vector<const DataArrayChar *>& arr);
     template<class InputIterator>
     void insertAtTheEnd(InputIterator first, InputIterator last);
-    MEDCOUPLING_EXPORT void updateTime() const { }
     MEDCOUPLING_EXPORT MemArray<char>& accessToMemArray() { return _mem; }
     MEDCOUPLING_EXPORT const MemArray<char>& accessToMemArray() const { return _mem; }
   public:
index 5df4f7150b71637dd40bcf3af923036533ed8d9b..9fdf9051a94992c12dec226df8ce93a30dd21a28 100644 (file)
@@ -2252,6 +2252,50 @@ namespace MEDCoupling
       std::reverse(work,work+nbOfCompo);
     std::reverse(_info_on_compo.begin(),_info_on_compo.end());
   }
+  
+  /*!
+   * Checks if all values in \a this array are equal to \a val at precision \a eps.
+   *  \param [in] val - value to check equality of array values to.
+   *  \param [in] eps - precision to check the equality.
+   *  \return bool - \a true if all values are in range (_val_ - _eps_; _val_ + _eps_),
+   *                 \a false else.
+   *  \throw If \a this->getNumberOfComponents() != 1
+   *  \throw If \a this is not allocated.
+   */
+  template<class T>
+  bool DataArrayTemplateFP<T>::isUniform(T val, T eps) const
+  {
+    this->checkAllocated();
+    if(this->getNumberOfComponents()!=1)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
+    int nbOfTuples(this->getNumberOfTuples());
+    const T *w(this->begin()),*end2(this->end());
+    const T vmin(val-eps),vmax(val+eps);
+    for(;w!=end2;w++)
+      if(*w<vmin || *w>vmax)
+        return false;
+    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();
+  }
 }
 
 #endif
diff --git a/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx b/src/MEDCoupling/MEDCouplingMemArrayFloat.cxx
new file mode 100644 (file)
index 0000000..a064018
--- /dev/null
@@ -0,0 +1,169 @@
+// Copyright (C) 2007-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#include "MEDCouplingMemArray.txx"
+
+using namespace MEDCoupling;
+
+template class MEDCoupling::MemArray<float>;
+template class MEDCoupling::DataArrayTemplate<float>;
+template class MEDCoupling::DataArrayTemplateFP<float>;
+
+DataArrayFloat *DataArrayFloat::New()
+{
+  return new DataArrayFloat;
+}
+
+DataArrayFloat *DataArrayFloat::deepCopy() const
+{
+  return new DataArrayFloat(*this);
+}
+
+void DataArrayFloat::reprStream(std::ostream& stream) const
+{
+  stream << "Name of float array : \"" << _name << "\"\n";
+  reprWithoutNameStream(stream);
+}
+
+void DataArrayFloat::reprZipStream(std::ostream& stream) const
+{
+  stream << "Name of float array : \"" << _name << "\"\n";
+  reprZipWithoutNameStream(stream);
+}
+
+void DataArrayFloat::reprZipWithoutNameStream(std::ostream& stream) const
+{
+  DataArray::reprWithoutNameStream(stream);
+  stream.precision(7);
+  _mem.repr(getNumberOfComponents(),stream);
+}
+
+void DataArrayFloat::reprCppStream(const std::string& varName, std::ostream& stream) const
+{
+  int nbTuples(getNumberOfTuples()),nbComp(getNumberOfComponents());
+  const float *data(begin());
+  stream.precision(7);
+  stream << "DataArrayFloat *" << varName << "=DataArrayFloat::New();" << std::endl;
+  if(nbTuples*nbComp>=1)
+    {
+      stream << "const float " << varName << "Data[" << nbTuples*nbComp << "]={";
+      std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator<float>(stream,","));
+      stream << data[nbTuples*nbComp-1] << "};" << std::endl;
+      stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl;
+    }
+  else
+    stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl;
+  stream << varName << "->setName(\"" << getName() << "\");" << std::endl;
+}
+
+void DataArrayFloat::reprQuickOverview(std::ostream& stream) const
+{
+  static const std::size_t MAX_NB_OF_BYTE_IN_REPR=300;
+  stream << "DataArrayFloat C++ instance at " << this << ". ";
+  if(isAllocated())
+    {
+      int nbOfCompo=(int)_info_on_compo.size();
+      if(nbOfCompo>=1)
+        {
+          int nbOfTuples=getNumberOfTuples();
+          stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl;
+          reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR);
+        }
+      else
+        stream << "Number of components : 0.";
+    }
+  else
+    stream << "*** No data allocated ****";
+}
+
+void DataArrayFloat::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const
+{
+  const float *data(begin());
+  int nbOfTuples(getNumberOfTuples());
+  int nbOfCompo=(int)_info_on_compo.size();
+  std::ostringstream oss2; oss2 << "[";
+  oss2.precision(7);
+  std::string oss2Str(oss2.str());
+  bool isFinished=true;
+  for(int i=0;i<nbOfTuples && isFinished;i++)
+    {
+      if(nbOfCompo>1)
+        {
+          oss2 << "(";
+          for(int j=0;j<nbOfCompo;j++,data++)
+            {
+              oss2 << *data;
+              if(j!=nbOfCompo-1) oss2 << ", ";
+            }
+          oss2 << ")";
+        }
+      else
+        oss2 << *data++;
+      if(i!=nbOfTuples-1) oss2 << ", ";
+      std::string oss3Str(oss2.str());
+      if(oss3Str.length()<maxNbOfByteInRepr)
+        oss2Str=oss3Str;
+      else
+        isFinished=false;
+    }
+  stream << oss2Str;
+  if(!isFinished)
+    stream << "... ";
+  stream << "]";
+}
+
+std::string DataArrayFloat::reprNotTooLong() const
+{
+  std::ostringstream ret;
+  reprNotTooLongStream(ret);
+  return ret.str();
+}
+
+void DataArrayFloat::reprNotTooLongStream(std::ostream& stream) const
+{
+  stream << "Name of float array : \"" << _name << "\"\n";
+  reprNotTooLongWithoutNameStream(stream);
+}
+
+void DataArrayFloat::reprNotTooLongWithoutNameStream(std::ostream& stream) const
+{
+  DataArray::reprWithoutNameStream(stream);
+  stream.precision(7);
+  _mem.reprNotTooLong(getNumberOfComponents(),stream);
+}
+
+bool DataArrayFloat::isEqualIfNotWhy(const DataArrayFloat& other, float prec, std::string& reason) const
+{
+  if(!areInfoEqualsIfNotWhy(other,reason))
+    return false;
+  return _mem.isEqual(other._mem,prec,reason);
+}
+
+bool DataArrayFloat::isEqual(const DataArrayFloat& other, float prec) const
+{
+  std::string tmp;
+  return isEqualIfNotWhy(other,prec,tmp);
+}
+
+bool DataArrayFloat::isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const
+{
+  std::string tmp;
+  return _mem.isEqual(other._mem,prec,tmp);
+}
index 0a30d982d97defc1ffe18aa698a3f107e390031c..b7c82686a656bb705a01776a4b2e72d0c1e957d1 100644 (file)
@@ -26,6 +26,14 @@ const char Traits<double>::ArrayTypeName[]="DataArrayDouble";
 
 const char Traits<double>::FieldTypeName[]="MEDCouplingFieldDouble";
 
+const char Traits<double>::NPYStr[]="FLOAT64";
+
+const char Traits<float>::ArrayTypeName[]="DataArrayFloat";
+
+const char Traits<float>::FieldTypeName[]="MEDCouplingFieldFloat";
+
+const char Traits<float>::NPYStr[]="FLOAT32";
+
 const char Traits<int>::ArrayTypeName[]="DataArrayInt";
 
 const char Traits<int>::FieldTypeName[]="MEDCouplingFieldInt";
index 5a22379bf02963c97dd236326f8a67821c66fe4a..262328e7173231b72e27a2c9f118e443f53d1039 100644 (file)
@@ -32,6 +32,7 @@ namespace MEDCoupling
   };
 
   class DataArrayInt;
+  class DataArrayFloat;
   class DataArrayDouble;
   class DataArrayChar;
   class DataArrayByte;
@@ -43,10 +44,22 @@ namespace MEDCoupling
   {
     static const char ArrayTypeName[];
     static const char FieldTypeName[];
+    static const char NPYStr[];
     typedef DataArrayDouble ArrayType;
     typedef DataArrayDouble ArrayTypeCh;
     typedef MEDCouplingFieldDouble FieldType;
   };
+
+  template<>
+  struct MEDCOUPLING_EXPORT Traits<float>
+  {
+    static const char ArrayTypeName[];
+    static const char FieldTypeName[];
+    static const char NPYStr[];
+    typedef DataArrayFloat ArrayType;
+    typedef DataArrayFloat ArrayTypeCh;
+    //typedef MEDCouplingFieldFloat FieldType;
+  };
   
   template<>
   struct MEDCOUPLING_EXPORT Traits<int>
index a3cf107e343143fcd98a56ca7b1e7da006e4a8cb..9a3a0f16dca048e495af6b8768a2f199cfd93142 100644 (file)
@@ -56,6 +56,7 @@ SET (MC_Swig_interf
     MEDCouplingRemapper.i
     MEDCouplingTypemaps.i
     MEDCouplingDataArrayTypemaps.i
+    MEDCouplingDataArrayTraits.hxx
 )
 
 INCLUDE_DIRECTORIES(
index b6ceeba3bbabdeb8ae353d540b51ef352dd68769..ba29ca98d45f446c4303a34378756b18717d6dea 100644 (file)
@@ -173,6 +173,8 @@ using namespace INTERP_KERNEL;
 %init %{ import_array(); %}
 #endif
 
+%init %{ initializeMe(); %}
+
 %feature("autodoc", "1");
 %feature("docstring");
 
@@ -460,6 +462,15 @@ using namespace INTERP_KERNEL;
 %include "MEDCouplingRefCountObject.i"
 %include "MEDCouplingMemArray.i"
 
+%inline
+{
+  void initializeMe()
+  {
+    SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
+    SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+  }
+}
+
 namespace INTERP_KERNEL
 { 
   /*!
@@ -824,7 +835,7 @@ namespace MEDCoupling
            int spaceDim=self->getSpaceDimension();
            INTERP_KERNEL::AutoPtr<double> tmp=new double[2*spaceDim];
            self->getBoundingBox(tmp);
-           PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,spaceDim);
+           PyObject *ret=convertDblArrToPyListOfTuple<double>(tmp,2,spaceDim);
            return ret;
          }
 
@@ -2618,7 +2629,7 @@ namespace MEDCoupling
         double vals[6];
         std::copy(vec,vec+3,vals);
         std::copy(pos,pos+3,vals+3);
-        return convertDblArrToPyListOfTuple(vals,3,2);
+        return convertDblArrToPyListOfTuple<double>(vals,3,2);
       }
       
       static MEDCouplingUMesh *MergeUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception)
@@ -4165,7 +4176,7 @@ namespace MEDCoupling
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> res=new double[sz];
         self->getValueOn(spaceLoc,res);
-        return convertDblArrToPyList(res,sz);
+        return convertDblArrToPyList<double>(res,sz);
       }
 
        PyObject *getValueOnPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception)
@@ -4173,7 +4184,7 @@ namespace MEDCoupling
          int sz=self->getNumberOfComponents();
          INTERP_KERNEL::AutoPtr<double> res=new double[sz];
          self->getValueOnPos(i,j,k,res);
-         return convertDblArrToPyList(res,sz);
+         return convertDblArrToPyList<double>(res,sz);
        }
 
       DataArrayDouble *getValueOnMulti(PyObject *locs) const throw(INTERP_KERNEL::Exception)
@@ -4207,7 +4218,7 @@ namespace MEDCoupling
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> res=new double[sz];
         self->getValueOn(spaceLoc,time,res);
-        return convertDblArrToPyList(res,sz);
+        return convertDblArrToPyList<double>(res,sz);
       }
 
       void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception)
@@ -4259,35 +4270,35 @@ namespace MEDCoupling
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->accumulate(tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
       PyObject *integral(bool isWAbs) const throw(INTERP_KERNEL::Exception)
       {
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->integral(isWAbs,tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
       PyObject *getWeightedAverageValue(bool isWAbs=true) const throw(INTERP_KERNEL::Exception)
       {
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->getWeightedAverageValue(tmp,isWAbs);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
       PyObject *normL1() const throw(INTERP_KERNEL::Exception)
       {
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->normL1(tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
       PyObject *normL2() const throw(INTERP_KERNEL::Exception)
       {
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->normL2(tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
       void renumberCells(PyObject *li, bool check=true) throw(INTERP_KERNEL::Exception)
       {
diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx b/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx
new file mode 100644 (file)
index 0000000..10521d8
--- /dev/null
@@ -0,0 +1,350 @@
+// Copyright (C) 2007-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// Author : Anthony Geay (EDF R&D)
+
+#ifndef __MEDCOUPLINGDATAARRAYTRAITS_HXX__
+#define __MEDCOUPLINGDATAARRAYTRAITS_HXX__
+
+#include "MEDCouplingMemArray.hxx"
+
+#include <Python.h>
+
+#ifdef WITH_NUMPY
+#include <numpy/arrayobject.h>
+#if NPY_API_VERSION <= 0x00000006
+#  define MED_NUMPY_OWNDATA NPY_OWNDATA
+#else
+#  define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
+#endif
+#endif
+
+// specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
+// method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
+// if no more alive the "standart" DataArray deallocator is called.
+void numarrdeal(void *pt, void *wron)
+{
+  void **wronc=(void **)wron;
+  PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
+  PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
+  if(obj!=Py_None)
+    {
+      Py_XINCREF(obj);
+      PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
+      objC->flags|=MED_NUMPY_OWNDATA;
+      Py_XDECREF(weakRefOnOwner);
+      Py_XDECREF(obj);
+    }
+  else
+    {
+      typedef void (*MyDeallocator)(void *,void *);
+      MyDeallocator deall=(MyDeallocator)wronc[1];
+      deall(pt,NULL);
+      Py_XDECREF(weakRefOnOwner);
+    }
+  delete [] wronc;
+}
+
+template<class MCData>
+struct PyCallBackDataArraySt {
+    PyObject_HEAD
+    MCData *_pt_mc;
+};
+
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayFloat> PyCallBackDataArrayFloat;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
+
+extern "C"
+{
+  static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
+  
+  static PyObject *callbackmcdataarraychar___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+  {
+    PyCallBackDataArrayChar *self = (PyCallBackDataArrayChar *) ( type->tp_alloc(type, 0) );
+    return (PyObject *)self;
+  }
+
+  static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+  {
+    PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
+    return (PyObject *)self;
+  }
+  
+  static PyObject *callbackmcdataarrayfloat___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+  {
+    PyCallBackDataArrayFloat *self = (PyCallBackDataArrayFloat *) ( type->tp_alloc(type, 0) );
+    return (PyObject *)self;
+  }
+  
+  static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+  {
+    PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
+    return (PyObject *)self;
+  }
+  
+  static void callbackmcdataarray_dealloc(PyObject *self)
+  {
+    Py_TYPE(self)->tp_free(self);
+  }
+
+  
+  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+  static PyObject *callbackmcdataarraychar_call(PyCallBackDataArrayChar *self, PyObject *args, PyObject *kw)
+  {
+    if(self->_pt_mc)
+      {
+        MEDCoupling::MemArray<char>& mma=self->_pt_mc->accessToMemArray();
+        mma.destroy();
+      }
+    Py_XINCREF(Py_None);
+    return Py_None;
+  }
+
+  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+  static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
+  {
+    if(self->_pt_mc)
+      {
+        MEDCoupling::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
+        mma.destroy();
+      }
+    Py_XINCREF(Py_None);
+    return Py_None;
+  }
+
+  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+  static PyObject *callbackmcdataarrayfloat_call(PyCallBackDataArrayFloat *self, PyObject *args, PyObject *kw)
+  {
+    if(self->_pt_mc)
+      {
+        MEDCoupling::MemArray<float>& mma=self->_pt_mc->accessToMemArray();
+        mma.destroy();
+      }
+    Py_XINCREF(Py_None);
+    return Py_None;
+  }
+  
+  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+  static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
+  {
+    if(self->_pt_mc)
+      {
+        MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
+        mma.destroy();
+      }
+    Py_XINCREF(Py_None);
+    return Py_None;
+  }
+}
+
+PyTypeObject PyCallBackDataArrayChar_RefType = {
+  PyVarObject_HEAD_INIT(&PyType_Type, 0)
+  "callbackmcdataarraychar",
+  sizeof(PyCallBackDataArrayChar),
+  0,
+  callbackmcdataarray_dealloc,            /*tp_dealloc*/
+  0,                          /*tp_print*/
+  0,                          /*tp_getattr*/
+  0,                          /*tp_setattr*/
+  0,                          /*tp_compare*/
+  0,                          /*tp_repr*/
+  0,                          /*tp_as_number*/
+  0,                          /*tp_as_sequence*/
+  0,                          /*tp_as_mapping*/
+  0,                          /*tp_hash*/
+  (ternaryfunc)callbackmcdataarraychar_call,  /*tp_call*/
+  0,                          /*tp_str*/
+  0,                          /*tp_getattro*/
+  0,                          /*tp_setattro*/
+  0,                          /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
+  0,                          /*tp_doc*/
+  0,                          /*tp_traverse*/
+  0,                          /*tp_clear*/
+  0,                          /*tp_richcompare*/
+  0,                          /*tp_weaklistoffset*/
+  0,                          /*tp_iter*/
+  0,                          /*tp_iternext*/
+  0,                          /*tp_methods*/
+  0,                          /*tp_members*/
+  0,                          /*tp_getset*/
+  0,                          /*tp_base*/
+  0,                          /*tp_dict*/
+  0,                          /*tp_descr_get*/
+  0,                          /*tp_descr_set*/
+  0,                          /*tp_dictoffset*/
+  callbackmcdataarray___init__,           /*tp_init*/
+  PyType_GenericAlloc,        /*tp_alloc*/
+  callbackmcdataarraychar___new__,            /*tp_new*/
+  PyObject_GC_Del,            /*tp_free*/
+};
+
+
+PyTypeObject PyCallBackDataArrayInt_RefType = {
+  PyVarObject_HEAD_INIT(&PyType_Type, 0)
+  "callbackmcdataarrayint",
+  sizeof(PyCallBackDataArrayInt),
+  0,
+  callbackmcdataarray_dealloc,            /*tp_dealloc*/
+  0,                          /*tp_print*/
+  0,                          /*tp_getattr*/
+  0,                          /*tp_setattr*/
+  0,                          /*tp_compare*/
+  0,                          /*tp_repr*/
+  0,                          /*tp_as_number*/
+  0,                          /*tp_as_sequence*/
+  0,                          /*tp_as_mapping*/
+  0,                          /*tp_hash*/
+  (ternaryfunc)callbackmcdataarrayint_call,  /*tp_call*/
+  0,                          /*tp_str*/
+  0,                          /*tp_getattro*/
+  0,                          /*tp_setattro*/
+  0,                          /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
+  0,                          /*tp_doc*/
+  0,                          /*tp_traverse*/
+  0,                          /*tp_clear*/
+  0,                          /*tp_richcompare*/
+  0,                          /*tp_weaklistoffset*/
+  0,                          /*tp_iter*/
+  0,                          /*tp_iternext*/
+  0,                          /*tp_methods*/
+  0,                          /*tp_members*/
+  0,                          /*tp_getset*/
+  0,                          /*tp_base*/
+  0,                          /*tp_dict*/
+  0,                          /*tp_descr_get*/
+  0,                          /*tp_descr_set*/
+  0,                          /*tp_dictoffset*/
+  callbackmcdataarray___init__,           /*tp_init*/
+  PyType_GenericAlloc,        /*tp_alloc*/
+  callbackmcdataarrayint___new__,            /*tp_new*/
+  PyObject_GC_Del,            /*tp_free*/
+};
+
+PyTypeObject PyCallBackDataArrayFloat_RefType = {
+  PyVarObject_HEAD_INIT(&PyType_Type, 0)
+  "callbackmcdataarraydouble",
+  sizeof(PyCallBackDataArrayFloat),
+  0,
+  callbackmcdataarray_dealloc,            /*tp_dealloc*/
+  0,                          /*tp_print*/
+  0,                          /*tp_getattr*/
+  0,                          /*tp_setattr*/
+  0,                          /*tp_compare*/
+  0,                          /*tp_repr*/
+  0,                          /*tp_as_number*/
+  0,                          /*tp_as_sequence*/
+  0,                          /*tp_as_mapping*/
+  0,                          /*tp_hash*/
+  (ternaryfunc)callbackmcdataarraydouble_call,  /*tp_call*/
+  0,                          /*tp_str*/
+  0,                          /*tp_getattro*/
+  0,                          /*tp_setattro*/
+  0,                          /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
+  0,                          /*tp_doc*/
+  0,                          /*tp_traverse*/
+  0,                          /*tp_clear*/
+  0,                          /*tp_richcompare*/
+  0,                          /*tp_weaklistoffset*/
+  0,                          /*tp_iter*/
+  0,                          /*tp_iternext*/
+  0,                          /*tp_methods*/
+  0,                          /*tp_members*/
+  0,                          /*tp_getset*/
+  0,                          /*tp_base*/
+  0,                          /*tp_dict*/
+  0,                          /*tp_descr_get*/
+  0,                          /*tp_descr_set*/
+  0,                          /*tp_dictoffset*/
+  callbackmcdataarray___init__,           /*tp_init*/
+  PyType_GenericAlloc,        /*tp_alloc*/
+  callbackmcdataarrayfloat___new__,            /*tp_new*/
+  PyObject_GC_Del,            /*tp_free*/
+};
+
+PyTypeObject PyCallBackDataArrayDouble_RefType = {
+  PyVarObject_HEAD_INIT(&PyType_Type, 0)
+  "callbackmcdataarraydouble",
+  sizeof(PyCallBackDataArrayDouble),
+  0,
+  callbackmcdataarray_dealloc,            /*tp_dealloc*/
+  0,                          /*tp_print*/
+  0,                          /*tp_getattr*/
+  0,                          /*tp_setattr*/
+  0,                          /*tp_compare*/
+  0,                          /*tp_repr*/
+  0,                          /*tp_as_number*/
+  0,                          /*tp_as_sequence*/
+  0,                          /*tp_as_mapping*/
+  0,                          /*tp_hash*/
+  (ternaryfunc)callbackmcdataarraydouble_call,  /*tp_call*/
+  0,                          /*tp_str*/
+  0,                          /*tp_getattro*/
+  0,                          /*tp_setattro*/
+  0,                          /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
+  0,                          /*tp_doc*/
+  0,                          /*tp_traverse*/
+  0,                          /*tp_clear*/
+  0,                          /*tp_richcompare*/
+  0,                          /*tp_weaklistoffset*/
+  0,                          /*tp_iter*/
+  0,                          /*tp_iternext*/
+  0,                          /*tp_methods*/
+  0,                          /*tp_members*/
+  0,                          /*tp_getset*/
+  0,                          /*tp_base*/
+  0,                          /*tp_dict*/
+  0,                          /*tp_descr_get*/
+  0,                          /*tp_descr_set*/
+  0,                          /*tp_dictoffset*/
+  callbackmcdataarray___init__,           /*tp_init*/
+  PyType_GenericAlloc,        /*tp_alloc*/
+  callbackmcdataarraydouble___new__,            /*tp_new*/
+  PyObject_GC_Del,            /*tp_free*/
+};
+
+template<class T>
+struct NPYTraits
+{
+};
+
+template<>
+struct NPYTraits<double>
+{
+  static const int NPYObjectType=NPY_DOUBLE;
+  static PyTypeObject *NPYFunc;
+  static PyObject *Array_SWIGTYPE;
+};
+
+template<>
+struct NPYTraits<float>
+{
+  static const int NPYObjectType=NPY_FLOAT;
+  static PyTypeObject *NPYFunc;
+};
+
+#endif
index 8cb326457a0aecbfe9be8f1a0e537dd50298ecf2..ef8946fbf70a1d660f74c9b5fae443c991165217 100644 (file)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
 
 #ifndef __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
 #define __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
 
 #include "InterpKernelAutoPtr.hxx"
+#include "MEDCouplingDataArrayTraits.hxx"
 
 #include <sstream>
 
@@ -72,245 +73,6 @@ int InterpreteNegativeInt(int val, int nbelem)
     return val;
 }
 
-#ifdef WITH_NUMPY
-#include <numpy/arrayobject.h>
-#if NPY_API_VERSION <= 0x00000006
-#  define MED_NUMPY_OWNDATA NPY_OWNDATA
-#else
-#  define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
-#endif
-
-// specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
-// method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
-// if no more alive the "standart" DataArray deallocator is called.
-void numarrdeal(void *pt, void *wron)
-{
-  void **wronc=(void **)wron;
-  PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
-  PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
-  if(obj!=Py_None)
-    {
-      Py_XINCREF(obj);
-      PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
-      objC->flags|=MED_NUMPY_OWNDATA;
-      Py_XDECREF(weakRefOnOwner);
-      Py_XDECREF(obj);
-    }
-  else
-    {
-      typedef void (*MyDeallocator)(void *,void *);
-      MyDeallocator deall=(MyDeallocator)wronc[1];
-      deall(pt,NULL);
-      Py_XDECREF(weakRefOnOwner);
-    }
-  delete [] wronc;
-}
-
-template<class MCData>
-struct PyCallBackDataArraySt {
-    PyObject_HEAD
-    MCData *_pt_mc;
-};
-
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
-
-extern "C"
-{
-  static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
-  
-  static PyObject *callbackmcdataarraychar___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-  {
-    PyCallBackDataArrayChar *self = (PyCallBackDataArrayChar *) ( type->tp_alloc(type, 0) );
-    return (PyObject *)self;
-  }
-
-  static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-  {
-    PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
-    return (PyObject *)self;
-  }
-
-  static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-  {
-    PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
-    return (PyObject *)self;
-  }
-  
-  static void callbackmcdataarray_dealloc(PyObject *self)
-  {
-    Py_TYPE(self)->tp_free(self);
-  }
-
-  
-  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
-  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
-  static PyObject *callbackmcdataarraychar_call(PyCallBackDataArrayChar *self, PyObject *args, PyObject *kw)
-  {
-    if(self->_pt_mc)
-      {
-        MEDCoupling::MemArray<char>& mma=self->_pt_mc->accessToMemArray();
-        mma.destroy();
-      }
-    Py_XINCREF(Py_None);
-    return Py_None;
-  }
-
-  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
-  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
-  static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
-  {
-    if(self->_pt_mc)
-      {
-        MEDCoupling::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
-        mma.destroy();
-      }
-    Py_XINCREF(Py_None);
-    return Py_None;
-  }
-  
-  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
-  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
-  static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
-  {
-    if(self->_pt_mc)
-      {
-        MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
-        mma.destroy();
-      }
-    Py_XINCREF(Py_None);
-    return Py_None;
-  }
-}
-
-PyTypeObject PyCallBackDataArrayChar_RefType = {
-  PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarraychar",
-  sizeof(PyCallBackDataArrayChar),
-  0,
-  callbackmcdataarray_dealloc,            /*tp_dealloc*/
-  0,                          /*tp_print*/
-  0,                          /*tp_getattr*/
-  0,                          /*tp_setattr*/
-  0,                          /*tp_compare*/
-  0,                          /*tp_repr*/
-  0,                          /*tp_as_number*/
-  0,                          /*tp_as_sequence*/
-  0,                          /*tp_as_mapping*/
-  0,                          /*tp_hash*/
-  (ternaryfunc)callbackmcdataarraychar_call,  /*tp_call*/
-  0,                          /*tp_str*/
-  0,                          /*tp_getattro*/
-  0,                          /*tp_setattro*/
-  0,                          /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
-  0,                          /*tp_doc*/
-  0,                          /*tp_traverse*/
-  0,                          /*tp_clear*/
-  0,                          /*tp_richcompare*/
-  0,                          /*tp_weaklistoffset*/
-  0,                          /*tp_iter*/
-  0,                          /*tp_iternext*/
-  0,                          /*tp_methods*/
-  0,                          /*tp_members*/
-  0,                          /*tp_getset*/
-  0,                          /*tp_base*/
-  0,                          /*tp_dict*/
-  0,                          /*tp_descr_get*/
-  0,                          /*tp_descr_set*/
-  0,                          /*tp_dictoffset*/
-  callbackmcdataarray___init__,           /*tp_init*/
-  PyType_GenericAlloc,        /*tp_alloc*/
-  callbackmcdataarraychar___new__,            /*tp_new*/
-  PyObject_GC_Del,            /*tp_free*/
-};
-
-
-PyTypeObject PyCallBackDataArrayInt_RefType = {
-  PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarrayint",
-  sizeof(PyCallBackDataArrayInt),
-  0,
-  callbackmcdataarray_dealloc,            /*tp_dealloc*/
-  0,                          /*tp_print*/
-  0,                          /*tp_getattr*/
-  0,                          /*tp_setattr*/
-  0,                          /*tp_compare*/
-  0,                          /*tp_repr*/
-  0,                          /*tp_as_number*/
-  0,                          /*tp_as_sequence*/
-  0,                          /*tp_as_mapping*/
-  0,                          /*tp_hash*/
-  (ternaryfunc)callbackmcdataarrayint_call,  /*tp_call*/
-  0,                          /*tp_str*/
-  0,                          /*tp_getattro*/
-  0,                          /*tp_setattro*/
-  0,                          /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
-  0,                          /*tp_doc*/
-  0,                          /*tp_traverse*/
-  0,                          /*tp_clear*/
-  0,                          /*tp_richcompare*/
-  0,                          /*tp_weaklistoffset*/
-  0,                          /*tp_iter*/
-  0,                          /*tp_iternext*/
-  0,                          /*tp_methods*/
-  0,                          /*tp_members*/
-  0,                          /*tp_getset*/
-  0,                          /*tp_base*/
-  0,                          /*tp_dict*/
-  0,                          /*tp_descr_get*/
-  0,                          /*tp_descr_set*/
-  0,                          /*tp_dictoffset*/
-  callbackmcdataarray___init__,           /*tp_init*/
-  PyType_GenericAlloc,        /*tp_alloc*/
-  callbackmcdataarrayint___new__,            /*tp_new*/
-  PyObject_GC_Del,            /*tp_free*/
-};
-
-PyTypeObject PyCallBackDataArrayDouble_RefType = {
-  PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarraydouble",
-  sizeof(PyCallBackDataArrayDouble),
-  0,
-  callbackmcdataarray_dealloc,            /*tp_dealloc*/
-  0,                          /*tp_print*/
-  0,                          /*tp_getattr*/
-  0,                          /*tp_setattr*/
-  0,                          /*tp_compare*/
-  0,                          /*tp_repr*/
-  0,                          /*tp_as_number*/
-  0,                          /*tp_as_sequence*/
-  0,                          /*tp_as_mapping*/
-  0,                          /*tp_hash*/
-  (ternaryfunc)callbackmcdataarraydouble_call,  /*tp_call*/
-  0,                          /*tp_str*/
-  0,                          /*tp_getattro*/
-  0,                          /*tp_setattro*/
-  0,                          /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
-  0,                          /*tp_doc*/
-  0,                          /*tp_traverse*/
-  0,                          /*tp_clear*/
-  0,                          /*tp_richcompare*/
-  0,                          /*tp_weaklistoffset*/
-  0,                          /*tp_iter*/
-  0,                          /*tp_iternext*/
-  0,                          /*tp_methods*/
-  0,                          /*tp_members*/
-  0,                          /*tp_getset*/
-  0,                          /*tp_base*/
-  0,                          /*tp_dict*/
-  0,                          /*tp_descr_get*/
-  0,                          /*tp_descr_set*/
-  0,                          /*tp_dictoffset*/
-  callbackmcdataarray___init__,           /*tp_init*/
-  PyType_GenericAlloc,        /*tp_alloc*/
-  callbackmcdataarraydouble___new__,            /*tp_new*/
-  PyObject_GC_Del,            /*tp_free*/
-};
-
 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
 // in input when an another DataArray is already client of this.
 template<class MCData>
@@ -587,8 +349,6 @@ PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) t
   return ret;
 }
 
-#endif
-
 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
 {
   PyObject *ret=0;
@@ -618,6 +378,8 @@ static PyObject *convertDataArray(MEDCoupling::DataArray *dac, int owner) throw(
     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayDouble,owner);
   if(dynamic_cast<MEDCoupling::DataArrayInt *>(dac))
     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayInt,owner);
+  if(dynamic_cast<MEDCoupling::DataArrayFloat *>(dac))
+    ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayFloat,owner);
   if(dynamic_cast<MEDCoupling::DataArrayByte *>(dac))
     ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_MEDCoupling__DataArrayByte,owner);
   if(dynamic_cast<MEDCoupling::DataArrayAsciiChar *>(dac))
@@ -1251,9 +1013,10 @@ static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< st
     throw INTERP_KERNEL::Exception(msg);
 }
 
-static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
+template<class T>
+PyObject *convertDblArrToPyList(const T *ptr, int size) throw(INTERP_KERNEL::Exception)
 {
-  PyObject *ret=PyList_New(size);
+  PyObject *ret(PyList_New(size));
   for(int i=0;i<size;i++)
     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
   return ret;
@@ -1261,16 +1024,17 @@ static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP
 
 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
 {
-  int size=v.size();
-  PyObject *ret=PyList_New(size);
+  int size(v.size());
+  PyObject *ret(PyList_New(size));
   for(int i=0;i<size;i++)
     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
   return ret;
 }
 
-static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
+template<class T>
+PyObject *convertDblArrToPyListOfTuple(const T *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
 {
-  PyObject *ret=PyList_New(nbOfTuples);
+  PyObject *ret(PyList_New(nbOfTuples));
   for(int i=0;i<nbOfTuples;i++)
     {
       PyObject *t=PyTuple_New(nbOfComp);
@@ -1582,18 +1346,19 @@ static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std:
  *
  * switch between (int,vector<int>,DataArrayInt)
  */
-static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, MEDCoupling::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+template<class T>
+void convertObjToPossibleCpp4(PyObject *value, int& sw, T& iTyypp, std::vector<T>& stdvecTyypp, typename MEDCoupling::Traits<T>::ArrayType *& daIntTyypp, swig_type_info *ti) throw(INTERP_KERNEL::Exception)
 {
   sw=-1;
   if(PyFloat_Check(value))
     {
-      iTyypp=PyFloat_AS_DOUBLE(value);
+      iTyypp=(T)PyFloat_AS_DOUBLE(value);
       sw=1;
       return;
     }
   if(PyInt_Check(value))
     {
-      iTyypp=(double)PyInt_AS_LONG(value);
+      iTyypp=(T)PyInt_AS_LONG(value);
       sw=1;
       return;
     }
@@ -1605,9 +1370,9 @@ static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, s
         {
           PyObject *o=PyTuple_GetItem(value,i);
           if(PyFloat_Check(o))
-            stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
+            stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
           else if(PyInt_Check(o))
-            stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
+            stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
           else
             {
               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
@@ -1625,9 +1390,9 @@ static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, s
         {
           PyObject *o=PyList_GetItem(value,i);
           if(PyFloat_Check(o))
-            stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
+            stdvecTyypp[i]=(T)PyFloat_AS_DOUBLE(o);
           else if(PyInt_Check(o))
-            stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
+            stdvecTyypp[i]=(T)PyInt_AS_LONG(o);
           else
             {
               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
@@ -1638,10 +1403,10 @@ static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, s
       return;
     }
   void *argp;
-  int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_MEDCoupling__DataArrayDouble,0|0);
+  int status=SWIG_ConvertPtr(value,&argp,ti,0|0);
   if(!SWIG_IsOK(status))
     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
-  daIntTyypp=reinterpret_cast< MEDCoupling::DataArrayDouble * >(argp);
+  daIntTyypp=reinterpret_cast< typename MEDCoupling::Traits<T>::ArrayType * >(argp);
   sw=3;
 }
 
@@ -2677,5 +2442,583 @@ static PyObject *convertPartDefinition(MEDCoupling::PartDefinition *pd, int owne
   return ret;
 }
 
+template<class T>
+static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0, PyObject *nbOfTuples, PyObject *elt2)
+{
+  const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
+  std::string msg(msgBase);
+#ifdef WITH_NUMPY
+  msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
 #endif
+  msg+=" !";
+  if(PyList_Check(elt0) || PyTuple_Check(elt0))
+    {
+      if(nbOfTuples)
+        {
+          if(PyInt_Check(nbOfTuples))
+            {
+              int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
+              if(nbOfTuples1<0)
+                throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
+              if(elt2)
+                {
+                  if(PyInt_Check(elt2))
+                    {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
+                      int nbOfCompo=PyInt_AS_LONG(elt2);
+                      if(nbOfCompo<0)
+                        throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
+                      MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+                      std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo));
+                      ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
+                      return ret.retn();
+                    }
+                  else
+                    throw INTERP_KERNEL::Exception(msg.c_str());
+                }
+              else
+                {//DataArrayDouble.New([1.,3.,4.],3)
+                  MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+                  int tmpp1(-1);
+                  std::vector<double> tmp(fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1));
+                  ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
+                  return ret.retn();
+                }
+            }
+          else
+            throw INTERP_KERNEL::Exception(msg.c_str());
+        }
+      else
+        {// DataArrayDouble.New([1.,3.,4.])
+          MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+          int tmpp1(-1),tmpp2(-1);
+          std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
+          ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
+          return ret.retn();
+        }
+    }
+  else if(PyInt_Check(elt0))
+    {
+      int nbOfTuples1(PyInt_AS_LONG(elt0));
+      if(nbOfTuples1<0)
+        throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
+      if(nbOfTuples)
+        {
+          if(!elt2)
+            {
+              if(PyInt_Check(nbOfTuples))
+                {//DataArrayDouble.New(5,2)
+                  int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
+                  if(nbOfCompo<0)
+                    throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
+                  MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+                  ret->alloc(nbOfTuples1,nbOfCompo);
+                  return ret.retn();
+                }
+              else
+                throw INTERP_KERNEL::Exception(msg.c_str());
+            }
+          else
+            throw INTERP_KERNEL::Exception(msg.c_str());
+        }
+      else
+        {//DataArrayDouble.New(5)
+          MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > ret(MEDCoupling::Traits<T>::ArrayType::New());
+          ret->alloc(nbOfTuples1,1);
+          return ret.retn();
+        }
+    }
+#ifdef WITH_NUMPY
+  else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
+    {//DataArrayDouble.New(numpyArray)
+      return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
+    }
+#endif
+  else
+    throw INTERP_KERNEL::Exception(msg.c_str());
+  throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
+}
+
+template<class T>
+typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value, swig_type_info *ti)
+{
+  self->checkAllocated();
+  const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
+  int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
+  int sw1,sw2;
+  T i1;
+  std::vector<T> v1;
+  typename MEDCoupling::Traits<T>::ArrayType *d1=0;
+  convertObjToPossibleCpp4<T>(value,sw1,i1,v1,d1,ti);
+  int it1,ic1;
+  std::vector<int> vt1,vc1;
+  std::pair<int, std::pair<int,int> > pt1,pc1;
+  MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
+  convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
+  MEDCoupling::MCAuto< typename MEDCoupling::Traits<T>::ArrayType > tmp;
+  switch(sw2)
+    {
+    case 1:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 2:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 3:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 4:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 5:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 6:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 7:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 8:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
+            return self;
+          case 3:
+            self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 9:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
+            return self;
+          case 3:
+            self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 10:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
+            return self;
+          case 3:
+            self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 11:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
+            return self;
+          case 3:
+            self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 12:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
+            return self;
+          case 3:
+            self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 13:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
+            return self;
+          case 3:
+            self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 14:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
+            return self;
+          case 3:
+            self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 15:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
+            return self;
+          case 3:
+            self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    case 16:
+      {
+        switch(sw1)
+          {
+          case 1:
+            self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          case 2:
+            tmp=MEDCoupling::Traits<T>::ArrayType::New();
+            tmp->useArray(&v1[0],false,MEDCoupling::CPP_DEALLOC,1,v1.size());
+            self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
+            return self;
+          case 3:
+            self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
+            return self;
+          default:
+            throw INTERP_KERNEL::Exception(msg);
+          }
+        break;
+      }
+    default:
+      throw INTERP_KERNEL::Exception(msg);
+    }
+  return self;
+}
+
+template<class T>
+PyObject *DataArrayT__getitem__internal(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, swig_type_info *ti)
+{
+  const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
+  const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
+  self->checkAllocated();
+  int nbOfTuples(self->getNumberOfTuples()),nbOfComponents(self->getNumberOfComponents());
+  int it1,ic1;
+  std::vector<int> vt1,vc1;
+  std::pair<int, std::pair<int,int> > pt1,pc1;
+  MEDCoupling::DataArrayInt *dt1=0,*dc1=0;
+  int sw;
+  convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
+  MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType > ret;
+  switch(sw)
+    {
+    case 1:
+      if(nbOfComponents==1)
+        return PyFloat_FromDouble((T)self->getIJSafe(it1,0));
+      return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),ti, SWIG_POINTER_OWN | 0 );
+    case 2:
+      return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),ti, SWIG_POINTER_OWN | 0 );
+    case 3:
+      return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),ti, SWIG_POINTER_OWN | 0 );
+    case 4:
+      return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),ti, SWIG_POINTER_OWN | 0 );
+    case 5:
+      return PyFloat_FromDouble((T)self->getIJSafe(it1,ic1));
+    case 6:
+      {
+        ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+        std::vector<int> v2(1,ic1);
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 7:
+      {
+        ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
+        std::vector<int> v2(1,ic1);
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 8:
+      {
+        ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+        std::vector<int> v2(1,ic1);
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 9:
+      {
+        ret=self->selectByTupleIdSafe(&it1,&it1+1);
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 10:
+      {
+        ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 11:
+      {
+        ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 12:
+      {
+        ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 13:
+      {
+        ret=self->selectByTupleIdSafe(&it1,&it1+1);
+        int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+        std::vector<int> v2(nbOfComp);
+        for(int i=0;i<nbOfComp;i++)
+          v2[i]=pc1.first+i*pc1.second.second;
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 14:
+      {
+        ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
+        int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+        std::vector<int> v2(nbOfComp);
+        for(int i=0;i<nbOfComp;i++)
+          v2[i]=pc1.first+i*pc1.second.second;
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 15:
+      {
+        ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
+        int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+        std::vector<int> v2(nbOfComp);
+        for(int i=0;i<nbOfComp;i++)
+          v2[i]=pc1.first+i*pc1.second.second;
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    case 16:
+      {
+        ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
+        int nbOfComp(MEDCoupling::DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2));
+        std::vector<int> v2(nbOfComp);
+        for(int i=0;i<nbOfComp;i++)
+          v2[i]=pc1.first+i*pc1.second.second;
+        return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),ti, SWIG_POINTER_OWN | 0 );
+      }
+    default:
+      throw INTERP_KERNEL::Exception(msg);
+    }
+}
+
+template<class T>
+struct SWIGTITraits
+{ };
+
+template<>
+struct SWIGTITraits<double>
+{ static swig_type_info *TI; };
+
+template<>
+struct SWIGTITraits<float>
+{ static swig_type_info *TI; };
+
+swig_type_info *SWIGTITraits<double>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayDouble is null when called here ! Postpone initialization at inlined initializeMe()
+swig_type_info *SWIGTITraits<float>::TI=NULL;//unfortunately SWIGTYPE_p_MEDCoupling__DataArrayFloat is null when called here ! Postpone initialization at inlined initializeMe()
 
+PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
+
+PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
+
+template<class T>
+typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
+{
+  return DataArrayT__setitem__internal<T>(self,obj,value,SWIGTITraits<T>::TI);
+}
+
+template<class T>
+PyObject *DataArrayT__getitem(const typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
+{
+  return DataArrayT__getitem__internal<T>(self,obj,SWIGTITraits<T>::TI);
+}
+
+#endif
index 426faae0e98d8088cddaa4e3beb036da95730837..e152e6e336ca2d0d8a792f98f29b4a134dc24ddd 100644 (file)
@@ -121,7 +121,7 @@ namespace MEDCoupling
         int sz(arr->getNumberOfComponents());
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->normL1(mesh,arr,tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
 
       virtual PyObject *normL2(const MEDCouplingMesh *mesh, const DataArrayDouble *arr) const throw(INTERP_KERNEL::Exception)
@@ -131,7 +131,7 @@ namespace MEDCoupling
         int sz(arr->getNumberOfComponents());
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->normL2(mesh,arr,tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
 
       virtual PyObject *integral(const MEDCouplingMesh *mesh, const DataArrayDouble *arr, bool isWAbs) const throw(INTERP_KERNEL::Exception)
@@ -141,7 +141,7 @@ namespace MEDCoupling
         int sz(arr->getNumberOfComponents());
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->integral(mesh,arr,isWAbs,tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
 
       virtual PyObject *getCellIdsHavingGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception)
@@ -196,7 +196,7 @@ namespace MEDCoupling
         //
         INTERP_KERNEL::AutoPtr<double> res(new double[spaceDim]);
         self->getValueOn(arr,mesh,spaceLoc,res);
-        return convertDblArrToPyList(res,spaceDim);
+        return convertDblArrToPyList<double>(res,spaceDim);
       }
 
       virtual PyObject *getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k) const throw(INTERP_KERNEL::Exception)
@@ -206,7 +206,7 @@ namespace MEDCoupling
         int sz(arr->getNumberOfComponents());
          INTERP_KERNEL::AutoPtr<double> res=new double[sz];
          self->getValueOnPos(arr,mesh,i,j,k,res);
-         return convertDblArrToPyList(res,sz);
+         return convertDblArrToPyList<double>(res,sz);
        }
       
       virtual DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, PyObject *loc) const throw(INTERP_KERNEL::Exception)
@@ -353,21 +353,21 @@ namespace MEDCoupling
       {
         std::size_t sz(0);
         const double *ret(MEDCouplingFieldDiscretizationGaussNE::GetWeightArrayFromGeometricType(geoType,sz));
-        return convertDblArrToPyList(ret,sz);
+        return convertDblArrToPyList<double>(ret,sz);
       }
       
       static PyObject *GetRefCoordsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
       {
         std::size_t sz(0);
         const double *ret(MEDCouplingFieldDiscretizationGaussNE::GetRefCoordsFromGeometricType(geoType,sz));
-        return convertDblArrToPyList(ret,sz);
+        return convertDblArrToPyList<double>(ret,sz);
       }
       
       static PyObject *GetLocsFromGeometricType(INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception)
       {
         std::size_t sz(0);
         const double *ret(MEDCouplingFieldDiscretizationGaussNE::GetLocsFromGeometricType(geoType,sz));
-        return convertDblArrToPyList(ret,sz);
+        return convertDblArrToPyList<double>(ret,sz);
       }
     }
   };
index 4c0fd75c3effb6a699bc8ebd7ab05d61ad743a1a..1fd7a8d6e065eb6c3bb974a6411be28ba2bd85a6 100644 (file)
@@ -49,6 +49,7 @@
 %newobject MEDCoupling::DataArray::selectByTupleIdSafe;
 %newobject MEDCoupling::DataArray::selectByTupleIdSafeSlice;
 %newobject MEDCoupling::DataArray::Aggregate;
+%newobject MEDCoupling::DataArrayFloat::New;
 %newobject MEDCoupling::DataArrayInt::New;
 %newobject MEDCoupling::DataArrayInt::__iter__;
 %newobject MEDCoupling::DataArrayInt::selectPartDef;
@@ -657,6 +658,90 @@ namespace MEDCoupling
       }
     }
   };
+
+  class DataArrayFloat : public DataArray
+  {
+  public:
+    static DataArrayFloat *New();
+    void fillWithValue(float val) throw(INTERP_KERNEL::Exception);
+    bool isEqual(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception);
+    bool isEqualWithoutConsideringStr(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception);
+    bool isUniform(float val, float eps) const throw(INTERP_KERNEL::Exception);
+    void pushBackSilent(float val) throw(INTERP_KERNEL::Exception);
+    void iota(float init=0.) throw(INTERP_KERNEL::Exception);
+    %extend
+    {
+      DataArrayFloat() throw(INTERP_KERNEL::Exception)
+      {
+        return DataArrayFloat::New();
+      }
+
+      static DataArrayFloat *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
+      {
+        return DataArrayT_New<float>(elt0,nbOfTuples,elt2);
+      }
+   
+      DataArrayFloat(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
+      {
+        return MEDCoupling_DataArrayFloat_New__SWIG_1(elt0,nbOfTuples,elt2);
+      }
+
+      std::string __repr__() const throw(INTERP_KERNEL::Exception)
+      {
+        std::ostringstream oss;
+        self->reprQuickOverview(oss);
+        return oss.str();
+      }
+
+      std::string __str__() const throw(INTERP_KERNEL::Exception)
+      {
+        return self->reprNotTooLong();
+      }
+
+      int __len__() const throw(INTERP_KERNEL::Exception)
+      {
+        if(self->isAllocated())
+          {
+            return self->getNumberOfTuples();
+          }
+        else
+          {
+            throw INTERP_KERNEL::Exception("DataArrayFloat::__len__ : Instance is NOT allocated !");
+          }
+      }
+
+      PyObject *getValues() const throw(INTERP_KERNEL::Exception)
+      {
+        const float *vals(self->begin());
+        return convertDblArrToPyList<float>(vals,self->getNbOfElems());
+      }
+
+      PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception)
+      {
+        const float *vals(self->begin());
+        int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples());
+        return convertDblArrToPyListOfTuple<float>(vals,nbOfComp,nbOfTuples);
+      }
+
+      PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+      {
+        return DataArrayT__getitem<float>(self,obj);
+      }
+
+      DataArrayFloat *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
+      {
+        return DataArrayT__setitem__<float>(self,obj,value);
+      }
+      
+#ifdef WITH_NUMPY
+      PyObject *toNumPyArray() throw(INTERP_KERNEL::Exception) // not const. It is not a bug !
+      {
+        return ToNumPyArray<DataArrayFloat,float>(self,NPY_FLOAT,"DataArrayFloat");
+      }
+#endif
+      
+    }
+  };
   
   class DataArrayInt;
   class DataArrayDoubleIterator;
@@ -779,109 +864,19 @@ namespace MEDCoupling
     %extend
     {
       DataArrayDouble() throw(INTERP_KERNEL::Exception)
-        {
-          return DataArrayDouble::New();
-        }
+      {
+        return DataArrayDouble::New();
+      }
 
       static DataArrayDouble *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
       {
-        const char *msgBase="MEDCoupling::DataArrayDouble::New : Available API are : \n-DataArrayDouble.New()\n-DataArrayDouble.New([1.,3.,4.])\n-DataArrayDouble.New([1.,3.,4.],3)\n-DataArrayDouble.New([1.,3.,4.,5.],2,2)\n-DataArrayDouble.New([1.,3.,4.,5.,7,8.],3,2)\n-DataArrayDouble.New([(1.,3.),(4.,5.),(7,8.)])\n-DataArrayDouble.New(5)\n-DataArrayDouble.New(5,2)";
-        std::string msg(msgBase);
-#ifdef WITH_NUMPY
-        msg+="\n-DataArrayDouble.New(numpy array with dtype=float64)";
-#endif
-        msg+=" !";
-        if(PyList_Check(elt0) || PyTuple_Check(elt0))
-          {
-            if(nbOfTuples)
-              {
-                if(PyInt_Check(nbOfTuples))
-                  {
-                    int nbOfTuples1=PyInt_AS_LONG(nbOfTuples);
-                    if(nbOfTuples1<0)
-                      throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
-                    if(elt2)
-                      {
-                        if(PyInt_Check(elt2))
-                          {//DataArrayDouble.New([1.,3.,4.,5.],2,2)
-                            int nbOfCompo=PyInt_AS_LONG(elt2);
-                            if(nbOfCompo<0)
-                              throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
-                            MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
-                            std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo);
-                            ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
-                            return ret.retn();
-                          }
-                        else
-                          throw INTERP_KERNEL::Exception(msg.c_str());
-                      }
-                    else
-                      {//DataArrayDouble.New([1.,3.,4.],3)
-                        MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
-                        int tmpp1=-1;
-                        std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1);
-                        ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
-                        return ret.retn();
-                      }
-                  }
-                else
-                  throw INTERP_KERNEL::Exception(msg.c_str());
-              }
-            else
-              {// DataArrayDouble.New([1.,3.,4.])
-                MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
-                int tmpp1=-1,tmpp2=-1;
-                std::vector<double> tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2);
-                ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer());
-                return ret.retn();
-              }
-          }
-        else if(PyInt_Check(elt0))
-          {
-            int nbOfTuples1=PyInt_AS_LONG(elt0);
-            if(nbOfTuples1<0)
-              throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive set of allocated memory !");
-            if(nbOfTuples)
-              {
-                if(!elt2)
-                  {
-                    if(PyInt_Check(nbOfTuples))
-                      {//DataArrayDouble.New(5,2)
-                        int nbOfCompo=PyInt_AS_LONG(nbOfTuples);
-                        if(nbOfCompo<0)
-                          throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !");
-                        MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
-                        ret->alloc(nbOfTuples1,nbOfCompo);
-                        return ret.retn();
-                      }
-                    else
-                      throw INTERP_KERNEL::Exception(msg.c_str());
-                  }
-                else
-                  throw INTERP_KERNEL::Exception(msg.c_str());
-              }
-            else
-              {//DataArrayDouble.New(5)
-                MCAuto<DataArrayDouble> ret=DataArrayDouble::New();
-                ret->alloc(nbOfTuples1,1);
-                return ret.retn();
-              }
-          }
-#ifdef WITH_NUMPY
-        else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
-          {//DataArrayDouble.New(numpyArray)
-            return BuildNewInstance<DataArrayDouble,double>(elt0,NPY_DOUBLE,&PyCallBackDataArrayDouble_RefType,"FLOAT64");
-          }
-#endif
-        else
-          throw INTERP_KERNEL::Exception(msg.c_str());
-        throw INTERP_KERNEL::Exception(msg.c_str());//to make g++ happy
+        return DataArrayT_New<double>(elt0,nbOfTuples,elt2);
       }
    
       DataArrayDouble(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *elt2=0) throw(INTERP_KERNEL::Exception)
-        {
-          return MEDCoupling_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2);
-        }
+      {
+        return MEDCoupling_DataArrayDouble_New__SWIG_1(elt0,nbOfTuples,elt2);
+      }
 
       DataArrayDouble *selectPartDef(const PartDefinition* pd) const throw(INTERP_KERNEL::Exception)
       {
@@ -987,8 +982,8 @@ namespace MEDCoupling
 
       PyObject *getValues() const throw(INTERP_KERNEL::Exception)
       {
-        const double *vals=self->getConstPointer();
-        return convertDblArrToPyList(vals,self->getNbOfElems());
+        const double *vals(self->begin());
+        return convertDblArrToPyList<double>(vals,self->getNbOfElems());
       }
 
 #ifdef WITH_NUMPY
@@ -1012,10 +1007,9 @@ namespace MEDCoupling
 
       PyObject *getValuesAsTuple() const throw(INTERP_KERNEL::Exception)
       {
-        const double *vals=self->getConstPointer();
-        int nbOfComp=self->getNumberOfComponents();
-        int nbOfTuples=self->getNumberOfTuples();
-        return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples);
+        const double *vals(self->begin());
+        int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples());
+        return convertDblArrToPyListOfTuple<double>(vals,nbOfComp,nbOfTuples);
       }
 
       DataArrayDouble *symmetry3DPlane(PyObject *point, PyObject *normalVector) throw(INTERP_KERNEL::Exception)
@@ -1043,7 +1037,7 @@ namespace MEDCoupling
         const double *vectorPtr(convertObjToPossibleCpp5_Safe(normalVector,sw,val,a,aa,bb,msg,1,3,true));
         double res[9];
         DataArrayDouble::GiveBaseForPlane(vectorPtr,res);
-        return convertDblArrToPyListOfTuple(res,3,3);
+        return convertDblArrToPyListOfTuple<double>(res,3,3);
       }
 
       DataArrayDouble *fromCartToCylGiven(const DataArrayDouble *coords, PyObject *center, PyObject *vector) const
@@ -1199,10 +1193,10 @@ namespace MEDCoupling
 
       PyObject *getMinMaxPerComponent() const throw(INTERP_KERNEL::Exception)
       {
-        int nbOfCompo=self->getNumberOfComponents();
-        INTERP_KERNEL::AutoPtr<double> tmp=new double[2*nbOfCompo];
+        int nbOfCompo(self->getNumberOfComponents());
+        INTERP_KERNEL::AutoPtr<double> tmp(new double[2*nbOfCompo]);
         self->getMinMaxPerComponent(tmp);
-        PyObject *ret=convertDblArrToPyListOfTuple(tmp,2,nbOfCompo);
+        PyObject *ret=convertDblArrToPyListOfTuple<double>(tmp,2,nbOfCompo);
         return ret;
       }
 
@@ -1211,7 +1205,7 @@ namespace MEDCoupling
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->accumulate(tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
 
       DataArrayDouble *accumulatePerChunck(PyObject *indexArr) const throw(INTERP_KERNEL::Exception)
@@ -1271,7 +1265,7 @@ namespace MEDCoupling
         int sz=self->getNumberOfComponents();
         INTERP_KERNEL::AutoPtr<double> tmp=new double[sz];
         self->getTuple(tupleId,tmp);
-        return convertDblArrToPyList(tmp,sz);
+        return convertDblArrToPyList<double>(tmp,sz);
       }
 
       static DataArrayDouble *Aggregate(PyObject *li) throw(INTERP_KERNEL::Exception)
@@ -1321,454 +1315,12 @@ namespace MEDCoupling
 
       PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
       {
-        const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";
-        const char msg2[]="DataArrayDouble::__getitem__ : Mismatch of slice values in 2nd parameter (components) !";
-        self->checkAllocated();
-        int nbOfTuples=self->getNumberOfTuples();
-        int nbOfComponents=self->getNumberOfComponents();
-        int it1,ic1;
-        std::vector<int> vt1,vc1;
-        std::pair<int, std::pair<int,int> > pt1,pc1;
-        DataArrayInt *dt1=0,*dc1=0;
-        int sw;
-        convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
-        MCAuto<DataArrayDouble> ret;
-        switch(sw)
-          {
-          case 1:
-            if(nbOfComponents==1)
-              return PyFloat_FromDouble(self->getIJSafe(it1,0));
-            return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&it1,&it1+1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-          case 2:
-            return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size())),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-          case 3:
-            return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-          case 4:
-            return SWIG_NewPointerObj(SWIG_as_voidptr(self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems())),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-          case 5:
-            return PyFloat_FromDouble(self->getIJSafe(it1,ic1));
-          case 6:
-            {
-              ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
-              std::vector<int> v2(1,ic1);
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 7:
-            {
-              ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
-              std::vector<int> v2(1,ic1);
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 8:
-            {
-              ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
-              std::vector<int> v2(1,ic1);
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 9:
-            {
-              ret=self->selectByTupleIdSafe(&it1,&it1+1);
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 10:
-            {
-              ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 11:
-            {
-              ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 12:
-            {
-              ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(vc1)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 13:
-            {
-              ret=self->selectByTupleIdSafe(&it1,&it1+1);
-              int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
-              std::vector<int> v2(nbOfComp);
-              for(int i=0;i<nbOfComp;i++)
-                v2[i]=pc1.first+i*pc1.second.second;
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 14:
-            {
-              ret=self->selectByTupleIdSafe(&vt1[0],&vt1[0]+vt1.size());
-              int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
-              std::vector<int> v2(nbOfComp);
-              for(int i=0;i<nbOfComp;i++)
-                v2[i]=pc1.first+i*pc1.second.second;
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 15:
-            {
-              ret=self->selectByTupleIdSafeSlice(pt1.first,pt1.second.first,pt1.second.second);
-              int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
-              std::vector<int> v2(nbOfComp);
-              for(int i=0;i<nbOfComp;i++)
-                v2[i]=pc1.first+i*pc1.second.second;
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          case 16:
-            {
-              ret=self->selectByTupleIdSafe(dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems());
-              int nbOfComp=DataArray::GetNumberOfItemGivenBESRelative(pc1.first,pc1.second.first,pc1.second.second,msg2);
-              std::vector<int> v2(nbOfComp);
-              for(int i=0;i<nbOfComp;i++)
-                v2[i]=pc1.first+i*pc1.second.second;
-              return SWIG_NewPointerObj(SWIG_as_voidptr(ret->keepSelectedComponents(v2)),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 );
-            }
-          default:
-            throw INTERP_KERNEL::Exception(msg);
-          }
+        return DataArrayT__getitem<double>(self,obj);
       }
 
       DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception)
       {
-        self->checkAllocated();
-        const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !";
-        int nbOfTuples=self->getNumberOfTuples();
-        int nbOfComponents=self->getNumberOfComponents();
-        int sw1,sw2;
-        double i1;
-        std::vector<double> v1;
-        DataArrayDouble *d1=0;
-        convertObjToPossibleCpp4(value,sw1,i1,v1,d1);
-        int it1,ic1;
-        std::vector<int> vt1,vc1;
-        std::pair<int, std::pair<int,int> > pt1,pc1;
-        DataArrayInt *dt1=0,*dc1=0;
-        convertObjToPossibleCpp3(obj,nbOfTuples,nbOfComponents,sw2,it1,ic1,vt1,vc1,pt1,pc1,dt1,dc1);
-        MCAuto<DataArrayDouble> tmp;
-        switch(sw2)
-          {
-          case 1:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple1(i1,it1,it1+1,1,0,nbOfComponents,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues1(tmp,it1,it1+1,1,0,nbOfComponents,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues1(d1,it1,it1+1,1,0,nbOfComponents,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 2:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),0,nbOfComponents,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 3:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,0,nbOfComponents,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 4:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),0,nbOfComponents,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 5:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple1(i1,it1,it1+1,1,ic1,ic1+1,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues1(tmp,it1,it1+1,1,ic1,ic1+1,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues1(d1,it1,it1+1,1,ic1,ic1+1,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 6:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),ic1,ic1+1,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 7:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,ic1,ic1+1,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 8:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),ic1,ic1+1,1);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 9:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple2(i1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues2(tmp,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size(),false);
-                  return self;
-                case 3:
-                  self->setPartOfValues2(d1,&it1,&it1+1,&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 10:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple2(i1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues2(tmp,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size(),false);
-                  return self;
-                case 3:
-                  self->setPartOfValues2(d1,&vt1[0],&vt1[0]+vt1.size(),&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 11:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple4(i1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues4(tmp,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size(),false);
-                  return self;
-                case 3:
-                  self->setPartOfValues4(d1,pt1.first,pt1.second.first,pt1.second.second,&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 12:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple2(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues2(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size(),false);
-                  return self;
-                case 3:
-                  self->setPartOfValues2(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),&vc1[0],&vc1[0]+vc1.size());
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 13:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple1(i1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues1(tmp,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues1(d1,it1,it1+1,1,pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 14:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple3(i1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues3(tmp,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues3(d1,&vt1[0],&vt1[0]+vt1.size(),pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 15:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple1(i1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues1(tmp,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues1(d1,pt1.first,pt1.second.first,pt1.second.second,pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          case 16:
-            {
-              switch(sw1)
-                {
-                case 1:
-                  self->setPartOfValuesSimple3(i1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                case 2:
-                  tmp=DataArrayDouble::New();
-                  tmp->useArray(&v1[0],false,CPP_DEALLOC,1,v1.size());
-                  self->setPartOfValues3(tmp,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second,false);
-                  return self;
-                case 3:
-                  self->setPartOfValues3(d1,dt1->getConstPointer(),dt1->getConstPointer()+dt1->getNbOfElems(),pc1.first,pc1.second.first,pc1.second.second);
-                  return self;
-                default:
-                  throw INTERP_KERNEL::Exception(msg);
-                }
-              break;
-            }
-          default:
-            throw INTERP_KERNEL::Exception(msg);
-          }
-        return self;
+        return DataArrayT__setitem__<double>(self,obj,value);
       }
 
       DataArrayDouble *__neg__() const throw(INTERP_KERNEL::Exception)
index 7b20363432c3aaaffe837482311f8fc2ae60a322..427211046ca574076ee3154bb7f2a64c0a697be9 100644 (file)
@@ -756,6 +756,307 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         gc.collect()
         pass
 
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test29(self):
+        """Same as test9 with float32"""
+        sz=20
+        a=array(0,dtype=float32)
+        a.resize(sz)
+        a[:]=4
+        self.assertEqual(getrefcount(a),2)
+        a=a.cumsum(dtype=float32)
+        self.assertEqual(getrefcount(a),2)
+        d=DataArrayFloat(a)
+        d[:]=2
+        #
+        e=DataArrayFloat(sz) ; e.fillWithValue(2)
+        self.assertTrue(d.isEqual(e,1e-7))
+        #
+        a[:]=4 ; e.fillWithValue(4)
+        self.assertTrue(d.isEqual(e,1e-7))
+        pass
+    
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test30(self):
+        """Same as test10 with float32"""
+        sz=20
+        a=array(0,dtype=float32)
+        a.resize(sz,2)
+        self.assertEqual(getrefcount(a),2)
+        b=a.reshape(2*sz)
+        self.assertEqual(getrefcount(a),3)
+        self.assertEqual(getrefcount(b),2)
+        b[:]=5
+        d=DataArrayFloat(b)
+        #
+        e=DataArrayFloat(sz*2) ; e.fillWithValue(5)
+        self.assertTrue(d.isEqual(e,1e-7))
+        pass
+    
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test31(self):
+        """Same as test11 with float32"""
+        sz=10
+        a=array(0,dtype=float32)
+        a.resize(sz,2)
+        b=a.reshape(2*sz)
+        c=a.reshape(2,sz)
+        b[:]=6
+        b[7:17]=7
+        d=DataArrayFloat(b)
+        self.assertTrue(d.isEqual(DataArrayFloat([6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,6,6,6]),1e-7))
+        #
+        a=zeros((10,2),dtype=float32)
+        b=a.T
+        c=b.view()
+        a.shape=20
+        a[3:]=10.
+        d=DataArrayFloat(a)
+        self.assertTrue(d.isEqual(DataArrayFloat([0,0,0,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]),1e-7))
+        pass
+    
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test32(self):
+        """Same as test12 with float32"""
+        a=zeros(20,dtype=float32)
+        b = a[::-1]
+        self.assertRaises(InterpKernelException,DataArrayFloat.New,b) # b is not contiguous in memory
+        pass
+    
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test33(self):
+        """Same as test13 with float32"""
+        a=arange(20,dtype=float32)
+        self.assertEqual(weakref.getweakrefcount(a),0)
+        d=DataArrayFloat(a)
+        self.assertEqual(weakref.getweakrefcount(a),1)
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(d.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        self.assertEqual(len(d),20)
+        a[:]=2 # modifying a and d because a and d share the same chunk of data
+        self.assertTrue(d.isUniform(2,1e-7))
+        del d # d is destroyed, a retrieves its ownership of its initial chunk of data
+        ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+        import gc
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        a[:]=4 # a can be used has usual
+        self.assertTrue(DataArrayFloat(a).isUniform(4,1e-7))
+        pass
+    
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test34(self):
+        """Same as test14 with float32"""
+        a=arange(20,dtype=float32)
+        d=DataArrayFloat(a) # d owns data of a
+        e=DataArrayFloat(a) # a not owned -> e only an access to chunk of a 
+        self.assertTrue(d.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        self.assertTrue(e.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        a[:]=6
+        self.assertTrue(d.isUniform(6,1e-7))
+        self.assertTrue(e.isUniform(6,1e-7))
+        del a # a destroyed -> d no change because owned and e array is has no more data set
+        ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+        import gc
+        gc.collect()
+        self.assertTrue(d.isUniform(6,1e-7))
+        self.assertTrue(not e.isAllocated())
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test35(self):
+        """Same as test15 with float32"""
+        a=array(0,dtype=float32) ; a.resize(10,2)
+        b=a.reshape(20)
+        c=a.reshape(2,10)
+        d=DataArrayFloat(b) # d owns data of a
+        e=DataArrayFloat(b) # a not owned -> e only an access to chunk of a
+        f=DataArrayFloat(b) # a not owned -> e only an access to chunk of a
+        del d # d removed -> a ownes again data
+        ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+        import gc
+        gc.collect()
+        self.assertTrue(e.isUniform(0,1e-7))
+        e[:]=6
+        self.assertTrue(e.isUniform(6,1e-7))
+        self.assertTrue(f.isUniform(6,1e-7))
+        self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
+        self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
+        b[:]=arange(20)
+        del b # no impact on e and f because a is the base of a.
+        ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+        gc.collect()
+        self.assertTrue(f.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        self.assertTrue(e.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
+        ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+        gc.collect()
+        self.assertTrue(f.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        self.assertTrue(e.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-7))
+        del c # c killed -> a killed -> e and d are put into not allocated state
+        ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+        gc.collect()
+        self.assertTrue(not e.isAllocated())
+        self.assertTrue(not f.isAllocated())
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test36(self):
+        """Same as test16 with float32"""
+        a=arange(20,dtype=float32)
+        self.assertTrue(a.flags["OWNDATA"])
+        d=DataArrayFloat(a) # d owns data of a
+        self.assertTrue(not a.flags["OWNDATA"])
+        d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertTrue(d.isEqual(DataArrayFloat([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),1e-7))
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test37(self):
+        """Same as test20 with float32"""
+        sz=20
+        a=array(0,dtype=float32)
+        a.resize(sz/2,2)
+        a[:]=4
+        self.assertEqual(getrefcount(a),2)
+        d=DataArrayFloat(a)
+        self.assertEqual(10,d.getNumberOfTuples())
+        self.assertEqual(2,d.getNumberOfComponents())
+        self.assertEqual(sz,d.getNbOfElems())
+        self.assertTrue(d.isEqual(DataArrayFloat([(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.)]),1e-7))
+        a[:]=7
+        self.assertTrue(d.isEqual(DataArrayFloat([(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.)]),1e-7))
+        #
+        b=a.reshape((2,5,2))
+        self.assertRaises(InterpKernelException,DataArrayFloat.New,b) # b has not dimension in [0,1] !
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test38(self):
+        """Same as test22 with float32"""
+        d=DataArrayFloat(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        #
+        d=DataArrayInt(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test39(self):
+        """Same as test23 with float32"""
+        d=DataArrayFloat(10)
+        d.iota()
+        a=d.toNumPyArray()
+        b=d.toNumPyArray()
+        c=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        #
+        d=DataArrayInt(10)
+        d.iota()
+        a=d.toNumPyArray()
+        b=d.toNumPyArray()
+        c=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test40(self):
+        """Same as test24 with float32"""
+        d=DataArrayFloat(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        del a
+        gc.collect()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        b=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(b.base is a)
+        del a
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        #
+        d=DataArrayInt(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        del a
+        gc.collect()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        b=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(b.base is a)
+        del a
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        pass
+
     def setUp(self):
         pass
     pass
index 6f8782e8ba3a9e60aa39e4e6069c61fc02923e92..fba1600f602534ae54aa060f614f1d245358af34 100644 (file)
@@ -44,6 +44,8 @@ using namespace INTERP_KERNEL;
 %init %{ import_array(); %}
 #endif
 
+%init %{ initializeMe(); %}
+
 %feature("autodoc", "1");
 %feature("docstring");
 
@@ -56,6 +58,15 @@ using namespace INTERP_KERNEL;
 %include "MEDCouplingRefCountObject.i"
 %include "MEDCouplingMemArray.i"
 
+%inline
+{
+  void initializeMe()
+  {
+    SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
+    SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+  }
+}
+
 class Renumbering
 {
 public: