From f6f7ce980797187aed031ae7979be2bf17f82429 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 26 Aug 2017 11:10:34 +0800 Subject: sky.py: Add more numeric special methods --- fg21sim/sky.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/fg21sim/sky.py b/fg21sim/sky.py index bae18a6..17ffd62 100644 --- a/fg21sim/sky.py +++ b/fg21sim/sky.py @@ -126,6 +126,58 @@ class SkyBase: else: raise NotImplemented + def __iadd__(self, other): + """ + Augmented arithmetic assignment: ``+=``. + + NOTE + ---- + These augmented arithmetic assignment methods should attempt + to do the operation in-place (modifying ``self``) and return + the result (which could be, but does not have to be, ``self``). + """ + if isinstance(other, self.__class__): + self.data += other.data + return self + elif isinstance(other, (int, float, np.ndarray)): + self.data += other + return self + else: + raise NotImplemented + + def __isub__(self, other): + """Augmented arithmetic assignment: ``-=``.""" + if isinstance(other, self.__class__): + self.data -= other.data + return self + elif isinstance(other, (int, float, np.ndarray)): + self.data -= other + return self + else: + raise NotImplemented + + def __imul__(self, other): + """Augmented arithmetic assignment: ``*=``.""" + if isinstance(other, self.__class__): + self.data *= other.data + return self + elif isinstance(other, (int, float, np.ndarray)): + self.data *= other + return self + else: + raise NotImplemented + + def __itruediv__(self, other): + """Augmented arithmetic assignment: ``/=``.""" + if isinstance(other, self.__class__): + self.data /= other.data + return self + elif isinstance(other, (int, float, np.ndarray)): + self.data /= other + return self + else: + raise NotImplemented + def __neg__(self): """Unary arithmetic operation: ``-``.""" return -self.data -- cgit v1.2.2