]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
OK first implementation of float32
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 26 Apr 2017 12:47:55 +0000 (14:47 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 26 Apr 2017 12:47:55 +0000 (14:47 +0200)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling/MEDCouplingMemArrayFloat.cxx [new file with mode: 0644]
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.cxx [new file with mode: 0644]
src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx [new file with mode: 0644]
src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i
src/MEDCoupling_Swig/MEDCouplingNumPyTest.py
src/RENUMBER_Swig/MEDRenumberCommon.i

index 4b5da2176995172b21e0bb616137f43e513e7c33..5067c1373dbe12a61bde8103a3da473b1c0c2312 100644 (file)
@@ -831,25 +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 that \a this array is consistently **increasing** or **decreasing** in value,
  * with at least absolute difference value of |\a eps| at each step.
index 76dae5355053aaccc7a10f0cd9c947323104194e..8a57b8d140fdf044dc7b9e55c045fdb5f763cec5 100644 (file)
@@ -302,6 +302,7 @@ namespace MEDCoupling
   {
   public:
     MEDCOUPLING_EXPORT bool isUniform(T val, T eps) const;
+    MEDCOUPLING_EXPORT void iota(T init=0.);
   };
 }
 
@@ -314,11 +315,11 @@ namespace MEDCoupling
   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 DataArrayTemplate<float>::mySelectByTupleRanges(ranges); }
-    MEDCOUPLING_EXPORT DataArrayFloat *keepSelectedComponents(const std::vector<int>& compoIds) const { return DataArrayTemplate<float>::myKeepSelectedComponents(compoIds); }
-    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<float>::mySelectByTupleId(new2OldBg,new2OldEnd); }
-    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const { return DataArrayTemplate<float>::mySelectByTupleIdSafe(new2OldBg,new2OldEnd); }
-    MEDCOUPLING_EXPORT DataArrayFloat *selectByTupleIdSafeSlice(int bg, int end2, int step) const { return DataArrayTemplate<float>::mySelectByTupleIdSafeSlice(bg,end2,step); }
+    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;
@@ -351,7 +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 void checkMonotonic(bool increasing, double eps) const;
     MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const;
     MEDCOUPLING_EXPORT std::string repr() const;
