Skip to content

Commit 3718571

Browse files
committed
Refactor truncation slightly
1 parent 5934671 commit 3718571

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/factorizations/truncation.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,23 @@ function MatrixAlgebraKit.truncate!(
2424
)
2525
end
2626

27+
# cannot use regular slicing here: I want to slice without altering blockstructure
28+
# solution: use boolean indexing and slice the mask, effectively cheaply inverting the map
29+
function MatrixAlgebraKit.findtruncated(
30+
values::AbstractVector, strategy::BlockPermutedDiagonalTruncationStrategy
31+
)
32+
ind = MatrixAlgebraKit.findtruncated(values, strategy.strategy)
33+
indexmask = falses(length(values))
34+
indexmask[ind] .= true
35+
return indexmask
36+
end
37+
2738
function MatrixAlgebraKit.truncate!(
2839
::typeof(svd_trunc!),
2940
(U, S, Vᴴ)::TBlockUSVᴴ,
3041
strategy::BlockPermutedDiagonalTruncationStrategy,
3142
)
32-
ind = MatrixAlgebraKit.findtruncated(diagview(S), strategy.strategy)
33-
# cannot use regular slicing here: I want to slice without altering blockstructure
34-
# solution: use boolean indexing and slice the mask, effectively cheaply inverting the map
35-
indexmask = falses(size(S, 1))
36-
indexmask[ind] .= true
43+
indexmask = MatrixAlgebraKit.findtruncated(diagview(S), strategy)
3744

3845
# first determine the block structure of the output to avoid having assumptions on the
3946
# data structures

0 commit comments

Comments
 (0)