Skip to content

Commit

Permalink
First pass at improving documentation for trivial operators
Browse files Browse the repository at this point in the history
  • Loading branch information
MargaretDuff committed Oct 18, 2024
1 parent 6485259 commit c14f9ea
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
10 changes: 5 additions & 5 deletions Wrappers/Python/cil/optimisation/operators/IdentityOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

class IdentityOperator(LinearOperator):

'''IdentityOperator: Id: X -> Y, Id(x) = x\in Y
r''' `IdentityOperator`: :math:`\mathrm{Id}: X \rightarray Y`, :math:`\mathrm{Id}(x) = x`
X : gm_domain
Y : gm_range ( Default: Y = X )
:math:`X` : domain
:math:`Y` : range ( Default: :math:`Y = X` )
'''

Expand All @@ -42,7 +42,7 @@ def __init__(self, domain_geometry, range_geometry=None):

def direct(self,x,out=None):

'''Returns Id(x)'''
'''Returns :math:`Id(x)` '''

if out is None:
return x.copy()
Expand All @@ -52,7 +52,7 @@ def direct(self,x,out=None):

def adjoint(self,x, out=None):

'''Returns Id(x)'''
'''Returns :math:`\mathrm{Id}(x)=x ` '''


if out is None:
Expand Down
44 changes: 37 additions & 7 deletions Wrappers/Python/cil/optimisation/operators/MatrixOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
from cil.optimisation.operators import LinearOperator

class MatrixOperator(LinearOperator):
""" Matrix wrapped into a LinearOperator
r""" Matrix wrapped into a LinearOperator
:param: a numpy matrix
Parameters
----------
A: a numpy matrix
The matrix to be wrapped into a LinearOperator
"""

def __init__(self,A):
'''creator
:param A: numpy ndarray representing a matrix
'''
"""Constructor"""
self.A = A
M_A, N_A = self.A.shape
domain_geometry = VectorGeometry(N_A, dtype=A.dtype)
Expand All @@ -42,7 +42,20 @@ def __init__(self,A):
range_geometry=range_geometry)

def direct(self,x, out=None):

r"""Returns :math:`A*x`
Parameters
----------
x : DataContainer
Input data
out : DataContainer, optional
Output data, default is None
Returns
-------
DataContainer
:math:`A*x`
"""

if out is None:
tmp = self.range_geometry().allocate()
tmp.fill(numpy.dot(self.A,x.as_array()))
Expand All @@ -55,6 +68,21 @@ def direct(self,x, out=None):
return out

def adjoint(self,x, out=None):
r"""Returns :math:`A^{T}*x`
Parameters
----------
x : DataContainer
Input data
out : DataContainer, optional
Output data, default is None
Returns
-------
DataContainer
:math:`A^{T}*x`
"""

if out is None:
tmp = self.domain_geometry().allocate()
tmp.fill(numpy.dot(self.A.transpose().conjugate(),x.as_array()))
Expand All @@ -64,4 +92,6 @@ def adjoint(self,x, out=None):
return out

def size(self):
r"""Returns the size of the matrix
"""
return self.A.shape
22 changes: 14 additions & 8 deletions Wrappers/Python/cil/optimisation/operators/ZeroOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@
from cil.optimisation.operators import LinearOperator

class ZeroOperator(LinearOperator):
r'''ZeroOperator: O: X -> Y, maps any element of :math:`x\in X` into the zero element :math:`\in Y, O(x) = O_{Y}`
r''' `ZeroOperator`: :math:`\mathrm{O}: X \rightarrow Y`, maps any element of :math:`x\in X` into the zero element in the space :math:`Y`, so :math:`\mathrm{O}(x) = \mathrm{O}_{Y}`.
:param gm_domain: domain of the operator
:param gm_range: range of the operator, default: same as domain
Parameters
----------
domain_geometry: CIL Geometry
domain of the operator
range_geometry: CIL Geometry, optional
range of the operator, default: same as domain
Note:
Note
-----
.. math::
O^{*}: Y^{*} -> X^{*} \text{(Adjoint)}
< O(x), y > = < x, O^{*}(y) >
\langle O(x), y \rangle = \langle x, O^{*}(y) \rangle
'''
def __init__(self, domain_geometry, range_geometry=None):
if range_geometry is None:
Expand All @@ -39,21 +45,21 @@ def __init__(self, domain_geometry, range_geometry=None):
range_geometry=range_geometry)

def direct(self,x,out=None):
'''Returns O(x)'''
r'''Returns :math:`\mathrm{O}(x)`'''
if out is None:
return self.range_geometry().allocate(value=0)
else:
out.fill(self.range_geometry().allocate(value=0))
return out

def adjoint(self,x, out=None):
'''Returns O^{*}(y)'''
r'''Returns :math:`\mathrm{O}^{*}(y)` '''
if out is None:
return self.domain_geometry().allocate(value=0)
else:
out.fill(self.domain_geometry().allocate(value=0))
return out

def calculate_norm(self, **kwargs):
'''Evaluates operator norm of ZeroOperator'''
r'''Evaluates operator norm of `ZeroOperator`'''
return 0

0 comments on commit c14f9ea

Please sign in to comment.