Skip to content

Commit a3af231

Browse files
committed
move BlockPermutedDiagonalAlgorithm and update docstring
1 parent 8c42786 commit a3af231

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/factorizations/svd.jl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@ using MatrixAlgebraKit:
33
MatrixAlgebraKit, check_input, default_svd_algorithm, svd_compact!, svd_full!
44
using TypeParameterAccessors: realtype
55

6-
"""
7-
BlockPermutedDiagonalAlgorithm(A::MatrixAlgebraKit.AbstractAlgorithm)
8-
9-
A wrapper for `MatrixAlgebraKit.AbstractAlgorithm` that implements the wrapped algorithm on
10-
a block-by-block basis, which is possible if the input matrix is a block-diagonal matrix or
11-
a block permuted block-diagonal matrix.
12-
"""
13-
struct BlockPermutedDiagonalAlgorithm{F} <: MatrixAlgebraKit.AbstractAlgorithm
14-
falg::F
15-
end
16-
function block_algorithm(alg::BlockPermutedDiagonalAlgorithm, a::AbstractMatrix)
17-
return block_algorithm(alg, typeof(a))
18-
end
19-
function block_algorithm(alg::BlockPermutedDiagonalAlgorithm, A::Type{<:AbstractMatrix})
20-
return alg.falg(A)
21-
end
22-
236
function MatrixAlgebraKit.default_svd_algorithm(
247
::Type{<:AbstractBlockSparseMatrix}; kwargs...
258
)

src/factorizations/utility.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using MatrixAlgebraKit: MatrixAlgebraKit
2+
13
function infimum(r1::AbstractUnitRange, r2::AbstractUnitRange)
24
(isone(first(r1)) && isone(first(r2))) ||
35
throw(ArgumentError("infimum only defined for ranges starting at 1"))
@@ -50,3 +52,23 @@ function isblockdiagonal(A::AbstractBlockSparseMatrix)
5052
# this is guaranteed as long as eachblockstoredindex is unique, which we assume
5153
return true
5254
end
55+
56+
"""
57+
BlockPermutedDiagonalAlgorithm([f]) <: MatrixAlgebraKit.AbstractAlgorithm
58+
59+
Type for handling algorithms on a block-by-block basis, which is possible for
60+
block-diagonal or block-permuted-diagonal input matrices.
61+
Additionally this wrapper may take a function that, given the input type of the blocks,
62+
returns the actual algorithm that will be used. This can be leveraged to allow for different
63+
algorithms for each block.
64+
"""
65+
struct BlockPermutedDiagonalAlgorithm{F} <: MatrixAlgebraKit.AbstractAlgorithm
66+
falg::F
67+
end
68+
69+
function block_algorithm(alg::BlockPermutedDiagonalAlgorithm, a::AbstractMatrix)
70+
return block_algorithm(alg, typeof(a))
71+
end
72+
function block_algorithm(alg::BlockPermutedDiagonalAlgorithm, A::Type{<:AbstractMatrix})
73+
return alg.falg(A)
74+
end

0 commit comments

Comments
 (0)