Skip to content

Commit

Permalink
Merge pull request #12095 from JuliaLang/ksh/linalgtests
Browse files Browse the repository at this point in the history
Fill out linalg tests
  • Loading branch information
kshyatt committed Jul 10, 2015
2 parents a227951 + c64edb5 commit 14af2d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function eigmin(A::Union{Number, StridedMatrix}; permute::Bool=true, scale::Bool
iseltype(v,Complex) ? error("DomainError: complex eigenvalues cannot be ordered") : minimum(v)
end

inv(A::Eigen) = A.vectors/Diagonal(A.values)*A.vectors'
inv(A::Eigen) = A.vectors * inv(Diagonal(A.values)) / A.vectors
det(A::Eigen) = prod(A.values)

# Generalized eigenproblem
Expand Down
20 changes: 20 additions & 0 deletions test/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ let n=10
@test_approx_eq Symmetric(asym)*x+y asym*x+y
end

C = zeros(eltya,n,n)
# mat * mat
if eltya <: Complex
@test_approx_eq Hermitian(asym) * a asym * a
@test_approx_eq a * Hermitian(asym) a * asym
@test_approx_eq Hermitian(asym) * Hermitian(asym) asym*asym
@test_throws DimensionMismatch Hermitian(asym) * ones(eltya,n+1)
Base.LinAlg.A_mul_B!(C,a,asym)
@test_approx_eq C a*asym
end
if eltya <: Real && eltya != Int
@test_approx_eq Symmetric(asym) * Symmetric(asym) asym*asym
@test_approx_eq Symmetric(asym) * a asym * a
@test_approx_eq a * Symmetric(asym) a * asym
@test_throws DimensionMismatch Symmetric(asym) * ones(eltya,n+1)
Base.LinAlg.A_mul_B!(C,a,asym)
@test_approx_eq C a*asym
end

# solver
Expand All @@ -109,6 +114,21 @@ let n=10
if eltya <: Real && eltya != Int
@test_approx_eq inv(Symmetric(asym)) inv(asym)
end

# conversion
@test Symmetric(asym) == convert(Symmetric,Symmetric(asym))
if eltya <: Real && eltya != Int
typs = [Float16,Float32,Float64]
for typ in typs
@test Symmetric(convert(Matrix{typ},asym)) == convert(Symmetric{typ,Matrix{typ}},Symmetric(asym))
end
end
if eltya <: Complex && eltya != Int
typs = [Complex64,Complex128]
for typ in typs
@test Hermitian(convert(Matrix{typ},asym)) == convert(Hermitian{typ,Matrix{typ}},Hermitian(asym))
end
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/linalg1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ debug && println("non-symmetric eigen decomposition")
if eltya != BigFloat && eltyb != BigFloat # Revisit when implemented in julia
d,v = eig(a)
for i in 1:size(a,2) @test_approx_eq a*v[:,i] d[i]*v[:,i] end
f = eigfact(a)
@test_approx_eq det(a) det(f)
@test_approx_eq inv(a) inv(f)

num_fact = eigfact(one(eltya))
@test num_fact.values[1] == one(eltya)
end

debug && println("symmetric generalized eigenproblem")
Expand Down
4 changes: 4 additions & 0 deletions test/linalg4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ let a=[1.0:n;]
for newtype in [Diagonal, Bidiagonal, Tridiagonal, SymTridiagonal]
@test_throws ArgumentError convert(newtype,A)
end
A = Diagonal(a)
for newtype in [UpperTriangular, LowerTriangular]
@test full(convert(newtype,A)) == full(A)
end
end

# Binary ops among special types
Expand Down

0 comments on commit 14af2d1

Please sign in to comment.