Skip to content

Commit 70c4b5d

Browse files
committed
Make some sparse elementwise binary operations short children of map rather than {broadcast + shape check}.
1 parent b730db2 commit 70c4b5d

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

base/sparse/sparsematrix.jl

+8-11
Original file line numberDiff line numberDiff line change
@@ -2278,17 +2278,14 @@ round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)
22782278

22792279
## Binary arithmetic and boolean operators
22802280

2281-
# TODO: These seven functions should probably be reimplemented in terms of sparse map
2282-
# when a better sparse map exists. (And vectorized min, max, &, |, and xor should be
2283-
# deprecated in favor of compact-broadcast syntax.)
2284-
_checksameshape(A, B) = size(A) == size(B) || throw(DimensionMismatch("size(A) must match size(B)"))
2285-
(+)(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(+, A, B))
2286-
(-)(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(-, A, B))
2287-
min(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(min, A, B))
2288-
max(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(max, A, B))
2289-
(&)(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(&, A, B))
2290-
(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(|, A, B))
2291-
xor(A::SparseMatrixCSC, B::SparseMatrixCSC) = (_checksameshape(A, B); broadcast(xor, A, B))
2281+
(+)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(+, A, B)
2282+
(-)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(-, A, B)
2283+
# TODO: Vectorized min, max, |, and xor should be deprecated in favor of compact-broadcast syntax.
2284+
min(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(min, A, B)
2285+
max(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(max, A, B)
2286+
(&)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(&, A, B)
2287+
(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(|, A, B)
2288+
xor(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(xor, A, B)
22922289

22932290
(.+)(A::SparseMatrixCSC, B::Number) = Array(A) .+ B
22942291
( +)(A::SparseMatrixCSC, B::Array ) = Array(A) + B

0 commit comments

Comments
 (0)