mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
import numpy as np
|
|
from functools import partial
|
|
|
|
class Location:
|
|
"""
|
|
A location is a point designated by a spatial coordinate x.
|
|
|
|
Locations are wrappers around a Numpy N-dimensional array.
|
|
"""
|
|
|
|
def __init__(self, x):
|
|
self.x = np.asarray(x)
|
|
|
|
def __repr__(self):
|
|
return "Location({})".format(repr(self.x))
|
|
|
|
def __getitem__(self, key):
|
|
return self.x[key]
|
|
|
|
def __setitem__(self, key, val):
|
|
self.x[key] = val
|
|
|
|
# math
|
|
def __add__(self, other):
|
|
if isinstance(other, Location):
|
|
other = other.x
|
|
|
|
return self.__class__(self.x + other)
|
|
|
|
def __sub__(self, other):
|
|
if isinstance(other, Location):
|
|
other = other.x
|
|
|
|
return self.__class__(self.x - other)
|
|
|
|
def __mul__(self, other):
|
|
return self.__class__(self.x * other)
|
|
|
|
def __eq__(self, other):
|
|
if isinstance(other, Location):
|
|
other = other.x
|
|
|
|
return np.all(self.x == other)
|
|
|
|
# math alias functions
|
|
__radd__ = __add__
|
|
__rsub__ = __sub__
|
|
__rmul__ = __mul__
|