Skip to content

add fkeep! and children for sparse vectors#15585

Merged
tkelman merged 2 commits into
JuliaLang:masterfrom
KristofferC:kc/fkeep_sparse_vector
Apr 13, 2016
Merged

add fkeep! and children for sparse vectors#15585
tkelman merged 2 commits into
JuliaLang:masterfrom
KristofferC:kc/fkeep_sparse_vector

Conversation

@KristofferC

Copy link
Copy Markdown
Member

Since these exist for sparse matrices it makes sense that they do for sparse vectors.

I used functors to keep the same style of code for matrices and vectors. If functors gives no performance benefit they can be swapped out for both matrices and vectors in a separate PR.

x
end

immutable DroptolFuncVec <: Base.Func{3} end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK passing anonymous functions is fast now, so you don't need to use functors, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see PR description.

@KristofferC KristofferC force-pushed the kc/fkeep_sparse_vector branch 2 times, most recently from 81b55e9 to 0ffe3cc Compare March 23, 2016 08:57
@KristofferC

Copy link
Copy Markdown
Member Author

Updated to address comments. I looked and anonymous functions seems to work as well as functors but I rather keep the PRs small.

Comment thread base/sparse/sparsevector.jl Outdated
end

function fkeep!{Tv,Ti}(x::SparseVector{Tv,Ti}, f, other, trim::Bool = true)
function fkeep!(x::SparseVector{Tv,Ti}, f, other, trim::Bool = true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the extraneous {Tv,Ti} is the cause of the build failure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, will fix. Thanks

@KristofferC KristofferC force-pushed the kc/fkeep_sparse_vector branch 2 times, most recently from cfcd3b6 to 83326ca Compare March 23, 2016 10:17
Comment thread base/sparse/sparsematrix.jl Outdated
is `true`, this method trims `A.rowval` and `A.nzval` to length `nnz(A)` after dropping
elements.
through `A`, requiring `O(A.n, nnz(A))`-time for matrices and `O(nnz(A))`-time for vectors
and no space beyond that passed in. If `trim` is `true`, this method trims `A.rowval/A.nzind` and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a division

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trims A.rowval or A.nzind

like that?

@KristofferC KristofferC force-pushed the kc/fkeep_sparse_vector branch from 83326ca to 3a476f7 Compare March 29, 2016 09:06
@KristofferC

Copy link
Copy Markdown
Member Author

Updated to address @tkelman documentation comment.

@KristofferC

Copy link
Copy Markdown
Member Author

Test error seems irrelevant (SubArrays) on one worker.

@KristofferC

Copy link
Copy Markdown
Member Author

This is good to go from my P.O.V

@ViralBShah ViralBShah added the sparse Sparse arrays label Apr 4, 2016
xdrop = Base.droptol!(copy(x), 1.5)
@test exact_equal(xdrop, SparseVector(7, [1, 2, 5, 6, 7], [3., 2., -2., -3., 3.]))
Base.droptol!(xdrop, 2.5)
@test exact_equal(xdrop, SparseVector(7, [1, 6, 7], [3., -3., 3.]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a test of droptol! where the tolerance is exactly equal to one of the nonzero values? then I think this is done

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@KristofferC KristofferC force-pushed the kc/fkeep_sparse_vector branch from 3a476f7 to 5a30b99 Compare April 13, 2016 07:42
@KristofferC KristofferC force-pushed the kc/fkeep_sparse_vector branch from 5a30b99 to 2ad39b4 Compare April 13, 2016 08:20
@KristofferC

Copy link
Copy Markdown
Member Author

This will slightly clash with #15804 since it adds a few functor methods. Maybe they can be fixed in the same way in that PR.

@tkelman tkelman merged commit 1b4618e into JuliaLang:master Apr 13, 2016
@tkelman

tkelman commented Apr 13, 2016

Copy link
Copy Markdown
Contributor

hopefully @martinholters won't mind getting rid of a couple more there?

@KristofferC KristofferC deleted the kc/fkeep_sparse_vector branch April 13, 2016 17:48
@martinholters

Copy link
Copy Markdown
Member

I won't.

@martinholters martinholters mentioned this pull request Apr 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sparse Sparse arrays

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants