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 Jun 23, 2016
1 parent 91bbb1e commit a159ac5
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 259 deletions.
4 changes: 2 additions & 2 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ debug && println("real svds")
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(convert(Array, A))

## singular values match:
@test_approx_eq S1[1][:S] S2[2][1:2]
Expand Down Expand Up @@ -196,7 +196,7 @@ debug && println("complex svds")
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(convert(Array, A))

## singular values match:
@test_approx_eq 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 @@ -62,12 +62,12 @@ for relty in (Int, Float32, Float64, BigFloat), elty in (relty, Complex{relty})

@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 convert(Array, T) == diagm(dv) + diagm(ev, isupper?1:-1)
@test Bidiagonal(convert(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 convert(Array, abs(T)) == abs(diagm(dv)) + abs(diagm(ev, isupper?1:-1))
@test convert(Array, real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
@test convert(Array, imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))
z = zeros(elty, n)

debug && println("Idempotent tests")
Expand Down Expand Up @@ -113,7 +113,7 @@ for relty in (Int, Float32, Float64, BigFloat), elty in (relty, Complex{relty})
b += im*convert(Matrix{elty}, rand(1:10, n, 2))
end
end
Tfull = full(T)
Tfull = convert(Array, T)
condT = cond(map(Complex128,Tfull))
promty = typeof((zero(relty)*zero(relty) + zero(relty)*zero(relty))/one(relty))
if relty != BigFloat
Expand Down Expand Up @@ -184,7 +184,7 @@ for relty in (Int, Float32, Float64, BigFloat), elty in (relty, Complex{relty})

debug && println("Singular systems")
if (elty <: BlasReal)
@test_approx_eq full(svdfact(T)) full(svdfact!(copy(Tfull)))
@test_approx_eq convert(Array, svdfact(T)) convert(Array, svdfact!(copy(Tfull)))
@test_approx_eq svdvals(Tfull) svdvals(T)
u1, d1, v1 = svd(Tfull)
u2, d2, v2 = svd(T)
Expand All @@ -206,9 +206,9 @@ for relty in (Int, Float32, Float64, BigFloat), elty in (relty, Complex{relty})
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 = convert(Array, T2)
for op in (+, -, *)
@test_approx_eq full(op(T, T2)) op(Tfull, Tfull2)
@test_approx_eq convert(Array, op(T, T2)) op(Tfull, Tfull2)
end
end

Expand All @@ -234,7 +234,7 @@ A = Bidiagonal(ones(Float32,10),ones(Float32,9),true)
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},convert(Array, A)))
@test promote(C,A) == (C,Tridiagonal(zeros(Float64,9),convert(Vector{Float64},A.dv),convert(Vector{Float64},A.ev)))

