]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
+=,-=,*=,/= on DataArrayTuple
authorageay <ageay>
Mon, 1 Oct 2012 08:05:43 +0000 (08:05 +0000)
committerageay <ageay>
Mon, 1 Oct 2012 08:05:43 +0000 (08:05 +0000)
src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling/MEDCouplingMemArray.txx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingFinalize.i
src/MEDCoupling_Swig/MEDCouplingRemapper.i
src/MEDLoader/Swig/MEDLoader.i

index 2b53fcb6ba6388bcf5244f7676a0c47c66c4cc89..a112e3edad4a4cce8654e2b2eb4a0e05711931ef 100644 (file)
@@ -1612,7 +1612,7 @@ void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &ar
     }
 }
 
-void DataArrayDouble::useArray(const double *array, bool ownership,  DeallocType type, int nbOfTuple, int nbOfCompo)
+void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo)
 {
   _nb_of_tuples=nbOfTuple;
   _info_on_compo.resize(nbOfCompo);
@@ -1620,6 +1620,14 @@ void DataArrayDouble::useArray(const double *array, bool ownership,  DeallocType
   declareAsNew();
 }
 
+void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo)
+{
+  _nb_of_tuples=nbOfTuple;
+  _info_on_compo.resize(nbOfCompo);
+  _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
+  declareAsNew();
+}
+
 void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception)
 {
   const double *tmp=getConstPointer();
@@ -3325,7 +3333,7 @@ DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCom
   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
     {
       DataArrayDouble *ret=DataArrayDouble::New();
-      ret->useArray(_pt,false,CPP_DEALLOC,nbOfTuples,nbOfCompo);
+      ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
       return ret;
     }
   else
@@ -3793,6 +3801,14 @@ void DataArrayInt::useArray(const int *array, bool ownership,  DeallocType type,
   declareAsNew();
 }
 
+void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo)
+{
+  _nb_of_tuples=nbOfTuple;
+  _info_on_compo.resize(nbOfCompo);
+  _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo);
+  declareAsNew();
+}
+
 DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
 {
   if(_mem.isNull())
@@ -6419,7 +6435,7 @@ DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const
   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
     {
       DataArrayInt *ret=DataArrayInt::New();
-      ret->useArray(_pt,false,CPP_DEALLOC,nbOfTuples,nbOfCompo);
+      ret->useExternalArrayWithRWAccess(_pt,nbOfTuples,nbOfCompo);
       return ret;
     }
   else
index a909478d490cb75473f06901dd19675c3a980263..675a563ec7afd27401713c0a79b56d0ad0b67f24 100644 (file)
@@ -75,6 +75,7 @@ namespace ParaMEDMEM
     void alloc(int nbOfElements) throw(INTERP_KERNEL::Exception);
     void reAlloc(int newNbOfElements) throw(INTERP_KERNEL::Exception);
     void useArray(const T *array, bool ownership, DeallocType type, int nbOfElem);
+    void useExternalArrayWithRWAccess(const T *array, int nbOfElem);
     void writeOnPlace(int id, T element0, const T *others, int sizeOfOthers);
     ~MemArray() { destroy(); }
   private:
@@ -218,6 +219,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT const double *begin() const { return getConstPointer(); }
     MEDCOUPLING_EXPORT const double *end() const { return getConstPointer()+getNbOfElems(); }
     MEDCOUPLING_EXPORT void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
+    MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo);
     MEDCOUPLING_EXPORT void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
     MEDCOUPLING_EXPORT void checkNoNullValues() const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception);
@@ -462,6 +464,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT std::set<int> getDifferentValues() const throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo);
+    MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo);
     MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); }
     MEDCOUPLING_EXPORT static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);
     MEDCOUPLING_EXPORT void addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception);
index f12a076233e23e801e2fa6026a5cc8cdfb2bb981..e569249d8dfddf3bdbbce777a9ca2d119c86e449 100644 (file)
@@ -68,6 +68,16 @@ namespace ParaMEDMEM
     _dealloc=type;
   }
 
