1- using GradedArrays: FusedGradedMatrix, FusedGradedVector, GradedBlockAlgorithm, U1, Z2
2- using LinearAlgebra: Diagonal, I, eigvals, norm, istril, istriu, isposdef
31import MatrixAlgebraKit as MAK
2+ using GradedArrays: FusedGradedMatrix, FusedGradedVector, GradedBlockAlgorithm, U1, Z2
3+ using LinearAlgebra: Diagonal, I, eigvals, isposdef, istril, istriu, norm
44using MatrixAlgebraKit: isisometric, isunitary
55using Test: @test , @testset
66
@@ -30,11 +30,13 @@ function has_positive_diagonal(A)
3030 all (≈ (zero (real (T))), imag (diagview (A)))
3131 end
3232end
33- isleftnull (N, A; atol:: Real = 0 , rtol:: Real = precision (eltype (A))) =
34- isapprox (norm (A' * N), 0 ; atol = max (atol, norm (A) * rtol))
33+ function isleftnull (N, A; atol:: Real = 0 , rtol:: Real = precision (eltype (A)))
34+ return isapprox (norm (A' * N), 0 ; atol = max (atol, norm (A) * rtol))
35+ end
3536
36- isrightnull (Nᴴ, A; atol:: Real = 0 , rtol:: Real = precision (eltype (A))) =
37- isapprox (norm (A * Nᴴ' ), 0 ; atol = max (atol, norm (A) * rtol))
37+ function isrightnull (Nᴴ, A; atol:: Real = 0 , rtol:: Real = precision (eltype (A)))
38+ return isapprox (norm (A * Nᴴ' ), 0 ; atol = max (atol, norm (A) * rtol))
39+ end
3840
3941@testset " Factorizations" begin
4042
@@ -108,7 +110,7 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
108110 @test isapprox (
109111 sort (S. blocks[i]; rev = true ),
110112 sort (MAK. diagview (S2. blocks[i]); rev = true );
111- atol = 1.0e-10 ,
113+ atol = 1.0e-10
112114 )
113115 end
114116 end
@@ -156,7 +158,6 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
156158 end
157159 end
158160
159-
160161 # -----------------------------------------------------------------------
161162 @testset " LQ" begin
162163 @testset " compact" begin
@@ -225,7 +226,7 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
225226 @test isapprox (
226227 sort (D. blocks[i]; by = real),
227228 sort (MAK. diagview (D2. blocks[i]); by = real);
228- atol = 1.0e-10 ,
229+ atol = 1.0e-10
229230 )
230231 end
231232 end
@@ -256,7 +257,7 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
256257 @test isapprox (
257258 sort (real .(D. blocks[i])),
258259 sort (real .(MAK. diagview (D2. blocks[i])));
259- atol = 1.0e-10 ,
260+ atol = 1.0e-10
260261 )
261262 end
262263 end
@@ -295,14 +296,14 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
295296 using MatrixAlgebraKit: notrunc, truncrank, trunctol, truncerror
296297
297298 @testset " notrunc" begin
298- U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc= notrunc ())
299+ U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc = notrunc ())
299300 @test U isa FusedGradedMatrix
300301 @test S isa FusedGradedMatrix
301302 @test Vᴴ isa FusedGradedMatrix
302303 @test ε ≈ 0 atol = precision (eltype (A_rect))
303304 @test A_rect ≈ U * S * Vᴴ
304305 @test isisometric (U)
305- @test isisometric (Vᴴ; side= :right )
306+ @test isisometric (Vᴴ; side = :right )
306307
307308 # same sectors as compact SVD
308309 U0, S0, Vᴴ0 = MAK. svd_compact (A_rect)
@@ -312,19 +313,19 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
312313
313314 @testset " truncrank" begin
314315 maxrank = 4
315- U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc= truncrank (maxrank))
316+ U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc = truncrank (maxrank))
316317 @test U isa FusedGradedMatrix
317318 # total number of kept singular values ≤ maxrank
318319 @test sum (size (b, 2 ) for b in U. blocks) <= maxrank
319320 # reconstruction error ≈ reported truncation error
320321 @test norm (A_rect - U * S * Vᴴ) ≈ ε atol = precision (eltype (A_rect))
321322 @test isisometric (U)
322- @test isisometric (Vᴴ; side= :right )
323+ @test isisometric (Vᴴ; side = :right )
323324 end
324325
325326 @testset " trunctol" begin
326327 atol = 0.5
327- U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc= trunctol (; atol))
328+ U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc = trunctol (; atol))
328329 @test U isa FusedGradedMatrix
329330 # all kept singular values are above the tolerance
330331 for b in S. blocks
@@ -335,14 +336,15 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
335336
336337 @testset " truncerror" begin
337338 atol = 0.3
338- U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc= truncerror (; atol))
339+ U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc = truncerror (; atol))
339340 @test U isa FusedGradedMatrix
340341 @test ε <= atol + precision (eltype (A_rect))
341342 @test norm (A_rect - U * S * Vᴴ) ≈ ε atol = precision (eltype (A_rect))
342343 end
343344
344345 @testset " combined (truncrank & trunctol)" begin
345- U, S, Vᴴ, ε = MAK. svd_trunc (A_rect; trunc= truncrank (3 ) & trunctol (; atol= 0.3 ))
346+ U, S, Vᴴ, ε =
347+ MAK. svd_trunc (A_rect; trunc = truncrank (3 ) & trunctol (; atol = 0.3 ))
346348 @test U isa FusedGradedMatrix
347349 @test sum (size (b, 2 ) for b in U. blocks) <= 3
348350 for b in S. blocks
@@ -351,7 +353,7 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
351353 end
352354
353355 @testset " svd_trunc_no_error" begin
354- U, S, Vᴴ = MAK. svd_trunc_no_error (A_rect; trunc= truncrank (3 ))
356+ U, S, Vᴴ = MAK. svd_trunc_no_error (A_rect; trunc = truncrank (3 ))
355357 @test U isa FusedGradedMatrix
356358 @test sum (size (b, 2 ) for b in U. blocks) <= 3
357359 end
@@ -362,7 +364,7 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
362364 using MatrixAlgebraKit: notrunc, truncrank, trunctol, truncerror
363365
364366 @testset " notrunc" begin
365- D, V, ε = MAK. eigh_trunc (A_herm; trunc= notrunc ())
367+ D, V, ε = MAK. eigh_trunc (A_herm; trunc = notrunc ())
366368 @test D isa FusedGradedMatrix
367369 @test V isa FusedGradedMatrix
368370 @test ε ≈ 0 atol = precision (eltype (A_herm))
@@ -373,15 +375,15 @@ isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
373375
374376 @testset " truncrank" begin
375377 maxrank = 5
376- D, V, ε = MAK. eigh_trunc (A_herm; trunc= truncrank (maxrank))
378+ D, V, ε = MAK. eigh_trunc (A_herm; trunc = truncrank (maxrank))
377379 @test D isa FusedGradedMatrix
378380 @test sum (size (b, 2 ) for b in V. blocks) <= maxrank
379381 @test isisometric (V)
380382 end
381383
382384 @testset " trunctol (keep largest by abs)" begin
383385 atol = 0.3
384- D, V, ε = MAK. eigh_trunc (A_herm; trunc= trunctol (; atol))
386+ D, V, ε = MAK. eigh_trunc (A_herm; trunc = trunctol (; atol))
385387 @test D isa FusedGradedMatrix
386388 for b in D. blocks
387389 @test all (≥ (atol) ∘ abs, MAK. diagview (b))
0 commit comments