Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove string "Array" funnybusiness #23583

Merged
merged 3 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions test/linalg/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ bimg = randn(n,2)/2
@testset for eltya in (Float32, Float64, Complex64, Complex128, Int)
a = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
a2 = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(a2real, a2img) : a2real)
@testset for atype in ("Array", "SubArray")
asym = a.'+ a # symmetric indefinite
aher = a' + a # Hermitian indefinite
apd = a' * a # Positive-definite
if atype == "Array"
a = a
a2 = a2
else
a = view(a , 1:n, 1:n)
a2 = view(a2 , 1:n, 1:n)
aher = view(aher, 1:n, 1:n)
apd = view(apd , 1:n, 1:n)
end
asym = a.'+ a # symmetric indefinite
aher = a' + a # Hermitian indefinite
apd = a' * a # Positive-definite
for (a, a2, aher, apd) in ((a, a2, aher, apd),
(view(a, 1:n, 1:n),
view(a2, 1:n, 1:n),
view(aher, 1:n, 1:n),
view(apd , 1:n, 1:n)))
ε = εa = eps(abs(float(one(eltya))))

@testset for eltyb in (Float32, Float64, Complex64, Complex128, Int)
Expand All @@ -44,13 +39,7 @@ bimg = randn(n,2)/2
@test isa(factorize(asym), LinAlg.BunchKaufman)
@test isa(factorize(aher), LinAlg.BunchKaufman)

@testset for btype in ("Array", "SubArray")
if btype == "Array"
b = b
else
b = view(b, 1:n, 1:2)
end

for b in (b, view(b, 1:n, 1:2))
εb = eps(abs(float(one(eltyb))))
ε = max(εa,εb)

Expand Down Expand Up @@ -113,13 +102,7 @@ end
As3[1, end] -= im

for As = (As1, As2, As3)
@testset for Astype in ("Array", "SubArray")
if Astype == "Array"
As = As
else
As = view(As, 1:n, 1:n)
end

for As in (As, view(As, 1:n, 1:n))
@testset for rook in (false, true)
@testset for uplo in (:L, :U)
F = bkfact(issymmetric(As) ? Symmetric(As, uplo) : Hermitian(As, uplo), rook)
Expand Down
57 changes: 7 additions & 50 deletions test/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ srand(1234321)
ainit = rand(n,n)
@testset "for $elty" for elty in (Float32, Float64, Complex64, Complex128)
ainit = convert(Matrix{elty}, ainit)
for arraytype in ("Array", "SubArray")
if arraytype == "Array"
a = ainit
else
a = view(ainit, 1:n, 1:n)
end
for a in (copy(ainit), view(ainit, 1:n, 1:n))
@test cond(a,1) ≈ 4.837320054554436e+02 atol=0.01
@test cond(a,2) ≈ 1.960057871514615e+02 atol=0.01
@test cond(a,Inf) ≈ 3.757017682707787e+02 atol=0.01
Expand Down Expand Up @@ -60,16 +55,7 @@ bimg = randn(n,2)/2
binit = eltyb == Int ? rand(1:5, n, 2) : convert(Matrix{eltyb}, eltyb <: Complex ? complex.(breal, bimg) : breal)
εb = eps(abs(float(one(eltyb))))
ε = max(εa,εb)

for arraytype in ("Array", "SubArray")
if arraytype == "Array"
a = ainit
b = binit
else
a = view(ainit, 1:n, 1:n)
b = view(binit, 1:n, 1:2)
end

for (a, b) in ((copy(ainit), copy(binit)), (view(ainit, 1:n, 1:n), view(binit, 1:n, 1:2)))
@testset "Solve square general system of equations" begin
κ = cond(a,1)
x = a \ b
Expand All @@ -90,15 +76,7 @@ bimg = randn(n,2)/2
end
end # for eltyb

for arraytype in ("Array", "SubArray")
if arraytype == "Array"
a = ainit
a2 = ainit2
else
a = view(ainit, 1:n, 1:n)
a2 = view(ainit2, 1:n, 1:n)
end

for (a, a2) in ((copy(ainit), copy(ainit2)), (view(ainit, 1:n, 1:n), view(ainit2, 1:n, 1:n)))
@testset "Test pinv" begin
pinva15 = pinv(a[:,1:n1])
@test a[:,1:n1]*pinva15*a[:,1:n1] ≈ a[:,1:n1]
Expand Down Expand Up @@ -169,14 +147,9 @@ end # for eltya

