Skip to content

Commit 6f2f739

Browse files
committed
(Re-)introduce broadcast!(::typeof(identity), ...) for sparse arrays for performance
1 parent b0ae001 commit 6f2f739

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

base/sparse/higherorderfns.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ ambiguityfunnel{Tf}(f::Tf, x, y) = _aresameshape(x, y) ? _noshapecheck_map(f, x,
148148
broadcast(::typeof(+), x::SparseVector, y::SparseVector) = ambiguityfunnel(+, x, y) # base/sparse/sparsevectors.jl:1266
149149
broadcast(::typeof(-), x::SparseVector, y::SparseVector) = ambiguityfunnel(-, x, y) # base/sparse/sparsevectors.jl:1266
150150
broadcast(::typeof(*), x::SparseVector, y::SparseVector) = ambiguityfunnel(*, x, y) # base/sparse/sparsevectors.jl:1266
151-
151+
# specializations to improve performance for C .= A
152+
@inline broadcast!(::typeof(identity), C::SparseVector, A::SparseVector) =
153+
(@boundscheck _checksameshape(C, A); return copy!(C, A))
154+
@inline broadcast!(::typeof(identity), C::SparseMatrixCSC, A::SparseMatrixCSC) =
155+
(@boundscheck _checksameshape(C, A); return copy!(C, A))
152156

153157
# (4) _map_zeropres!/_map_notzeropres! specialized for a single sparse vector/matrix
154158
"Stores only the nonzero entries of `map(f, Array(A))` in `C`."

0 commit comments

Comments
 (0)