+  template<class T>
+  void MemArray<T>::useExternalArrayWithRWAccess(const T *array, int nbOfElem)
+  {
+    _nb_of_elem=nbOfElem;
+    destroy();
+    _pointer.setInternal(const_cast<T *>(array));
+    _ownership=false;
+    _dealloc=CPP_DEALLOC;
+  }
+  
   template<class T>
   void MemArray<T>::writeOnPlace(int id, T element0, const T *others, int sizeOfOthers)
   {
index ff905cc1ade9f5f17e54230653e331f4f3731ddd..04d497020f95629c6af7c83f978e0d5248e738e2 100644 (file)
@@ -59,6 +59,33 @@ def ParaMEDMEMDataArrayIntIdiv(self,*args):
 def ParaMEDMEMDataArrayIntImod(self,*args):
     import _MEDCoupling
     return _MEDCoupling.DataArrayInt____imod___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIadd(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIsub(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleImul(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIdiv(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayDoubleTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIadd(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIsub(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImul(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIdiv(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImod(self,*args):
+    import _MEDCoupling
+    return _MEDCoupling.DataArrayIntTuple____imod___(self, self, *args)
 %}
 
 %include "MEDCouplingFinalize.i"
index c635023fc39a9f484f1a782ade72bbf06955ee6c..4f63e6fd3fd5f32e6ad69db3c74014280e6204c9 100644 (file)
@@ -10182,6 +10182,54 @@ class MEDCouplingBasicsTest(unittest.TestCase):
             pass
         pass
 
+    def testSwigDataTupleIOp1(self):
+        d=DataArrayDouble(10,1)
+        d.iota(7.)
+        for elt in d:
+            elt+=2.
+            pass
+        toTest=DataArrayDouble([9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0])
+        self.assertTrue(toTest.isEqual(d,1e-12))
+        for elt in d:
+            elt-=2.
+            pass
+        toTest=DataArrayDouble([7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0])
+        self.assertTrue(toTest.isEqual(d,1e-12))
+        for elt in d:
+            elt*=2.
+            pass
+        toTest=DataArrayDouble([14.0,16.0,18.0,20.0,22.0,24.0,26.0,28.0,30.0,32.0])
+        self.assertTrue(toTest.isEqual(d,1e-12))
+        for elt in d:
+            elt/=2.
+            pass
+        toTest=DataArrayDouble([7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0])
+        self.assertTrue(toTest.isEqual(d,1e-12))
+        #
+        d=DataArrayInt(10,1)
+        d.iota(7)
+        for elt in d:
+            elt+=2
+            pass
+        self.assertEqual(d.getValues(),[9,10,11,12,13,14,15,16,17,18])
+        for elt in d:
+            elt-=2
+            pass
+        self.assertEqual(d.getValues(),[7,8,9,10,11,12,13,14,15,16])
+        for elt in d:
+            elt*=2
+            pass
+        self.assertEqual(d.getValues(),[14,16,18,20,22,24,26,28,30,32])
+        for elt in d:
+            elt/=2
+            pass
+        self.assertEqual(d.getValues(),[7,8,9,10,11,12,13,14,15,16])
+        for elt in d:
+            elt%=3
+            pass
+        self.assertEqual(d.getValues(),[1,2,0,1,2,0,1,2,0,1])
+        pass
+
     def setUp(self):
         pass
     pass
index b6e2d0b64d0603f72ebf3d85d8733251e7ee7c6e..085293b0c9405d55d120950ae93e10bd174a8660 100644 (file)
@@ -2444,7 +2444,39 @@ namespace ParaMEDMEM
   {
     return self->buildDADouble(1,self->getNumberOfCompo());
   }
+
+  PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=self->buildDADouble(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayDouble____iadd___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
   
+  PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=self->buildDADouble(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayDouble____isub___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+  
+  PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=self->buildDADouble(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayDouble____imul___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+
+  PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=self->buildDADouble(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayDouble____idiv___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+
   PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
   {
     int sw;
@@ -4108,6 +4140,46 @@ namespace ParaMEDMEM
   {
     return self->buildDAInt(1,self->getNumberOfCompo());
   }
+
+  PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=self->buildDAInt(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayInt____iadd___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+  
+  PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=self->buildDAInt(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayInt____isub___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+  
+  PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=self->buildDAInt(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayInt____imul___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+
+  PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=self->buildDAInt(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayInt____idiv___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
+
+  PyObject *___imod___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
+  {
+    MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=self->buildDAInt(1,self->getNumberOfCompo());
+    ParaMEDMEM_DataArrayInt____imod___(ret,0,obj);
+    Py_XINCREF(trueSelf);
+    return trueSelf;
+  }
   
   PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
   {
index 5f47296fa9e752f20d6de68bb9438900c4c9eebf..909b4cf959caf78155fd680a6ea4ffb5f50d1c6b 100644 (file)
@@ -34,6 +34,17 @@ MEDCouplingFieldDouble.__isub__=ParaMEDMEMMEDCouplingFieldDoubleIsub
 MEDCouplingFieldDouble.__imul__=ParaMEDMEMMEDCouplingFieldDoubleImul
 MEDCouplingFieldDouble.__idiv__=ParaMEDMEMMEDCouplingFieldDoubleIdiv
 
+DataArrayDoubleTuple.__iadd__=ParaMEDMEMDataArrayDoubleTupleIadd
+DataArrayDoubleTuple.__isub__=ParaMEDMEMDataArrayDoubleTupleIsub
+DataArrayDoubleTuple.__imul__=ParaMEDMEMDataArrayDoubleTupleImul
+DataArrayDoubleTuple.__idiv__=ParaMEDMEMDataArrayDoubleTupleIdiv
+
+DataArrayIntTuple.__iadd__=ParaMEDMEMDataArrayIntTupleIadd
+DataArrayIntTuple.__isub__=ParaMEDMEMDataArrayIntTupleIsub
+DataArrayIntTuple.__imul__=ParaMEDMEMDataArrayIntTupleImul
+DataArrayIntTuple.__idiv__=ParaMEDMEMDataArrayIntTupleIdiv
+DataArrayIntTuple.__imod__=ParaMEDMEMDataArrayIntTupleImod
+
 del ParaMEDMEMDataArrayDoubleIadd
 del ParaMEDMEMDataArrayDoubleIsub
 del ParaMEDMEMDataArrayDoubleImul
@@ -47,4 +58,13 @@ del ParaMEDMEMDataArrayIntIsub
 del ParaMEDMEMDataArrayIntImul
 del ParaMEDMEMDataArrayIntIdiv
 del ParaMEDMEMDataArrayIntImod
+del ParaMEDMEMDataArrayDoubleTupleIadd
+del ParaMEDMEMDataArrayDoubleTupleIsub
+del ParaMEDMEMDataArrayDoubleTupleImul
+del ParaMEDMEMDataArrayDoubleTupleIdiv
+del ParaMEDMEMDataArrayIntTupleIadd
+del ParaMEDMEMDataArrayIntTupleIsub
+del ParaMEDMEMDataArrayIntTupleImul
+del ParaMEDMEMDataArrayIntTupleIdiv
+del ParaMEDMEMDataArrayIntTupleImod
 %}
index f1f97995d573df27bc31fe61ccc4db0a604964e8..3b2359a61f6b28cc6ccb3b5800093b5c7b9988bb 100644 (file)
@@ -124,6 +124,33 @@ def ParaMEDMEMDataArrayIntIdiv(self,*args):
 def ParaMEDMEMDataArrayIntImod(self,*args):
     import _MEDCouplingRemapper
     return _MEDCouplingRemapper.DataArrayInt____imod___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIadd(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayDoubleTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIsub(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayDoubleTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleImul(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayDoubleTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIdiv(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayDoubleTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIadd(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayIntTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIsub(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayIntTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImul(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayIntTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIdiv(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayIntTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImod(self,*args):
+    import _MEDCouplingRemapper
+    return _MEDCouplingRemapper.DataArrayIntTuple____imod___(self, self, *args)
 %}
 
 %include "MEDCouplingFinalize.i"
index b8051e39dfc6f6721a59c61017370c643a3c3365..1f4b743e01d168fb499458f543c55c1f38f15f40 100644 (file)
@@ -60,6 +60,33 @@ def ParaMEDMEMDataArrayIntIdiv(self,*args):
 def ParaMEDMEMDataArrayIntImod(self,*args):
     import _MEDLoader
     return _MEDLoader.DataArrayInt____imod___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIadd(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayDoubleTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIsub(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayDoubleTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleImul(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayDoubleTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayDoubleTupleIdiv(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayDoubleTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIadd(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayIntTuple____iadd___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIsub(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayIntTuple____isub___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImul(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayIntTuple____imul___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleIdiv(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayIntTuple____idiv___(self, self, *args)
+def ParaMEDMEMDataArrayIntTupleImod(self,*args):
+    import _MEDLoader
+    return _MEDLoader.DataArrayIntTuple____imod___(self, self, *args)
 %}
 
 %include "MEDCouplingFinalize.i"