Skip to content

Commit 15b29bc

Browse files
kshyattfredrikekre
authored andcommitted
Remove string "Array" funnybusiness (#23583)
* Remove string "Array" funnybusiness * Remove last string things and fix comments * Re-add missing test
1 parent 172f36e commit 15b29bc

File tree

9 files changed

+135
-289
lines changed

9 files changed

+135
-289
lines changed

test/linalg/bunchkaufman.jl

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ bimg = randn(n,2)/2
2222
@testset for eltya in (Float32, Float64, Complex64, Complex128, Int)
2323
a = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
2424
a2 = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(a2real, a2img) : a2real)
25-
@testset for atype in ("Array", "SubArray")
26-
asym = a.'+ a # symmetric indefinite
27-
aher = a' + a # Hermitian indefinite
28-
apd = a' * a # Positive-definite
29-
if atype == "Array"
30-
a = a
31-
a2 = a2
32-
else
33-
a = view(a , 1:n, 1:n)
34-
a2 = view(a2 , 1:n, 1:n)
35-
aher = view(aher, 1:n, 1:n)
36-
apd = view(apd , 1:n, 1:n)
37-
end
25+
asym = a.'+ a # symmetric indefinite
26+
aher = a' + a # Hermitian indefinite
27+
apd = a' * a # Positive-definite
28+
for (a, a2, aher, apd) in ((a, a2, aher, apd),
29+
(view(a, 1:n, 1:n),
30+
view(a2, 1:n, 1:n),
31+
view(aher, 1:n, 1:n),
32+
view(apd , 1:n, 1:n)))
3833
ε = εa = eps(abs(float(one(eltya))))
3934

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

47-
@testset for btype in ("Array", "SubArray")
48-
if btype == "Array"
49-
b = b
50-
else
51-
b = view(b, 1:n, 1:2)
52-
end
53-
42+
for b in (b, view(b, 1:n, 1:2))
5443
εb = eps(abs(float(one(eltyb))))
5544
ε = max(εa,εb)
5645

@@ -113,13 +102,7 @@ end
113102
As3[1, end] -= im
114103

115104
for As = (As1, As2, As3)
116-
@testset for Astype in ("Array", "SubArray")
117-
if Astype == "Array"
118-
As = As
119-
else
120-
As = view(As, 1:n, 1:n)
121-
end
122-
105+
for As in (As, view(As, 1:n, 1:n))
123106
@testset for rook in (false, true)
124107
@testset for uplo in (:L, :U)
125108
F = bkfact(issymmetric(As) ? Symmetric(As, uplo) : Hermitian(As, uplo), rook)

test/linalg/dense.jl

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ srand(1234321)
2020
ainit = rand(n,n)
2121
@testset "for $elty" for elty in (Float32, Float64, Complex64, Complex128)
2222
ainit = convert(Matrix{elty}, ainit)
23-
for arraytype in ("Array", "SubArray")
24-
if arraytype == "Array"
25-
a = ainit
26-
else
27-
a = view(ainit, 1:n, 1:n)
28-
end
23+
for a in (copy(ainit), view(ainit, 1:n, 1:n))
2924
@test cond(a,1) 4.837320054554436e+02 atol=0.01
3025
@test cond(a,2) 1.960057871514615e+02 atol=0.01
3126
@test cond(a,Inf) 3.757017682707787e+02 atol=0.01
@@ -60,16 +55,7 @@ bimg = randn(n,2)/2
6055
binit = eltyb == Int ? rand(1:5, n, 2) : convert(Matrix{eltyb}, eltyb <: Complex ? complex.(breal, bimg) : breal)
6156
εb = eps(abs(float(one(eltyb))))
6257
ε = max(εa,εb)
63-
64-
for arraytype in ("Array", "SubArray")
65-
if arraytype == "Array"
66-
a = ainit
67-
b = binit
68-
else
69-
a = view(ainit, 1:n, 1:n)
70-
b = view(binit, 1:n, 1:2)
71-
end
72-
58+
for (a, b) in ((copy(ainit), copy(binit)), (view(ainit, 1:n, 1:n), view(binit, 1:n, 1:2)))
7359
@testset "Solve square general system of equations" begin
7460
κ = cond(a,1)
7561
x = a \ b
@@ -90,15 +76,7 @@ bimg = randn(n,2)/2
9076
end
9177
end # for eltyb
9278

93-
for arraytype in ("Array", "SubArray")
94-
if arraytype == "Array"
95-
a = ainit
96-
a2 = ainit2
97-
else
98-
a = view(ainit, 1:n, 1:n)
99-
a2 = view(ainit2, 1:n, 1:n)
100-
end
101-
79+
for (a, a2) in ((copy(ainit), copy(ainit2)), (view(ainit, 1:n, 1:n), view(ainit2, 1:n, 1:n)))
10280
@testset "Test pinv" begin
10381
pinva15 = pinv(a[:,1:n1])
10482
@test a[:,1:n1]*pinva15*a[:,1:n1] a[:,1:n1]
@@ -169,14 +147,9 @@ end # for eltya
169147

170148
@testset "test triu/tril bounds checking" begin
171149
ainit = rand(5,7)
172-
for arraytype in ("Array", "SubArray")
173-
if arraytype == "Array"
174-
a = ainit
175-
else
176-
a = view(ainit, 1:size(ainit, 1), 1:size(ainit, 2))
177-
end
178-
@test_throws(ArgumentError,triu(a,8))
150+
for a in (copy(ainit), view(ainit, 1:size(ainit, 1), 1:size(ainit, 2)))
179151
@test_throws(ArgumentError,triu(a,-6))
152+
@test_throws(ArgumentError,triu(a,8))
180153
@test_throws(ArgumentError,tril(a,8))
181154
@test_throws(ArgumentError,tril(a,-6))
182155
end
@@ -253,14 +226,7 @@ end
253226
α = elty <: Integer ? randn() :
254227
elty <: Complex ? convert(elty, complex(randn(),randn())) :
255228
convert(elty, randn())
256-
for arraytype in ("Array", "SubArray")
257-
if arraytype == "Array"
258-
x = xinit
259-
y = yinit
260-
else
261-
x = view(xinit,1:2:nnorm)
262-
y = view(yinit,1:2:nnorm)
263-
end
229+
for (x, y) in ((copy(xinit), copy(yinit)), (view(xinit,1:2:nnorm), view(yinit,1:2:nnorm)))
264230
# Absolute homogeneity
265231
@test norm*x,-Inf) abs(α)*norm(x,-Inf)
266232
@test norm*x,-1) abs(α)*norm(x,-1)
@@ -309,16 +275,7 @@ end
309275
α = elty <: Integer ? randn() :
310276
elty <: Complex ? convert(elty, complex(randn(),randn())) :
311277
convert(elty, randn())
312-
313-
for arraytype in ("Array", "SubArray")
314-
if arraytype == "Array"
315-
A = Ainit
316-
B = Binit
317-
else
318-
A = view(Ainit,1:nmat,1:nmat)
319-
B = view(Binit,1:nmat,1:nmat)
320-
end
321-
278+
for (A, B) in ((copy(Ainit), copy(Binit)), (view(Ainit,1:nmat,1:nmat), view(Binit,1:nmat,1:nmat)))
322279
# Absolute homogeneity
323280
@test norm*A,1) abs(α)*norm(A,1)
324281
elty <: Union{BigFloat,Complex{BigFloat},BigInt} || @test norm*A) abs(α)*norm(A) # two is default

test/linalg/diagonal.jl

Lines changed: 65 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ n=12 #Size of matrix problem to test
88
srand(1)
99

1010
@testset for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
11-
d=convert(Vector{elty}, randn(n))
12-
v=convert(Vector{elty}, randn(n))
13-
U=convert(Matrix{elty}, randn(n,n))
11+
dd=convert(Vector{elty}, randn(n))
12+
vv=convert(Vector{elty}, randn(n))
13+
UU=convert(Matrix{elty}, randn(n,n))
1414
if elty <: Complex
15-
d+=im*convert(Vector{elty}, randn(n))
16-
v+=im*convert(Vector{elty}, randn(n))
17-
U+=im*convert(Matrix{elty}, randn(n,n))
15+
dd+=im*convert(Vector{elty}, randn(n))
16+
vv+=im*convert(Vector{elty}, randn(n))
17+
UU+=im*convert(Matrix{elty}, randn(n,n))
1818
end
19-
D = Diagonal(d)
20-
DM = diagm(d)
19+
D = Diagonal(dd)
20+
DM = diagm(dd)
2121

2222
@testset "constructor" begin
23-
for x in (d, GenericArray(d))
23+
for x in (dd, GenericArray(dd))
2424
@test Diagonal(x)::Diagonal{elty,typeof(x)} == DM
2525
@test Diagonal(x).diag === x
2626
@test Diagonal{elty}(x)::Diagonal{elty,typeof(x)} == DM
@@ -38,9 +38,9 @@ srand(1)
3838
@test Array(abs.(D)) == abs.(DM)
3939
@test Array(imag(D)) == imag(DM)
4040

41-
@test parent(D) == d
42-
@test diag(D) == d
43-
@test D[1,1] == d[1]
41+
@test parent(D) == dd
42+
@test diag(D) == dd
43+
@test D[1,1] == dd[1]
4444
@test D[1,2] == 0
4545

4646
@test issymmetric(D)
@@ -73,61 +73,49 @@ srand(1)
7373
end
7474

7575
@testset "Linear solve" begin
76-
let vv = v, UU = U
77-
@testset for atype in ("Array", "SubArray")
78-
if atype == "Array"
79-
v = vv
80-
U = UU
81-
else
82-
v = view(vv, 1:n)
83-
U = view(UU, 1:n, 1:2)
84-
end
85-
86-
@test D*v DM*v atol=n*eps(relty)*(1+(elty<:Complex))
87-
@test D*U DM*U atol=n^2*eps(relty)*(1+(elty<:Complex))
88-
89-
@test U.'*D U.'*Array(D)
90-
@test U'*D U'*Array(D)
91-
92-
if relty != BigFloat
93-
atol_two = 2n^2 * eps(relty) * (1 + (elty <: Complex))
94-
atol_three = 2n^3 * eps(relty) * (1 + (elty <: Complex))
95-
@test D\v DM\v atol=atol_two
96-
@test D\U DM\U atol=atol_three
97-
@test A_ldiv_B!(D, copy(v)) DM\v atol=atol_two
98-
@test At_ldiv_B!(D, copy(v)) DM\v atol=atol_two
99-
@test Ac_ldiv_B!(conj(D), copy(v)) DM\v atol=atol_two
100-
@test A_ldiv_B!(D, copy(U)) DM\U atol=atol_three
101-
@test At_ldiv_B!(D, copy(U)) DM\U atol=atol_three
102-
@test Ac_ldiv_B!(conj(D), copy(U)) DM\U atol=atol_three
103-
Uc = adjoint(U)
104-
target = scale!(Uc, inv.(D.diag))
105-
@test A_rdiv_B!(Uc, D) target atol=atol_three
106-
@test_throws DimensionMismatch A_rdiv_B!(eye(elty, n-1), D)
107-
@test_throws SingularException A_rdiv_B!(Uc, zeros(D))
108-
@test A_rdiv_Bt!(Uc, D) target atol=atol_three
109-
@test A_rdiv_Bc!(Uc, conj(D)) target atol=atol_three
110-
@test A_ldiv_B!(D, eye(D)) D\eye(D) atol=atol_three
111-
@test_throws DimensionMismatch A_ldiv_B!(D, ones(elty, n + 1))
112-
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(relty, n)), copy(v))
113-
b = rand(elty, n, n)
114-
b = sparse(b)
115-
@test A_ldiv_B!(D, copy(b)) Array(D)\Array(b)
116-
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty, n)), copy(b))
117-
b = view(rand(elty, n), collect(1:n))
118-
b2 = copy(b)
119-
c = A_ldiv_B!(D, b)
120-
d = Array(D)\b2
121-
for i in 1:n
122-
@test c[i] d[i]
123-
end
124-
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty, n)), b)
125-
b = rand(elty, n+1, n+1)
126-
b = sparse(b)
127-
@test_throws DimensionMismatch A_ldiv_B!(D, copy(b))
128-
b = view(rand(elty, n+1), collect(1:n+1))
129-
@test_throws DimensionMismatch A_ldiv_B!(D, b)
130-
end
76+
for (v, U) in ((vv, UU), (view(vv, 1:n), view(UU, 1:n, 1:2)))
77+
@test D*v DM*v atol=n*eps(relty)*(1+(elty<:Complex))
78+
@test D*U DM*U atol=n^2*eps(relty)*(1+(elty<:Complex))
79+
80+
@test U.'*D U.'*Array(D)
81+
@test U'*D U'*Array(D)
82+
83+
if relty != BigFloat
84+
atol_two = 2n^2 * eps(relty) * (1 + (elty <: Complex))
85+
atol_three = 2n^3 * eps(relty) * (1 + (elty <: Complex))
86+
@test D\v DM\v atol=atol_two
87+
@test D\U DM\U atol=atol_three
88+
@test A_ldiv_B!(D, copy(v)) DM\v atol=atol_two
89+
@test At_ldiv_B!(D, copy(v)) DM\v atol=atol_two
90+
@test Ac_ldiv_B!(conj(D), copy(v)) DM\v atol=atol_two
91+
@test A_ldiv_B!(D, copy(U)) DM\U atol=atol_three
92+
@test At_ldiv_B!(D, copy(U)) DM\U atol=atol_three
93+
@test Ac_ldiv_B!(conj(D), copy(U)) DM\U atol=atol_three
94+
Uc = adjoint(U)
95+
target = scale!(Uc, inv.(D.diag))
96+
@test A_rdiv_B!(Uc, D) target atol=atol_three
97+
@test_throws DimensionMismatch A_rdiv_B!(eye(elty, n-1), D)
98+
@test_throws SingularException A_rdiv_B!(Uc, zeros(D))
99+
@test A_rdiv_Bt!(Uc, D) target atol=atol_three
100+
@test A_rdiv_Bc!(Uc, conj(D)) target atol=atol_three
101+
@test A_ldiv_B!(D, eye(D)) D\eye(D) atol=atol_three
102+
@test_throws DimensionMismatch A_ldiv_B!(D, ones(elty, n + 1))
103+
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(relty, n)), copy(v))
104+
b = rand(elty, n, n)
105+
b = sparse(b)
106+
@test A_ldiv_B!(D, copy(b)) Array(D)\Array(b)
107+
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty, n)), copy(b))
108+
b = view(rand(elty, n), collect(1:n))
109+
b2 = copy(b)
110+
c = A_ldiv_B!(D, b)
111+
d = Array(D)\b2
112+
@test c d
113+
@test_throws SingularException A_ldiv_B!(Diagonal(zeros(elty, n)), b)
114+
b = rand(elty, n+1, n+1)
115+
b = sparse(b)
116+
@test_throws DimensionMismatch A_ldiv_B!(D, copy(b))
117+
b = view(rand(elty, n+1), collect(1:n+1))
118+
@test_throws DimensionMismatch A_ldiv_B!(D, b)
131119
end
132120
end
133121
end
@@ -163,15 +151,15 @@ srand(1)
163151
@test D\D2 Diagonal(D2.diag./D.diag)
164152

