From: ageay Date: Mon, 1 Oct 2012 08:05:43 +0000 (+0000) Subject: +=,-=,*=,/= on DataArrayTuple X-Git-Tag: V6_main_FINAL~480 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=86a48e3b57a6673671581c4887e45b581a0293f2;p=tools%2Fmedcoupling.git +=,-=,*=,/= on DataArrayTuple --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 2b53fcb6b..a112e3eda 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -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 diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index a909478d4..675a563ec 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -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 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); diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index f12a07623..e569249d8 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -68,6 +68,16 @@ namespace ParaMEDMEM _dealloc=type; } + template + void MemArray::useExternalArrayWithRWAccess(const T *array, int nbOfElem) + { + _nb_of_elem=nbOfElem; + destroy(); + _pointer.setInternal(const_cast(array)); + _ownership=false; + _dealloc=CPP_DEALLOC; + } + template void MemArray::writeOnPlace(int id, T element0, const T *others, int sizeOfOthers) { diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index ff905cc1a..04d497020 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -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" diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index c635023fc..4f63e6fd3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -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 diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index b6e2d0b64..085293b0c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -2444,7 +2444,39 @@ namespace ParaMEDMEM { return self->buildDADouble(1,self->getNumberOfCompo()); } + + PyObject *___iadd___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr 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 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 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 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 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 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 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 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 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) { diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index 5f47296fa..909b4cf95 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -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 %} diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapper.i b/src/MEDCoupling_Swig/MEDCouplingRemapper.i index f1f97995d..3b2359a61 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapper.i +++ b/src/MEDCoupling_Swig/MEDCouplingRemapper.i @@ -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" diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index b8051e39d..1f4b743e0 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -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"