80
80
81
81
82
82
@testset " #1192 The following functions are available for the QR objects: inv, size, and \\ ." begin
83
- @testset " pivot= $pivot " for pivot in [ Val ( true ), Val ( false )] # , ColumnNorm()]
83
+ function test_pivot (pivot)
84
84
y = @SVector rand (5 )
85
85
Y = @SMatrix rand (5 ,5 )
86
86
A = @SMatrix rand (5 ,5 )
@@ -106,17 +106,15 @@ end
106
106
end
107
107
108
108
@testset " solve linear system" begin
109
- x = Matrix (A) \ Vector (y)
110
- @test x ≈ A \ y ≈ F \ y ≈ F \ Vector (y)
109
+ gold_x = Matrix (A) \ Vector (y)
110
+ @test gold_x ≈ A \ y ≈ F \ y ≈ F \ Vector (y)
111
+ @test 0 == @allocated F \ y
111
112
112
- x_under = Matrix (A_under) \ Vector (y)
113
- @test x_under == A_under \ y
114
- @test x_under ≈ F_under \ y
113
+ gold_x_under = Matrix (A_under) \ Vector (y)
114
+ @test gold_x_under == A_under \ y
115
+ @test gold_x_under ≈ F_under \ y
115
116
@test F_under \ y == F_under \ Vector (y)
116
-
117
- x_over = Matrix (A_over) \ Vector (y)
118
- @test x_over ≈ A_over \ y
119
- @test A_over * x_over ≈ y
117
+ @test 0 == @allocated F_under \ y
120
118
121
119
@test_throws DimensionMismatch F_over \ y
122
120
@test_throws DimensionMismatch qr (Matrix (A_over)) \ y
@@ -125,38 +123,46 @@ end
125
123
@testset " solve several linear systems" begin
126
124
@test F \ Y ≈ A \ Y
127
125
@test F_under \ Y ≈ A_under \ Y
126
+ @test 0 == @allocated F \ Y
128
127
end
129
128
130
129
@testset " ldiv!" begin
131
130
x = @MVector zeros (5 )
132
- ldiv! (x, F, y)
131
+ @test 0 == @allocated ldiv! (x, F, y)
133
132
@test x ≈ A \ y
134
133
135
134
X = @MMatrix zeros (5 ,5 )
136
135
Y = @SMatrix rand (5 ,5 )
137
- ldiv! (X, F, Y)
136
+ @test 0 == @allocated ldiv! (X, F, Y)
137
+ @test 0 == @allocated A \ Y
138
138
@test X ≈ A \ Y
139
139
end
140
140
141
141
@testset " invperm" begin
142
- x = @SVector [10 ,15 ,3 ,7 ]
142
+ v = @SVector [10 ,15 ,3 ,7 ]
143
143
p = @SVector [4 ,2 ,1 ,3 ]
144
- @test x == x[p][invperm (p)]
144
+ @test 0 == @allocated invperm (p)
145
+ @test v == v[p][invperm (p)]
145
146
@test StaticArrays. is_identity_perm (p[invperm (p)])
146
- @test_throws Union{BoundsError,ArgumentError} invperm (x )
147
+ @test_throws Union{BoundsError,ArgumentError} invperm (v )
147
148
end
148
149
149
150
@testset " 10x faster" begin
150
- time_to_test = @elapsed ( function ( )
151
- y2 = @SVector rand (50 )
152
- A2 = @SMatrix rand (50 ,5 )
151
+ function speed_test (n, iter )
152
+ y2 = @SVector rand (n )
153
+ A2 = @SMatrix rand (n ,5 )
153
154
F2 = qr (A2, pivot)
154
155
155
- min_time_to_solve = minimum (@elapsed (A2 \ y2) for _ in 1 : 1_000 )
156
- min_time_to_solve_qr = minimum (@elapsed (F2 \ y2) for _ in 1 : 1_000 )
156
+ min_time_to_solve = minimum (@elapsed (A2 \ y2) for _ in 1 : iter )
157
+ min_time_to_solve_qr = minimum (@elapsed (F2 \ y2) for _ in 1 : iter )
157
158
@test 10 min_time_to_solve_qr < min_time_to_solve
158
- end )()
159
- @test time_to_test < 10
159
+ end
160
+ speed_test (50 , 1_000 )
161
+ @test @elapsed (speed_test (50 , 1_000 )) < 1
160
162
end
161
163
end
164
+
165
+ @testset " pivot=$pivot " for pivot in [Val (true ), Val (false )] # , ColumnNorm()]
166
+ test_pivot (pivot)
167
+ end
162
168
end
0 commit comments