Skip to content

Commit dea318f

Browse files
committed
Eliminate full from test/linalg/triangular.jl and test/perf/threads/stockcorr/pstockcorr.jl.
1 parent cbeab1a commit dea318f

File tree

2 files changed

+94
-94
lines changed

2 files changed

+94
-94
lines changed

test/linalg/triangular.jl

+93-93
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ srand(123)
1111

1212
debug && println("Test basic type functionality")
1313
@test_throws DimensionMismatch LowerTriangular(randn(5, 4))
14-
@test LowerTriangular(randn(3, 3)) |> t -> [size(t, i) for i = 1:3] == [size(full(t), i) for i = 1:3]
14+
@test LowerTriangular(randn(3, 3)) |> t -> [size(t, i) for i = 1:3] == [size(Matrix(t), i) for i = 1:3]
1515

1616
# The following test block tries to call all methods in base/linalg/triangular.jl in order for a combination of input element types. Keep the ordering when adding code.
1717
for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloat}, Int)
@@ -29,13 +29,13 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
2929

3030
# Convert
3131
@test convert(AbstractMatrix{elty1}, A1) == A1
32-
@test convert(Matrix, A1) == full(A1)
32+
@test convert(Matrix, A1) == A1
3333

3434
# full!
35-
@test full!(copy(A1)) == full(A1)
35+
@test full!(copy(A1)) == A1
3636

3737
# fill!
38-
@test full!(fill!(copy(A1), 1)) == full(t1(ones(size(A1)...)))
38+
@test full!(fill!(copy(A1), 1)) == t1(ones(size(A1)...))
3939

4040
# similar
4141
@test isa(similar(A1), t1)
@@ -51,18 +51,18 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
5151
@test simA1 == A1
5252

5353
# getindex
54-
## Linear indexing
55-
for i = 1:length(A1)
56-
@test A1[i] == full(A1)[i]
54+
let mA1 = matrixA1
55+
# linear indexing
56+
for i in 1:length(A1)
57+
@test A1[i] == mA1[i]
58+
end
59+
# cartesian indexing
60+
for i in 1:size(A1, 1), j in 1:size(A1, 2)
61+
@test A1[i,j] == mA1[i,j]
62+
end
5763
end
5864
@test isa(A1[2:4,1], Vector)
5965

60-
## Cartesian indexing
61-
for i = 1:size(A1, 1)
62-
for j = 1:size(A1, 2)
63-
@test A1[i,j] == full(A1)[i,j]
64-
end
65-
end
6666

