-
Notifications
You must be signed in to change notification settings - Fork 15
Add from_dense
and to_dense
methods
#382
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
Conversation
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? |
Perhaps:
|
… `io.from_numpy`
Splitting I still need to update documentation. Do we like |
Yes, it is more readable now.
Looks good, I'm not sure how frequently this specific function is used (e.g. in algorithms). |
Updated and ready for review. |
We discussed this in our meeting today, and we settled on We could consider adding a |
@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). |
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 |
…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! 🚀 |
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 hassort=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 asMatrix.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.