Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 22cf1c27 authored by hhakim's avatar hhakim
Browse files

Extends scipy LinearOperator into pyfaust.lazylinop.LazyLinearOp.

parent de318fc6
No related branches found
No related tags found
No related merge requests found
## @package pyfaust.lazylinop @brief The pyfaust module for lazy linear operators.
import numpy as np
from scipy.sparse.linalg import LinearOperator
class LazyLinearOp:
class LazyLinearOp(LinearOperator):
"""
This class implements a lazy linear operator.
......@@ -21,8 +22,10 @@ class LazyLinearOp:
<b>See also:</b> LazyLinearOp.create.
"""
self._lambda_stack = init_lambda
self._shape = shape
self.shape = shape
self._root_obj = root_obj
self.dtype = None
super(LazyLinearOp, self).__init__(self.dtype, self.shape)
@staticmethod
def create(obj):
......@@ -98,13 +101,6 @@ class LazyLinearOp:
def _eval_if_lazy(o):
return o.eval() if isinstance(o, LazyLinearOp) else o
@property
def shape(self):
"""
Returns the shape of the LazyLinearOp.
"""
return self._shape
@property
def ndim(self):
"""
......@@ -161,10 +157,16 @@ class LazyLinearOp:
@property
def H(self):
"""
Returns the LazyLinearOp adjoint.
The LazyLinearOp adjoint.
"""
return self.getH()
def _adjoint(self):
"""
Returns the LazyLinearOp adjoint.
"""
return self.H
def __add__(self, op):
"""
Returns the LazyLinearOp for self + op.
......@@ -307,6 +309,31 @@ class LazyLinearOp:
' shape[0] or shape[1] to 1')
return self.__matmul__(op)
def _rmatvec(self, op):
"""
Returns self^H @ v, where self^H is the conjugate transpose of A.
LinearOperator need.
"""
return self.H @ op
def _matmat(self, op):
"""
See matmat.
LinearOperator need.
"""
if not hasattr(op, 'shape') or not hasattr(op, 'ndim'):
raise TypeError('op must have shape and ndim attributes')
if op.ndim > 2 or op.ndim == 0:
raise ValueError('op.ndim must be 1 or 2')
return self.__matmul__(op)
def _rmatmat(self, op):
"""
Returns self^H @ v, where self^H is the conjugate transpose of A.
LinearOperator need.
"""
return self.H @ op
def __imatmul__(self, op):
"""
Not implemented self @= op.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment