Skip to content

Commit

Permalink
Merge pull request JuliaLang#11198 from kshyatt/tritests
Browse files Browse the repository at this point in the history
More tests for tridiagonal matrices
  • Loading branch information
jakebolewski committed May 8, 2015
2 parents 4c76697 + 26c6f9f commit dc088f7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ let n = 12 #Size of matrix problem to test
b += im*convert(Vector{elty}, randn(n-1))
end

@test_throws DimensionMismatch SymTridiagonal(a, ones(n+1))

A = SymTridiagonal(a, b)
fA = map(elty <: Complex ? Complex128 : Float64, full(A))

debug && println("Diagonal extraction")
@test diag(A,1) == b
@test diag(A,-1) == b
@test diag(A,0) == a
@test_throws BoundsError diag(A,n+1)

debug && println("Idempotent tests")
for func in (conj, transpose, ctranspose)
@test func(func(A)) == A
Expand Down Expand Up @@ -80,6 +88,10 @@ let n = 12 #Size of matrix problem to test
for op in (+, -, *)
@test_approx_eq full(op(A, B)) op(fA, fB)
end
α = rand(elty)
@test_approx_eq full*A) α*full(A)
@test_approx_eq full(A*α) full(A)*α
@test_approx_eq full(A/α) full(A)/α
end

debug && println("Tridiagonal matrices")
Expand All @@ -94,9 +106,16 @@ let n = 12 #Size of matrix problem to test
c += im*convert(Vector{elty}, randn(n - 1))
end

@test_throws ArgumentError Tridiagonal(a,a,a)
A = Tridiagonal(a, b, c)
fA = map(elty <: Complex ? Complex128 : Float64, full(A))

debug && println("Diagonal extraction")
@test diag(A,-1) == a
@test diag(A,0) == b
@test diag(A,1) == c
@test_throws BoundsError diag(A,n+1)

debug && println("Simple unary functions")
for func in (det, inv)
@test_approx_eq_eps func(A) func(fA) n^2*sqrt(eps(relty))
Expand Down Expand Up @@ -125,5 +144,9 @@ let n = 12 #Size of matrix problem to test
for op in (+, -, *)
@test_approx_eq full(op(A, B)) op(fA, fB)
end
α = rand(elty)
@test_approx_eq full*A) α*full(A)
@test_approx_eq full(A*α) full(A)*α
@test_approx_eq full(A/α) full(A)/α
end
end

0 comments on commit dc088f7

Please sign in to comment.