@@ -371,19 +371,23 @@ function test_sketched_svd(
371371 return @testset " sketched svd_trunc! algorithm $alg $summary_str " for alg in algs
372372 @assert alg isa SketchedAlgorithm " Invalid sketched algorithm type: $(typeof (alg)) "
373373
374- A = instantiate_rank_deficient_matrix (T, sz; alg. trunc)
375- A += max (atol, rtol * norm (A)) * instantiate_matrix (T, sz)
374+ A = instantiate_almost_rank_deficient_matrix (T, sz; alg. trunc, atol, rtol)
376375 Ac = deepcopy (A)
377376
378377 alg2 = MatrixAlgebraKit. TruncatedAlgorithm (alg)
379378
380379 U, S, Vᴴ, ϵ = @testinferred svd_trunc (A, alg)
381380 @test Ac == A
381+ ϵ′ = norm (A - U * S * Vᴴ)
382+ @test ϵ′ ≈ ϵ atol = sqrt (rtol) * max (one (ϵ′), ϵ′) # comparison to 0 is hard, very imprecise calculation
382383
383- U′, S′, Vᴴ′, ϵ′ = svd_trunc (A, alg2)
384+ U′, S′, Vᴴ′ = svd_trunc_no_error (A, alg2)
385+
386+ # Need gauge fixing for comparison
387+ U, Vᴴ = MatrixAlgebraKit. gaugefix! (svd_trunc!, U, Vᴴ)
388+ U′, Vᴴ′ = MatrixAlgebraKit. gaugefix! (svd_trunc!, U′, Vᴴ′)
384389 @test U ≈ U′ atol = atol rtol = rtol
385390 @test S ≈ S′ atol = atol rtol = rtol
386391 @test Vᴴ ≈ Vᴴ′ atol = atol rtol = rtol
387- @test ϵ ≈ ϵ′ atol = atol rtol = rtol
388392 end
389393end
0 commit comments