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

Deprecate vectorized min and max over pairs of sparse matrices #19713

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 0 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,6 @@ round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)
(+)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(+, A, B)
(-)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(-, A, B)
# TODO: Vectorized min, max, |, and xor should be deprecated in favor of compact-broadcast syntax.
min(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(min, A, B)
max(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(max, A, B)
(&)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(&, A, B)
(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(|, A, B)
xor(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(xor, A, B)
Expand Down
22 changes: 11 additions & 11 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ do33 = ones(3)
sqrfloatmat, colfloatmat = sprand(4, 4, 0.5), sprand(4, 1, 0.5)
@test_throws DimensionMismatch (+)(sqrfloatmat, colfloatmat)
@test_throws DimensionMismatch (-)(sqrfloatmat, colfloatmat)
@test_throws DimensionMismatch min(sqrfloatmat, colfloatmat)
@test_throws DimensionMismatch max(sqrfloatmat, colfloatmat)
# @test_throws DimensionMismatch min(sqrfloatmat, colfloatmat) # vectorized min no longer exists
# @test_throws DimensionMismatch max(sqrfloatmat, colfloatmat) # vectorized max no longer exists
Copy link
Contributor

Choose a reason for hiding this comment

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

how about testing that map(min, ...) still throws ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, though those tests would be redundant with the similar tests #19690 introduces. Preference for redundancy or removal? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer redundancy, since spzeros((shapeA .- 1)...) used in those tests isn't quite the same as what this was doing

Copy link
Member Author

Choose a reason for hiding this comment

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

(Addressed in #19791. Thanks!)

sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5)
@test_throws DimensionMismatch (&)(sqrboolmat, colboolmat)
@test_throws DimensionMismatch (|)(sqrboolmat, colboolmat)
Expand Down Expand Up @@ -1515,11 +1515,11 @@ end
@test A12118 - B12118 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], [-1,1,3,1,4,7])
@test typeof(A12118 - B12118) == SparseMatrixCSC{Int,Int}

@test max(A12118, B12118) == sparse([1,2,3,4,5], [1,2,3,4,5], [2,2,3,4,5])
@test typeof(max(A12118, B12118)) == SparseMatrixCSC{Int,Int}
@test max.(A12118, B12118) == sparse([1,2,3,4,5], [1,2,3,4,5], [2,2,3,4,5])
@test typeof(max.(A12118, B12118)) == SparseMatrixCSC{Int,Int}

@test min(A12118, B12118) == sparse([1,2,4,5], [1,2,3,5], [1,1,-1,-2])
@test typeof(min(A12118, B12118)) == SparseMatrixCSC{Int,Int}
@test min.(A12118, B12118) == sparse([1,2,4,5], [1,2,3,5], [1,1,-1,-2])
@test typeof(min.(A12118, B12118)) == SparseMatrixCSC{Int,Int}
end

@testset "sparse matrix norms" begin
Expand Down Expand Up @@ -1598,17 +1598,17 @@ end
@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 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}
@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 (+, -, &, |, xor)
@test op(A13024, B13024) == op(Array(A13024), Array(B13024))
end
for op in (max, min)
@test op(A13024, B13024) == op.(Array(A13024), Array(B13024))
@test op.(A13024, B13024) == op.(Array(A13024), Array(B13024))
end
end

Expand Down