@testset "test triu/tril bounds checking" begin
ainit = rand(5,7)
for arraytype in ("Array", "SubArray")
if arraytype == "Array"
a = ainit
else
a = view(ainit, 1:size(ainit, 1), 1:size(ainit, 2))
end
@test_throws(ArgumentError,triu(a,8))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally removed this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Return Of The Test!

for a in (copy(ainit), view(ainit, 1:size(ainit, 1), 1:size(ainit, 2)))
@test_throws(ArgumentError,triu(a,-6))
@test_throws(ArgumentError,triu(a,8))
@test_throws(ArgumentError,tril(a,8))
@test_throws(ArgumentError,tril(a,-6))
end
Expand Down Expand Up @@ -253,14 +226,7 @@ end
α = elty <: Integer ? randn() :
elty <: Complex ? convert(elty, complex(randn(),randn())) :
convert(elty, randn())
for arraytype in ("Array", "SubArray")
if arraytype == "Array"
x = xinit
y = yinit
else
x = view(xinit,1:2:nnorm)
y = view(yinit,1:2:nnorm)
end
for (x, y) in ((copy(xinit), copy(yinit)), (view(xinit,1:2:nnorm), view(yinit,1:2:nnorm)))
# Absolute homogeneity
@test norm(α*x,-Inf) ≈ abs(α)*norm(x,-Inf)
@test norm(α*x,-1) ≈ abs(α)*norm(x,-1)
Expand Down Expand Up @@ -309,16 +275,7 @@ end
α = elty <: Integer ? randn() :
elty <: Complex ? convert(elty, complex(randn(),randn())) :
convert(elty, randn())

for arraytype in ("Array", "SubArray")
if arraytype == "Array"
A = Ainit
B = Binit
else
A = view(Ainit,1:nmat,1:nmat)
B = view(Binit,1:nmat,1:nmat)
end

for (A, B) in ((copy(Ainit), copy(Binit)), (view(Ainit,1:nmat,1:nmat), view(Binit,1:nmat,1:nmat)))
# Absolute homogeneity
@test norm(α*A,1) ≈ abs(α)*norm(A,1)
elty <: Union{BigFloat,Complex{BigFloat},BigInt} || @test norm(α*A) ≈ abs(α)*norm(A) # two is default
Expand Down
142 changes: 65 additions & 77 deletions test/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ n=12 #Size of matrix problem to test
srand(1)

@testset for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
d=convert(Vector{elty}, randn(n))
v=convert(Vector{elty}, randn(n))
U=convert(Matrix{elty}, randn(n,n))
dd=convert(Vector{elty}, randn(n))
vv=convert(Vector{elty}, randn(n))
UU=convert(Matrix{elty}, randn(n,n))
if elty <: Complex
d+=im*convert(Vector{elty}, randn(n))
v+=im*convert(Vector{elty}, randn(n))
U+=im*convert(Matrix{elty}, randn(n,n))
dd+=im*convert(Vector{elty}, randn(n))
vv+=im*convert(Vector{elty}, randn(n))
UU+=im*convert(Matrix{elty}, randn(n,n))
end
D = Diagonal(d)
DM = diagm(d)
D = Diagonal(dd)
DM = diagm(dd)

@testset "constructor" begin
for x in (d, GenericArray(d))
for x in (dd, GenericArray(dd))
@test Diagonal(x)::Diagonal{elty,typeof(x)} == DM
@test Diagonal(x).diag === x
@test Diagonal{elty}(x)::Diagonal{elty,typeof(x)} == DM
Expand All @@ -38,9 +38,9 @@ srand(1)
@test Array(abs.(D)) == abs.(DM)
@test Array(imag(D)) == imag(DM)

@test parent(D) == d
@test diag(D) == d
@test D[1,1] == d[1]
@test parent(D) == dd
@test diag(D) == dd
@test D[1,1] == dd[1]
@test D[1,2] == 0

@test issymmetric(D)
Expand Down Expand Up @@ -73,61 +73,49 @@ srand(1)
end

@testset "Linear solve" begin
let vv = v, UU = U
@testset for atype in ("Array", "SubArray")
if atype == "Array"
v = vv
U = UU
else
v = view(vv, 1:n)
U = view(UU, 1:n, 1:2)
end

@test D*v ≈ DM*v atol=n*eps(relty)*(1+(elty<:Complex))
@test D*U ≈ DM*U atol=n^2*eps(relty)*(1+(elty<:Complex))

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

if relty != BigFloat
atol_two = 2n^2 * eps(relty) * (1 + (elty <: Complex))
atol_three = 2n^3 * eps(relty) * (1 + (elty <: Complex))
@test D\v ≈ DM\v atol=atol_two
@test D\U ≈ DM\U atol=atol_three
@test A_ldiv_B!(D, copy(v)) ≈ DM\v atol=atol_two
@test At_ldiv_B!(D, copy(v)) ≈ DM\v atol=atol_two
@test Ac_ldiv_B!(conj(D), copy(v)) ≈ DM\v atol=atol_two
@test A_ldiv_B!(D, copy(U)) ≈ DM\U atol=atol_three
@test At_ldiv_B!(D, copy(U)) ≈ DM\U atol=atol_three
@test Ac_ldiv_B!(conj(D), copy(U)) ≈ DM\U atol=atol_three
Uc = adjoint(U)
target = scale!(Uc, inv.(D.diag))
@test A_rdiv_B!(Uc, D) ≈ target atol=atol_three
@test_throws DimensionMismatch A_rdiv_B!(eye(elty, n-1), D)
@test_throws SingularException A_rdiv_B!(Uc, zeros(D))
@test A_rdiv_Bt!(Uc, D) ≈ target atol=atol_three
@test A_rdiv_Bc!(Uc, conj(D)) ≈ target atol=atol_three
@test A_ldiv_B!(D, eye(D)) ≈ D\eye(D) atol=atol_three
@test_throws DimensionMismatch A_ldiv_B!(D, ones(elty, n + 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)) ≈ 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 = Array(D)\b2
for i in 1:n
@test c[i] ≈ d[i]
end
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty, n)), b)
b = rand(elty, n+1, n+1)
b = sparse(b)
@test_throws DimensionMismatch A_ldiv_B!(D, copy(b))
b = view(rand(elty, n+1), collect(1:n+1))
@test_throws DimensionMismatch A_ldiv_B!(D, b)
end
for (v, U) in ((vv, UU), (view(vv, 1:n), view(UU, 1:n, 1:2)))
@test D*v ≈ DM*v atol=n*eps(relty)*(1+(elty<:Complex))
@test D*U ≈ DM*U atol=n^2*eps(relty)*(1+(elty<:Complex))

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

if relty != BigFloat
atol_two = 2n^2 * eps(relty) * (1 + (elty <: Complex))
atol_three = 2n^3 * eps(relty) * (1 + (elty <: Complex))
@test D\v ≈ DM\v atol=atol_two
@test D\U ≈ DM\U atol=atol_three
@test A_ldiv_B!(D, copy(v)) ≈ DM\v atol=atol_two
@test At_ldiv_B!(D, copy(v)) ≈ DM\v atol=atol_two
@test Ac_ldiv_B!(conj(D), copy(v)) ≈ DM\v atol=atol_two
@test A_ldiv_B!(D, copy(U)) ≈ DM\U atol=atol_three
@test At_ldiv_B!(D, copy(U)) ≈ DM\U atol=atol_three
@test Ac_ldiv_B!(conj(D), copy(U)) ≈ DM\U atol=atol_three
Uc = adjoint(U)
target = scale!(Uc, inv.(D.diag))
@test A_rdiv_B!(Uc, D) ≈ target atol=atol_three
@test_throws DimensionMismatch A_rdiv_B!(eye(elty, n-1), D)
@test_throws SingularException A_rdiv_B!(Uc, zeros(D))
@test A_rdiv_Bt!(Uc, D) ≈ target atol=atol_three
@test A_rdiv_Bc!(Uc, conj(D)) ≈ target atol=atol_three
@test A_ldiv_B!(D, eye(D)) ≈ D\eye(D) atol=atol_three
@test_throws DimensionMismatch A_ldiv_B!(D, ones(elty, n + 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)) ≈ 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 = Array(D)\b2
@test c ≈ d
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty, n)), b)
b = rand(elty, n+1, n+1)
b = sparse(b)
@test_throws DimensionMismatch A_ldiv_B!(D, copy(b))
b = view(rand(elty, n+1), collect(1:n+1))
@test_throws DimensionMismatch A_ldiv_B!(D, b)
end
end
end
Expand Down Expand Up @@ -163,15 +151,15 @@ srand(1)
@test D\D2 ≈ Diagonal(D2.diag./D.diag)

