1d set/getindex for sparse#7047
Conversation
|
I suspect these are going to be very slow, especially the |
|
Yes. This PR is not marked to fix the issue. |
|
How about doing it as part of this PR? |
|
I don't understand when this could would be used? |
|
Just like you index a dense matrix with a vector, so can you with a sparse matrix. See the linked issue. It is also needed for completeness. Currently the following does not work: |
|
I more meant the "abstractness" of it - surely this would be a lot slower than a specialized method? This would like it would for any |
|
The abstract methods would make it quicker to add new concrete types and optimize them incrementally. |
|
I agree. The abstract implementations are not useful except as an implementation guide. We can merge when the implementation of the remaining methods is done. |
|
Added implementation for |
|
Tests in the gcc build are failing. I can't quite tell if it is related to this PR or not. |
|
It passes now. I had to rename a local variable to something other than |
|
@ViralBShah Rebased and passing the tests. |
|
Could you remove the |
|
Also Cc:@mauro3 |
There was a problem hiding this comment.
Is it possible to reuse the binarysearch method in sparsematrix.jl?
There was a problem hiding this comment.
I don't think it is possible to reuse the binarysearch method here. This expects slightly different result than what binarysearch would give. Here ridx points to the index uptill row, and has a valid value irrespective of whether row was found in rowval[r1:r2]. And r1 is advanced till ridx so that subsequent searches in the same column are narrower.
There was a problem hiding this comment.
This sounds like the binary search which is implemented in sort.jl under the name of searchsortedfirst (which was not what I needed, thus I wrote my own). Also, note that you should probably use >>>, see http://googleresearch.blogspot.co.uk/2006/06/extra-extra-read-all-about-it-nearly.html
There was a problem hiding this comment.
Thanks, searchsortedfirst indeed can be used. I shall update the PR.
There was a problem hiding this comment.
I am curious if this has any performance impact. Worth checking for sure.
There was a problem hiding this comment.
Will check that. There are a few other places in sparsematrix.jl where searchsorted can be used. Shall replace them as well if there's no performance impact.
There was a problem hiding this comment.
There is a difference in performance. Here's a code snippet and some results for comparison: https://gist.github.com/tanmaykm/6871d2d014df4a92f40f
But it does not seem significant.
|
Removed the abstract methods. |
|
Added changes to use existing search methods. No noticeable performance impact. Before: With this change: Test code: https://gist.github.com/tanmaykm/e878ff0fe14f6b01b6dd |
|
Thanks for working through the various things. |
1d set/getindex for abstract sparse
|
Any idea what's going on here? |
|
I don't get this. I saw this yesterday though, but it seemed to go away after a |
|
Ok. The other odd linalg-related thing is this test failure; it's new to me. |
|
I think it's an inference problem. The test works just fine at top-level. |
|
@jiahao The test failure seems to be unrelated to this PR. Should we have a new issue? I don't get the failure on my mac. |
|
As far as I'm aware, it's only happening in my dict-print PR: #7147. I cannot reproduce on master on my local machine. |
|
I've seen the |
also replaced binarysearch with methods from sort.jl ref JuliaLang#7131, JuliaLang#7047
ref #7023
This implements
setindex!andgetindexwith 1d and boolean indices forAbstractSparseMatrix. An optimized implementation forSparseMatrixCSCcan be done separately.