Skip to content

Commit b2f1c62

Browse files
MargaretDuffSam Porter
andauthored
SAPYB for block data container can take None (#2008)
--------- Signed-off-by: Margaret Duff <[email protected]> Co-authored-by: Sam Porter <[email protected]>
1 parent f0f97a4 commit b2f1c62

File tree

3 files changed

+170
-197
lines changed

3 files changed

+170
-197
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Updated the `SPDHG` algorithm to take a stochastic `Sampler`(#1644)
1212
- Updated the `SPDHG` algorithm to include setters for step sizes (#1644)
1313
- Add FluxNormaliser processor (#1878)
14+
- SAPBY for the BlockDataContainer now does not require an `out` to be passed (#2008)
1415
- Dependencies:
1516
- Added scikit-image to CIL-Demos conda install command as needed for new Callbacks notebook.
1617
- Changes that break backwards compatibility:

Wrappers/Python/cil/framework/block.py

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -236,63 +236,88 @@ def __getitem__(self, row):
236236
def add(self, other, *args, **kwargs):
237237
'''Algebra: add method of BlockDataContainer with number/DataContainer or BlockDataContainer
238238
239-
:param: other (number, DataContainer or subclasses or BlockDataContainer
240-
:param: out (optional): provides a placehold for the resul.
239+
Parameters
240+
----------
241+
other : number, DataContainer or subclasses or BlockDataContainer
242+
out : BlockDataContainer, optional
243+
Provides a placeholder for the result
241244
'''
242245
return self.binary_operations(BlockDataContainer.ADD, other, *args, **kwargs)
243246
def subtract(self, other, *args, **kwargs):
244247
'''Algebra: subtract method of BlockDataContainer with number/DataContainer or BlockDataContainer
245248
246-
:param: other (number, DataContainer or subclasses or BlockDataContainer
247-
:param: out (optional): provides a placeholder for the result.
249+
Parameters
250+
----------
251+
other : number, DataContainer or subclasses or BlockDataContainer
252+
out : BlockDataContainer, optional
253+
Provides a placeholder for the result
248254
'''
249255
return self.binary_operations(BlockDataContainer.SUBTRACT, other, *args, **kwargs)
250256
def multiply(self, other, *args, **kwargs):
251257
'''Algebra: multiply method of BlockDataContainer with number/DataContainer or BlockDataContainer
252258
253-
:param: other (number, DataContainer or subclasses or BlockDataContainer)
254-
:param: out (optional): provides a placeholder for the result.
259+
Parameters
260+
----------
261+
other : number, DataContainer or subclasses or BlockDataContainer
262+
out : BlockDataContainer, optional
263+
Provides a placeholder for the result
255264
'''
256265
return self.binary_operations(BlockDataContainer.MULTIPLY, other, *args, **kwargs)
257266
def divide(self, other, *args, **kwargs):
258267
'''Algebra: divide method of BlockDataContainer with number/DataContainer or BlockDataContainer
259268
260-
:param: other (number, DataContainer or subclasses or BlockDataContainer)
261-
:param: out (optional): provides a placeholder for the result.
269+
Parameters
270+
----------
271+
other : number, DataContainer or subclasses or BlockDataContainer
272+
out : BlockDataContainer, optional
273+
Provides a placeholder for the result
274+
262275
'''
263276
return self.binary_operations(BlockDataContainer.DIVIDE, other, *args, **kwargs)
264277
def power(self, other, *args, **kwargs):
265278
'''Algebra: power method of BlockDataContainer with number/DataContainer or BlockDataContainer
266279
267-
:param: other (number, DataContainer or subclasses or BlockDataContainer
268-
:param: out (optional): provides a placeholder for the result.
280+
Parameters
281+
----------
282+
other : number, DataContainer or subclasses or BlockDataContainer
283+
out : BlockDataContainer, optional
284+
Provides a placeholder for the result
269285
'''
270286
return self.binary_operations(BlockDataContainer.POWER, other, *args, **kwargs)
271287
def maximum(self, other, *args, **kwargs):
272-
'''Algebra: power method of BlockDataContainer with number/DataContainer or BlockDataContainer
288+
'''Algebra: maximum method of BlockDataContainer with number/DataContainer or BlockDataContainer
273289
274-
:param: other (number, DataContainer or subclasses or BlockDataContainer)
275-
:param: out (optional): provides a placeholder for the result.
290+
Parameters
291+
----------
292+
other : number, DataContainer or subclasses or BlockDataContainer
293+
out : BlockDataContainer, optional
294+
Provides a placeholder for the result
276295
'''
277296
return self.binary_operations(BlockDataContainer.MAXIMUM, other, *args, **kwargs)
278297
def minimum(self, other, *args, **kwargs):
279-
'''Algebra: power method of BlockDataContainer with number/DataContainer or BlockDataContainer
280-
281-
:param: other (number, DataContainer or subclasses or BlockDataContainer)
282-
:param: out (optional): provides a placeholder for the result.
298+
'''Algebra: minimum method of BlockDataContainer with number/DataContainer or BlockDataContainer
299+
300+
Parameters
301+
----------
302+
other : number, DataContainer or subclasses or BlockDataContainer
303+
out : BlockDataContainer, optional
304+
Provides a placeholder for the result
305+
283306
'''
284307
return self.binary_operations(BlockDataContainer.MINIMUM, other, *args, **kwargs)
285308

286-
def sapyb(self, a, y, b, out, num_threads = NUM_THREADS):
309+
def sapyb(self, a, y, b, out=None, num_threads = NUM_THREADS):
287310
r'''performs axpby element-wise on the BlockDataContainer containers
288311
289312
Does the operation .. math:: a*x+b*y and stores the result in out, where x is self
290313
291-
:param a: scalar
292-
:param b: scalar
293-
:param y: compatible (Block)DataContainer
294-
:param out: (Block)DataContainer to store the result
295-
314+
Parameters
315+
----------
316+
a : scalar or BlockDataContainer
317+
b : scalar or BlockDataContainer
318+
y : compatible (Block)DataContainer
319+
out : BlockDataContainer, optional
320+
Provides a placeholder for the result
296321
297322
Example:
298323
--------
@@ -307,9 +332,9 @@ def sapyb(self, a, y, b, out, num_threads = NUM_THREADS):
307332
>>> out = bdc1.sapyb(a,bdc2,b)
308333
'''
309334
if out is None:
310-
raise ValueError("out container cannot be None")
335+
out = self * 0
311336
kwargs = {'a':a, 'b':b, 'out':out, 'num_threads': NUM_THREADS}
312-
self.binary_operations(BlockDataContainer.SAPYB, y, **kwargs)
337+
return self.binary_operations(BlockDataContainer.SAPYB, y, **kwargs)
313338

314339

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

0 commit comments

Comments
 (0)