diff options
author | Aaron LI <aly@aaronly.me> | 2017-08-26 11:10:34 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2017-08-26 11:10:34 +0800 |
commit | f6f7ce980797187aed031ae7979be2bf17f82429 (patch) | |
tree | 31cb7a69a4f4b2dc500eba4f45d55fda4968fcab /fg21sim | |
parent | 3bd085a34ceae6e56e3bee9887f93efdc1164932 (diff) | |
download | fg21sim-f6f7ce980797187aed031ae7979be2bf17f82429.tar.bz2 |
sky.py: Add more numeric special methods
Diffstat (limited to 'fg21sim')
-rw-r--r-- | fg21sim/sky.py | 52 |
1 files changed, 52 insertions, 0 deletions
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 |