diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2019-04-16 07:30:00 -0400 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2019-04-16 07:30:00 -0400 |
commit | f5077318f11935f1c6c66855ffb34195be8739b7 (patch) | |
tree | 85e60ef2226a8faa183e3902c7c596fb10f2c5c6 | |
parent | 982ddc562fb77fd866ab92d4dcc19099c189fad8 (diff) | |
download | framework-f5077318f11935f1c6c66855ffb34195be8739b7.tar.gz framework-f5077318f11935f1c6c66855ffb34195be8739b7.tar.bz2 framework-f5077318f11935f1c6c66855ffb34195be8739b7.tar.xz framework-f5077318f11935f1c6c66855ffb34195be8739b7.zip |
moved LinearOperatorMatrix
-rw-r--r-- | Wrappers/Python/ccpi/optimisation/operators/LinearOperatorMatrix.py | 51 | ||||
-rwxr-xr-x | Wrappers/Python/ccpi/optimisation/operators/__init__.py | 2 |
2 files changed, 52 insertions, 1 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/operators/LinearOperatorMatrix.py b/Wrappers/Python/ccpi/optimisation/operators/LinearOperatorMatrix.py new file mode 100644 index 0000000..62e22e0 --- /dev/null +++ b/Wrappers/Python/ccpi/optimisation/operators/LinearOperatorMatrix.py @@ -0,0 +1,51 @@ +import numpy +from scipy.sparse.linalg import svds +from ccpi.framework import DataContainer +from ccpi.framework import AcquisitionData +from ccpi.framework import ImageData +from ccpi.framework import ImageGeometry +from ccpi.framework import AcquisitionGeometry +from numbers import Number +from ccpi.optimisation.operators import LinearOperator +class LinearOperatorMatrix(LinearOperator): + def __init__(self,A): + self.A = A + self.s1 = None # Largest singular value, initially unknown + super(LinearOperatorMatrix, self).__init__() + + def direct(self,x, out=None): + if out is None: + return type(x)(numpy.dot(self.A,x.as_array())) + else: + numpy.dot(self.A, x.as_array(), out=out.as_array()) + + + def adjoint(self,x, out=None): + if out is None: + return type(x)(numpy.dot(self.A.transpose(),x.as_array())) + else: + numpy.dot(self.A.transpose(),x.as_array(), out=out.as_array()) + + + def size(self): + return self.A.shape + + def get_max_sing_val(self): + # If unknown, compute and store. If known, simply return it. + if self.s1 is None: + self.s1 = svds(self.A,1,return_singular_vectors=False)[0] + return self.s1 + else: + return self.s1 + def allocate_direct(self): + '''allocates the memory to hold the result of adjoint''' + #numpy.dot(self.A.transpose(),x.as_array()) + M_A, N_A = self.A.shape + out = numpy.zeros((N_A,1)) + return DataContainer(out) + def allocate_adjoint(self): + '''allocate the memory to hold the result of direct''' + #numpy.dot(self.A.transpose(),x.as_array()) + M_A, N_A = self.A.shape + out = numpy.zeros((M_A,1)) + return DataContainer(out) diff --git a/Wrappers/Python/ccpi/optimisation/operators/__init__.py b/Wrappers/Python/ccpi/optimisation/operators/__init__.py index 7040d3a..811adf6 100755 --- a/Wrappers/Python/ccpi/optimisation/operators/__init__.py +++ b/Wrappers/Python/ccpi/optimisation/operators/__init__.py @@ -19,5 +19,5 @@ from .GradientOperator import Gradient from .SymmetrizedGradientOperator import SymmetrizedGradient
from .IdentityOperator import Identity
from .ZeroOperator import ZeroOp
-
+from .LinearOperatorMatrix import LinearOperatorMatrix
|