-
-
Notifications
You must be signed in to change notification settings - Fork 132
Implement __array__ protocol #87
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
|
I haven't thought through this very deeply. Criticism welcome from @nils-werner and @hameerabbasi |
sparse/tests/test_coo.py
Outdated
|
|
||
| assert_eq(x, xx) | ||
| assert_eq(x.T.dot(x), xx.T.dot(xx)) | ||
| assert isinstance(x + xx, (COO, scipy.sparse.spmatrix)) |
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.
Perhaps test only for COO? Since we're "higher level" than scipy.sparse, it makes sense that mixed binary operations don't return scipy.sparse.spmatrix. Otherwise we have things like x + xx + x returning scipy.sparse.spmatrix.
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.
In addition (just as a minor quip) I would parametrize this with format for scipy.sparse and check for (at least) csr, csc, coo and dok.
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.
Done
sparse/coo.py
Outdated
| x = self.todense() | ||
| if dtype and x.dtype != dtype: | ||
| x = x.astype(dtype) | ||
| if not isinstance(x, np.ndarray): |
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.
Maybe np.asarray? It passes through things that are already arrays.
But, in any case, do we really need this check, since .todense() already returns an np.ndarray.
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.
Removed
hameerabbasi
left a comment
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.
Some minor comments. It seems to work fine! spmatrix + COO returns COO as desired now! (at least with CSR, CSC and COO).
In addition, for now it's okay, but later with #10 (which I'm working on next), I would like to treat this with the auto-densification rules...
|
Hmm. I just tested this some more: |
|
Can you explain more about how you're getting that error? I'm not able to reproduce. |
|
|
|
Yeah, I mentioned this in the other PR, but just for completeness |
|
In that case, this gets a +1 from me. :) |
|
We should merge this, I'll rebase #84 on top of it, and then I'm totally fine releasing. |
|
@hameerabbasi ok to release current master as 0.2.0 ? |
|
Of course. :) |
* Implement __array__ protocol * add parametrized test for scipy sparse interactions
One approach to the problems described in #72