Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Addsemiring(A @ B @ C) that applies semiring to both matmuls#501

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
eriknw merged 18 commits intopython-graphblas:mainfromeriknw:multi_arg_semiring
Nov 4, 2023

Conversation

@eriknw
Copy link
Member

@eriknweriknw commentedSep 5, 2023
edited
Loading

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 asgb.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 asbinaryop(A | B & C) (do not support for now)

@codecov
Copy link

codecovbot commentedOct 29, 2023
edited
Loading

Codecov Report

Merging#501 (baf4709) intomain (7935e50) willincrease coverage by0.19%.
The diff coverage is99.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

@eriknweriknw marked this pull request as ready for reviewOctober 30, 2023 03:35
@eriknw
Copy link
MemberAuthor

eriknw commentedOct 30, 2023
edited
Loading

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 asbinop(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 asplus(a | b | c | d) orplus_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 ofgb.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 explicitlor andland as appropriate.

Applying operators like this alsoonly apply to infix notation.plus(a | b | c) is not the same asa.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 meanC = min_plus(A @ B) orC = 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))

@eriknw
Copy link
MemberAuthor

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

SultanOrazbayev reacted with thumbs up emoji

@jim22k
Copy link
Member

I'm okay with this approach. I agree thatgb.min_plus(A @ B @ C) is more likely thanX = 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

@eriknweriknw merged commitc6d1e31 intopython-graphblas:mainNov 4, 2023
@eriknw
Copy link
MemberAuthor

This is in--thanks all!

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

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@eriknw@jim22k

[8]ページ先頭

©2009-2025 Movatter.jp