# Performance specialisations for A*_mul_B!
vv = similar(v)
@test (r = full(D) * v ; A_mul_B!(vv, D, v) ≈ r ≈ vv)
@test (r = full(D)' * v ; Ac_mul_B!(vv, D, v) ≈ r ≈ vv)
@test (r = full(D).' * v ; At_mul_B!(vv, D, v) ≈ r ≈ vv)
vvv = similar(vv)
@test (r = full(D) * vv ; A_mul_B!(vvv, D, vv) ≈ r ≈ vvv)
@test (r = full(D)' * vv ; Ac_mul_B!(vvv, D, vv) ≈ r ≈ vvv)
@test (r = full(D).' * vv ; At_mul_B!(vvv, D, vv) ≈ r ≈ vvv)

UU = similar(U)
@test (r = full(D) * U ; A_mul_B!(UU, D, U) ≈ r ≈ UU)
@test (r = full(D)' * U ; Ac_mul_B!(UU, D, U) ≈ r ≈ UU)
@test (r = full(D).' * U ; At_mul_B!(UU, D, U) ≈ r ≈ UU)
UUU = similar(UU)
@test (r = full(D) * UU ; A_mul_B!(UUU, D, UU) ≈ r ≈ UUU)
@test (r = full(D)' * UU ; Ac_mul_B!(UUU, D, UU) ≈ r ≈ UUU)
@test (r = full(D).' * UU ; At_mul_B!(UUU, D, UU) ≈ r ≈ UUU)

# make sure that A_mul_B{c,t}! works with B as a Diagonal
VV = Array(D)
Expand Down Expand Up @@ -225,8 +213,8 @@ srand(1)
@test adjoint(D) == conj(D)
end
# Translates to Ac/t_mul_B, which is specialized after issue 21286
@test(D' * v == conj(D) * v)
@test(D.' * v == D * v)
@test(D' * vv == conj(D) * vv)
@test(D.' * vv == D * vv)
end

#logdet
Expand Down
23 changes: 7 additions & 16 deletions test/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ aimg = randn(n,n)/2
aa = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
asym = aa'+aa # symmetric indefinite
apd = aa'*aa # symmetric positive-definite
@testset for atype in ("Array", "SubArray")
if atype == "Array"
a = aa
else
a = view(aa, 1:n, 1:n)
asym = view(asym, 1:n, 1:n)
apd = view(apd, 1:n, 1:n)
end
for (a, asym, apd) in ((aa, asym, apd),
(view(aa, 1:n, 1:n),
view(asym, 1:n, 1:n),
view(apd, 1:n, 1:n)))
ε = εa = eps(abs(float(one(eltya))))

α = rand(eltya)
Expand Down Expand Up @@ -56,7 +52,7 @@ aimg = randn(n,n)/2
@test_throws DomainError eigmax(a - a')
end
@testset "symmetric generalized eigenproblem" begin
if atype == "Array"
if isa(a, Array)
asym_sg = asym[1:n1, 1:n1]
a_sg = a[:,n1+1:n2]
else
Expand All @@ -77,7 +73,7 @@ aimg = randn(n,n)/2
@test v == f[:vectors]
end
@testset "Non-symmetric generalized eigenproblem" begin
if atype == "Array"
if isa(a, Array)
a1_nsg = a[1:n1, 1:n1]
a2_nsg = a[n1+1:n2, n1+1:n2]
else
Expand Down Expand Up @@ -110,12 +106,7 @@ end

# test a matrix larger than 140-by-140 for #14174
let aa = rand(200, 200)
for atype in ("Array", "SubArray")
if atype == "Array"
a = aa
else
a = view(aa, 1:n, 1:n)
end
for a in (aa, view(aa, 1:n, 1:n))
f = eigfact(a)
@test a ≈ f[:vectors] * Diagonal(f[:values]) / f[:vectors]
end
Expand Down
Loading