Removed duplication

master
Per A Brodtkorb 8 years ago
parent 08c5b78eb4
commit a44dd995cf

@ -1637,24 +1637,26 @@ class Cheb1d(object):
return self return self
def __add__(self, other): def __add__(self, other):
other = Cheb1d(other) new, other = self._copy(other)
new = Cheb1d(self)
new.coeffs = polyadd(self.coeffs, other.coeffs) new.coeffs = polyadd(self.coeffs, other.coeffs)
return new return new
def __radd__(self, other): def __radd__(self, other):
return self.__add__(other) return self.__add__(other)
def __sub__(self, other): def _copy(self, other):
other = Cheb1d(other) other = Cheb1d(other)
new = Cheb1d(self) new = Cheb1d(self)
return new, other
def __sub__(self, other):
new, other = self._copy(other)
new.coeffs = polysub(self.coeffs, other.coeffs) new.coeffs = polysub(self.coeffs, other.coeffs)
return new return new
def __rsub__(self, other): def __rsub__(self, other):
other = Cheb1d(other) new = self.__sub__(other)
new = Cheb1d(self) new.coeffs *= -1
new.coeffs = polysub(other.coeffs, new.coeffs)
return new return new
def __eq__(self, other): def __eq__(self, other):
@ -1670,23 +1672,10 @@ class Cheb1d(object):
raise ValueError("Attributes cannot be changed this way.") raise ValueError("Attributes cannot be changed this way.")
def __getattr__(self, key): def __getattr__(self, key):
if key in ['c', 'coef', 'coefficients']: name = dict(c='coeffs', coef='coeffs', coefficients='coeffs',
return self.coeffs o='order', k='kind').get(key, key)
elif key in ['o']: return getattr(self, name)
return self.order return self.__dict__[name]
elif key in ['a']:
return self.a
elif key in ['b']:
return self.b
elif key in ['k']:
return self.kind
else:
try:
return self.__dict__[key]
except KeyError:
raise AttributeError(
"'%s' has no attribute '%s'" %
(self.__class__, key))
def __getitem__(self, val): def __getitem__(self, val):
if val > self.order: if val > self.order:

Loading…
Cancel
Save