165153
# Performance specialisations for A*_mul_B!
166-
vv = similar(v)
167-
@test (r = full(D) * v ; A_mul_B!(vv, D, v) r vv)
168-
@test (r = full(D)' * v ; Ac_mul_B!(vv, D, v) r vv)
169-
@test (r = full(D).' * v ; At_mul_B!(vv, D, v) r vv)
154+
vvv = similar(vv)
155+
@test (r = full(D) * vv ; A_mul_B!(vvv, D, vv) r vvv)
156+
@test (r = full(D)' * vv ; Ac_mul_B!(vvv, D, vv) r vvv)
157+
@test (r = full(D).' * vv ; At_mul_B!(vvv, D, vv) r vvv)
170158

171-
UU = similar(U)
172-
@test (r = full(D) * U ; A_mul_B!(UU, D, U) r UU)
173-
@test (r = full(D)' * U ; Ac_mul_B!(UU, D, U) r UU)
174-
@test (r = full(D).' * U ; At_mul_B!(UU, D, U) r UU)
159+
UUU = similar(UU)
160+
@test (r = full(D) * UU ; A_mul_B!(UUU, D, UU) r UUU)
161+
@test (r = full(D)' * UU ; Ac_mul_B!(UUU, D, UU) r UUU)
162+
@test (r = full(D).' * UU ; At_mul_B!(UUU, D, UU) r UUU)
175163

176164
# make sure that A_mul_B{c,t}! works with B as a Diagonal
177165
VV = Array(D)
@@ -225,8 +213,8 @@ srand(1)
225213
@test adjoint(D) == conj(D)
226214
end
227215
# Translates to Ac/t_mul_B, which is specialized after issue 21286
228-
@test(D' * v == conj(D) * v)
229-
@test(D.' * v == D * v)
216+
@test(D' * vv == conj(D) * vv)
217+
@test(D.' * vv == D * vv)
230218
end
231219

232220
#logdet

test/linalg/eigen.jl

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ aimg = randn(n,n)/2
1919
aa = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
2020
asym = aa'+aa # symmetric indefinite
2121
apd = aa'*aa # symmetric positive-definite
22-
@testset for atype in ("Array", "SubArray")
23-
if atype == "Array"
24-
a = aa
25-
else
26-
a = view(aa, 1:n, 1:n)
27-
asym = view(asym, 1:n, 1:n)
28-
apd = view(apd, 1:n, 1:n)
29-
end
22+
for (a, asym, apd) in ((aa, asym, apd),
23+
(view(aa, 1:n, 1:n),
24+
view(asym, 1:n, 1:n),
25+
view(apd, 1:n, 1:n)))
3026
ε = εa = eps(abs(float(one(eltya))))
3127

3228
α = rand(eltya)
@@ -56,7 +52,7 @@ aimg = randn(n,n)/2
5652
@test_throws DomainError eigmax(a - a')
5753
end
5854
@testset "symmetric generalized eigenproblem" begin
59-
if atype == "Array"
55+
if isa(a, Array)
6056
asym_sg = asym[1:n1, 1:n1]
6157
a_sg = a[:,n1+1:n2]
6258
else
@@ -77,7 +73,7 @@ aimg = randn(n,n)/2
7773
@test v == f[:vectors]
7874
end
7975
@testset "Non-symmetric generalized eigenproblem" begin
80-
if atype == "Array"
76+
if isa(a, Array)
8177
a1_nsg = a[1:n1, 1:n1]
8278
a2_nsg = a[n1+1:n2, n1+1:n2]
8379
else
@@ -110,12 +106,7 @@ end
110106

111107
# test a matrix larger than 140-by-140 for #14174
112108
let aa = rand(200, 200)
113-
for atype in ("Array", "SubArray")
114-
if atype == "Array"
115-
a = aa
116-
else
117-
a = view(aa, 1:n, 1:n)
118-
end
109+
for a in (aa, view(aa, 1:n, 1:n))
119110
f = eigfact(a)
120111
@test a f[:vectors] * Diagonal(f[:values]) / f[:vectors]
121112
end

0 commit comments

Comments
 (0)