summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2019-02-18 15:23:29 +0000
committerEdoardo Pasca <edo.paskino@gmail.com>2019-02-18 15:23:29 +0000
commit74891953a24416b9680dee13354d57b42cd8f63c (patch)
treeece3a5262ca4b5adc77e74713151df65718be882 /Wrappers/Python
parentb9d3b0722c03cded15973417514d4639e390311e (diff)
downloadframework-74891953a24416b9680dee13354d57b42cd8f63c.tar.gz
framework-74891953a24416b9680dee13354d57b42cd8f63c.tar.bz2
framework-74891953a24416b9680dee13354d57b42cd8f63c.tar.xz
framework-74891953a24416b9680dee13354d57b42cd8f63c.zip
added reverse multiplication of operator with number
Diffstat (limited to 'Wrappers/Python')
-rwxr-xr-xWrappers/Python/ccpi/optimisation/ops.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/ops.py b/Wrappers/Python/ccpi/optimisation/ops.py
index 450b084..3845621 100755
--- a/Wrappers/Python/ccpi/optimisation/ops.py
+++ b/Wrappers/Python/ccpi/optimisation/ops.py
@@ -24,26 +24,49 @@ from ccpi.framework import AcquisitionData
from ccpi.framework import ImageData
from ccpi.framework import ImageGeometry
from ccpi.framework import AcquisitionGeometry
-
+from numbers import Number
# Maybe operators need to know what types they take as inputs/outputs
# to not just use generic DataContainer
class Operator(object):
+ '''Operator that maps from a space X -> Y'''
+ def __init__(self, **kwargs):
+ self.scalar = 1
+ def is_linear(self):
+ '''Returns if the operator is linear'''
+ return False
def direct(self,x, out=None):
- return x
- def adjoint(self,x, out=None):
- return x
+ raise NotImplementedError
def size(self):
# To be defined for specific class
raise NotImplementedError
- def get_max_sing_val(self):
+ def norm(self):
raise NotImplementedError
def allocate_direct(self):
+ '''Allocates memory on the Y space'''
raise NotImplementedError
def allocate_adjoint(self):
+ '''Allocates memory on the X space'''
+ raise NotImplementedError
+ def range_dim(self):
raise NotImplementedError
+ def domain_dim(self):
+ raise NotImplementedError
+ def __rmul__(self, other):
+ '''reverse multiplication of Operator with number sets the variable scalar in the Operator'''
+ assert isinstance(other, Number)
+ self.scalar = other
+ return self
+class LinearOperator(Operator):
+ '''Operator that maps from a space X -> Y'''
+ def is_linear(self):
+ '''Returns if the operator is linear'''
+ return True
+ def adjoint(self,x, out=None):
+ raise NotImplementedError
+
class Identity(Operator):
def __init__(self):
self.s1 = 1.0
@@ -75,12 +98,16 @@ class TomoIdentity(Operator):
super(TomoIdentity, self).__init__()
def direct(self,x,out=None):
+ if self.scalar != 1:
+ x *= self.scalar
if out is None:
return x.copy()
else:
out.fill(x)
def adjoint(self,x, out=None):
+ if self.scalar != 1:
+ x *= self.scalar
if out is None:
return x.copy()
else: