From: ageay Date: Tue, 9 Apr 2013 15:46:03 +0000 (+0000) Subject: Extend operator __imul,isub,idiv,ipow__ of MEDCouplingFieldDouble X-Git-Tag: V6_main_FINAL~170 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a53c3788fe780e2e7e6519b38da322b69c9d1b4;p=tools%2Fmedcoupling.git Extend operator __imul,isub,idiv,ipow__ of MEDCouplingFieldDouble --- diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 7349f9d8b..528ab96a5 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -3746,33 +3746,271 @@ namespace ParaMEDMEM { throw INTERP_KERNEL::Exception(msg); } } } - - PyObject *___isub___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + + PyObject *___isub___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self-=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__isub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__isub__ : 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) + { + *self-=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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); + self->getArray()->applyLin(1.,-val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self-=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self-=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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()); + self->getArray()->substractEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } - PyObject *___imul___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self*=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__imul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__imul__ : 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) + { + *self*=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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); + self->getArray()->applyLin(val,0); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self*=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self*=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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()); + self->getArray()->multiplyEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } - PyObject *___idiv___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self/=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__idiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__idiv__ : 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) + { + *self/=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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(val==0.) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble.__idiv__ : trying to divide by zero !"); + if(!self->getArray()) + throw INTERP_KERNEL::Exception(msg2); + self->getArray()->applyLin(1./val,0); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self/=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self/=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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()); + self->getArray()->divideEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } - PyObject *___ipow___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) + PyObject *___ipow___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception) { - *self^=other; - Py_XINCREF(trueSelf); - return trueSelf; + const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__ipow__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double."; + const char msg2[]="in MEDCouplingFieldDouble.__ipow__ : 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) + { + *self^=*other; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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); + self->getArray()->applyPow(val); + Py_XINCREF(trueSelf); + return trueSelf; + } + case 2: + { + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(a); + *self^=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr aaa=aa->buildDADouble(1,self->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret2=self->clone(false); + ret2->setArray(aaa); + *self^=*ret2; + Py_XINCREF(trueSelf); + return trueSelf; + } + 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()); + self->getArray()->powEqual(aaa); + Py_XINCREF(trueSelf); + return trueSelf; + } + default: + { throw INTERP_KERNEL::Exception(msg); } + } } static MEDCouplingFieldDouble *MergeFields(PyObject *li) throw(INTERP_KERNEL::Exception)