|
| 1 | +using MatrixAlgebraKit: |
| 2 | + MatrixAlgebraKit, default_eig_algorithm, default_eigh_algorithm, eig_full!, eigh_full! |
| 3 | + |
| 4 | +function MatrixAlgebraKit.default_eig_algorithm( |
| 5 | + arrayt::Type{<:AbstractBlockSparseMatrix}; kwargs... |
| 6 | +) |
| 7 | + alg = default_eig_algorithm(blocktype(arrayt); kwargs...) |
| 8 | + return BlockPermutedDiagonalAlgorithm(alg) |
| 9 | +end |
| 10 | + |
| 11 | +function MatrixAlgebraKit.initialize_output( |
| 12 | + ::typeof(eig_full!), A::AbstractBlockSparseMatrix, alg::BlockPermutedDiagonalAlgorithm |
| 13 | +) |
| 14 | + D = similar(A, complex(eltype(A))) |
| 15 | + V = similar(A, complex(eltype(A))) |
| 16 | + return (D, V) |
| 17 | +end |
| 18 | + |
| 19 | +function MatrixAlgebraKit.eig_full!( |
| 20 | + A::AbstractBlockSparseMatrix, (D, V), alg::BlockPermutedDiagonalAlgorithm |
| 21 | +) |
| 22 | + for I in blockdiagindices(A) |
| 23 | + d, v = eig_full!(A[I], alg.alg) |
| 24 | + D[I] = d |
| 25 | + V[I] = v |
| 26 | + end |
| 27 | + return (D, V) |
| 28 | +end |
| 29 | + |
| 30 | +# TODO: this is a hardcoded for now to get around this function not being defined in the |
| 31 | +# type domain |
| 32 | +function MatrixAlgebraKit.default_eigh_algorithm( |
| 33 | + arrayt::Type{<:AbstractBlockSparseMatrix}; kwargs... |
| 34 | +) |
| 35 | + alg = default_eigh_algorithm(blocktype(arrayt); kwargs...) |
| 36 | + return BlockPermutedDiagonalAlgorithm(alg) |
| 37 | +end |
| 38 | + |
| 39 | +function MatrixAlgebraKit.initialize_output( |
| 40 | + ::typeof(eigh_full!), A::AbstractBlockSparseMatrix, alg::BlockPermutedDiagonalAlgorithm |
| 41 | +) |
| 42 | + D = similar(A, complex(eltype(A))) |
| 43 | + V = similar(A, complex(eltype(A))) |
| 44 | + return (D, V) |
| 45 | +end |
| 46 | + |
| 47 | +function MatrixAlgebraKit.eigh_full!( |
| 48 | + A::AbstractBlockSparseMatrix, (D, V), alg::BlockPermutedDiagonalAlgorithm |
| 49 | +) |
| 50 | + for I in blockdiagindices(A) |
| 51 | + d, v = eigh_full!(A[I], alg.alg) |
| 52 | + D[I] = d |
| 53 | + V[I] = v |
| 54 | + end |
| 55 | + return (D, V) |
| 56 | +end |
0 commit comments