import Base.LinAlg: fillslots!, UnitLowerTriangular
Expand Down Expand Up @@ -271,14 +271,14 @@ let #fill!
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 convert(Array, fill!(x, val)) == fill!(convert(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 convert(Array, fill!(x, 0)) == fill!(convert(Array, x), 0)
end
end
end
22 changes: 11 additions & 11 deletions test/linalg/cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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 - convert(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 @@ -65,13 +65,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},convert(Array, SymTridiagonal([2,2],[-1])))
U = Bidiagonal([2,sqrt(eltya(3))],[-1],true) / sqrt(eltya(2))
@test_approx_eq full(chol(S)) full(U)
@test_approx_eq convert(Array, chol(S)) convert(Array, U)

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

@test size(cpapd) == size(apd)
@test full(copy(cpapd)) apd
@test convert(Array, copy(cpapd)) apd
@test det(cpapd) det(apd)
@test cpapd[:P]*cpapd[:L]*cpapd[:U]*cpapd[:P]' apd
end
Expand Down Expand Up @@ -151,9 +151,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 = convert(Array, Base.LinAlg._chol!(X*X', LowerTriangular))
U = convert(Array, Base.LinAlg._chol!(X*X', UpperTriangular))
XX = convert(Array, X*X')

@test sum(sum(norm, L*L' - XX)) < eps()
@test sum(sum(norm, U'*U - XX)) < eps()
Expand All @@ -167,8 +167,8 @@ for elty in (Float32, Float64, Complex{Float32}, Complex{Float64})
A = randn(5,5)
end
A = convert(Matrix{elty}, A'A)
@test_approx_eq full(cholfact(A)[:L]) full(invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{LowerTriangular}}, copy(A), LowerTriangular))
@test_approx_eq full(cholfact(A)[:U]) full(invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{UpperTriangular}}, copy(A), UpperTriangular))
@test_approx_eq convert(Array, cholfact(A)[:L]) convert(Array, invoke(Base.LinAlg._chol!, Tuple{AbstractMatrix, Type{LowerTriangular}}, copy(A), LowerTriangular))
@test_approx_eq convert(Array, cholfact(A)[:U]) convert(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 convert(Array, factorize(A)) convert(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 convert(Array, factorize(A)) convert(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
32 changes: 16 additions & 16 deletions test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
@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 convert(Array, real(D)) == real(DM)
@test convert(Array, abs(D)) == abs(DM)
@test convert(Array, imag(D)) == imag(DM)

@test parent(D) == d
@test diag(D) == d
Expand Down Expand Up @@ -79,12 +79,12 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
@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)) convert(Array, D)\convert(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 = convert(Array, D)\b2
for i in 1:n
@test c[i] d[i]
end
Expand All @@ -101,23 +101,23 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
D2 = Diagonal(d)
DM2= diagm(d)
for op in (+, -, *)
@test full(op(D, D2)) op(DM, DM2)
@test convert(Array, op(D, D2)) op(DM, DM2)
end
# binary ops with plain numbers
a = rand()
@test full(a*D) a*DM
@test full(D*a) DM*a
@test full(D/a) DM/a
@test convert(Array, a*D) a*DM
@test convert(Array, D*a) DM*a
@test convert(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)) convert(Array, D)*convert(Array, b)
@test At_mul_B!(copy(D), copy(b)) convert(Array, D).'*convert(Array, b)
@test Ac_mul_B!(copy(D), copy(b)) convert(Array, D)'*convert(Array, b)
end

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

#division of two Diagonals
@test D/D2 Diagonal(D.diag./D2.diag)
Expand Down Expand Up @@ -155,7 +155,7 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
debug && println("conj and transpose")
@test transpose(D) == D
if elty <: BlasComplex
@test full(conj(D)) conj(DM)
@test convert(Array, conj(D)) conj(DM)
@test ctranspose(D) == conj(D)
end

Expand Down Expand Up @@ -233,7 +233,7 @@ end
# inv
for d in (randn(n), [1, 2, 3], [1im, 2im, 3im])
D = Diagonal(d)
@test inv(D) inv(full(D))
@test inv(D) inv(convert(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 @@ -27,11 +27,11 @@ let n = 10
@test size(H[:Q], 2) == size(A, 2)
@test size(H[:Q]) == size(A)
@test_throws KeyError H[:Z]
@test_approx_eq full(H) A
@test_approx_eq convert(Array, H) A
@test_approx_eq (H[:Q] * H[:H]) * H[:Q]' A
@test_approx_eq (H[:Q]' * A) * H[:Q] H[:H]
#getindex for HessenbergQ
@test_approx_eq H[:Q][1,1] full(H[:Q])[1,1]
@test_approx_eq H[:Q][1,1] convert(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 @@ -46,7 +46,7 @@ let # gebrd, bdsqr & throw for bdsdc
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_approx_eq full(Bidiagonal(d, e, true)) U*Diagonal(s)*Vt
@test_approx_eq convert(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 @@ -52,25 +52,25 @@ debug && println("LQ decomposition")
@test size(lqa[:Q],3) == 1
@test Base.LinAlg.getq(lqa) == lqa[:Q]
@test_throws KeyError lqa[:Z]
@test full(lqa') a'
@test convert(Array, lqa') a'
@test lqa * lqa' a * a'
@test lqa' * lqa a' * a
@test q*full(q, thin = false)' eye(eltya,n)
@test q*convert(Array, q, thin = false)' eye(eltya,n)
@test l*q a
@test full(lqa) a
@test full(copy(lqa)) a
@test convert(Array, lqa) a
@test convert(Array, copy(lqa)) a
@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)*convert(Array, q, thin=false) 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 convert(Array, q, thin=false)*b 100ε
@test_approx_eq_eps q.'*b convert(Array, q, thin=false).'*b 100ε
@test_approx_eq_eps q'*b convert(Array, q, thin=false)'*b 100ε
@test_approx_eq_eps a*q a*convert(Array, q, thin=false) 100ε
@test_approx_eq_eps a*q.' a*convert(Array, q, thin=false).' 100ε
@test_approx_eq_eps a*q' a*convert(Array, q, thin=false)' 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 @@ -80,10 +80,10 @@ debug && println("LQ decomposition")
debug && println("Matmul with LQ factorizations")
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 convert(Array, q)*convert(Array, q)' eye(eltya,n1)
@test (convert(Array, q,thin=false)'*convert(Array, q,thin=false))[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,convert(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
22 changes: 11 additions & 11 deletions test/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
if eltya <: BlasFloat
num = rand(eltya)
@test lu(num) == (one(eltya),num,1)
@test_approx_eq full(lufact(num)) eltya[num]
@test_approx_eq convert(Array, lufact(num)) eltya[num]
end
for eltyb in (Float32, Float64, Complex64, Complex128, Int)
b = eltyb == Int ? rand(1:5, n, 2) : convert(Matrix{eltyb}, eltyb <: Complex ? complex(breal, bimg) : breal)
Expand Down Expand Up @@ -68,7 +68,7 @@ debug && println("(Automatic) Square LU decomposition")
@test norm(a'*(lua'\a') - a', 1) < ε*κ*n^2
@test norm(a*(lua\c) - c, 1) < ε*κ*n # c is a vector
@test norm(a'*(lua'\c) - c, 1) < ε*κ*n # c is a vector
@test_approx_eq full(lua) a
@test_approx_eq convert(Array, lua) a
if eltya <: Real && eltyb <: Real
@test norm(a.'*(lua.'\b) - b,1) < ε*κ*n*2 # Two because the right hand side has two columns
@test norm(a.'*(lua.'\c) - c,1) < ε*κ*n
Expand All @@ -81,13 +81,13 @@ debug && println("(Automatic) Square LU decomposition")
end

debug && println("Tridiagonal LU")
κd = cond(full(d),1)
κd = cond(convert(Array, d),1)
lud = lufact(d)
@test lufact(lud) == lud
@test_throws KeyError lud[:Z]
@test lud[:L]*lud[:U] lud[:P]*full(d)
@test lud[:L]*lud[:U] full(d)[lud[:p],:]
@test full(lud) d
@test lud[:L]*lud[:U] lud[:P]*convert(Array, d)
@test lud[:L]*lud[:U] convert(Array, d)[lud[:p],:]
@test convert(Array, lud) d
f = zeros(eltyb, n+1)
@test_throws DimensionMismatch lud\f
@test_throws DimensionMismatch lud.'\f
Expand All @@ -102,17 +102,17 @@ debug && println("Tridiagonal LU")

@test norm(d*(lud\b) - b, 1) < ε*κd*n*2 # Two because the right hand side has two columns
if eltya <: Real
@test norm((lud.'\b) - full(d.')\b, 1) < ε*κd*n*2 # Two because the right hand side has two columns
@test norm((lud.'\b) - convert(Array, d.')\b, 1) < ε*κd*n*2 # Two because the right hand side has two columns
end
if eltya <: Complex
@test norm((lud'\b) - full(d')\b, 1) < ε*κd*n*2 # Two because the right hand side has two columns
@test norm((lud'\b) - convert(Array, d')\b, 1) < ε*κd*n*2 # Two because the right hand side has two columns
end
end
end
if eltya <: BlasFloat && eltyb <: BlasFloat
e = rand(eltyb,n,n)
@test norm(e/lud - e/d,1) < ε*κ*n^2
@test norm((lud.'\e') - full(d.')\e',1) < ε*κd*n^2
@test norm((lud.'\e') - convert(Array, d.')\e',1) < ε*κd*n^2
#test singular
du = rand(eltya,n-1)
dl = rand(eltya,n-1)
Expand All @@ -136,11 +136,11 @@ end

# test conversion routine
a = Tridiagonal(rand(9),rand(10),rand(9))
fa = full(a)
fa = convert(Array, a)
falu = lufact(fa)
alu = lufact(a)
falu = convert(typeof(falu),alu)
@test full(alu) == fa
@test convert(Array, alu) == fa

# Test rational matrices
## Integrate in general tests when more linear algebra is implemented in julia
Expand Down
Loading

0 comments on commit a159ac5

Please sign in to comment.