Skip to content
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

map lacks specializations for sparse matrices/vectors #19363

Closed
Sacha0 opened this issue Nov 18, 2016 · 6 comments
Closed

map lacks specializations for sparse matrices/vectors #19363

Sacha0 opened this issue Nov 18, 2016 · 6 comments
Labels

Comments

@Sacha0
Copy link
Member

Sacha0 commented Nov 18, 2016

map lacks specializations for sparse matrices/vectors (in contrast to broadcast):

julia> VERSION
v"0.6.0-dev.1234"

julia> @which map(sin, speye(4))
map(f, A::Union{AbstractArray,AbstractSet,Associative}) in Base at abstractarray.jl:1784

julia> @which map(sin, spzeros(4))
map(f, A::Union{AbstractArray,AbstractSet,Associative}) in Base at abstractarray.jl:1784

julia> @which map!(sin, speye(4))
map!{F}(f::F, A::AbstractArray) in Base at abstractarray.jl:1775

julia> @which map!(sin, spzeros(4))
map!{F}(f::F, A::AbstractArray) in Base at abstractarray.jl:1775

This lack results in poor performance (see jump-dev/JuMP.jl#889). Ref. discussion in #7010. Best!

@stevengj
Copy link
Member

It would be easy to add map(f, args::AbstractSparseVector...) = broadcast(f, args..) and map(f, args::AbstractSparseMatrix) = broadcast(f, args), since I think the semantics of map and broadcast agree for multiple sparse-vector arguments or a single sparse-matrix argument.

@simonster
Copy link
Member

The semantics do not agree if some but not all sparse vectors have only a single element. But it seems like we could handle this by first checking dimensions and then calling broadcast if they match.

@tkelman tkelman added the domain:arrays:sparse Sparse arrays label Nov 18, 2016
@tkelman
Copy link
Contributor

tkelman commented Nov 18, 2016

Do any existing map methods assume purity?

@Sacha0
Copy link
Member Author

Sacha0 commented Nov 19, 2016

I would probably go the other direction --- implement special cases of broadcast (specifically those where dimensions agree) via map, or implement both broadcast and map via common underlying methods. Best!

@Sacha0
Copy link
Member Author

Sacha0 commented Dec 8, 2016

#19438 provided map/map! specializations for SparseMatrixCSCs (less a map!(f, A::SparseMatrixCSC) method), partially fixing this issue.

@tkelman
Copy link
Contributor

tkelman commented Dec 31, 2016

assuming the rest was closed by #19690

@tkelman tkelman closed this as completed Dec 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants