Commit 9e8af84e authored by Gordian Edenhofer's avatar Gordian Edenhofer
Browse files

sugar.py makeOp: Use ScalingOperator

Adapt the ScalingOperator class to not depend on sugar.py in order to
use it within sugar.py without getting a circular dependency.
parent ecc96428
Pipeline #68937 passed with stages
in 26 minutes and 23 seconds
......@@ -17,8 +17,10 @@
import numpy as np
from ..sugar import full
from .endomorphic_operator import EndomorphicOperator
from ..field import Field
from ..multi_domain import MultiDomain
from ..multi_field import MultiField
class ScalingOperator(EndomorphicOperator):
......@@ -65,7 +67,10 @@ class ScalingOperator(EndomorphicOperator):
if fct == 1.:
return x
if fct == 0.:
return full(self.domain, 0.)
# Avoid a circular import by replicating `..sugar.full`
if isinstance(x.domain, (dict, MultiDomain)):
return MultiField.full(x.domain, 0.)
return Field.full(x.domain, 0.)
MODES_WITH_ADJOINT = self.ADJOINT_TIMES | self.ADJOINT_INVERSE_TIMES
MODES_WITH_INVERSE = self.INVERSE_TIMES | self.ADJOINT_INVERSE_TIMES
......
......@@ -25,13 +25,13 @@ from . import utilities
from .domain_tuple import DomainTuple
from .domains.power_space import PowerSpace
from .field import Field
from .logger import logger
from .multi_domain import MultiDomain
from .multi_field import MultiField
from .operators.block_diagonal_operator import BlockDiagonalOperator
from .operators.diagonal_operator import DiagonalOperator
from .operators.distributors import PowerDistributor
from .operators.operator import Operator
from .operators.scaling_operator import ScalingOperator
from .plot import Plot
__all__ = ['PS_field', 'power_analyze', 'create_power_operator',
......@@ -327,6 +327,8 @@ def makeOp(input):
----------
input : None, Field or MultiField
- if None, None is returned.
- if Field on scalar-domain, a ScalingOperator with the coefficient
given by the Field is returned.
- if Field, a DiagonalOperator with the coefficients given by this
Field is returned.
- if MultiField, a BlockDiagonalOperator with entries given by this
......@@ -338,6 +340,8 @@ def makeOp(input):
"""
if input is None:
return None
if input.domain is DomainTuple.scalar_domain():
return ScalingOperator(input.domain, float(input.val))
if isinstance(input, Field):
return DiagonalOperator(input)
if isinstance(input, MultiField):
......
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