GeezerVison is showing github.com — Add `from_dense` and `to_dense` methods by eriknw · Pull Request #382 · python-graphblas/python-graphblas
Conversation
eriknw
commented
Feb 4, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Closes #378.
@jim22k, I think we discussed to/from dense years ago, and I think we punted on methods like in this PR b/c it's surprisingly awkward to do in GraphBLAS. This PR shows that, indeed, this is difficult to do well, so I think they're good methods to add.
I also added sort=True to e.g. to_csr, because the C spec says column indices within a row may be unsorted, but sometimes we want them to be sorted. to_coo already has sort=True, so adding sorting more places seems natural.
Currently, from_dense is also used to create a fully dense Vector/Matrix from a scalar, which requires the shape to be provided. I think I like this better than a separate method such as Matrix.from_scalar(1, nrows=3, ncols=4).
This also improves some handling of sub-array dtypes.
I still need to add documentation. I think the APIs and behaviors need the most careful review.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coveralls
commented
Feb 4, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

coverage: 99.396% (-0.08%) from 99.48%
when pulling b4a80a4 on eriknw:from_dense
into 1bbce69 on python-graphblas:main.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
missing_value= is a nice addition to from_dense. However, missing_value= doesn't make any sense for building a dense object from a scalar, so I feel like this is now squeezing too much functionality into from_dense.
Compare:
def from_dense(cls, value, missing_value=None, dtype=None, *, nrows=None, ncols=None, name=None):
# handle scalars and arrays
vs
def from_dense_scalar(cls, value, nrows, ncols, dtype=None, *, name=None):
def from_dense_array(cls, values, missing_value=None, dtype=None, *, name=None):
I prefer two methods. But, what should we name them?
|
SultanOrazbayev reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
eriknw
commented
Feb 8, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
I prefer two methods. But, what should we name them?
Perhaps:
from_dense for arrays
- Add
fill_value=None to the main constructor to fill with a scalar
- e.g.,
Vector(size=5, fill_value=10)
- or
from_iso_value for scalar
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Splitting from_dense into two functions (one for "dense from scalar") simplified the implementation, so +1 from me.
I still need to update documentation. Do we like from_iso_value?
|
SultanOrazbayev reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Splitting from_dense into two functions (one for "dense from scalar") simplified the implementation, so +1 from me.
Yes, it is more readable now.
I still need to update documentation. Do we like from_iso_value?
Looks good, I'm not sure how frequently this specific function is used (e.g. in algorithms).
|
eriknw reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Updated and ready for review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
We discussed this in our meeting today, and we settled on from_scalar instead of from_iso_value. We should also add a couple more notes such as this being cheap / low storage in SuiteSparse:GraphBLAS, and maybe show an alternative example for how to create a new matrix with a scalar value and a mask.
We could consider adding a mask= keyword to from_scalar, but this implies a shape, which makes things a little awkward.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
from_iso_value is renamed to from_scalar, and I made a note about SuiteSparse:GraphBLAS being efficient.
@jim22k, what note about masks did you want to add?
I think this PR is ready to merge, but I'll wait for an approval (for a couple days).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The note could say that if you want to create an iso-valued Matrix or Vector with the same structure as an existing object, use obj.apply(binary.second, right=scalar).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…calar
A more flexible way with any mask is e.g.:
```python
w = Vector(v.dtype, size=v.size)
w(~v.S) << value
```
|
Thanks @jim22k and @SultanOrazbayev for your input on this PR! Even though I'm getting credit for commits, I know y'all deserve credit for helping too, because your engagement does make things better ❤️
This is going in! 🚀
|
jim22k reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
jim22k
jim22k approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
deprecation
Something is being removed
feature
Something is missing
io
Data input, output, and conversions
Milestone
No milestone
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.
|