summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Wrappers/Python/ccpi/optimisation/operators/ScaledOperator.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/operators/ScaledOperator.py b/Wrappers/Python/ccpi/optimisation/operators/ScaledOperator.py
new file mode 100644
index 0000000..c29effc
--- /dev/null
+++ b/Wrappers/Python/ccpi/optimisation/operators/ScaledOperator.py
@@ -0,0 +1,14 @@
+from ccpi.optimisation.operators import LinearOperator
+from numbers import Number
+
+class ScaledOperator(LinearOperator):
+ def __init__(self, operator, scalar):
+ if not isinstance (scalar, Number):
+ raise TypeError('expected scalar: got {}'.format(type(scalar))
+ self.scalar = scalar
+ self.operator = operator
+ def direct(self, x, out=None):
+ return self.scalar * self.operator.direct(x, out=out)
+ def adjoint(self, x, out=None):
+ if self.operator.is_linear():
+ return self.scalar * self.operator.adjoint(x, out=out)