From: ageay Date: Wed, 10 Apr 2013 15:13:38 +0000 (+0000) Subject: support of operation DataArrayDouble +*/- MEDCouplingFieldDouble X-Git-Tag: V6_main_FINAL~161 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5004e652328dc5f028ff4aa9f79e2a562a3eafe3;p=tools%2Fmedcoupling.git support of operation DataArrayDouble +*/- MEDCouplingFieldDouble --- diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 0f0f21e9b..e4f9c8d56 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -5081,7 +5081,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): c.changeSpaceDimension(2); # d=DataArrayDouble.New(); - d.alloc(5,1); + d.alloc(5); d.iota(); e=MEDCouplingCMesh.New(); e.setCoordsAt(0,d); @@ -11986,17 +11986,17 @@ class MEDCouplingBasicsTest(unittest.TestCase): f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 ff=f+2 ff.checkCoherency() - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2, 9), (3, 10), (4, 11), (5, 12), (6, 13)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12)) ff=f+arr ff.checkCoherency() - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0, 7), (2, 10), (4, 13), (6, 16), (8, 19)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12)) self.assertRaises(InterpKernelException,f.__add__,f2) f2.setArray(arr) ff=f+f2 ff.checkCoherency() - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0, 7), (2, 10), (4, 13), (6, 16), (8, 19)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12)) ff=f+[5,8] - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5, 15), (6, 16), (7, 17), (8, 18), (9, 19)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12)) ### MEDCouplingFieldDouble.__sub__ m=MEDCouplingDataForTest.build2DTargetMesh_1() f=MEDCouplingFieldDouble(ON_CELLS) @@ -12018,17 +12018,17 @@ class MEDCouplingBasicsTest(unittest.TestCase): f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 ff=f-2 ff.checkCoherency() - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2, 5), (-1, 6), (0, 7), (1, 8), (2, 9)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12)) ff=f-arr ff.checkCoherency() - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0, 7), (0, 6), (0, 5), (0, 4), (0, 3)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12)) self.assertRaises(InterpKernelException,f.__sub__,f2) f2.setArray(arr) ff=f-f2 ff.checkCoherency() - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0, 7), (0, 6), (0, 5), (0, 4), (0, 3)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(0,6),(0,5),(0,4),(0,3)]),1e-12)) ff=f-[5,8] - self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-5, -1), (-4, 0), (-3, 1), (-2, 2), (-1, 3)]),1e-12)) + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(-5,-1),(-4,0),(-3,1),(-2,2),(-1,3)]),1e-12)) ### MEDCouplingFieldDouble.__mul__ m=MEDCouplingDataForTest.build2DTargetMesh_1() f=MEDCouplingFieldDouble(ON_CELLS) @@ -12155,6 +12155,232 @@ class MEDCouplingBasicsTest(unittest.TestCase): f+=[0.1,0.2] f.checkCoherency() self.assertTrue(f.getArray().isEqual(DataArrayDouble([(2.1,9.2),(5.1,14.2),(8.1,19.2),(11.1,24.2),(14.1,29.2)]),1e-12)) + ## MEDCouplingFieldDouble.__isub__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__isub__,2) + self.assertRaises(InterpKernelException,f.__isub__,range(5)) + self.assertRaises(InterpKernelException,f.__isub__,arr) + self.assertRaises(InterpKernelException,f.__isub__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__isub__,2) + self.assertRaises(InterpKernelException,f.__isub__,range(5)) + self.assertRaises(InterpKernelException,f.__isub__,arr) + self.assertRaises(InterpKernelException,f.__isub__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f-=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-1,6),(0,7),(1,8),(2,9)]),1e-12)) + f-=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-2,4),(-2,3),(-2,2),(-2,1)]),1e-12)) + f2.setArray(arr) + f-=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2,5),(-3,2),(-4,-1),(-5,-4),(-6,-7)]),1e-12)) + f-=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(-2.1,4.8),(-3.1,1.8),(-4.1,-1.2),(-5.1,-4.2),(-6.1,-7.2)]),1e-12)) + ## MEDCouplingFieldDouble.__imul__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__imul__,2) + self.assertRaises(InterpKernelException,f.__imul__,range(5)) + self.assertRaises(InterpKernelException,f.__imul__,arr) + self.assertRaises(InterpKernelException,f.__imul__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__imul__,2) + self.assertRaises(InterpKernelException,f.__imul__,range(5)) + self.assertRaises(InterpKernelException,f.__imul__,arr) + self.assertRaises(InterpKernelException,f.__imul__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f*=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12)) + f*=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,32),(8,72),(18,120),(32,176)]),1e-12)) + f2.setArray(arr) + f*=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(2,64),(16,288),(54,720),(128,1408)]),1e-12)) + f*=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0),(0.2,12.8),(1.6,57.6),(5.4,144),(12.8,281.6)]),1e-12)) + ## MEDCouplingFieldDouble.__idiv__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__idiv__,2) + self.assertRaises(InterpKernelException,f.__idiv__,range(5)) + self.assertRaises(InterpKernelException,f.__idiv__,arr) + self.assertRaises(InterpKernelException,f.__idiv__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__idiv__,2) + self.assertRaises(InterpKernelException,f.__idiv__,range(5)) + self.assertRaises(InterpKernelException,f.__idiv__,arr) + self.assertRaises(InterpKernelException,f.__idiv__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f/=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,3.5),(0.5,4),(1,4.5),(1.5,5),(2,5.5)]),1e-12)) + f/=arr + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,1.75),(0.25,1),(0.3333333333333333,0.75),(0.375,0.625),(0.4,0.55)]),1e-12)) + f2.setArray(arr) + f/=f2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,0.875),(0.125,0.25),(0.1111111111111111,0.125),(0.09375,0.078125),(0.08,0.055)]),1e-12)) + f/=[0.1,0.2] + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,4.375),(1.25,1.25),(1.1111111111111111,0.625),(0.9375,0.390625),(0.8,0.275)]),1e-12)) + ## MEDCouplingFieldDouble.__ipow__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__ipow__,2) + self.assertRaises(InterpKernelException,f.__ipow__,range(5)) + self.assertRaises(InterpKernelException,f.__ipow__,arr) + self.assertRaises(InterpKernelException,f.__ipow__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__ipow__,2) + self.assertRaises(InterpKernelException,f.__ipow__,range(5)) + self.assertRaises(InterpKernelException,f.__ipow__,arr) + self.assertRaises(InterpKernelException,f.__ipow__,f2) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + f.checkCoherency() + f**=2 + f.checkCoherency() + self.assertTrue(f.getArray().isEqual(DataArrayDouble([(0,49),(1,64),(4,81),(9,100),(16,121)]),1e-12)) + ## MEDCouplingFieldDouble.__radd__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__radd__,2) + self.assertRaises(InterpKernelException,f.__radd__,range(5)) + self.assertRaises(InterpKernelException,f.__radd__,arr) + self.assertRaises(InterpKernelException,f.__radd__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__radd__,2) + self.assertRaises(InterpKernelException,f.__radd__,range(5)) + self.assertRaises(InterpKernelException,f.__radd__,arr) + self.assertRaises(InterpKernelException,f.__radd__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2+f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,9),(3,10),(4,11),(5,12),(6,13)]),1e-12)) + ff=arr+f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,7),(2,10),(4,13),(6,16),(8,19)]),1e-12)) + self.assertRaises(InterpKernelException,f.__radd__,f2) + ff=[5,8]+f + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(5,15),(6,16),(7,17),(8,18),(9,19)]),1e-12)) + ### MEDCouplingFieldDouble.__rsub__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__rsub__,2) + self.assertRaises(InterpKernelException,f.__rsub__,range(5)) + self.assertRaises(InterpKernelException,f.__rsub__,arr) + self.assertRaises(InterpKernelException,f.__rsub__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__rsub__,2) + self.assertRaises(InterpKernelException,f.__rsub__,range(5)) + self.assertRaises(InterpKernelException,f.__rsub__,arr) + self.assertRaises(InterpKernelException,f.__rsub__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2-f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,-5),(1,-6),(0,-7),(-1,-8),(-2,-9)]),1e-12)) + ff=arr-f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,-7),(0,-6),(0,-5),(0,-4),(0,-3)]),1e-12)) + self.assertRaises(InterpKernelException,f.__rsub__,f2) + ### MEDCouplingFieldDouble.__rmul__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(5) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__rmul__,2) + self.assertRaises(InterpKernelException,f.__rmul__,range(5)) + self.assertRaises(InterpKernelException,f.__rmul__,arr) + self.assertRaises(InterpKernelException,f.__rmul__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__rmul__,2) + self.assertRaises(InterpKernelException,f.__rmul__,range(5)) + self.assertRaises(InterpKernelException,f.__rmul__,arr) + self.assertRaises(InterpKernelException,f.__rmul__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(5) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2*f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,14),(2,16),(4,18),(6,20),(8,22)]),1e-12)) + ff=arr*f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,0),(1,16),(4,36),(9,60),(16,88)]),1e-12)) + self.assertRaises(InterpKernelException,f.__rmul__,f2) + ff=f*[5,8] + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(0,56),(5,64),(10,72),(15,80),(20,88)]),1e-12)) + ### MEDCouplingFieldDouble.__rdiv__ + m=MEDCouplingDataForTest.build2DTargetMesh_1() + f=MEDCouplingFieldDouble(ON_CELLS) + f.setMesh(m) + arr=DataArrayDouble(5,2) + arr[:,0]=range(1,6) ; arr[:,1]=2*arr[:,0] + f2=f.clone(True) + self.assertRaises(InterpKernelException,f.__rdiv__,2) + self.assertRaises(InterpKernelException,f.__rdiv__,range(5)) + self.assertRaises(InterpKernelException,f.__rdiv__,arr) + self.assertRaises(InterpKernelException,f.__rdiv__,f2) + f.setArray(DataArrayDouble()) + self.assertRaises(InterpKernelException,f.__rdiv__,2) + self.assertRaises(InterpKernelException,f.__rdiv__,range(5)) + self.assertRaises(InterpKernelException,f.__rdiv__,arr) + self.assertRaises(InterpKernelException,f.__rdiv__,f2) + self.assertRaises(InterpKernelException,f.__getitem__,(slice(None),0)) + f.getArray().alloc(5,2) + f.getArray()[:,0]=range(1,6) ; f.getArray()[:,1]=f.getArray()[:,0]+7 + ff=2/f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(2,0.25),(1,0.22222222222222221),(0.66666666666666663,0.20000000000000001),(0.5,0.18181818181818182),(0.40000000000000002,0.16666666666666666)]),1e-12)) + ff=arr/f + ff.checkCoherency() + self.assertTrue(ff.getArray().isEqual(DataArrayDouble([(1,0.25),(1,0.44444444444444442),(1,0.59999999999999998),(1,0.72727272727272729),(1,0.83333333333333337)]),1e-12)) + self.assertRaises(InterpKernelException,f.__rdiv__,f2) pass def setUp(self): diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 2cf90fc05..5874ed8ab 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -45,6 +45,7 @@ using namespace ParaMEDMEM; using namespace INTERP_KERNEL; + %} %template(ivec) std::vector; @@ -288,13 +289,9 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::findClosestTupleId; %newobject ParaMEDMEM::DataArrayDouble::duplicateEachTupleNTimes; %newobject ParaMEDMEM::DataArrayDouble::__neg__; -%newobject ParaMEDMEM::DataArrayDouble::__add__; %newobject ParaMEDMEM::DataArrayDouble::__radd__; -%newobject ParaMEDMEM::DataArrayDouble::__sub__; %newobject ParaMEDMEM::DataArrayDouble::__rsub__; -%newobject ParaMEDMEM::DataArrayDouble::__mul__; %newobject ParaMEDMEM::DataArrayDouble::__rmul__; -%newobject ParaMEDMEM::DataArrayDouble::__div__; %newobject ParaMEDMEM::DataArrayDouble::__rdiv__; %newobject ParaMEDMEM::DataArrayDouble::__pow__; %newobject ParaMEDMEM::DataArrayDouble::__rpow__; @@ -1224,7 +1221,7 @@ namespace ParaMEDMEM static void Rotate2DAlg(PyObject *center, double angle, PyObject *coords) throw(INTERP_KERNEL::Exception) { - int sz,sz2; + int sz; INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); int sw,nbNodes=0; double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; @@ -2706,7 +2703,7 @@ namespace ParaMEDMEM %extend { PyObject *getMesh() const throw(INTERP_KERNEL::Exception) { - MEDCouplingMesh *ret1=(MEDCouplingMesh *)self->getMesh(); + MEDCouplingMesh *ret1=const_cast(self->getMesh()); if(ret1) ret1->incrRef(); return convertMesh(ret1,SWIG_POINTER_OWN | 0 ); @@ -3395,74 +3392,12 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__add__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; - const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !"; - void *argp; - // - if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) - { - MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); - if(other) - return (*self)+(*other); - else - throw INTERP_KERNEL::Exception(msg); - } - // - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); - ret->applyLin(1.,val); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 2: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Add(self->getArray(),a); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 3: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Add(self->getArray(),aaa); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 4: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Add(self->getArray(),aaa); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - default: - { throw INTERP_KERNEL::Exception(msg); } - } + return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj); } MEDCouplingFieldDouble *__radd__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_MEDCouplingFieldDouble___add__(self,obj); + return ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(self,obj); } MEDCouplingFieldDouble *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -3534,141 +3469,17 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *__rsub__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rsub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; - const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !"; - void *argp; - // - if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) - { - MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); - if(other) - return (*other)-(*self); - else - throw INTERP_KERNEL::Exception(msg); - } - // - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); - ret->applyLin(-1.,val); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 2: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Substract(a,self->getArray()); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 3: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Substract(aaa,self->getArray()); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 4: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Substract(aaa,self->getArray()); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - default: - { throw INTERP_KERNEL::Exception(msg); } - } + return ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(self,obj); } MEDCouplingFieldDouble *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__mul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; - const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !"; - void *argp; - // - if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) - { - MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); - if(other) - return (*self)*(*other); - else - throw INTERP_KERNEL::Exception(msg); - } - // - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); - ret->applyLin(val,0.); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 2: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Multiply(self->getArray(),a); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 3: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Multiply(self->getArray(),aaa); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 4: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Multiply(self->getArray(),aaa); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - default: - { throw INTERP_KERNEL::Exception(msg); } - } + return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj); } MEDCouplingFieldDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_MEDCouplingFieldDouble___mul__(self,obj); + return ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(self,obj); } MEDCouplingFieldDouble *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) @@ -3742,67 +3553,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *__rdiv__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rdiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; - const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !"; - void *argp; - // - if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) - { - MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); - if(other) - return (*other)/(*self); - else - throw INTERP_KERNEL::Exception(msg); - } - // - double val; - DataArrayDouble *a; - DataArrayDoubleTuple *aa; - std::vector bb; - int sw; - convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); - switch(sw) - { - case 1: - { - MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); - ret->applyInv(val); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 2: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Divide(a,self->getArray()); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 3: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Divide(aaa,self->getArray()); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - case 4: - { - if(!self->getArray()) - throw INTERP_KERNEL::Exception(msg2); - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::Divide(aaa,self->getArray()); - MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); - ret2->setArray(ret); - return ret2.retn(); - } - default: - { throw INTERP_KERNEL::Exception(msg); } - } + return ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(self,obj); } MEDCouplingFieldDouble *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 9b057fb97..af37bec17 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -139,7 +139,6 @@ namespace ParaMEDMEM void setIJSilent(int tupleId, int compoId, double newVal) throw(INTERP_KERNEL::Exception); double *getPointer() throw(INTERP_KERNEL::Exception); void checkNoNullValues() const throw(INTERP_KERNEL::Exception); - void getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception); DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const throw(INTERP_KERNEL::Exception); void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception); double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); @@ -687,10 +686,9 @@ namespace ParaMEDMEM DataArrayDoubleTuple *aa; std::vector bb; int sw; - int tupleId=-1,nbTuples=-1,nbOfCompo=self->getNumberOfComponents(); + int tupleId=-1,nbOfCompo=self->getNumberOfComponents(); const double *pt=convertObjToPossibleCpp5_Safe(tuple,sw,val,a,aa,bb,"Python wrap of DataArrayDouble::distanceToTuple",1,nbOfCompo,true); // - int cellId=-1,nodeId=-1; double ret0=self->distanceToTuple(pt,pt+nbOfCompo,tupleId); PyObject *ret=PyTuple_New(2); PyTuple_SetItem(ret,0,PyFloat_FromDouble(ret0)); @@ -1210,14 +1208,30 @@ namespace ParaMEDMEM return self->negate(); } - DataArrayDouble *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) + PyObject *__add__(PyObject *obj) throw(INTERP_KERNEL::Exception) { - const char msg[]="Unexpected situation in __add__ !"; + const char msg[]="Unexpected situation in DataArrayDouble.__add__ !"; double val; DataArrayDouble *a; DataArrayDoubleTuple *aa; std::vector bb; int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { @@ -1225,21 +1239,21 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,val); - return ret.retn(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 2: { - return DataArrayDouble::Add(self,a); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Add(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 3: { MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Add(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Add(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 4: { MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Add(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Add(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } default: throw INTERP_KERNEL::Exception(msg); @@ -1320,7 +1334,7 @@ namespace ParaMEDMEM } } - DataArrayDouble *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) + PyObject *__sub__(PyObject *obj) throw(INTERP_KERNEL::Exception) { const char msg[]="Unexpected situation in __sub__ !"; double val; @@ -1328,6 +1342,22 @@ namespace ParaMEDMEM DataArrayDoubleTuple *aa; std::vector bb; int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { @@ -1335,21 +1365,21 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,-val); - return ret.retn(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 2: { - return DataArrayDouble::Substract(self,a); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Substract(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 3: { MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Substract(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Substract(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 4: { MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Substract(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Substract(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } default: throw INTERP_KERNEL::Exception(msg); @@ -1430,7 +1460,7 @@ namespace ParaMEDMEM } } - DataArrayDouble *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) + PyObject *__mul__(PyObject *obj) throw(INTERP_KERNEL::Exception) { const char msg[]="Unexpected situation in __mul__ !"; double val; @@ -1438,6 +1468,22 @@ namespace ParaMEDMEM DataArrayDoubleTuple *aa; std::vector bb; int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { @@ -1445,21 +1491,21 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0.); - return ret.retn(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 2: { - return DataArrayDouble::Multiply(self,a); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Multiply(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 3: { MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Multiply(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Multiply(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 4: { MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Multiply(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Multiply(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } default: throw INTERP_KERNEL::Exception(msg); @@ -1540,7 +1586,7 @@ namespace ParaMEDMEM } } - DataArrayDouble *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) + PyObject *__div__(PyObject *obj) throw(INTERP_KERNEL::Exception) { const char msg[]="Unexpected situation in __div__ !"; double val; @@ -1548,6 +1594,22 @@ namespace ParaMEDMEM DataArrayDoubleTuple *aa; std::vector bb; int sw; + // + void *argp; + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + { + PyObject *tmp=SWIG_NewPointerObj(SWIG_as_voidptr(self),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); + MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(other,tmp); + Py_XDECREF(tmp); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble, SWIG_POINTER_OWN | 0 ); + } + else + throw INTERP_KERNEL::Exception(msg); + } + // convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); switch(sw) { @@ -1557,21 +1619,21 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1/val,0.); - return ret.retn(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 2: { - return DataArrayDouble::Divide(self,a); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Divide(self,a)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 3: { MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); - return DataArrayDouble::Divide(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Divide(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } case 4: { MEDCouplingAutoRefCountObjectPtr aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size()); - return DataArrayDouble::Divide(self,aaa); + return SWIG_NewPointerObj(SWIG_as_voidptr(DataArrayDouble::Divide(self,aaa)),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ); } default: throw INTERP_KERNEL::Exception(msg); @@ -3406,8 +3468,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Add(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Add(self,aaaa); } case 3: { @@ -3442,8 +3504,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Add(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Add(self,aaaa); } case 4: { @@ -3516,8 +3578,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Substract(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Substract(self,aaaa); } case 3: { @@ -3552,8 +3614,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Substract(aaa,self); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Substract(aaaa,self); } case 4: { @@ -3626,8 +3688,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Multiply(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Multiply(self,aaaa); } case 3: { @@ -3662,8 +3724,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Multiply(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Multiply(self,aaaa); } case 4: { @@ -3736,8 +3798,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Divide(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Divide(self,aaaa); } case 3: { @@ -3772,8 +3834,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Divide(aaa,self); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Divide(aaaa,self); } case 4: { @@ -3846,8 +3908,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Modulus(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Modulus(self,aaaa); } case 3: { @@ -3882,8 +3944,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Modulus(aaa,self); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Modulus(aaaa,self); } case 3: { @@ -3953,8 +4015,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Pow(self,aaa); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Pow(self,aaaa); } case 3: { @@ -3989,8 +4051,8 @@ namespace ParaMEDMEM } case 2: { - MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); - return DataArrayInt::Pow(aaa,self); + MEDCouplingAutoRefCountObjectPtr aaaa=DataArrayInt::New(); aaaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Pow(aaaa,self); } case 3: { diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index c13cffe2d..fbbf34ea6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -1423,7 +1423,7 @@ static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, dou f=ret; return &f[0]; } - catch(INTERP_KERNEL::Exception& e) { throw e; } + catch(INTERP_KERNEL::Exception& exc) { throw exc; } } void *argp; int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0); @@ -1839,3 +1839,281 @@ static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& s } throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple"); } + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__add__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)+(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(1.,val); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj); +} + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rsub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*other)-(*self); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(-1.,val); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} + +static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__mul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*self)*(*other); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyLin(val,0.); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +} + +ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj); +} + +ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception) +{ + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rdiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !"; + void *argp; + // + if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0))) + { + ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp); + if(other) + return (*other)/(*self); + else + throw INTERP_KERNEL::Exception(msg); + } + // + double val; + ParaMEDMEM::DataArrayDouble *a; + ParaMEDMEM::DataArrayDoubleTuple *aa; + std::vector bb; + int sw; + convertObjToPossibleCpp5(obj,sw,val,a,aa,bb); + switch(sw) + { + case 1: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=self->getArray()->deepCpy(); + ret->applyInv(val); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 2: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 3: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + case 4: + { + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray()); + ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(ret); + return ret2.retn(); + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } +}