-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
MIT-licensed SparseMatrixCSC fkeep! and children #14702
Conversation
Travis discontent unrelated? |
yeah
there must be a race condition in a makefile or the parser or something... |
Nice performance gain. Would you be able to add some tests as well? Doesn't seem like there are any at the moment. |
I added a test for |
lgtm |
@tkelman Merge this? |
triu!(A::SparseMatrixCSC, k::Integer = 0) = fkeep!(A, TriuFunc(), k) | ||
|
||
immutable DroptolFunc <: Base.Func{4} end | ||
call{Tv,Ti}(::DroptolFunc, i::Ti, j::Ti, x::Tv, tol::Real) = abs(x) >= tol |
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.
previous implementation of droptol used >
here
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.
Fixed, thanks!
@tkelman Are more tests needed here? |
Yes, aside from the clarification about "attach" each of the differences I highlighted means a missing corner case that should be tested against (and would fail until fixed). |
call{Tv,Ti}(::TrilFunc, i::Ti, j::Ti, x::Tv, k::Integer) = i + k >= j | ||
call{Tv,Ti}(::TriuFunc, i::Ti, j::Ti, x::Tv, k::Integer) = j >= i + k | ||
function tril!(A::SparseMatrixCSC, k::Integer = 0) | ||
if k >= A.n - 1 |
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.
the old boundserror conditions were, effectively, k > n || -k > m
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.
Do you prefer the old checks? I would be happy with either. The new checks are what I came up with in vacuum on the basis of logical consistency. I imagine you saw my comment above?
Added bounds checking on k. When adding tests for said bounds checks, I noticed (by way of existing tests) that the old checks may not be as tight as the new checks and throw BoundsErrors rather than ArgumentErrors. Thoughts on the new checks? Thanks!
edit: Sorry. Ignore this. Posted prior to seeing your response below. Thanks!
Added tests for these edge cases. Thanks! |
ref Line 91 in 91dcdaa
tril! - if we're going to offset this check by one (or two?), we should be consistent between dense and sparse.
edit: may as well make the error message consistent as well |
Nice catch! Shall fix. |
Actually, the |
Our last few comments have been crossing paths. It does probably make sense to offset the current dense checks by one (though would need to check all the other |
Agreed. I would be happy to symmetrize the checks. My reasoning for the asymmetric checks was as follows:
Cheers, proposal for action on my part: Keep the offset checks (symmetric, asymmetric, whichever you prefer) in this pull request. Open an issue regarding consistency of |
Travis x86_64 unhappiness seemingly unrelated? |
I don't think it's our job to guess what the user's intent was. It may be a silly thing to ask for, but it's valid and within the bounds of the array so I don't think an exception is called for if you ask for the entire array. |
Checks symmetrized. Thanks! Edit: And fixed tests. |
7101000
to
58a6799
Compare
32 bit travis failure is a new one, looks unrelated though:
|
AppVeyor i686 failures also seem unrelated? |
58a6799
to
83352ee
Compare
Rebased. Is this in shape to merge? Did I miss anything above? Thanks! (Prompted by #14798 (comment).) |
This probably doesn't need to use functors any more? |
True, and likewise with |
Yeah that makes sense. |
|
||
immutable TrilFunc <: Base.Func{4} end | ||
immutable TriuFunc <: Base.Func{4} end | ||
call{Tv,Ti}(::TrilFunc, i::Ti, j::Ti, x::Tv, k::Integer) = i + k >= j |
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.
oh, but call
is now deprecated
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.
I can put the functors-to-functions PR together in the not-too-distant future, certainly within the deprecation cycle. Would that be alright? Thanks!
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.
This can still use functors, but it should do so using the non-deprecated syntax to avoid introducing warnings to the tests. The tests should currently be running with --depwarn=error
on CI so I'm surprised this didn't fail.
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.
Thanks for the pointer; I was unaware of the new syntax. Assuming I found the right issues, this should be fixed now (?). Thanks!
…tril!, triu!, droptol!, and dropzeros[!] with MIT-licensed versions. See JuliaLang#13001 and JuliaLang#14631. Also add a test for dropzeros!.
83352ee
to
f893c06
Compare
The Appveyor i686 discontent (failure on 7f845ff/test/arrayops.jl#L1060) seems unrelated? |
MIT-licensed SparseMatrixCSC fkeep! and children
Nice! |
@tkelman Much thanks for the thorough review here as well! |
Followup to #13001 and #14631. This pull request replaces the LGPL-licensed SparseMatrixCSC
fkeep!
method and childrentril!
,triu!
,droptol!
, anddropzeros[!]
(noticed signature during cleanup) in base/sparse/csparse.jl with MIT-licensed versions.These methods run in
O(A.n, nnz(A))
time and require no space beyond that passed in. The new methods perform better than the old methods, particularly for large matrices; are the new implementations missing anything that would require additional time?When editing base/sparse/csparse.jl to remove the existing methods, I folded all blocks to avoid peaking at the LGPL code. So someone should check that the removal was graceful given it was blind but for method signatures.
Benchmarks:
On master:
On this PR's branch:
The
dropzeros!
benchmark isn't particularly meaningful given the absence of stored zeros in the test matrices. Thanks, and best!