-
Notifications
You must be signed in to change notification settings - Fork 15
AA << op.plus_times(P.T @ A @ P)
?
#132
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
Comments
Sorry, I made a mistake. Both expressions work as expected. I was using the wrong semiring. It should have been |
Surprisingly, it works! Did you expect that it would? |
AA << op.plus_minus(P.T @ A @ P)
?AA << op.plus_times(P.T @ A @ P)
?
Good question. Yes, I expect this to work only for the
Although I generally prefer to be explicit, we think these are convenient enough to be special. The above behavior can be disabled via Hence, Note that this doesn't extend to other semirings. For example, |
Makes sense. So Then your last line:
is perfectly understandable, though counter-intuitive especially if one is unaware of the default semiring behaviour. |
Thanks for the explanation. |
You bet! Thanks for raising the issue. I'm always happy to discuss usability issues. As you pointed out, the current behavior of Doing the same for e.g. |
I'd need to think about it a bit some more to decide which should be preferred. But currently I'm leaning towards applying the specified semiring to all operators in its scope. Perhaps there's a PEP specification somewhere that would be the deciding factor? |
Hi @eriknw Thinking about this a bit further, I'm now in agreement with your preference, as it is consistent with standard associativity rules. But there is one feature I think would be quite useful if it was made available, namely, the ability to change the default semiring or binary operation associated with an operator. Is that an idea that appeals to you? |
Thanks for the feedback, and interesting idea. We could do something like the following: # Change it until we change it again
>>> gb.config.set(matmul_default=op.min_plus)
>>> C << A @ B
# or only change within the context
>>> with gb.config.set(matmul_default=op.min_plus):
... C << A @ B How would you like to spell this? Would you use it? |
Nice @eriknw ! Both options would do the job. Perhaps the second option is safer and less verbose, as it automatically reverts back to the prior default semiring when the context is exited, right? I would certainly use either of them. Then more readable mathematical expressions, such as F << A @ B @ C @ D @ E could be possible for any semiring while also avoiding possible confusion. Or is this perhaps going too far beyond what GraphBLAS is intended to make possible? But I believe that transforming an adjacency matrix by a permutation transformation, for example, should be on the TODO list of GraphBLAS maintainers if it isn't already. Thanks for this! |
We could forego using the config altogether and do something like this: with op.min_times:
C << A @ B and
Here, a BinaryOp or Monoid used as a context manager sets the default for both ewise_add and ewise_mult. This would actually be a lot easier to make work than e.g. @jim22k what are your thoughts? We've bounced around a few ideas that essentially do the same thing:
|
Cool! One question: What then would be the difference between with op.plus:
D << A | B & C and with op.plus:
D << A | B | C or with op.plus:
D << A & B & C ? Order of expression evaluation only? |
|
Interesting. I certainly have no objections to it. I just found your last example a mathematical curiosity since, coming from a physics background, I normally wouldn't craft such an expression myself — I mean one where multiple operators map onto the same underlying monoid and thus, effectively, only their order of precedence dictates the path taken during expression evaluation. Perhaps you have seen applications where such functionality is useful? |
Sorry I'm late to the party. I like this style because it is explicit.
I could live with this approach, although I feel it lacks the self-explanatory nature of explicitly calling out
I don't like this approach -- feels too magical. And there are likely some edge cases which could lead to surprising results:
|
Uh oh!
There was an error while loading. Please reload this page.
Hi @eriknw
Oops! I stretched the infix notation a bit too far by testing the following line, which is an expression one would often encounter when transforming matrix-quantities (like graph adjacency-matrices, for example):
where
A
,AA
andP
are all matrices. (That is,A
is transformed byP
intoAA
.P
could be a permutation matrix, for example.)The expression was executed without throwing an exception, but the result was incorrect. To be precise, the structure of the answer was correct but the values were all 0 (which was incorrect).
Of course, the right way to do it was this:
which gave the right answer.
But it would be great if the former notation was also possible. What do you think?
The text was updated successfully, but these errors were encountered: