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 `A.setdiag(x, k)` by eriknw · Pull Request #493 · python-graphblas/python-graphblas

Conversation

@eriknw

@eriknw eriknw commented Aug 23, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

See: #487.

This adds setdiag method to Matrix and Updater (such as A("+").setdiag(v)). setdiag is not available on transposed matrices or expressions. setdiag is doing an assignment, but with functional syntax instead of with __setitem__, so it is most similar to setting a Vector or scalar to a single row or column of a Matrix, so we follow the same semantics.

This supports masking and accumulation, but punts for complemented masks (complemented masks now implemented) or replace=True.

Tests, documentation, feedback, and criticism are still needed.

Sorry, something went wrong.

Uh oh!

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

All reactions
@eriknw
Experiment with adding A.setdiag(x, k)
3f31627
@eriknw
eriknw marked this pull request as draft August 23, 2023 03:26
@coveralls

coveralls commented Aug 23, 2023 •
edited by github-actions Bot
Loading

Uh oh!

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

Copy link
Copy Markdown

Coverage Status

coverage: 98.838% (-0.9%) from 99.743% when pulling 9e51b87 on eriknw:wip_setdiag into bf28a79 on python-graphblas:main.

All reactions

Sorry, something went wrong.

Uh oh!

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

eriknw added 2 commits September 11, 2023 10:18
@eriknw
Merge branch 'main' into wip_setdiag
ffc0421
@eriknw
Update setdiag to have mask= and accum= arguments; also, tests
f9c95c5
@eriknw eriknw changed the title Experiment with adding A.setdiag(x, k) Add A.setdiag(x, k) Sep 12, 2023
eriknw added 2 commits September 12, 2023 08:08
@eriknw
Write docstring for A.setdiag
457cd03
@eriknw
Bump black and ruff
da98a68
@eriknw
eriknw marked this pull request as ready for review September 12, 2023 06:27
@eriknw eriknw added enhancement Improve existing functionality or make things work better feature Something is missing labels Sep 12, 2023
@eriknw

eriknw commented Sep 12, 2023

Copy link
Copy Markdown
Member Author

This is ready for review. I updated it to implement option 2 from #487 (comment) by adding mask= and accum= arguments to setdiag.

The main remaining question I have is regarding clear_missing=True argument. Does it make sense? Is the name good? Or should it not be included at all? Also, are the code and docstrings clear enough, or should any more docs be added?

I think the pros and cons from #487 (comment) are still accurate and I think are worth rereading when reviewing this PR. I am +1 for adding matrix.setdiag for reasons stated in that comment.

CC @q-aaronzolnailucas @SultanOrazbayev @jim22k

All reactions

Sorry, something went wrong.

Uh oh!

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

jim22k
jim22k reviewed Sep 13, 2023
View reviewed changes

@jim22k jim22k left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to allow A(mask, accum=accum).setdiag(v)? Which would just delegate to the keywords in the setdiag method.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread graphblas/tests/test_matrix.py Resolved

Uh oh!

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

Comment thread graphblas/core/matrix.py Resolved

Uh oh!

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

Comment thread graphblas/core/matrix.py Resolved

Uh oh!

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

@eriknw
Raise if assigning to diagonal of size 0
acb0067
@eriknw

eriknw commented Sep 14, 2023

Copy link
Copy Markdown
Member Author

Do you plan to allow A(mask, accum=accum).setdiag(v)? Which would just delegate to the keywords in the setdiag method.

Unsure. I removed this. It would be very easy to add back. What do you think?

All reactions

Sorry, something went wrong.

Uh oh!

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

@eriknw
Remove clear_missing= from setdiag
7665530
Use `second` as the accumulator for `clear_missing=False` behavior.
jim22k
jim22k approved these changes Sep 14, 2023
View reviewed changes
@jim22k

jim22k commented Sep 14, 2023

Copy link
Copy Markdown
Member

Do you plan to allow A(mask, accum=accum).setdiag(v)? Which would just delegate to the keywords in the setdiag method.

Unsure. I removed this. It would be very easy to add back. What do you think?

Add it as an issue to discuss, but don't hold up this PR for that.

All reactions

Sorry, something went wrong.

Uh oh!

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

eriknw added 2 commits September 15, 2023 09:33
@eriknw
Pass **opts to more calls in setdiag
bd37af5
@eriknw
Better handle setdiag with dimensions of size 0
0f62bbd
@eriknw

eriknw commented Sep 15, 2023

Copy link
Copy Markdown
Member Author

For a 0-length vector where k == 0, I could maybe see an exception. But if k != 0 and the off-diagonal is length zero, that is out of range. I think raising is the correct approach.

This (allowing to set 0-length when k == 0) is actually what setdiag in scipy.sparse does. I think this is a good idea and let's us better handle length 0 dimensions. For example, should it be possible to set any diagonal in a 0x2 Matrix? My latest commit allows this.

For the record, scipy.sparse setdiag also allows the size of the vector of new values to be too large or too small. Should we follow suite, or require that the vector exactly match the size of the diagonal, which is what we currently do?

All reactions

Sorry, something went wrong.

Uh oh!

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

eriknw
eriknw commented Sep 15, 2023
View reviewed changes
Comment thread graphblas/core/matrix.py
Comment on lines +2914 to +2919
Diag = v.diag(k)
if Diag.shape != self.shape:
Diag.resize(self._nrows, self._ncols)
if mask is None:
mask = Diag.S
self(accum=accum, mask=mask, **opts) << Diag

@eriknw eriknw Sep 15, 2023

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity and those who browse this PR, these lines are the main recipe for setting the diagonal of a Matrix with a Vector. The rest of the function mostly deals with handing different input types and giving good error messages when necessary.

Sorry, something went wrong.

Uh oh!

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

SultanOrazbayev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
eriknw added 3 commits September 22, 2023 16:10
@eriknw
Support numpy 1.26.0
7c2f0ae
@eriknw
Merge branch 'main' into wip_setdiag
5a36511
@eriknw
oops
9e51b87
@eriknw
eriknw merged commit 2d6faf2 into python-graphblas:main Sep 22, 2023
This was referenced Sep 22, 2023
Question: Most efficient way to set or remove the diagonal in large matrices #487
Closed
Try to fix failing test #505
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jim22k jim22k jim22k approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

enhancement Improve existing functionality or make things work better feature Something is missing

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.

3 participants

@eriknw @coveralls @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.