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

Allow broadcasting in ewise operations #72

Open
rayegun opened this issue Nov 9, 2022 · 3 comments
Open

Allow broadcasting in ewise operations #72

rayegun opened this issue Nov 9, 2022 · 3 comments

Comments

@rayegun
Copy link
Collaborator

rayegun commented Nov 9, 2022

Forgive me if this is already an open issue.

It would be very nice to add broadcasting of vectors into matrices to the spec. See Python/Julia and more languages for prior art. For instance if you ewise_mul(A::GrB_Matrix, v::GrB_Vector) v would expand across columns. Transpose operator could be used to expand across rows.

Note that this treats GrB_Vector explicitly as a column vector, which may not be in line with the spec.

This can already be achieved with a Diagonal matrix multiplication, but this has a few issues:

  1. At least SS:GrB doesn't implement a Diagonal type internally, so it has storage/construction overhead as I understand it.
  2. To expand over columns the diagonal must be on the left, vice versa for expanding over rows. This can be a problem for operations without commutativity.
@eriknw
Copy link
Member

eriknw commented Nov 9, 2022

This may be related to (or part of) the rank promotion issue: #24

We have found this functionality to be useful for many algorithms--we use it all the time. We added syntax in python-graphblas that performs recipes for ewise-multiply, ewise-add, and ewise-union (Tim's GxB extension with left and right defaults) between Matrix and Vector objects. We apply masks as appropriate for the latter two operations.

So, +1 from me.

Yes, one can use GrB_Matrix_diag to first expand the vector to matrix. One then needs to do mxm with a semiring where only the binaryop is used. If we added methods to do this instead, it could take a BinaryOp (and/or Monoid--or even IndexUnaryOp if you're twisted) instead of a Semiring.

@rayegun
Copy link
Collaborator Author

rayegun commented Nov 9, 2022

How do you implement the add and union rank promotion? The emul is clear to me.

@eriknw
Copy link
Member

eriknw commented Nov 9, 2022

How do you implement the add and union rank promotion? The emul is clear to me.

See the important bits here: https://github.com/python-graphblas/python-graphblas/blob/856356bd02e28936059e5b8af22c6cb327495d98/graphblas/core/matrix.py#L50-L65

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