Skip to content

Commit a5ae045

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

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

base/sparse/higherorderfns.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ 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+
function broadcast!(::typeof(identity), C::SparseVector, A::SparseVector)
153+
_checksameshape(C, A); return copy!(C, A)
154+
end
155+
function broadcast!(::typeof(identity), C::SparseMatrixCSC, A::SparseMatrixCSC)
156+
_checksameshape(C, A); return copy!(C, A)
157+
end
152158

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

0 commit comments

Comments
 (0)