Skip to content

Support A.power(0) #518

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

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Support A.power(0) #518

merged 1 commit into from
Dec 12, 2023

Conversation

eriknw
Copy link
Member

@eriknw eriknw commented Nov 4, 2023

CC @michelp who requested this.

When n=0, I decided to create a complete diagonal matrix using the identity of the binaryop if the identity exists (and raise if it doesn't).

We want the following equality to hold:

I = A.power(0, semiring)
semiring(I @ A @ I).isequal(A)

We could try to make the diagonal more sparse to better support hypersparse matrices, but this would need to determine both nonempty rows and nonempty columns, because I needs to be able to be the left-identity and the right-identity. Creating the complete diagonal matrix is much simpler.

CC @jim22k. When we added Matrix.power in #483, I believe we discussed n=0, and we decided to punt until it was needed. As we discussed, n=0 is a little awkward b/c the identity value isn't always available (since it ought to come from the binaryop--not the monoid--of the semiring), and we weren't sure whether we should try to return a sparse diagonal or if this is what the user would want and expect. I think the behavior in this PR is the best approach.

Copy link

codecov bot commented Nov 4, 2023

Codecov Report

Merging #518 (5bddc8c) into main (7935e50) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #518      +/-   ##
==========================================
+ Coverage   99.20%   99.24%   +0.04%     
==========================================
  Files          95       95              
  Lines       21291    21305      +14     
  Branches     3999     4001       +2     
==========================================
+ Hits        21121    21144      +23     
+ Misses        124      112      -12     
- Partials       46       49       +3     

@eriknw eriknw merged commit 0bfcb66 into python-graphblas:main Dec 12, 2023
@eriknw eriknw added the enhancement Improve existing functionality or make things work better label Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing functionality or make things work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants