From 975fb540193d0b8f79df85f939126d78bd0d8f32 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 25 Mar 2013 16:33:45 +0000 Subject: [PATCH] pow on DataArrayInt and reverse with multi component --- src/MEDCoupling_Swig/MEDCoupling.i | 3 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 26 ++++- src/MEDCoupling_Swig/MEDCouplingCommon.i | 110 ++++++++++++++++++ src/MEDCoupling_Swig/MEDCouplingFinalize.i | 1 + 4 files changed, 138 insertions(+), 2 deletions(-) diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 04d497020..de843c7b6 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -59,6 +59,9 @@ def ParaMEDMEMDataArrayIntIdiv(self,*args): def ParaMEDMEMDataArrayIntImod(self,*args): import _MEDCoupling return _MEDCoupling.DataArrayInt____imod___(self, self, *args) +def ParaMEDMEMDataArrayIntIpow(self,*args): + import _MEDCoupling + return _MEDCoupling.DataArrayInt____ipow___(self, self, *args) def ParaMEDMEMDataArrayDoubleTupleIadd(self,*args): import _MEDCoupling return _MEDCoupling.DataArrayDoubleTuple____iadd___(self, self, *args) diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 5929a4dae..82d5e46a9 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -4570,7 +4570,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): dbl2.alloc(7,2); self.assertRaises(InterpKernelException, dbl2.isUniform, 10., 1e-15); self.assertRaises(InterpKernelException, dbl2.sort); - self.assertRaises(InterpKernelException, dbl2.reverse); self.assertRaises(InterpKernelException, dbl2.iota, 10.); dbl=DataArrayDouble.New(); @@ -4578,7 +4577,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertRaises(InterpKernelException, dbl.iota, 10.); self.assertRaises(InterpKernelException, dbl.isUniform, 10., 1e-15); self.assertRaises(InterpKernelException, dbl.sort); - self.assertRaises(InterpKernelException, dbl.reverse); self.assertRaises(InterpKernelException, dbl.fromNoInterlace); self.assertRaises(InterpKernelException, dbl.toNoInterlace); @@ -11692,6 +11690,30 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass pass + def testSwig2DAReverseMultiCompo1(self): + d=DataArrayDouble(6,2) + d[:,0]=range(6) + d[:,1]=range(10,16) + d.reverse() + self.assertTrue(d.isEqual(DataArrayDouble([5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],6,2),1e-14)) + d=DataArrayDouble(7,2) + d[:,0]=range(7) + d[:,1]=range(10,17) + d.reverse() + self.assertTrue(d.isEqual(DataArrayDouble([6.,16.,5.,15.,4.,14.,3.,13.,2.,12.,1.,11.,0.,10.],7,2),1e-14)) + # + d=DataArrayInt(6,2) + d[:,0]=range(6) + d[:,1]=range(10,16) + d.reverse() + self.assertTrue(d.isEqual(DataArrayInt([5,15,4,14,3,13,2,12,1,11,0,10],6,2))) + d=DataArrayInt(7,2) + d[:,0]=range(7) + d[:,1]=range(10,17) + d.reverse() + self.assertTrue(d.isEqual(DataArrayInt([6,16,5,15,4,14,3,13,2,12,1,11,0,10],7,2))) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 1de0e431b..b60d7000e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -174,6 +174,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::Substract; %newobject ParaMEDMEM::DataArrayInt::Multiply; %newobject ParaMEDMEM::DataArrayInt::Divide; +%newobject ParaMEDMEM::DataArrayInt::Pow; %newobject ParaMEDMEM::DataArrayInt::BuildUnion; %newobject ParaMEDMEM::DataArrayInt::BuildIntersection; %newobject ParaMEDMEM::DataArrayInt::Range; @@ -204,6 +205,8 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::__rdiv__; %newobject ParaMEDMEM::DataArrayInt::__mod__; %newobject ParaMEDMEM::DataArrayInt::__rmod__; +%newobject ParaMEDMEM::DataArrayInt::__pow__; +%newobject ParaMEDMEM::DataArrayInt::__rpow__; %newobject ParaMEDMEM::DataArrayIntTuple::buildDAInt; %newobject ParaMEDMEM::DataArrayChar::convertToIntArr; %newobject ParaMEDMEM::DataArrayChar::renumber; @@ -7462,6 +7465,113 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception(msg); } } + + DataArrayInt *__pow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __pow__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyPow(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Pow(self,aaa); + } + case 3: + { + return DataArrayInt::Pow(self,a); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Pow(self,aaaa); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + DataArrayInt *__rpow__(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __rpow__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); + ret->applyRPow(val); + return ret.retn(); + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr aaa=DataArrayInt::New(); aaa->useArray(&aa[0],false,CPP_DEALLOC,1,(int)aa.size()); + return DataArrayInt::Pow(aaa,self); + } + case 3: + { + return DataArrayInt::Pow(a,self); + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + return DataArrayInt::Pow(aaaa,self); + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + + PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) + { + const char msg[]="Unexpected situation in __ipow__ !"; + int val; + DataArrayInt *a; + std::vector aa; + DataArrayIntTuple *aaa; + int sw; + convertObjToPossibleCpp1(obj,sw,val,aa,a,aaa); + switch(sw) + { + case 1: + { + self->applyPow(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + self->powEqual(a); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 4: + { + MEDCouplingAutoRefCountObjectPtr aaaa=aaa->buildDAInt(1,self->getNumberOfComponents()); + self->powEqual(aaaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } }; namespace ParaMEDMEM diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index 909b4cf95..d686aa607 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -28,6 +28,7 @@ DataArrayInt.__isub__=ParaMEDMEMDataArrayIntIsub DataArrayInt.__imul__=ParaMEDMEMDataArrayIntImul DataArrayInt.__idiv__=ParaMEDMEMDataArrayIntIdiv DataArrayInt.__imod__=ParaMEDMEMDataArrayIntImod +DataArrayInt.__ipow__=ParaMEDMEMDataArrayIntIpow MEDCouplingFieldDouble.__iadd__=ParaMEDMEMMEDCouplingFieldDoubleIadd MEDCouplingFieldDouble.__isub__=ParaMEDMEMMEDCouplingFieldDoubleIsub -- 2.39.2