@@ -373,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;
index 317ab3c0b5ef1f2b55da05028074ca77921aaba7..9fdf9051a94992c12dec226df8ce93a30dd21a28 100644 (file)
@@ -2265,17 +2265,37 @@ namespace MEDCoupling
   template<class T>
   bool DataArrayTemplateFP<T>::isUniform(T val, T eps) const
   {
-    DataArrayTemplate<T>::checkAllocated();
-    if(DataArrayTemplate<T>::getNumberOfComponents()!=1)
+    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(DataArrayTemplate<T>::getNumberOfTuples());
-    const T *w(DataArrayTemplate<T>::begin()),*end2(DataArrayTemplate<T>::end());
+    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 6d2a57f87e66631cf07c5a411dcf35b14688fbed..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
 { 
   /*!
diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.cxx b/src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.cxx
new file mode 100644 (file)
index 0000000..d7ad141
--- /dev/null
@@ -0,0 +1,25 @@
+// 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 "MEDCouplingDataArrayTraits.hxx"
+
+PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
+
+PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
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 2e41183131dc075c19b0ac2c3315850adc645eaa..a17faf18349c964ddad2309aba9f290e295f2a19 100644 (file)
@@ -2883,6 +2883,113 @@ typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__internal(typena
   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
 { };
@@ -2895,9 +3002,8 @@ template<>
 struct SWIGTITraits<float>
 { static swig_type_info *TI; };
 
-swig_type_info *SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
-
-swig_type_info *SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+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()
 
 template<class T>
 typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj, PyObject *value)
@@ -2905,4 +3011,10 @@ typename MEDCoupling::Traits<T>::ArrayType *DataArrayT__setitem__(typename MEDCo
   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 94c9873e06020f665ef01c52bd50e18f6c67f60c..1fd7a8d6e065eb6c3bb974a6411be28ba2bd85a6 100644 (file)
@@ -668,6 +668,7 @@ namespace MEDCoupling
     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)
@@ -722,6 +723,11 @@ namespace MEDCoupling
         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);
@@ -1309,109 +1315,7 @@ 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)
index 3a7197450f9ebae61240cf7477e66d7494ebd712..427211046ca574076ee3154bb7f2a64c0a697be9 100644 (file)
@@ -32,7 +32,7 @@ import os,gc,weakref,unittest
 class MEDCouplingNumPyTest(unittest.TestCase):
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess1(self):
+    def test1(self):
         sz=20
         a=array(0,dtype=int32)
         a.resize(sz)
@@ -52,7 +52,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess2(self):
+    def test2(self):
         sz=20
         a=array(0,dtype=int32)
         a.resize(sz,2)
@@ -68,7 +68,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess3(self):
+    def test3(self):
         sz=10
         a=array(0,dtype=int32)
         a.resize(sz,2)
@@ -89,14 +89,14 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess4(self):
+    def test4(self):
         a=zeros(20,dtype=int32)
         b = a[::-1]
         self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b is not contiguous in memory
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess5(self):
+    def test5(self):
         a=arange(20,dtype=int32)
         self.assertEqual(weakref.getweakrefcount(a),0)
         d=DataArrayInt(a)
@@ -115,7 +115,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess6(self):
+    def test6(self):
         a=arange(20,dtype=int32)
         d=DataArrayInt(a) # d owns data of a
         e=DataArrayInt(a) # a not owned -> e only an access to chunk of a 
@@ -133,7 +133,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess7(self):
+    def test7(self):
         a=array(0,dtype=int32) ; a.resize(10,2)
         b=a.reshape(20)
         c=a.reshape(2,10)
@@ -169,7 +169,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess8(self):
+    def test8(self):
         a=arange(20,dtype=int32)
         self.assertTrue(a.flags["OWNDATA"])
         d=DataArrayInt(a) # d owns data of a
@@ -181,7 +181,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess9(self):
+    def test9(self):
         sz=20
         a=array(0,dtype=float64)
         a.resize(sz)
@@ -200,7 +200,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess10(self):
+    def test10(self):
         sz=20
         a=array(0,dtype=float64)
         a.resize(sz,2)
@@ -216,7 +216,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess11(self):
+    def test11(self):
         sz=10
         a=array(0,dtype=float64)
         a.resize(sz,2)
@@ -237,14 +237,14 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess12(self):
+    def test12(self):
         a=zeros(20,dtype=float64)
         b = a[::-1]
         self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b is not contiguous in memory
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess13(self):
+    def test13(self):
         a=arange(20,dtype=float64)
         self.assertEqual(weakref.getweakrefcount(a),0)
         d=DataArrayDouble(a)
@@ -264,7 +264,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess14(self):
+    def test14(self):
         a=arange(20,dtype=float64)
         d=DataArrayDouble(a) # d owns data of a
         e=DataArrayDouble(a) # a not owned -> e only an access to chunk of a 
@@ -282,7 +282,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess15(self):
+    def test15(self):
         a=array(0,dtype=float64) ; a.resize(10,2)
         b=a.reshape(20)
         c=a.reshape(2,10)
@@ -318,7 +318,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess16(self):
+    def test16(self):
         a=arange(20,dtype=float64)
         self.assertTrue(a.flags["OWNDATA"])
         d=DataArrayDouble(a) # d owns data of a
@@ -330,7 +330,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess17(self):
+    def test17(self):
         d=DataArrayInt.Range(0,20,1)
         a=d.toNumPyArray()
         self.assertTrue(not a.flags["OWNDATA"])
@@ -356,7 +356,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess18(self):
+    def test18(self):
         d=DataArrayInt.Range(0,20,1)
         d=d.convertToDblArr()
         a=d.toNumPyArray()
@@ -383,7 +383,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess19(self):
+    def test19(self):
         sz=20
         a=array(0,dtype=int32)
         a.resize(sz/2,2)
@@ -402,7 +402,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess20(self):
+    def test20(self):
         sz=20
         a=array(0,dtype=float64)
         a.resize(sz/2,2)
@@ -421,7 +421,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess21(self):
+    def test21(self):
         #tests that only DataArray*(npArray) contructor is available
         a=array(0,dtype=int32)
         a.resize(20)
@@ -436,7 +436,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess22(self):
+    def test22(self):
         d=DataArrayDouble(10)
         d.iota()
         a=d.toNumPyArray()
@@ -457,7 +457,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess23(self):
+    def test23(self):
         d=DataArrayDouble(10)
         d.iota()
         a=d.toNumPyArray()
@@ -500,7 +500,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess24(self):
+    def test24(self):
         d=DataArrayDouble(10)
         d.iota()
         a=d.toNumPyArray()
@@ -557,7 +557,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess25(self):
+    def test25(self):
         a=arange(10,dtype=int32)
         b=DataArrayInt(a)
         c=DataArrayInt(a)
@@ -632,7 +632,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess26(self):
+    def test26(self):
         d=DataArrayInt(15) ; d.iota()
         d.rearrange(3)
         a=d.toNumPyArray()
@@ -656,7 +656,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess27(self):
+    def test27(self):
         m0=DenseMatrix(DataArrayDouble([2,3,4,5,1,6]),2,3)
         m0np=m0.toNumPyMatrix()
         self.assertEqual(m0np.shape,(2,3))
@@ -664,7 +664,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def tess28(self):
+    def test28(self):
         """Test on DataArrayBytes"""
         # use case 1
         d=DataArrayByte(256)
@@ -912,7 +912,6 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         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
-class MEDCouplingNumPyTest2:
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
     def test37(self):
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: