Commit cc375a68 authored by Tim Keil's avatar Tim Keil

simplify the if statement

parent 0a91fa36
......@@ -62,8 +62,7 @@ class Function(ParametricObject):
return self
other = ConstantFunction(other, dim_domain=self.dim_domain)
if self.name != 'LincombFunction' or (self.name == 'LincombFunction'
and not isinstance(self, LincombFunction)):
if self.name != 'LincombFunction' or not isinstance(self, LincombFunction):
if other.name == 'LincombFunction' and isinstance(other, LincombFunction):
functions = (self,) + other.functions
coefficients = (1.,) + (other.coefficients if sign == 1. else tuple(-c for c in other.coefficients))
......@@ -89,8 +88,7 @@ class Function(ParametricObject):
return self
other = ConstantFunction(other, dim_domain=self.dim_domain)
if self.name != 'LincombFunction' or (self.name == 'LincombFunction'
and not isinstance(self, LincombFunction)):
if self.name != 'LincombFunction' or not isinstance(self, LincombFunction):
functions, coefficients = (other, self), (1., sign)
else:
functions = (other,) + self.functions
......
......@@ -524,8 +524,7 @@ class Operator(ParametricObject):
if not isinstance(other, Operator):
return NotImplemented
from pymor.operators.constructions import LincombOperator
if self.name != 'LincombOperator' or (self.name == 'LincombOperator'
and not isinstance(self, LincombOperator)):
if self.name != 'LincombOperator' or not isinstance(self, LincombOperator):
if other.name == 'LincombOperator' and isinstance(other, LincombOperator):
operators = (self,) + other.operators
coefficients = (1.,) + (other.coefficients if sign == 1. else tuple(-c for c in other.coefficients))
......@@ -545,8 +544,7 @@ class Operator(ParametricObject):
return NotImplemented
from pymor.operators.constructions import LincombOperator
# note that 'other' can never be a LincombOperator
if self.name != 'LincombOperator' or (self.name == 'LincombOperator'
and not isinstance(self, LincombOperator)):
if self.name != 'LincombOperator' or not isinstance(self, LincombOperator)):
operators, coefficients = (other, self), (1., sign)
else:
operators = (other,) + self.operators
......@@ -569,8 +567,7 @@ class Operator(ParametricObject):
def __mul__(self, other):
assert isinstance(other, (Number, ParameterFunctional))
from pymor.operators.constructions import LincombOperator
if self.name != 'LincombOperator' or (self.name == 'LincombOperator'
and not isinstance(self, LincombOperator)):
if self.name != 'LincombOperator' or not isinstance(self, LincombOperator):
return LincombOperator((self,), (other,))
else:
return self.with_(coefficients=tuple(c * other for c in self.coefficients))
......
......@@ -54,8 +54,7 @@ class ParameterFunctional(ParametricObject):
return self
other = ConstantParameterFunctional(other)
if self.name != 'LincombParameterFunctional' or (self.name == 'LincombParameterFunctional'
and not isinstance(self, LincombParameterFunctional)):
if self.name != 'LincombParameterFunctional' or not isinstance(self, LincombParameterFunctional):
if other.name == 'LincombParameterFunctional' and isinstance(other, LincombParameterFunctional):
functionals = (self,) + other.functionals
coefficients = (1.,) + (other.coefficients if sign == 1. else tuple(-c for c in other.coefficients))
......@@ -79,8 +78,7 @@ class ParameterFunctional(ParametricObject):
return self
other = ConstantParameterFunctional(other)
if self.name != 'LincombParameterFunctional' or (self.name == 'LincombParameterFunctional'
and not isinstance(self, LincombParameterFunctional)):
if self.name != 'LincombParameterFunctional' or not isinstance(self, LincombParameterFunctional):
functionals, coefficients = (other, self), (1., sign)
else:
functionals = (other,) + self.functionals
......@@ -103,8 +101,7 @@ class ParameterFunctional(ParametricObject):
def __mul__(self, other):
if not isinstance(other, (Number, ParameterFunctional)):
return NotImplemented
if self.name != 'ProductParameterFunctional' or (self.name == 'LincombParameterFunctional'
and not isinstance(self, LincombParameterFunctional)):
if self.name != 'ProductParameterFunctional' or not isinstance(self, ProductParameterFunctional):
if isinstance(other, ProductParameterFunctional) and other.name == 'ProductParameterFunctional':
return other.with_(factors=other.factors + [self])
else:
......
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