Skip to content

Commit 093101c

Browse files
committed
Fixes and tests
1 parent ef39e51 commit 093101c

4 files changed

Lines changed: 76 additions & 1 deletion

File tree

‎ext/TensorKitGPUArraysExt.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function MatrixAlgebraKit.findtruncated_svd(values::GPUSectorVector, strategy::S
8585
return Adapt.adapt(Vector, MatrixAlgebraKit.findtruncated(values, strategy))
8686
end
8787

88-
for strat in (:(MatrixAlgebraKit.TruncationByOrder), :(MatrixAlgebraKit.TruncationByError), :(MatrixAlgebraKit.TruncationIntersection), :(TensorKit.Factorizations.TruncationSpace))
88+
for strat in (:(MatrixAlgebraKit.TruncationByOrder), :(MatrixAlgebraKit.TruncationByError), :(MatrixAlgebraKit.TruncationIntersection), :(MatrixAlgebraKit.TruncationMultiplets), :(TensorKit.Factorizations.TruncationSpace))
8989
@eval function MatrixAlgebraKit.findtruncated_svd(values::GPUSectorVector, strategy::$strat)
9090
# returning a GPUSectorVector wrecks things in truncate_{co}domain
9191
# because of scalar indexing

‎test/amd/factorizations.jl‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,31 @@ for V in spacelist
434434
@test norm(t - U5 * S5 * Vᴴ5) ≈ ϵ5 atol = eps(real(T))^(4 / 5)
435435
@test minimum(diagview(S5)) >= λ
436436
@test abs(dim(domain(S5)) - nvals) ≤ maximum(c -> blockdim(domain(t), c), blocksectors(t); init = 1)
437+
438+
U0, S0, Vᴴ0 = svd_compact(t, alg)
439+
Sd = similar(S0)
440+
copyto!(Sd.data, real(T)[3 - mod(i, 3) for i in 0:(length(Sd.data) - 1)])
441+
td = U0 * Sd * Vᴴ0
442+
rtol = sqrt(eps(real(T)))
443+
_, Sr, _, _ = svd_trunc(td; trunc = truncrank(nvals), alg)
444+
for mode in (:down, :up)
445+
trunc = truncmultiplets(truncrank(nvals); rtol, mode)
446+
U6, S6, Vᴴ6, ϵ6 = @constinferred svd_trunc(td; trunc, alg)
447+
@test td * Vᴴ6' ≈ U6 * S6
448+
@test isisometric(U6)
449+
@test isisometric(Vᴴ6; side = :right)
450+
@test norm(td - U6 * S6 * Vᴴ6) ≈ ϵ6 atol = eps(real(T))^(4 / 5)
451+
if mode == :down
452+
@test space(S6, 1) ≾ space(Sr, 1)
453+
else
454+
@test space(Sr, 1) ≾ space(S6, 1)
455+
end
456+
if dim(domain(S6)) > 0
457+
λ6 = minimum(diagview(S6))
458+
_, S7, _, _ = svd_trunc(td; trunc = trunctol(; atol = λ6 - 1 // 2), alg)
459+
@test space(S6, 1) == space(S7, 1)
460+
end
461+
end
437462
end
438463
end
439464

‎test/cuda/factorizations.jl‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,31 @@ for V in spacelist
453453
@test norm(t - U5 * S5 * Vᴴ5) ≈ ϵ5 atol = eps(real(T))^(4 / 5)
454454
@test minimum(diagview(S5)) >= λ
455455
@test abs(dim(domain(S5)) - nvals) ≤ maximum(c -> blockdim(domain(t), c), blocksectors(t); init = 1)
456+
457+
U0, S0, Vᴴ0 = svd_compact(t)
458+
Sd = similar(S0)
459+
copyto!(Sd.data, real(T)[3 - mod(i, 3) for i in 0:(length(Sd.data) - 1)])
460+
td = U0 * Sd * Vᴴ0
461+
rtol = sqrt(eps(real(T)))
462+
_, Sr, _, _ = svd_trunc(td; trunc = truncrank(nvals))
463+
for mode in (:down, :up)
464+
trunc = truncmultiplets(truncrank(nvals); rtol, mode)
465+
U6, S6, Vᴴ6, ϵ6 = @constinferred svd_trunc(td; trunc)
466+
@test td * Vᴴ6' ≈ U6 * S6
467+
@test isisometric(U6)
468+
@test isisometric(Vᴴ6; side = :right)
469+
@test norm(td - U6 * S6 * Vᴴ6) ≈ ϵ6 atol = eps(real(T))^(4 / 5)
470+
if mode == :down
471+
@test space(S6, 1) ≾ space(Sr, 1)
472+
else
473+
@test space(Sr, 1) ≾ space(S6, 1)
474+
end
475+
if dim(domain(S6)) > 0
476+
λ6 = minimum(diagview(S6))
477+
_, S7, _, _ = svd_trunc(td; trunc = trunctol(; atol = λ6 - 1 // 2))
478+
@test space(S6, 1) == space(S7, 1)
479+
end
480+
end
456481
end
457482
end
458483

‎test/factorizations/svd.jl‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,31 @@ for V in spacelist
290290
@test norm(t - U5 * S5 * Vᴴ5) ≈ ϵ5 atol = eps(real(T))^(4 / 5)
291291
@test minimum(diagview(S5)) >= λ
292292
@test abs(dim(domain(S5)) - nvals) ≤ maximum(c -> blockdim(domain(t), c), blocksectors(t); init = 1)
293+
294+
U0, S0, Vᴴ0 = svd_compact(t)
295+
Sd = similar(S0)
296+
copyto!(Sd.data, real(T)[3 - mod(i, 3) for i in 0:(length(Sd.data) - 1)])
297+
td = U0 * Sd * Vᴴ0
298+
rtol = sqrt(eps(real(T)))
299+
_, Sr, _, _ = svd_trunc(td; trunc = truncrank(nvals))
300+
for mode in (:down, :up)
301+
trunc = truncmultiplets(truncrank(nvals); rtol, mode)
302+
U6, S6, Vᴴ6, ϵ6 = @constinferred svd_trunc(td; trunc)
303+
@test td * Vᴴ6' ≈ U6 * S6
304+
@test isisometric(U6)
305+
@test isisometric(Vᴴ6; side = :right)
306+
@test norm(td - U6 * S6 * Vᴴ6) ≈ ϵ6 atol = eps(real(T))^(4 / 5)
307+
if mode == :down
308+
@test space(S6, 1) ≾ space(Sr, 1)
309+
else
310+
@test space(Sr, 1) ≾ space(S6, 1)
311+
end
312+
if dim(domain(S6)) > 0
313+
λ6 = minimum(diagview(S6))
314+
_, S7, _, _ = svd_trunc(td; trunc = trunctol(; atol = λ6 - 1 // 2))
315+
@test space(S6, 1) == space(S7, 1)
316+
end
317+
end
293318
end
294319
end
295320
end

0 commit comments

Comments
 (0)