Skip to content

Commit

Permalink
Migrate full(X) to convert(Array, X) in tests in test/linalg.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 committed Oct 9, 2016
1 parent c33e7a4 commit 034e97f
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 263 deletions.
4 changes: 2 additions & 2 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ end
let # svds test
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], [2.0, -1.0, 6.1, 7.0, 1.5])
S1 = svds(A, nsv = 2)
S2 = svd(full(A))
S2 = svd(Array(A))

## singular values match:
@test S1[1][:S] S2[2][1:2]
Expand Down Expand Up @@ -201,7 +201,7 @@ end
let # complex svds test
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp.(im*[2.0:2:10;]))
S1 = svds(A, nsv = 2)
S2 = svd(full(A))
S2 = svd(Array(A))

## singular values match:
@test S1[1][:S] S2[2][1:2]
Expand Down
24 changes: 12 additions & 12 deletions test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ srand(1)
@testset "Constructor and basic properties" begin
@test size(T, 1) == size(T, 2) == n
@test size(T) == (n, n)
@test full(T) == diagm(dv) + diagm(ev, isupper?1:-1)
@test Bidiagonal(full(T), isupper) == T
@test Array(T) == diagm(dv) + diagm(ev, isupper?1:-1)
@test Bidiagonal(Array(T), isupper) == T
@test big(T) == T
@test full(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1))
@test full(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
@test full(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))
@test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1))
@test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))
end
z = zeros(elty, n)

Expand Down Expand Up @@ -100,7 +100,7 @@ srand(1)
@test_throws ArgumentError triu!(Bidiagonal(dv,ev,'U'),n+1)
end

Tfull = full(T)
Tfull = Array(T)
@testset "Linear solves" begin
if relty <: AbstractFloat
c = convert(Matrix{elty}, randn(n,n))
Expand Down Expand Up @@ -189,7 +189,7 @@ srand(1)

@testset "Singular systems" begin
if (elty <: BlasReal)
@test full(svdfact(T)) full(svdfact!(copy(Tfull)))
@test Array(svdfact(T)) Array(svdfact!(copy(Tfull)))
@test svdvals(Tfull) svdvals(T)
u1, d1, v1 = svd(Tfull)
u2, d2, v2 = svd(T)
Expand All @@ -212,9 +212,9 @@ srand(1)
dv = convert(Vector{elty}, relty <: AbstractFloat ? randn(n) : rand(1:10, n))
ev = convert(Vector{elty}, relty <: AbstractFloat ? randn(n-1) : rand(1:10, n-1))
T2 = Bidiagonal(dv, ev, isupper2)
Tfull2 = full(T2)
Tfull2 = Array(T2)
for op in (+, -, *)
@test full(op(T, T2)) op(Tfull, Tfull2)
@test Array(op(T, T2)) op(Tfull, Tfull2)
end
end
end
Expand All @@ -240,7 +240,7 @@ end
B = rand(Float64,10,10)
C = Tridiagonal(rand(Float64,9),rand(Float64,10),rand(Float64,9))
@test promote_rule(Matrix{Float64}, Bidiagonal{Float64}) == Matrix{Float64}
@test promote(B,A) == (B,convert(Matrix{Float64},full(A)))
@test promote(B,A) == (B,convert(Matrix{Float64},Array(A)))
@test promote(C,A) == (C,Tridiagonal(zeros(Float64,9),convert(Vector{Float64},A.dv),convert(Vector{Float64},A.ev)))
end

