Skip to content
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

SAPYB for BlockDataContainer #1997

Open
samdporter opened this issue Nov 22, 2024 · 1 comment
Open

SAPYB for BlockDataContainer #1997

samdporter opened this issue Nov 22, 2024 · 1 comment
Assignees

Comments

@samdporter
Copy link
Contributor

samdporter commented Nov 22, 2024

In order to work with other code (e.g SVRGFunction) BlockDataContainer.sapyb method needs to be able to accept out=None and should return a BlockDataContainer

    def sapyb(self, a, y, b, out, num_threads = NUM_THREADS):
        r'''performs axpby element-wise on the BlockDataContainer containers'''
        if out is None:
            out = self*0 
        kwargs = {'a':a, 'b':b, 'out':out, 'num_threads': NUM_THREADS}
        return self.binary_operations(BlockDataContainer.SAPYB, y, **kwargs)

Currently throws error in SVRG.approximate_gradient

@MargaretDuff
Copy link
Member

Thanks @samdporter

Yep, that would be a quick fix to currently not allowing the user to pass None to out:

def sapyb(self, a, y, b, out, 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
Example:
--------
>>> a = 2
>>> b = 3
>>> ig = ImageGeometry(10,11)
>>> x = ig.allocate(1)
>>> y = ig.allocate(2)
>>> bdc1 = BlockDataContainer(2*x, y)
>>> bdc2 = BlockDataContainer(x, 2*y)
>>> out = bdc1.sapyb(a,bdc2,b)
'''
if out is None:
raise ValueError("out container cannot be None")
kwargs = {'a':a, 'b':b, 'out':out, 'num_threads': NUM_THREADS}
self.binary_operations(BlockDataContainer.SAPYB, y, **kwargs)

Will chat to the team about any checks we might need or if they can remember the thinking in the first place

@MargaretDuff MargaretDuff self-assigned this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants