-
Notifications
You must be signed in to change notification settings - Fork 5
Add TruncationUnion to support supplying minimal ranks
#183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e2d59d7
4320dcd
0fd7a90
f22622c
9753b3f
3760c3c
7a56644
d6524a7
84e6e1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,29 @@ function test_svd_trunc( | |
| @test diagview(S2) ≈ diagview(S)[1:2] | ||
| end | ||
| end | ||
| @testset "mix minrank and tol" begin | ||
| m4 = 4 | ||
| U = instantiate_unitary(T, A, m4) | ||
| Sdiag = similar(A, real(eltype(T)), m4) | ||
| copyto!(Sdiag, [0.9, 0.3, 0.1, 0.01]) | ||
| S = Diagonal(Sdiag) | ||
| Vᴴ = instantiate_unitary(T, A, m4) | ||
| A = U * S * Vᴴ | ||
| for trunc_fun in ( | ||
| (rtol, minrank) -> (; rtol, minrank), | ||
| (rtol, minrank) -> trunctol(; rtol) | truncrank(minrank), | ||
| ) | ||
| # trunctol(rtol=0.5) keeps 1 value, truncrank(3) keeps 3, union keeps 3 | ||
| U1, S1, V1ᴴ, ϵ1 = svd_trunc(A; trunc = trunc_fun(0.5, 3)) | ||
| @test length(diagview(S1)) == 3 | ||
| @test diagview(S1) ≈ diagview(S)[1:3] | ||
|
|
||
| # trunctol(rtol=0.2) keeps 2 values, truncrank(1) keeps 1, union keeps 2 | ||
| U2, S2, V2ᴴ = svd_trunc_no_error(A; trunc = trunc_fun(0.2, 1)) | ||
| @test length(diagview(S2)) == 2 | ||
| @test diagview(S2) ≈ diagview(S)[1:2] | ||
| end | ||
| end | ||
| @testset "specify truncation algorithm" begin | ||
| atol = sqrt(eps(real(eltype(T)))) | ||
| m4 = 4 | ||
|
|
@@ -294,6 +317,29 @@ function test_svd_trunc_algs( | |
| @test collect(diagview(S2)) ≈ collect(diagview(S)[1:2]) | ||
| end | ||
| end | ||
| @testset "mix minrank and tol" begin | ||
| m4 = 4 | ||
| U = instantiate_unitary(T, A, m4) | ||
| Sdiag = similar(A, real(eltype(T)), m4) | ||
| copyto!(Sdiag, real(eltype(T))[0.9, 0.3, 0.1, 0.01]) | ||
| S = Diagonal(Sdiag) | ||
| Vᴴ = instantiate_unitary(T, A, m4) | ||
| A = U * S * Vᴴ | ||
| for trunc_fun in ( | ||
| (rtol, minrank) -> (; rtol, minrank), | ||
| (rtol, minrank) -> trunctol(; rtol) | truncrank(minrank), | ||
| ) | ||
| # trunctol(rtol=0.5) keeps 1 value, truncrank(3) keeps 3, union keeps 3 | ||
| U1, S1, V1ᴴ, ϵ1 = svd_trunc(A; trunc = trunc_fun(0.5, 3), alg) | ||
| @test length(diagview(S1)) == 3 | ||
| @test collect(diagview(S1)) ≈ collect(diagview(S)[1:3]) | ||
|
|
||
| # trunctol(rtol=0.2) keeps 2 values, truncrank(1) keeps 1, union keeps 2 | ||
| U2, S2, V2ᴴ, ϵ2 = svd_trunc(A; trunc = trunc_fun(0.2, 1), alg) | ||
| @test length(diagview(S2)) == 2 | ||
| @test collect(diagview(S2)) ≈ collect(diagview(S)[1:2]) | ||
| end | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am probably too tired, but this looks like two times the same identical block of code / set of tests?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, but with the addition of the |
||
| @testset "specify truncation algorithm" begin | ||
| atol = sqrt(eps(real(eltype(T)))) | ||
| m4 = 4 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the tolerance be both/either relative/absolute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes to all, although for this particular set of examples I think the focus is more on the fact that you can combine them, not necessarily on what
trunctolaccepts, which should be listed in the docstrings