Skip to content

SAPYB for block data container can take None #2008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Updated the `SPDHG` algorithm to take a stochastic `Sampler`(#1644)
- Updated the `SPDHG` algorithm to include setters for step sizes (#1644)
- Add FluxNormaliser processor (#1878)
- SAPBY for the BlockDataContainer now does not require an `out` to be passed (#2008)
- Dependencies:
- Added scikit-image to CIL-Demos conda install command as needed for new Callbacks notebook.
- Changes that break backwards compatibility:
Expand Down
75 changes: 50 additions & 25 deletions Wrappers/Python/cil/framework/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,63 +236,88 @@ def __getitem__(self, row):
def add(self, other, *args, **kwargs):
'''Algebra: add method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer
:param: out (optional): provides a placehold for the resul.
Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result
'''
return self.binary_operations(BlockDataContainer.ADD, other, *args, **kwargs)
def subtract(self, other, *args, **kwargs):
'''Algebra: subtract method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer
:param: out (optional): provides a placeholder for the result.
Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result
'''
return self.binary_operations(BlockDataContainer.SUBTRACT, other, *args, **kwargs)
def multiply(self, other, *args, **kwargs):
'''Algebra: multiply method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer)
:param: out (optional): provides a placeholder for the result.
Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result
'''
return self.binary_operations(BlockDataContainer.MULTIPLY, other, *args, **kwargs)
def divide(self, other, *args, **kwargs):
'''Algebra: divide method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer)
:param: out (optional): provides a placeholder for the result.
Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result

'''
return self.binary_operations(BlockDataContainer.DIVIDE, other, *args, **kwargs)
def power(self, other, *args, **kwargs):
'''Algebra: power method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer
:param: out (optional): provides a placeholder for the result.
Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result
'''
return self.binary_operations(BlockDataContainer.POWER, other, *args, **kwargs)
def maximum(self, other, *args, **kwargs):
'''Algebra: power method of BlockDataContainer with number/DataContainer or BlockDataContainer
'''Algebra: maximum method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer)
:param: out (optional): provides a placeholder for the result.
Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result
'''
return self.binary_operations(BlockDataContainer.MAXIMUM, other, *args, **kwargs)
def minimum(self, other, *args, **kwargs):
'''Algebra: power method of BlockDataContainer with number/DataContainer or BlockDataContainer

:param: other (number, DataContainer or subclasses or BlockDataContainer)
:param: out (optional): provides a placeholder for the result.
'''Algebra: minimum method of BlockDataContainer with number/DataContainer or BlockDataContainer

Parameters
----------
other : number, DataContainer or subclasses or BlockDataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result

'''
return self.binary_operations(BlockDataContainer.MINIMUM, other, *args, **kwargs)

def sapyb(self, a, y, b, out, num_threads = NUM_THREADS):
def sapyb(self, a, y, b, out=None, num_threads = NUM_THREADS):
r'''performs axpby element-wise on the BlockDataContainer containers

Does the operation .. math:: a*x+b*y and stores the result in out, where x is self

:param a: scalar
:param b: scalar
:param y: compatible (Block)DataContainer
:param out: (Block)DataContainer to store the result

Parameters
----------
a : scalar or BlockDataContainer
b : scalar or BlockDataContainer
y : compatible (Block)DataContainer
out : BlockDataContainer, optional
Provides a placeholder for the result

Example:
--------
Expand All @@ -307,9 +332,9 @@ def sapyb(self, a, y, b, out, num_threads = NUM_THREADS):
>>> out = bdc1.sapyb(a,bdc2,b)
'''
if out is None:
raise ValueError("out container cannot be None")
out = self * 0
kwargs = {'a':a, 'b':b, 'out':out, 'num_threads': NUM_THREADS}
self.binary_operations(BlockDataContainer.SAPYB, y, **kwargs)
return self.binary_operations(BlockDataContainer.SAPYB, y, **kwargs)


def axpby(self, a, b, y, out, dtype=numpy.float32, num_threads = NUM_THREADS):
Expand Down
Loading
Loading