Commit de06f078 authored by Tim Keil's avatar Tim Keil

make addition commutative

parent 8f7ae9e7
......@@ -63,13 +63,15 @@ class Function(ParametricObject):
other = ConstantFunction(other, dim_domain=self.dim_domain)
if self.name != 'LincombFunction':
if isinstance(other, LincombFunction) and other.name == 'LincombFunction':
if other.name == 'LincombFunction':
assert isinstance(other, LincombFunction)
functions = (self,) + other.functions
coefficients = (1.,) + (other.coefficients if sign == 1. else tuple(-c for c in other.coefficients))
else:
functions, coefficients = (self, other), (1., sign)
elif isinstance(other, LincombFunction) and other.name == 'LincombFunction':
elif other.name == 'LincombFunction':
assert isinstance(self, LincombFunction)
assert isinstance(other, LincombFunction)
functions = self.functions + other.functions
coefficients = self.coefficients + (other.coefficients if sign == 1.
else tuple(-c for c in other.coefficients))
......
......@@ -525,13 +525,15 @@ class Operator(ParametricObject):
return NotImplemented
from pymor.operators.constructions import LincombOperator
if self.name != 'LincombOperator':
if isinstance(other, LincombOperator) and other.name == 'LincombOperator':
if other.name == 'LincombOperator':
assert isinstance(other, LincombOperator)
operators = (self,) + other.operators
coefficients = (1.,) + (other.coefficients if sign == 1. else tuple(-c for c in other.coefficients))
else:
operators, coefficients = (self, other), (1., sign)
elif isinstance(other, LincombOperator) and other.name == 'LincombOperator':
elif other.name == 'LincombOperator':
assert isinstance(self, LincombOperator)
assert isinstance(other, LincombOperator)
operators = self.operators + other.operators
coefficients = self.coefficients + (other.coefficients if sign == 1.
else tuple(-c for c in other.coefficients))
......
......@@ -55,13 +55,15 @@ class ParameterFunctional(ParametricObject):
other = ConstantParameterFunctional(other)
if self.name != 'LincombParameterFunctional':
if isinstance(other, LincombParameterFunctional) and other.name == 'LincombParameterFunctional':
if other.name == 'LincombParameterFunctional':
assert isinstance(other, LincombParameterFunctional)
functionals = (self,) + other.functionals
coefficients = (1.,) + (other.coefficients if sign == 1. else tuple(-c for c in other.coefficients))
else:
functionals, coefficients = (self, other), (1., sign)
elif isinstance(other, LincombParameterFunctional) and other.name == 'LincombParameterFunctional':
elif other.name == 'LincombParameterFunctional':
assert isinstance(self, LincombParameterFunctional)
assert isinstance(other, LincombParameterFunctional)
functionals = self.functionals + other.functionals
coefficients = self.coefficients + (other.coefficients if sign == 1.
else tuple(-c for c in other.coefficients))
......
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