Skip to content

Commit e10a7ae

Browse files
committed
Split blockdiagonal and blockpermuteddiagonal algorithms
1 parent 35df218 commit e10a7ae

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/factorizations/utility.jl

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,46 @@ function isblockdiagonal(A::AbstractBlockSparseMatrix)
5353
return true
5454
end
5555

56+
"""
57+
BlockDiagonalAlgorithm([f]) <: MatrixAlgebraKit.AbstractAlgorithm
58+
59+
Type for handling algorithms on a block-by-block basis, which is possible for
60+
block-diagonal input matrices.
61+
Additionally this algorithm may take a function that, given the individual blocks, returns
62+
the algorithm that will be used. This can be leveraged to allow for different algorithms for
63+
each block.
64+
"""
65+
struct BlockDiagonalAlgorithm{F} <: MatrixAlgebraKit.AbstractAlgorithm
66+
falg::F
67+
end
68+
69+
function block_algorithm(alg::BlockDiagonalAlgorithm, a::AbstractMatrix)
70+
return block_algorithm(alg, typeof(a))
71+
end
72+
function block_algorithm(alg::BlockDiagonalAlgorithm, A::Type{<:AbstractMatrix})
73+
return alg.falg(A)
74+
end
75+
5676
"""
5777
BlockPermutedDiagonalAlgorithm([f]) <: MatrixAlgebraKit.AbstractAlgorithm
5878
5979
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.
80+
block-diagonal or block-permuted-diagonal input matrices. The algorithms proceed by first
81+
permuting to a block-diagonal form, and then carrying out the algorithm.
82+
Additionally this algorithm may take a function that, given the individual blocks, returns
83+
the algorithm that will be used. This can be leveraged to allow for different algorithms for
84+
each block.
6485
"""
6586
struct BlockPermutedDiagonalAlgorithm{F} <: MatrixAlgebraKit.AbstractAlgorithm
6687
falg::F
6788
end
68-
6989
function block_algorithm(alg::BlockPermutedDiagonalAlgorithm, a::AbstractMatrix)
7090
return block_algorithm(alg, typeof(a))
7191
end
7292
function block_algorithm(alg::BlockPermutedDiagonalAlgorithm, A::Type{<:AbstractMatrix})
7393
return alg.falg(A)
7494
end
95+
96+
function BlockDiagonalAlgorithm(alg::BlockPermutedDiagonalAlgorithm)
97+
return BlockDiagonalAlgorithm(alg.falg)
98+
end

0 commit comments

Comments
 (0)