Skip to content

Commit

Permalink
fix sparse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Nov 18, 2021
1 parent 345e393 commit 19e361e
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ do33 = fill(1.,3)
AA = randn(2, 2)
for SS in (sprandn(3,3, 0.5), sparse(Int(1)I, 3, 3))
for S in (SS, view(SS, 1:3, 1:3))
I22 = Matrix(I, size(A))
@test @inferred(I*S) !== S # Don't alias
@test @inferred(S*I) !== S # Don't alias

Expand Down Expand Up @@ -334,12 +333,12 @@ end
# measure test a few multi-way combinations involving those types
@test issparse(vcat(spmat, densemat, annospcmats[1], annodmats[2]))
@test issparse(vcat(densemat, spmat, annodmats[1], annospcmats[2]))
@test issparse(hcat(spvec, annodmats[1], annospcmats[3], densevec, diagmat))
@test issparse(hcat(annodmats[2], annospcmats[4], spvec, densevec, diagmat))
@test issparse(hcat(spvec, annodmats[1], annospcmats[1], densevec, diagmat))
@test issparse(hcat(annodmats[2], annospcmats[2], spvec, densevec, diagmat))
@test issparse(hvcat((5,), diagmat, densevec, spvec, annodmats[1], annospcmats[1]))
@test issparse(hvcat((5,), spvec, annodmats[2], diagmat, densevec, annospcmats[2]))
@test issparse(cat(annodmats[1], diagmat, annospcmats[3], densevec, spvec; dims=(1,2)))
@test issparse(cat(spvec, diagmat, densevec, annospcmats[4], annodmats[2]; dims=(1,2)))
@test issparse(cat(annodmats[1], diagmat, annospcmats[2], densevec, spvec; dims=(1,2)))
@test issparse(cat(spvec, diagmat, densevec, annospcmats[1], annodmats[2]; dims=(1,2)))
end

@testset "hcat and vcat involving UniformScaling" begin
Expand Down Expand Up @@ -2370,29 +2369,26 @@ end
end

@testset "Diagonal linear solve" begin
for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
n = 12
for relty in (Float32, Float64), elty in (relty, Complex{relty})
dd=convert(Vector{elty}, randn(n))
if elty <: Complex
dd+=im*convert(Vector{elty}, randn(n))
end
D = Diagonal(dd)
if relty != BigFloat
b = rand(elty, n, n)
b = sparse(b)
@test ldiv!(D, copy(b)) Array(D)\Array(b)
@test_throws SingularException ldiv!(Diagonal(zeros(elty, n)), copy(b))
b = rand(elty, n+1, n+1)
b = sparse(b)
@test_throws DimensionMismatch ldiv!(D, copy(b))
b = view(rand(elty, n+1), Vector(1:n+1))
@test_throws DimensionMismatch ldiv!(D, b)
end
if relty <: BlasFloat
for b in (sparse(rand(elty,n,n)), sparse(rand(elty,n)))
@test lmul!(copy(D), copy(b)) Array(D)*Array(b)
@test lmul!(transpose(copy(D)), copy(b)) transpose(Array(D))*Array(b)
@test lmul!(adjoint(copy(D)), copy(b)) Array(D)'*Array(b)
end
b = rand(elty, n, n)
b = sparse(b)
@test ldiv!(D, copy(b)) Array(D)\Array(b)
@test_throws SingularException ldiv!(Diagonal(zeros(elty, n)), copy(b))
b = rand(elty, n+1, n+1)
b = sparse(b)
@test_throws DimensionMismatch ldiv!(D, copy(b))
b = view(rand(elty, n+1), Vector(1:n+1))
@test_throws DimensionMismatch ldiv!(D, b)
for b in (sparse(rand(elty,n,n)), sparse(rand(elty,n)))
@test lmul!(copy(D), copy(b)) Array(D)*Array(b)
@test lmul!(transpose(copy(D)), copy(b)) transpose(Array(D))*Array(b)
@test lmul!(adjoint(copy(D)), copy(b)) Array(D)'*Array(b)
end
end
end
Expand Down

0 comments on commit 19e361e

Please sign in to comment.