6767
# setindex! (and copy)
6868
A1c = copy(A1)
@@ -106,8 +106,8 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
106106
#tril/triu
107107
if uplo1 == :L
108108
@test tril(A1,0) == A1
109-
@test tril(A1,-1) == LowerTriangular(tril(full(A1),-1))
110-
@test tril(A1,1) == t1(tril(tril(full(A1),1)))
109+
@test tril(A1,-1) == LowerTriangular(tril(Matrix(A1), -1))
110+
@test tril(A1,1) == t1(tril(tril(Matrix(A1), 1)))
111111
@test_throws ArgumentError tril!(A1, -n - 2)
112112
@test_throws ArgumentError tril!(A1, n)
113113
@test triu(A1,0) == t1(diagm(diag(A1)))
@@ -117,8 +117,8 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
117117
@test_throws ArgumentError triu!(A1, n + 2)
118118
else
119119
@test triu(A1,0) == A1
120-
@test triu(A1,1) == UpperTriangular(triu(full(A1),1))
121-
@test triu(A1,-1) == t1(triu(triu(full(A1),-1)))
120+
@test triu(A1,1) == UpperTriangular(triu(Matrix(A1), 1))
121+
@test triu(A1,-1) == t1(triu(triu(Matrix(A1), -1)))
122122
@test_throws ArgumentError triu!(A1, -n)
123123
@test_throws ArgumentError triu!(A1, n + 2)
124124
@test tril(A1,0) == t1(diagm(diag(A1)))
@@ -134,11 +134,11 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
134134
# [c]transpose[!] (test views as well, see issue #14317)
135135
let vrange = 1:n-1, viewA1 = t1(view(A1.data, vrange, vrange))
136136
# transpose
137-
@test full(A1.') == full(A1).'
138-
@test full(viewA1.') == full(viewA1).'
137+
@test A1.' == Matrix(A1).'
138+
@test viewA1.' == Matrix(viewA1).'
139139
# adjoint
140-
@test full(A1') == full(A1)'
141-
@test full(viewA1') == full(viewA1)'
140+
@test A1' == Matrix(A1)'
141+
@test viewA1' == Matrix(viewA1)'
142142
# transpose!
143143
@test transpose!(copy(A1)) == A1.'
144144
@test transpose!(t1(view(copy(A1).data, vrange, vrange))) == viewA1.'
@@ -148,21 +148,21 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
148148
end
149149

150150
# diag
151-
@test diag(A1) == diag(full(A1))
151+
@test diag(A1) == diag(Matrix(A1))
152152

153153
# real
154-
@test full(real(A1)) == real(full(A1))
155-
@test full(imag(A1)) == imag(full(A1))
156-
@test full(abs.(A1)) == abs.(full(A1))
154+
@test real(A1) == real(Matrix(A1))
155+
@test imag(A1) == imag(Matrix(A1))
156+
@test abs.(A1) == abs.(Matrix(A1))
157157

158158
# Unary operations
159-
@test full(-A1) == -full(A1)
159+
@test -A1 == -Matrix(A1)
160160

161161
# copy and copy! (test views as well, see issue #14317)
162162
let vrange = 1:n-1, viewA1 = t1(view(A1.data, vrange, vrange))
163163
# copy
164-
@test copy(A1) == copy(full(A1))
165-
@test copy(viewA1) == copy(full(viewA1))
164+
@test copy(A1) == copy(Matrix(A1))
165+
@test copy(viewA1) == copy(Matrix(viewA1))
166166
# copy!
167167
B = similar(A1)
168168
copy!(B, A1)
@@ -180,7 +180,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
180180

181181
#exp/log
182182
if (elty1 == Float64 || elty1 == Complex128) && (t1 == UpperTriangular || t1 == LowerTriangular)
183-
@test exp(full(log(A1))) full(A1)
183+
@test exp(Matrix(log(A1))) A1
184184
end
185185

186186
# scale
@@ -218,25 +218,25 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
218218
end
219219

220220
# Binary operations
221-
@test A1*0.5 == full(A1)*0.5
222-
@test 0.5*A1 == 0.5*full(A1)
223-
@test A1/0.5 == full(A1)/0.5
224-
@test 0.5\A1 == 0.5\full(A1)
221+
@test A1*0.5 == Matrix(A1)*0.5
222+
@test 0.5*A1 == 0.5*Matrix(A1)
223+
@test A1/0.5 == Matrix(A1)/0.5
224+
@test 0.5\A1 == 0.5\Matrix(A1)
225225

226226
# inversion
227-
@test inv(A1) inv(lufact(full(A1)))
228-
inv(full(A1)) # issue #11298
227+
@test inv(A1) inv(lufact(Matrix(A1)))
228+
inv(Matrix(A1)) # issue #11298
229229
@test isa(inv(A1), t1)
230230
# make sure the call to LAPACK works right
231231
if elty1 <: BlasFloat
232-
@test Base.LinAlg.inv!(copy(A1)) inv(lufact(full(A1)))
232+
@test Base.LinAlg.inv!(copy(A1)) inv(lufact(Matrix(A1)))
233233
end
234234

235235
# Determinant
236-
@test det(A1) det(lufact(full(A1))) atol=sqrt(eps(real(float(one(elty1)))))*n*n
237-
@test logdet(A1) logdet(lufact(full(A1))) atol=sqrt(eps(real(float(one(elty1)))))*n*n
236+
@test det(A1) det(lufact(Matrix(A1))) atol=sqrt(eps(real(float(one(elty1)))))*n*n
237+
@test logdet(A1) logdet(lufact(Matrix(A1))) atol=sqrt(eps(real(float(one(elty1)))))*n*n
238238
lada, ladb = logabsdet(A1)
239-
flada, fladb = logabsdet(lufact(full(A1)))
239+
flada, fladb = logabsdet(lufact(Matrix(A1)))
240240
@test lada flada atol=sqrt(eps(real(float(one(elty1)))))*n*n
241241
@test ladb fladb atol=sqrt(eps(real(float(one(elty1)))))*n*n
242242

@@ -250,7 +250,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
250250
if !(elty1 in (BigFloat, Complex{BigFloat})) # Not handled yet
251251
vals, vecs = eig(A1)
252252
if (t1 == UpperTriangular || t1 == LowerTriangular) && elty1 != Int # Cannot really handle degenerate eigen space and Int matrices will probably have repeated eigenvalues.
253-
@test vecs*diagm(vals)/vecs full(A1) atol=sqrt(eps(float(real(one(vals[1])))))*(norm(A1,Inf)*n)^2
253+
@test vecs*diagm(vals)/vecs A1 atol=sqrt(eps(float(real(one(vals[1])))))*(norm(A1,Inf)*n)^2
254254
end
255255
end
256256

@@ -259,7 +259,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
259259
for p in (1.0, Inf)
260260
@test cond(A1,p) cond(A1,p) atol=(cond(A1,p)+cond(A1,p))
261261
end
262-
@test cond(A1,2) == cond(full(A1),2)
262+
@test cond(A1,2) == cond(Matrix(A1),2)
263263
end
264264

265265
if !(elty1 in (BigFloat, Complex{BigFloat})) # Not implemented yet
@@ -288,19 +288,19 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
288288
end
289289

290290
# Binary operations
291-
@test full(A1 + A2) == full(A1) + full(A2)
292-
@test full(A1 - A2) == full(A1) - full(A2)
291+
@test A1 + A2 == Matrix(A1) + Matrix(A2)
292+
@test A1 - A2 == Matrix(A1) - Matrix(A2)
293293

294294
# Triangular-Triangualar multiplication and division
295-
@test full(A1*A2) full(A1)*full(A2)
296-
@test full(A1.'A2) full(A1).'full(A2)
297-
@test full(A1'A2) full(A1)'full(A2)
298-
@test full(A1*A2.') full(A1)*full(A2).'
299-
@test full(A1*A2') full(A1)*full(A2)'
300-
@test full(A1.'A2.') full(A1).'full(A2).'
301-
@test full(A1'A2') full(A1)'full(A2)'
302-
@test full(A1/A2) full(A1)/full(A2)
303-
@test full(A1\A2) full(A1)\full(A2)
295+
@test A1*A2 Matrix(A1)*Matrix(A2)
296+
@test A1.'A2 Matrix(A1).'Matrix(A2)
297+
@test A1'A2 Matrix(A1)'Matrix(A2)
298+
@test A1*A2.' Matrix(A1)*Matrix(A2).'
299+
@test A1*A2' Matrix(A1)*Matrix(A2)'
300+
@test A1.'A2.' Matrix(A1).'Matrix(A2).'
301+
@test A1'A2' Matrix(A1)'Matrix(A2)'
302+
@test A1/A2 Matrix(A1)/Matrix(A2)
303+
@test A1\A2 Matrix(A1)\Matrix(A2)
304304
@test_throws DimensionMismatch eye(n+1)/A2
305305
@test_throws DimensionMismatch eye(n+1)/A2.'
306306
@test_throws DimensionMismatch eye(n+1)/A2'
@@ -321,29 +321,29 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
321321

322322
if !(eltyB in (BigFloat, Complex{BigFloat})) # rand does not support BigFloat and Complex{BigFloat} as of Dec 2015
323323
Tri = Tridiagonal(rand(eltyB,n-1),rand(eltyB,n),rand(eltyB,n-1))
324-
@test Base.LinAlg.A_mul_B!(Tri,copy(A1)) Tri*full(A1)
324+
@test Base.LinAlg.A_mul_B!(Tri,copy(A1)) Tri*Matrix(A1)
325325
end
326326

327327
# Triangular-dense Matrix/vector multiplication
328-
@test A1*B[:,1] full(A1)*B[:,1]
329-
@test A1*B full(A1)*B
330-
@test A1.'B[:,1] full(A1).'B[:,1]
331-
@test A1'B[:,1] full(A1)'B[:,1]
332-
@test A1.'B full(A1).'B
333-
@test A1'B full(A1)'B
334-
@test A1*B.' full(A1)*B.'
335-
@test A1*B' full(A1)*B'
336-
@test B*A1 B*full(A1)
337-
@test B[:,1].'A1 B[:,1].'full(A1)
338-
@test B[:,1]'A1 B[:,1]'full(A1)
339-
@test B.'A1 B.'full(A1)
340-
@test B'A1 B'full(A1)
341-
@test B*A1.' B*full(A1).'
342-
@test B*A1' B*full(A1)'
343-
@test B[:,1].'A1.' B[:,1].'full(A1).'
344-
@test B[:,1]'A1' B[:,1]'full(A1)'
345-
@test B.'A1.' B.'full(A1).'
346-
@test B'A1' B'full(A1)'
328+
@test A1*B[:,1] Matrix(A1)*B[:,1]
329+
@test A1*B Matrix(A1)*B
330+
@test A1.'B[:,1] Matrix(A1).'B[:,1]
331+
@test A1'B[:,1] Matrix(A1)'B[:,1]
332+
@test A1.'B Matrix(A1).'B
333+
@test A1'B Matrix(A1)'B
334+
@test A1*B.' Matrix(A1)*B.'
335+
@test A1*B' Matrix(A1)*B'
336+
@test B*A1 B*Matrix(A1)
337+
@test B[:,1].'A1 B[:,1].'Matrix(A1)
338+
@test B[:,1]'A1 B[:,1]'Matrix(A1)
339+
@test B.'A1 B.'Matrix(A1)
340+
@test B'A1 B'Matrix(A1)
341+
@test B*A1.' B*Matrix(A1).'
342+
@test B*A1' B*Matrix(A1)'
343+
@test B[:,1].'A1.' B[:,1].'Matrix(A1).'
344+
@test B[:,1]'A1' B[:,1]'Matrix(A1)'
345+
@test B.'A1.' B.'Matrix(A1).'
346+
@test B'A1' B'Matrix(A1)'
347347

348348
if eltyB == elty1
349349
@test A_mul_B!(zeros(B),A1,B) A1*B
@@ -361,29 +361,29 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
361361
@test_throws DimensionMismatch Base.LinAlg.A_mul_Bt!(ones(eltyB,n+1,n+1),A1)
362362

363363
# ... and division
364-
@test A1\B[:,1] full(A1)\B[:,1]
365-
@test A1\B full(A1)\B
366-
@test A1.'\B[:,1] full(A1).'\B[:,1]
367-
@test A1'\B[:,1] full(A1)'\B[:,1]
368-
@test A1.'\B full(A1).'\B
369-
@test A1'\B full(A1)'\B
370-
@test A1\B.' full(A1)\B.'
371-
@test A1\B' full(A1)\B'
372-
@test A1.'\B.' full(A1).'\B.'
373-
@test A1'\B' full(A1)'\B'
364+
@test A1\B[:,1] Matrix(A1)\B[:,1]
365+
@test A1\B Matrix(A1)\B
366+
@test A1.'\B[:,1] Matrix(A1).'\B[:,1]
367+
@test A1'\B[:,1] Matrix(A1)'\B[:,1]
368+
@test A1.'\B Matrix(A1).'\B
369+
@test A1'\B Matrix(A1)'\B
370+
@test A1\B.' Matrix(A1)\B.'
371+
@test A1\B' Matrix(A1)\B'
372+
@test A1.'\B.' Matrix(A1).'\B.'
373+
@test A1'\B' Matrix(A1)'\B'
374374
@test_throws DimensionMismatch A1\ones(elty1,n+2)
375375
@test_throws DimensionMismatch A1'\ones(elty1,n+2)
376376
@test_throws DimensionMismatch A1.'\ones(elty1,n+2)
377377
if t1 == UpperTriangular || t1 == LowerTriangular
378378
@test_throws Base.LinAlg.SingularException naivesub!(t1(zeros(elty1,n,n)),ones(eltyB,n))
379379
end
380-
@test B/A1 B/full(A1)
381-
@test B/A1.' B/full(A1).'
382-
@test B/A1' B/full(A1)'
383-
@test B.'/A1 B.'/full(A1)
384-
@test B'/A1 B'/full(A1)
385-
@test B.'/A1.' B.'/full(A1).'
386-
@test B'/A1' B'/full(A1)'
380+
@test B/A1 B/Matrix(A1)
381+
@test B/A1.' B/Matrix(A1).'
382+
@test B/A1' B/Matrix(A1)'
383+
@test B.'/A1 B.'/Matrix(A1)
384+
@test B'/A1 B'/Matrix(A1)
385+
@test B.'/A1.' B.'/Matrix(A1).'
386+
@test B'/A1' B'/Matrix(A1)'
387387

388388
# Error bounds
389389
!(elty1 in (BigFloat, Complex{BigFloat})) && !(eltyB in (BigFloat, Complex{BigFloat})) && errorbounds(A1, A1\B, B)
@@ -418,8 +418,8 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
418418

419419
debug && println("Solve upper triangular system")
420420
Atri = UpperTriangular(lufact(A)[:U]) |> t -> eltya <: Complex && eltyb <: Real ? real(t) : t # Here the triangular matrix can't be too badly conditioned
421-
b = convert(Matrix{eltyb}, eltya <: Complex ? full(Atri)*ones(n, 2) : full(Atri)*ones(n, 2))
422-
x = full(Atri) \ b
421+
b = convert(Matrix{eltyb}, eltya <: Complex ? Matrix(Atri)*ones(n, 2) : Matrix(Atri)*ones(n, 2))
422+
x = Matrix(Atri) \ b
423423

424424
debug && println("Test error estimates")
425425
if eltya != BigFloat && eltyb != BigFloat
@@ -446,8 +446,8 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
446446

447447
debug && println("Solve lower triangular system")
448448
Atri = UpperTriangular(lufact(A)[:U]) |> t -> eltya <: Complex && eltyb <: Real ? real(t) : t # Here the triangular matrix can't be too badly conditioned
449-
b = convert(Matrix{eltyb}, eltya <: Complex ? full(Atri)*ones(n, 2) : full(Atri)*ones(n, 2))
450-
x = full(Atri)\b
449+
b = convert(Matrix{eltyb}, eltya <: Complex ? Matrix(Atri)*ones(n, 2) : Matrix(Atri)*ones(n, 2))
450+
x = Matrix(Atri)\b
451451

452452
debug && println("Test error estimates")
453453
if eltya != BigFloat && eltyb != BigFloat

test/perf/threads/stockcorr/pstockcorr.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function pstockcorr(n)
7878
SimulPriceB[1,:] = CurrentPrice[2]
7979

8080
## Generating the paths of stock prices by Geometric Brownian Motion
81-
UpperTriangle = full(chol(Corr)) # UpperTriangle Matrix by Cholesky decomposition
81+
UpperTriangle = Matrix(chol(Corr)) # UpperTriangle Matrix by Cholesky decomposition
8282

8383
# Optimization: pre-allocate these for performance
8484
# NOTE: the new GC will hopefully fix this, but currently GC time

0 commit comments

Comments
 (0)