From d9994f9e1576c82e92bfe2684e11d2d768e95046 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Wed, 6 Mar 2019 22:14:37 +0000 Subject: created ScaledOperator.py --- .../Python/ccpi/optimisation/operators/ScaledOperator.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Wrappers/Python/ccpi/optimisation/operators/ScaledOperator.py 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) -- cgit v1.2.3