Expand Down Expand Up @@ -279,14 +279,14 @@ import Base.LinAlg: fillslots!, UnitLowerTriangular
b = Bidiagonal(randn(1,1), true)
st = SymTridiagonal(randn(1,1))
for x in (b, st)
@test full(fill!(x, val)) == fill!(full(x), val)
@test Array(fill!(x, val)) == fill!(Array(x), val)
end
b = Bidiagonal(randn(2,2), true)
st = SymTridiagonal(randn(3), randn(2))
t = Tridiagonal(randn(3,3))
for x in (b, t, st)
@test_throws ArgumentError fill!(x, val)
@test full(fill!(x, 0)) == fill!(full(x), 0)
@test Array(fill!(x, 0)) == fill!(Array(x), 0)
end
end
end
Expand Down
22 changes: 11 additions & 11 deletions test/linalg/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
for i=1:n, j=1:n
@test E[i,j] <= (n+1/(1-(n+1)ε)*real(sqrt(apd[i,i]*apd[j,j]))
end
E = abs.(apd - full(capd))
E = abs.(apd - Array(capd))
for i=1:n, j=1:n
@test E[i,j] <= (n+1/(1-(n+1)ε)*real(sqrt(apd[i,i]*apd[j,j]))
end
Expand All @@ -73,13 +73,13 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
end

# test chol of 2x2 Strang matrix
S = convert(AbstractMatrix{eltya},full(SymTridiagonal([2,2],[-1])))
S = convert(AbstractMatrix{eltya},Array(SymTridiagonal([2,2],[-1])))
U = Bidiagonal([2,sqrt(eltya(3))],[-1],true) / sqrt(eltya(2))
@test full(chol(S)) full(U)
@test Array(chol(S)) Array(U)

#lower Cholesky factor
lapd = cholfact(apd, :L)
@test full(lapd) apd
@test Array(lapd) apd
l = lapd[:L]
@test l*l' apd
@test triu(capd.factors) lapd[:U]
Expand Down Expand Up @@ -118,12 +118,12 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
if isreal(apd)
@test apd*inv(cpapd) eye(n)
end
@test full(cpapd) apd
@test Array(cpapd) apd
#getindex
@test_throws KeyError cpapd[:Z]

@test size(cpapd) == size(apd)
@test full(copy(cpapd)) apd
@test Array(copy(cpapd)) apd
@test det(cpapd) det(apd)
@test cpapd[:P]*cpapd[:L]*cpapd[:U]*cpapd[:P]' apd
end
Expand Down Expand Up @@ -174,9 +174,9 @@ begin
# Cholesky factor of Matrix with non-commutative elements, here 2x2-matrices

X = Matrix{Float64}[0.1*rand(2,2) for i in 1:3, j = 1:3]
L = full(Base.LinAlg._chol!(X*X', LowerTriangular))
U = full(Base.LinAlg._chol!(X*X', UpperTriangular))
XX = full(X*X')
L = Array(Base.LinAlg._chol!(X*X', LowerTriangular))
U = Array(Base.LinAlg._chol!(X*X', UpperTriangular))
XX = Array(X*X')

@test sum(sum(norm, L*L' - XX)) < eps()
@test sum(sum(norm, U'*U - XX)) < eps()
Expand All @@ -190,8 +190,8 @@ for elty in (Float32, Float64, Complex{Float32}, Complex{Float64})
A = randn(5,5)
end
A = convert(Matrix{elty}, A'A)
@test full(cholfact(A)[:L]) full(invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{LowerTriangular}}, copy(A), LowerTriangular))
@test full(cholfact(A)[:U]) full(invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{UpperTriangular}}, copy(A), UpperTriangular))
@test Array(cholfact(A)[:L]) Array(invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{LowerTriangular}}, copy(A), LowerTriangular))
@test Array(cholfact(A)[:U]) Array(invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{UpperTriangular}}, copy(A), UpperTriangular))
end

# Test up- and downdates
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ debug && println("Factorize")
@test factorize(A) == Bidiagonal(d,e,true)
if eltya <: Real
A = diagm(d) + diagm(e,1) + diagm(e,-1)
@test full(factorize(A)) full(factorize(SymTridiagonal(d,e)))
@test Array(factorize(A)) Array(factorize(SymTridiagonal(d,e)))
A = diagm(d) + diagm(e,1) + diagm(e,-1) + diagm(f,2) + diagm(f,-2)
@test inv(factorize(A)) inv(factorize(Symmetric(A)))
end
A = diagm(d) + diagm(e,1) + diagm(e2,-1)
@test full(factorize(A)) full(factorize(Tridiagonal(e2,d,e)))
@test Array(factorize(A)) Array(factorize(Tridiagonal(e2,d,e)))
A = diagm(d) + diagm(e,1) + diagm(f,2)
@test factorize(A) == UpperTriangular(A)
end # for eltya
Expand Down
38 changes: 19 additions & 19 deletions test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ srand(1)
@test typeof(convert(Diagonal{Complex64},D)) == Diagonal{Complex64}
@test typeof(convert(AbstractMatrix{Complex64},D)) == Diagonal{Complex64}

@test full(real(D)) == real(DM)
@test full(abs.(D)) == abs.(DM)
@test full(imag(D)) == imag(DM)
@test Array(real(D)) == real(DM)
@test Array(abs.(D)) == abs.(DM)
@test Array(imag(D)) == imag(DM)

@test parent(D) == d
@test diag(D) == d
Expand Down Expand Up @@ -76,8 +76,8 @@ srand(1)
@test_approx_eq_eps D*v DM*v n*eps(relty)*(elty<:Complex ? 2:1)
@test_approx_eq_eps D*U DM*U n^2*eps(relty)*(elty<:Complex ? 2:1)

@test U.'*D U.'*full(D)
@test U'*D U'*full(D)
@test U.'*D U.'*Array(D)
@test U'*D U'*Array(D)

if relty != BigFloat
@test_approx_eq_eps D\v DM\v 2n^2*eps(relty)*(elty<:Complex ? 2:1)
Expand All @@ -89,12 +89,12 @@ srand(1)
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(relty,n)),copy(v))
b = rand(elty,n,n)
b = sparse(b)
@test A_ldiv_B!(D,copy(b)) full(D)\full(b)
@test A_ldiv_B!(D,copy(b)) Array(D)\Array(b)
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty,n)),copy(b))
b = view(rand(elty,n),collect(1:n))
b2 = copy(b)
c = A_ldiv_B!(D,b)
d = full(D)\b2
d = Array(D)\b2
for i in 1:n
@test c[i] d[i]
end
Expand All @@ -113,27 +113,27 @@ srand(1)
DM2= diagm(d)
@testset "Binary operations" begin
for op in (+, -, *)
@test full(op(D, D2)) op(DM, DM2)
@test Array(op(D, D2)) op(DM, DM2)
end
@testset "with plain numbers" begin
a = rand()
@test full(a*D) a*DM
@test full(D*a) DM*a
@test full(D/a) DM/a
@test Array(a*D) a*DM
@test Array(D*a) DM*a
@test Array(D/a) DM/a
if relty <: BlasFloat
b = rand(elty,n,n)
b = sparse(b)
@test A_mul_B!(copy(D), copy(b)) full(D)*full(b)
@test At_mul_B!(copy(D), copy(b)) full(D).'*full(b)
@test Ac_mul_B!(copy(D), copy(b)) full(D)'*full(b)
@test A_mul_B!(copy(D), copy(b)) Array(D)*Array(b)
@test At_mul_B!(copy(D), copy(b)) Array(D).'*Array(b)
@test Ac_mul_B!(copy(D), copy(b)) Array(D)'*Array(b)
end
end

#a few missing mults
bd = Bidiagonal(D2)
@test D*D2.' full(D)*full(D2).'
@test D2*D.' full(D2)*full(D).'
@test D2*D' full(D2)*full(D)'
@test D*D2.' Array(D)*Array(D2).'
@test D2*D.' Array(D2)*Array(D).'
@test D2*D' Array(D2)*Array(D)'

#division of two Diagonals
@test D/D2 Diagonal(D.diag./D2.diag)
Expand Down Expand Up @@ -175,7 +175,7 @@ srand(1)
@testset "conj and transpose" begin
@test transpose(D) == D
if elty <: BlasComplex
@test full(conj(D)) conj(DM)
@test Array(conj(D)) conj(DM)
@test ctranspose(D) == conj(D)
end
end
Expand Down Expand Up @@ -260,7 +260,7 @@ end
@testset "inverse" begin
for d in (randn(n), [1, 2, 3], [1im, 2im, 3im])
D = Diagonal(d)
@test inv(D) inv(full(D))
@test inv(D) inv(Array(D))
end
@test_throws SingularException inv(Diagonal(zeros(n)))
@test_throws SingularException inv(Diagonal([0, 1, 2]))
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ let n = 10
@test size(H[:Q], 2) == size(A, 2)
@test size(H[:Q]) == size(A)
@test_throws KeyError H[:Z]
@test full(H) A
@test Array(H) A
@test (H[:Q] * H[:H]) * H[:Q]' A
@test (H[:Q]' *A) * H[:Q] H[:H]
#getindex for HessenbergQ
@test H[:Q][1,1] full(H[:Q])[1,1]
@test H[:Q][1,1] Array(H[:Q])[1,1]
end
end
end
2 changes: 1 addition & 1 deletion test/linalg/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end
d, e = convert(Vector{elty}, randn(n)), convert(Vector{elty}, randn(n - 1))
U, Vt, C = eye(elty, n), eye(elty, n), eye(elty, n)
s, _ = LAPACK.bdsqr!('U', copy(d), copy(e), Vt, U, C)
@test full(Bidiagonal(d, e, true)) U*Diagonal(s)*Vt
@test Array(Bidiagonal(d, e, true)) U*Diagonal(s)*Vt

@test_throws ArgumentError LAPACK.bdsqr!('A', d, e, Vt, U, C)
@test_throws DimensionMismatch LAPACK.bdsqr!('U', d, [e; 1], Vt, U, C)
Expand Down
28 changes: 14 additions & 14 deletions test/linalg/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ bimg = randn(n,2)/2
@test size(lqa[:Q],3) == 1
@test Base.LinAlg.getq(lqa) == lqa[:Q]
@test_throws KeyError lqa[:Z]
@test full(lqa') a'
@test Array(lqa') a'
@test lqa * lqa' a * a'
@test lqa' * lqa a' * a
@test q*full(q, thin = false)' eye(eltya,n)
@test q*Base.LinAlg.thickQ(q)' eye(eltya,n)
@test l*q a
@test full(lqa) a
@test full(copy(lqa)) a
@test Array(lqa) a
@test Array(copy(lqa)) a
end
@testset "Binary ops" begin
@test_approx_eq_eps a*(lqa\b) b 3000ε
@test_approx_eq_eps lqa*b qra[:Q]*qra[:R]*b 3000ε
@test_approx_eq_eps A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*full(q, thin=false) eye(n) 5000ε
@test_approx_eq_eps A_mul_Bc(eye(eltyb,size(q.factors,2)),q)*Base.LinAlg.thickQ(q) eye(n) 5000ε
if eltya != Int
@test eye(eltyb,n)*q convert(AbstractMatrix{tab},q)
end
@test_approx_eq_eps q*b full(q, thin=false)*b 100ε
@test_approx_eq_eps q.'*b full(q, thin=false).'*b 100ε
@test_approx_eq_eps q'*b full(q, thin=false)'*b 100ε
@test_approx_eq_eps a*q a*full(q, thin=false) 100ε
@test_approx_eq_eps a*q.' a*full(q, thin=false).' 100ε
@test_approx_eq_eps a*q' a*full(q, thin=false)' 100ε
@test_approx_eq_eps q*b Base.LinAlg.thickQ(q)*b 100ε
@test_approx_eq_eps q.'*b Base.LinAlg.thickQ(q).'*b 100ε
@test_approx_eq_eps q'*b Base.LinAlg.thickQ(q)'*b 100ε
@test_approx_eq_eps a*q a*Base.LinAlg.thickQ(q) 100ε
@test_approx_eq_eps a*q.' a*Base.LinAlg.thickQ(q).' 100ε
@test_approx_eq_eps a*q' a*Base.LinAlg.thickQ(q)' 100ε
@test_throws DimensionMismatch q*b[1:n1 + 1]
@test_throws DimensionMismatch Ac_mul_B(q,ones(eltya,n+2,n+2))
@test_throws DimensionMismatch ones(eltyb,n+2,n+2)*q
Expand All @@ -81,10 +81,10 @@ bimg = randn(n,2)/2
@testset "Matmul with LQ factorizations" begin
lqa = lqfact(a[:,1:n1])
l,q = lqa[:L], lqa[:Q]
@test full(q)*full(q)' eye(eltya,n1)
@test (full(q,thin=false)'*full(q,thin=false))[1:n1,:] eye(eltya,n1,n)
@test Array(q)*Array(q)' eye(eltya,n1)
@test (Base.LinAlg.thickQ(q)'*Base.LinAlg.thickQ(q))[1:n1,:] eye(eltya,n1,n)
@test_throws DimensionMismatch A_mul_B!(eye(eltya,n+1),q)
@test Ac_mul_B!(q,full(q)) eye(eltya,n1)
@test Ac_mul_B!(q,Array(q)) eye(eltya,n1)
@test_throws DimensionMismatch A_mul_Bc!(eye(eltya,n+1),q)
@test_throws BoundsError size(q,-1)
end
Expand Down
Loading

0 comments on commit 034e97f

Please sign in to comment.