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

Consistent broadcasting for BlockArray #159

Open
Michael-T-McCann opened this issue Jan 6, 2022 · 1 comment
Open

Consistent broadcasting for BlockArray #159

Michael-T-McCann opened this issue Jan 6, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request priority: low Low priority

Comments

@Michael-T-McCann
Copy link
Contributor

Michael-T-McCann commented Jan 6, 2022

Arithmetic operations (+, -, *, ...) between a SCICO BlockArray and a NumPy ndarray are defined in the BlockArray docs to work in two cases: (1) when the ndarray is 1d and has size (i.e., number of elements) equal to the number of blocks; (2) when the ndarray has size equal to the size of the BlockArray.

This definition may be over restrictive, e.g.,

x = np.zeros(
    (3,)
)
y = BlockArray.zeros(
    ((1,),)
)
x + y  # error

And maybe isn't implemented correctly, e.g.,

x = np.zeros(
    (3, 4)
)
y = BlockArray.zeros(
    ((6,), (6,))
)
assert x.size == y.size
x + y  # error

Ideally, we could find a simple principle that would be intuitive and cover all relevant cases. One approach would be to generalize NumPy's scalar + ndarray behavior. That is, consider the ndarray to have been expanded (by duplication) into a BlockArray with the same number of blocks as the BlockArray, then perform the operation on these BlockArrays.

Examples:

np.zeros( (3,) ) + BlockArray.zeros( ((1,),) )  # output shape: ((3,),) + ((1,),) = ((3,),) 
@Michael-T-McCann
Copy link
Contributor Author

(This may be outdated given the changes to BlockArray.)

@Michael-T-McCann Michael-T-McCann self-assigned this May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority: low Low priority
Projects
None yet
Development

No branches or pull requests

1 participant