Commit 8b54f1db authored by Tim Keil's avatar Tim Keil

do not allow the name 'LincombX' if not an Lincomb instance

parent 534893a3
......@@ -69,10 +69,12 @@ class Function(ParametricObject):
else:
functions, coefficients = (self, other), (1., sign)
elif isinstance(other, LincombFunction) and other.name == 'LincombFunction':
assert isinstance(self, LincombFunction)
functions = self.functions + other.functions
coefficients = self.coefficients + (other.coefficients if sign == 1.
else tuple(-c for c in other.coefficients))
else:
assert isinstance(self, LincombFunction)
functions, coefficients = self.functions + (other,), self.coefficients + (sign,)
return LincombFunction(functions, coefficients)
......@@ -91,6 +93,7 @@ class Function(ParametricObject):
if self.name != 'LincombFunction':
functions, coefficients = (other, self), (1., sign)
else:
assert isinstance(self, LincombFunction)
functions = (other,) + self.functions
coefficients = (1.,) + (self.coefficients if sign == 1. else tuple(-c for c in self.coefficients))
......@@ -119,9 +122,11 @@ class Function(ParametricObject):
else:
return ProductFunction([self, other])
elif isinstance(other, ProductFunction) and other.name == 'ProductFunction':
assert isinstance(self, ProductFunction)
functions = self.functions + other.functions
return ProductFunction(functions)
else:
assert isinstance(self, ProductFunction)
return self.with_(functions=self.functions + [other])
__rmul__ = __mul__
......
......@@ -61,10 +61,12 @@ class ParameterFunctional(ParametricObject):
else:
functionals, coefficients = (self, other), (1., sign)
elif isinstance(other, LincombParameterFunctional) and other.name == 'LincombParameterFunctional':
assert isinstance(self, LincombParameterFunctional)
functionals = self.functionals + other.functionals
coefficients = self.coefficients + (other.coefficients if sign == 1.
else tuple(-c for c in other.coefficients))
else:
assert isinstance(self, LincombParameterFunctional)
functionals, coefficients = self.functionals + (other,), self.coefficients + (sign,)
return LincombParameterFunctional(functionals, coefficients)
......@@ -82,6 +84,7 @@ class ParameterFunctional(ParametricObject):
if self.name != 'LincombParameterFunctional':
functionals, coefficients = (other, self), (1., sign)
else:
assert isinstance(self, LincombParameterFunctional)
functionals = (other,) + self.functionals
coefficients = (1.,) + (self.coefficients if sign == 1. else tuple(-c for c in self.coefficients))
......@@ -108,9 +111,11 @@ class ParameterFunctional(ParametricObject):
else:
return ProductParameterFunctional([self, other])
elif isinstance(other, ProductParameterFunctional) and other.name == 'ProductParameterFunctional':
assert isinstance(self, ProductParameterFunctional)
factors = self.factors + other.factors
return ProductParameterFunctional(factors)
else:
assert isinstance(self, ProductParameterFunctional)
return self.with_(factors=self.factors + [other])
__rmul__ = __mul__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment