aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/sky.py
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-08-26 11:10:34 +0800
committerAaron LI <aly@aaronly.me>2017-08-26 11:10:34 +0800
commitf6f7ce980797187aed031ae7979be2bf17f82429 (patch)
tree31cb7a69a4f4b2dc500eba4f45d55fda4968fcab /fg21sim/sky.py
parent3bd085a34ceae6e56e3bee9887f93efdc1164932 (diff)
downloadfg21sim-f6f7ce980797187aed031ae7979be2bf17f82429.tar.bz2
sky.py: Add more numeric special methods
Diffstat (limited to 'fg21sim/sky.py')
-rw-r--r--fg21sim/sky.py52
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