Commit 67071b5c authored by Martin Reinecke's avatar Martin Reinecke
Browse files

allow makeOp to produce ScalingOperators

parent eac8a311
Pipeline #72295 passed with stages
in 21 minutes and 47 seconds
......@@ -162,11 +162,11 @@ class Linearization(object):
def __truediv__(self, other):
if isinstance(other, Linearization):
return self.__mul__(other.one_over())
return self.__mul__(other.ptw("reciprocal"))
return self.__mul__(1./other)
def __rtruediv__(self, other):
return self.reciprocal().__mul__(other)
return self.ptw("reciprocal").__mul__(other)
def __pow__(self, power):
if not np.isscalar(power):
......@@ -317,7 +317,7 @@ def makeDomain(domain):
return DomainTuple.make(domain)
def makeOp(input):
def makeOp(input, dom=None):
"""Converts a Field or MultiField to a diagonal operator.
......@@ -331,12 +331,22 @@ def makeOp(input):
- if MultiField, a BlockDiagonalOperator with entries given by this
MultiField is returned.
dom : DomainTuple or MultiDomain
if `input` is a scalar, this is used as the operator's domain
No volume factors are applied.
if input is None:
return None
if np.isscalar(input):
if not isinstance(dom, (DomaiTuple, MultiDomain)):
raise TypeError("need proper `dom` argument")
return SalingOperator(dom, input)
if dom is not None:
if not dom == input.domain:
raise ValueError("domain mismatch")
if input.domain is DomainTuple.scalar_domain():
return ScalingOperator(input.domain, float(input.val))
if isinstance(input, Field):
Supports Markdown
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