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 `from_dense` and `to_dense` methods by eriknw · Pull Request #382 · python-graphblas/python-graphblas

Conversation

@eriknw

@eriknw eriknw commented Feb 4, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

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.

All reactions
@eriknw
Add from_dense and to_dense methods
44a9e6d
@eriknw eriknw added feature Something is missing io Data input, output, and conversions labels Feb 4, 2023
@eriknw
eriknw requested review from SultanOrazbayev and jim22k February 4, 2023 19:15
@coveralls

coveralls commented Feb 4, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Coverage Status

coverage: 99.396% (-0.08%) from 99.48%
when pulling b4a80a4 on eriknw:from_dense
into 1bbce69 on python-graphblas:main.

All reactions

Sorry, something went wrong.

Uh oh!

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

@eriknw eriknw mentioned this pull request Feb 4, 2023
Improve construction when inferring sub-array dtype (a.k.a. array subdtype) #381
Merged
@eriknw
oops; use cls, not self
3483ff5
@eriknw
eriknw marked this pull request as draft February 5, 2023 05:07
@eriknw
Add documentation (first draft)
c42e9ab
@eriknw
eriknw marked this pull request as ready for review February 5, 2023 17:56
eriknw added 2 commits February 6, 2023 22:21
@eriknw
bump ruff
d8902a1
@eriknw
That was fast!
e4fa913
SultanOrazbayev
SultanOrazbayev reviewed Feb 7, 2023
View reviewed changes
Comment thread graphblas/core/matrix.py Resolved

Uh oh!

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

SultanOrazbayev
SultanOrazbayev reviewed Feb 7, 2023
View reviewed changes
Comment thread scripts/check_versions.sh Resolved

Uh oh!

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

eriknw added 2 commits February 7, 2023 13:23
@eriknw
Add warning that to_dense can create very large arrays
0b2ac41
@eriknw
Add a test
687d443
eriknw
eriknw commented Feb 8, 2023
View reviewed changes
Comment thread graphblas/core/vector.py Resolved

Uh oh!

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

Comment thread graphblas/core/vector.py Resolved

Uh oh!

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

@eriknw
Merge branch 'main' into from_dense
9751e99
@eriknw

eriknw commented Feb 8, 2023

Copy link
Copy Markdown
Member Author

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@eriknw

eriknw commented Feb 8, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

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
All reactions

Sorry, something went wrong.

Uh oh!

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

@eriknw
Add from_iso_value, missing_value= to from_dense, and deprecate…
fe9d2c0
… `io.from_numpy`
@eriknw eriknw added the deprecation Something is being removed label Feb 9, 2023
@eriknw

eriknw commented Feb 9, 2023

Copy link
Copy Markdown
Member Author

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@SultanOrazbayev

SultanOrazbayev commented Feb 9, 2023

Copy link
Copy Markdown
Member

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@eriknw
Update documentation
0a93f93
@eriknw

eriknw commented Feb 10, 2023

Copy link
Copy Markdown
Member Author

Updated and ready for review.

All reactions

Sorry, something went wrong.

Uh oh!

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

eriknw added 2 commits February 9, 2023 22:09
@eriknw
better (haha, what was I thinking before?)
0bd936a
@eriknw
bump ruff
93d533a
@eriknw

eriknw commented Feb 15, 2023

Copy link
Copy Markdown
Member Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

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

@eriknw
Rename from_iso_value to from_scalar
cefc282
@eriknw

eriknw commented Feb 15, 2023

Copy link
Copy Markdown
Member Author

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).

All reactions

Sorry, something went wrong.

Uh oh!

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

@eriknw
Update flake8-bugbear and make improvements
06ee503
@jim22k

jim22k commented Feb 15, 2023

Copy link
Copy Markdown
Member

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).

All reactions

Sorry, something went wrong.

Uh oh!

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

jim22k
jim22k approved these changes Feb 15, 2023
View reviewed changes
@eriknw
Add comment for how to create iso-valued objects with structure and s…
b4a80a4
…calar

A more flexible way with any mask is e.g.:
```python
w = Vector(v.dtype, size=v.size)
w(~v.S) << value
```
@eriknw

eriknw commented Feb 17, 2023

Copy link
Copy Markdown
Member Author

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
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@eriknw
eriknw merged commit d226a51 into python-graphblas:main Feb 17, 2023
@eriknw eriknw mentioned this pull request Feb 19, 2023
Read Matrix Market with fast_matrix_market #391
Merged
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@SultanOrazbayev SultanOrazbayev SultanOrazbayev left review comments
@jim22k 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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add easier way to create dense vectors and matrices

Uh oh!

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

4 participants

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