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

Fix #13024, sparse & and | #13036

Merged
merged 1 commit into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -884,15 +884,21 @@ broadcast_zpreserving{Tv,Ti}(f::Function, A_1::Union{Array,BitArray,Number}, A_2

## Binary arithmetic and boolean operators

for op in (+, -, min, max)
for (op, pro) in ((+, :eltype_plus),
(-, :eltype_plus),
(min, :promote_eltype),
(max, :promote_eltype),
(&, :promote_eltype),
(|, :promote_eltype),
($, :promote_eltype))
body = gen_broadcast_body_sparse(op, true)
OP = Symbol(string(op))
@eval begin
function ($OP){Tv1,Ti1,Tv2,Ti2}(A_1::SparseMatrixCSC{Tv1,Ti1}, A_2::SparseMatrixCSC{Tv2,Ti2})
if size(A_1,1) != size(A_2,1) || size(A_1,2) != size(A_2,2)
throw(DimensionMismatch(""))
end
Tv = eltype_plus(A_1, A_2)
Tv = ($pro)(A_1, A_2)
B = spzeros(Tv, promote_type(Ti1, Ti2), broadcast_shape(A_1, A_2)...)
$body
B
Expand Down
27 changes: 27 additions & 0 deletions test/sparsedir/sparse.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

using Base.Test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just for running this as a script alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, to make ./julia test/sparsedir/sparse.jl work - should be harmless

# check sparse matrix construction
@test isequal(full(sparse(complex(ones(5,5),ones(5,5)))), complex(ones(5,5),ones(5,5)))

Expand Down Expand Up @@ -1102,3 +1104,28 @@ q = randperm(10)
# issue #13008
@test_throws ArgumentError sparse(collect(1:100), collect(1:100), fill(5,100), 5, 5)
@test_throws ArgumentError sparse(Int[], collect(1:5), collect(1:5))

# issue #13024
let
A13024 = sparse([1,2,3,4,5], [1,2,3,4,5], fill(true,5))
B13024 = sparse([1,2,4,5], [1,2,3,5], fill(true,4))

@test A13024 & B13024 == sparse([1,2,5], [1,2,5], fill(true,3))
@test typeof(A13024 & B13024) == SparseMatrixCSC{Bool,Int}

@test A13024 | B13024 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6))
@test typeof(A13024 | B13024) == SparseMatrixCSC{Bool,Int}

@test A13024 $ B13024 == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5)
@test typeof(A13024 $ B13024) == SparseMatrixCSC{Bool,Int}

@test max(A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6))
@test typeof(max(A13024, B13024)) == SparseMatrixCSC{Bool,Int}

@test min(A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3))
@test typeof(min(A13024, B13024)) == SparseMatrixCSC{Bool,Int}

for op in (+, -, &, |, $, max, min)
@test op(A13024, B13024) == op(full(A13024), full(B13024))
end
end