Skip to content

Commit e8147d9

Browse files
committed
Use map rather than broadcast and a shape check in some definitions of elementwise binary operations over sparse matrices.
1 parent 2ee7311 commit e8147d9

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
@@ -2280,17 +2280,14 @@ round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)
22802280

22812281
## Binary arithmetic and boolean operators
22822282

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

22952292
(.+)(A::SparseMatrixCSC, B::Number) = Array(A) .+ B
22962293
( +)(A::SparseMatrixCSC, B::Array ) = Array(A) + B

0 commit comments

Comments
 (0)