Skip to content

Commit 4f2bc30

Browse files
committed
add nullspace truncation specializations
1 parent 196cee1 commit 4f2bc30

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/factorizations/truncation.jl

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ function MAK.truncate(
7676
end
7777

7878
function MAK.truncate(
79-
::typeof(left_null!),
80-
(U, S)::Tuple{AbstractTensorMap, AbstractTensorMap},
81-
strategy::MatrixAlgebraKit.TruncationStrategy
79+
::typeof(left_null!), (U, S)::NTuple{2, AbstractTensorMap}, strategy::TruncationStrategy
8280
)
8381
extended_S = SectorDict(
8482
c => vcat(diagview(b), zeros(eltype(b), max(0, size(b, 2) - size(b, 1))))
@@ -90,6 +88,40 @@ function MAK.truncate(
9088
truncate_domain!(Ũ, U, ind)
9189
return Ũ, ind
9290
end
91+
function MAK.truncate(
92+
::typeof(right_null!), (S, Vᴴ)::NTuple{2, AbstractTensorMap}, strategy::TruncationStrategy
93+
)
94+
extended_S = SectorDict(
95+
c => vcat(diagview(b), zeros(eltype(b), max(0, size(b, 1) - size(b, 2))))
96+
for (c, b) in blocks(S)
97+
)
98+
ind = MAK.findtruncated(extended_S, strategy)
99+
V_truncated = truncate_space(space(Vᴴ, 1), ind)
100+
Ṽᴴ = similar(Vᴴ, V_truncated domain(Vᴴ))
101+
truncate_codomain!(Ṽᴴ, Vᴴ, ind)
102+
return Ṽᴴ, ind
103+
end
104+
105+
# special case `NoTruncation` for null: should keep exact zeros due to rectangularity
106+
# need to specialize to avoid ambiguity with special case in MatrixAlgebraKit
107+
function MAK.truncate(
108+
::typeof(left_null!), (U, S)::NTuple{2, AbstractTensorMap}, strategy::NoTruncation
109+
)
110+
ind = SectorDict(c => (size(b, 2) + 1):size(b, 1) for (c, b) in blocks(S))
111+
V_truncated = truncate_space(space(S, 1), ind)
112+
= similar(U, codomain(U) V_truncated)
113+
truncate_domain!(Ũ, U, ind)
114+
return Ũ, ind
115+
end
116+
function MAK.truncate(
117+
::typeof(right_null!), (S, Vᴴ)::NTuple{2, AbstractTensorMap}, strategy::NoTruncation
118+
)
119+
ind = SectorDict(c => (size(b, 1) + 1):size(b, 2) for (c, b) in blocks(S))
120+
V_truncated = truncate_space(space(Vᴴ, 1), ind)
121+
Ṽᴴ = similar(Vᴴ, V_truncated domain(Vᴴ))
122+
truncate_codomain!(Ṽᴴ, Vᴴ, ind)
123+
return Ṽᴴ, ind
124+
end
93125

94126
for f! in (:eig_trunc!, :eigh_trunc!)
95127
@eval function MAK.truncate(

0 commit comments

Comments
 (0)