@@ -11,7 +11,7 @@ srand(123)
11
11
12
12
debug && println (" Test basic type functionality" )
13
13
@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 ]
15
15
16
16
# 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.
17
17
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
29
29
30
30
# Convert
31
31
@test convert (AbstractMatrix{elty1}, A1) == A1
32
- @test convert (Matrix, A1) == full (A1)
32
+ @test convert (Matrix, A1) == A1
33
33
34
34
# full!
35
- @test full! (copy (A1)) == full (A1)
35
+ @test full! (copy (A1)) == A1
36
36
37
37
# fill!
38
- @test full! (fill! (copy (A1), 1 )) == full ( t1 (ones (size (A1)... ) ))
38
+ @test full! (fill! (copy (A1), 1 )) == t1 (ones (size (A1)... ))
39
39
40
40
# similar
41
41
@test isa (similar (A1), t1)
@@ -51,18 +51,18 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
51
51
@test simA1 == A1
52
52
53
53
# getindex
54
- # # Linear indexing
55
- for i = 1 : length (A1)
56
- @test A1[i] == full (A1)[i]
54
+ let mA1 = Matrix (A1)
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
57
63
end
58
64
@test isa (A1[2 : 4 ,1 ], Vector)
59
65
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
66
66
67
67
# setindex! (and copy)
68
68
A1c = copy (A1)
@@ -106,8 +106,8 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
106
106
# tril/triu
107
107
if uplo1 == :L
108
108
@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 )))
111
111
@test_throws ArgumentError tril! (A1, - n - 2 )
112
112
@test_throws ArgumentError tril! (A1, n)
113
113
@test triu (A1,0 ) == t1 (diagm (diag (A1)))
@@ -117,8 +117,8 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
117
117
@test_throws ArgumentError triu! (A1, n + 2 )
118
118
else
119
119
@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 )))
122
122
@test_throws ArgumentError triu! (A1, - n)
123
123
@test_throws ArgumentError triu! (A1, n + 2 )
124
124
@test tril (A1,0 ) == t1 (diagm (diag (A1)))
@@ -134,11 +134,11 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
134
134
# [c]transpose[!] (test views as well, see issue #14317)
135
135
let vrange = 1 : n- 1 , viewA1 = t1 (view (A1. data, vrange, vrange))
136
136
# transpose
137
- @test full ( A1.' ) == full (A1).'
138
- @test full ( viewA1.' ) == full (viewA1).'
137
+ @test A1.' == Matrix (A1).'
138
+ @test viewA1.' == Matrix (viewA1).'
139
139
# adjoint
140
- @test full ( A1' ) == full (A1)'
141
- @test full ( viewA1' ) == full (viewA1)'
140
+ @test A1' == Matrix (A1)'
141
+ @test viewA1' == Matrix (viewA1)'
142
142
# transpose!
143
143
@test transpose! (copy (A1)) == A1.'
144
144
@test transpose! (t1 (view (copy (A1). data, vrange, vrange))) == viewA1.'
@@ -148,21 +148,21 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
148
148
end
149
149
150
150
# diag
151
- @test diag (A1) == diag (full (A1))
151
+ @test diag (A1) == diag (Matrix (A1))
152
152
153
153
# 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))
157
157
158
158
# Unary operations
159
- @test full ( - A1) == - full (A1)
159
+ @test - A1 == - Matrix (A1)
160
160
161
161
# copy and copy! (test views as well, see issue #14317)
162
162
let vrange = 1 : n- 1 , viewA1 = t1 (view (A1. data, vrange, vrange))
163
163
# 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))
166
166
# copy!
167
167
B = similar (A1)
168
168
copy! (B, A1)
@@ -180,7 +180,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
180
180
181
181
# exp/log
182
182
if (elty1 == Float64 || elty1 == Complex128) && (t1 == UpperTriangular || t1 == LowerTriangular)
183
- @test exp (full (log (A1))) ≈ full (A1)
183
+ @test exp (Matrix (log (A1))) ≈ A1
184
184
end
185
185
186
186
# scale
@@ -218,25 +218,25 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
218
218
end
219
219
220
220
# 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)
225
225
226
226
# 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
229
229
@test isa (inv (A1), t1)
230
230
# make sure the call to LAPACK works right
231
231
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)))
233
233
end
234
234
235
235
# 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
238
238
lada, ladb = logabsdet (A1)
239
- flada, fladb = logabsdet (lufact (full (A1)))
239
+ flada, fladb = logabsdet (lufact (Matrix (A1)))
240
240
@test lada ≈ flada atol= sqrt (eps (real (float (one (elty1)))))* n* n
241
241
@test ladb ≈ fladb atol= sqrt (eps (real (float (one (elty1)))))* n* n
242
242
@@ -250,7 +250,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
250
250
if ! (elty1 in (BigFloat, Complex{BigFloat})) # Not handled yet
251
251
vals, vecs = eig (A1)
252
252
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
254
254
end
255
255
end
256
256
@@ -259,7 +259,7 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
259
259
for p in (1.0 , Inf )
260
260
@test cond (A1,p) ≈ cond (A1,p) atol= (cond (A1,p)+ cond (A1,p))
261
261
end
262
- @test cond (A1,2 ) == cond (full (A1),2 )
262
+ @test cond (A1,2 ) == cond (Matrix (A1),2 )
263
263
end
264
264
265
265
if ! (elty1 in (BigFloat, Complex{BigFloat})) # Not implemented yet
@@ -288,19 +288,19 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
288
288
end
289
289
290
290
# 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)
293
293
294
294
# 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)
304
304
@test_throws DimensionMismatch eye (n+ 1 )/ A2
305
305
@test_throws DimensionMismatch eye (n+ 1 )/ A2.'
306
306
@test_throws DimensionMismatch eye (n+ 1 )/ A2'
@@ -321,29 +321,29 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
321
321
322
322
if ! (eltyB in (BigFloat, Complex{BigFloat})) # rand does not support BigFloat and Complex{BigFloat} as of Dec 2015
323
323
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)
325
325
end
326
326
327
327
# 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)'
347
347
348
348
if eltyB == elty1
349
349
@test A_mul_B! (zeros (B),A1,B) ≈ A1* B
@@ -361,29 +361,29 @@ for elty1 in (Float32, Float64, BigFloat, Complex64, Complex128, Complex{BigFloa
361
361
@test_throws DimensionMismatch Base. LinAlg. A_mul_Bt! (ones (eltyB,n+ 1 ,n+ 1 ),A1)
362
362
363
363
# ... 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'
374
374
@test_throws DimensionMismatch A1\ ones (elty1,n+ 2 )
375
375
@test_throws DimensionMismatch A1' \ ones (elty1,n+ 2 )
376
376
@test_throws DimensionMismatch A1.' \ ones (elty1,n+ 2 )
377
377
if t1 == UpperTriangular || t1 == LowerTriangular
378
378
@test_throws Base. LinAlg. SingularException naivesub! (t1 (zeros (elty1,n,n)),ones (eltyB,n))
379
379
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)'
387
387
388
388
# Error bounds
389
389
! (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)
418
418
419
419
debug && println (" Solve upper triangular system" )
420
420
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
423
423
424
424
debug && println (" Test error estimates" )
425
425
if eltya != BigFloat && eltyb != BigFloat
@@ -446,8 +446,8 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
446
446
447
447
debug && println (" Solve lower triangular system" )
448
448
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
451
451
452
452
debug && println (" Test error estimates" )
453
453
if eltya != BigFloat && eltyb != BigFloat
0 commit comments