Skip to content

Commit b2f448c

Browse files
committed
Add dedicated truncation type
1 parent b444a44 commit b2f448c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/factorizations/truncation.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
using MatrixAlgebraKit: TruncationStrategy, diagview
22

3+
"""
4+
BlockPermutedDiagonalTruncationStrategy(strategy::MatrixAlgebraKit.TruncationStrategy)
5+
6+
A wrapper for `MatrixAlgebraKit.TruncationStrategy` that implements the wrapped strategy on
7+
a block-by-block basis, which is possible if the input matrix is a block-diagonal matrix or
8+
a block permuted block-diagonal matrix.
9+
"""
10+
struct BlockPermutedDiagonalTruncationStrategy{T<:MatrixAlgebraKit.TruncationStrategy} <:
11+
MatrixAlgebraKit.TruncationStrategy
12+
strategy::T
13+
end
14+
315
const TBlockUSVᴴ = Tuple{
416
<:AbstractBlockSparseMatrix,<:AbstractBlockSparseMatrix,<:AbstractBlockSparseMatrix
517
}
618

719
function MatrixAlgebraKit.truncate!(
8-
::typeof(svd_trunc!), (U, S, Vᴴ)::TBlockUSVᴴ, strategy::TruncationStrategy
20+
::typeof(svd_trunc!),
21+
(U, S, Vᴴ)::TBlockUSVᴴ,
22+
strategy::BlockPermutedDiagonalTruncationStrategy,
923
)
10-
ind = MatrixAlgebraKit.findtruncated(diagview(S), strategy)
24+
ind = MatrixAlgebraKit.findtruncated(diagview(S), strategy.strategy)
1125
# cannot use regular slicing here: I want to slice without altering blockstructure
1226
# solution: use boolean indexing and slice the mask, effectively cheaply inverting the map
1327
indexmask = falses(size(S, 1))
@@ -60,3 +74,4 @@ function MatrixAlgebraKit.truncate!(
6074

6175
return Ũ, S̃, Ṽᴴ
6276
end
77+

0 commit comments

Comments
 (0)