GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `semiring(A @ B @ C)` that applies semiring to both matmuls by eriknw · Pull Request #501 · python-graphblas/python-graphblas

Conversation

@eriknw

@eriknw eriknw commented Sep 5, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This is an experiment and possible beginning of implementation to address #132 and #498. This allows a semiring to be applied to many matrix multiplies, such as gb.op.plus_plus(A @ B @ C @ D).

I believe this pattern does arise in practice, and I expect this to be used in a way that is readable and intuitive. Currently, this:

D << gb.op.plus_plus(A @ B @ C)

is equivalent to:

D << gb.op.plus_plus(op.plus_times(A @ B) @ C)

which may be surprising and counterintuitive.

TODO:

  • tests
  • document (where/how?)
  • seek consensus
  • decide if we want to do similar for ewise infix such as binaryop(A | B & C) (do not support for now)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@eriknw
Add semiring(A @ B @ C) that applies semiring to both matmuls
6e8814b
@eriknw eriknw mentioned this pull request Sep 5, 2023
Correctness Bug: wrong semiring used in functional-style triple product #498
Closed
@eriknw
eriknw marked this pull request as draft September 6, 2023 02:06
eriknw added 15 commits September 8, 2023 00:22
@eriknw
WIP: begin implementing ewise add too
7d73cb6
@eriknw
Fix imports
6285d83
@eriknw
Merge branch 'main' into multi_arg_semiring
d8a5f47
@eriknw
checkpoint
fa61888
@eriknw
a little more
9b1fdb1
@eriknw
Merge branch 'main' into multi_arg_semiring
8a6333a
@eriknw
Merge branch 'main' into multi_arg_semiring
84ae93e
@eriknw
Merge branch 'main' into multi_arg_semiring
ef74652
@eriknw
bump pre-commit
0a26c3e
@eriknw
Merge branch 'multi_arg_semiring2' into multi_arg_semiring
2623bef
@eriknw
Merge branch 'main' into multi_arg_semiring
314c190
@eriknw
More tests
5396330
@eriknw
Merge branch 'main' into multi_arg_semiring
b278d2b
@eriknw
more tests
343081e
@eriknw
Getting very close I think
ecaf6ac
@codecov

codecov Bot commented Oct 29, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #501 (baf4709) into main (7935e50) will increase coverage by 0.19%.
The diff coverage is 99.69%.

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
+ Coverage   99.20%   99.39%   +0.19%     
==========================================
  Files          95       95              
  Lines       21291    21884     +593     
  Branches     3999     4138     +139     
==========================================
+ Hits        21121    21751     +630     
+ Misses        124       75      -49     
- Partials       46       58      +12     
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw
Clean up, and handle dimension mismatch more explicitly in infix exprs
18a1e1b
@eriknw
eriknw marked this pull request as ready for review October 30, 2023 03:35
@eriknw

eriknw commented Oct 30, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Hey @jim22k @SultanOrazbayev @michelp, this is pretty much ready if you want to take a look--I just need to write the error message when mixing infix notations such as binop(x & y | z).

This allows operators for ewise add, ewise mult, and matrix multiplication to apply to all the operands inside the operator when using infix notation such as plus(a | b | c | d) or plus_plus(A @ B @ C). This doesn't do any fancy reordering, applying of masks, or reuse of intermediates--it simply automatically computes the intermediate values (regardless of gb.config["autocompute"] setting).

Mixing ewise infix notation now raises: binop(x & y | z) is not allowed. This is because I think many people get tripped up by the operator precedence of & and |. The only time this may be a nuisance is if you are dealing with boolean values and are comfortable using & and | together, but I think it's better for the sake of future readers to require explicit lor and land as appropriate.

Applying operators like this also only apply to infix notation. plus(a | b | c) is not the same as a.ewise_add(b | c, plus) or (a | b).ewise_add(c, plus) (both of which are kind of weird and will probably raise).

Overall I think this change is for the better. I think the main "gotcha" this introduces is this:

>>> C = A @ B
>>> E << min_plus(C @ D)

Did they mean C = min_plus(A @ B) or C = plus_times(A @ B)? This could be avoided many different ways (depending on what is intended):

  1. C = (A @ B).new()
  2. C << A @ B
  3. C = semiring(A @ B)
  4. C << semiring(A @ B)
  5. AatB = A @ B # Using a better name to indicate an operator may still be applied

Hence, it's best practice to either be explicit with a semiring, call .new(), or assign into an output via <<.

Unless we want to detect whether an expression is assigned or inlined (which is possible, but let's not introduce that voodoo magic if we don't absolutely need to), this is the tradeoff we are stuck with. I think the multi-infix notation can be used well, as @alugowski did in #498. Edge cases exist here no matter what we do (I think), and I'm inclined to support what multiple users expected to work, which is what this PR does. This PR goes further by detecting and disallowing other syntax that is likely to be incorrect.

When we discussed this possibility before in #132, @ParticularMiner liked applying the operator to all infix operands as done in this PR (see: #132 (comment))

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw eriknw mentioned this pull request Oct 30, 2023
Handle dtypes (esp. UDTs) better in ewise_union #517
Merged
@eriknw
Merge branch 'main' into multi_arg_semiring
baf4709
@eriknw

eriknw commented Oct 30, 2023

Copy link
Copy Markdown
Member Author

This PR should now be easier to review b/c I added unrelated changes into main via #517.

SultanOrazbayev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jim22k

jim22k commented Oct 31, 2023

Copy link
Copy Markdown
Member

I'm okay with this approach. I agree that gb.min_plus(A @ B @ C) is more likely than X = A @ B; gb.min_plus(X @ C) and there will be some confusion either way. Such is a nature of delayed computation systems.

eriknw reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw
eriknw merged commit c6d1e31 into python-graphblas:main Nov 4, 2023
@eriknw

eriknw commented Nov 4, 2023

Copy link
Copy Markdown
Member Author

This is in--thanks all!

I found it nice to use this syntax when creating #518 (I wrote semiring(I @ A @ I))

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@eriknw @jim22k
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.