1
+ using BlockArrays: blocksizes
2
+ using LinearAlgebra: LinearAlgebra
1
3
using MatrixAlgebraKit:
2
- MatrixAlgebraKit, default_eig_algorithm, default_eigh_algorithm, eig_full!, eigh_full!
3
-
4
- function initialize_blocksparse_eig_output (
5
- f, A:: AbstractMatrix , alg:: BlockPermutedDiagonalAlgorithm
6
- )
7
- Td, Tv = fieldtypes (Base. promote_op (f, blocktype (A), typeof (alg. alg)))
8
- D = similar (A, BlockType (Td))
9
- V = similar (A, BlockType (Tv))
10
- return (D, V)
11
- end
12
-
13
- function blocksparse_eig_full! (
14
- f, A:: AbstractMatrix , (D, V), alg:: BlockPermutedDiagonalAlgorithm
15
- )
16
- for I in blockdiagindices (A)
17
- d, v = f (@view! (A[I]), alg. alg)
18
- D[I], V[I] = d, v
19
- end
20
- return (D, V)
21
- end
4
+ MatrixAlgebraKit,
5
+ default_eig_algorithm,
6
+ default_eigh_algorithm,
7
+ eig_full!,
8
+ eig_vals!,
9
+ eigh_full!,
10
+ eigh_vals!
22
11
23
12
for f in [:default_eig_algorithm , :default_eigh_algorithm ]
24
13
@eval begin
@@ -34,12 +23,41 @@ for f in [:eig_full!, :eigh_full!]
34
23
function MatrixAlgebraKit. initialize_output (
35
24
:: typeof ($ f), A:: AbstractBlockSparseMatrix , alg:: BlockPermutedDiagonalAlgorithm
36
25
)
37
- return initialize_blocksparse_eig_output ($ f, A, alg)
26
+ Td, Tv = fieldtypes (Base. promote_op ($ f, blocktype (A), typeof (alg. alg)))
27
+ D = similar (A, BlockType (Td))
28
+ V = similar (A, BlockType (Tv))
29
+ return (D, V)
38
30
end
39
31
function MatrixAlgebraKit. $f (
40
32
A:: AbstractBlockSparseMatrix , (D, V), alg:: BlockPermutedDiagonalAlgorithm
41
33
)
42
- return blocksparse_eig_full! ($ f, A, (D, V), alg)
34
+ for I in eachstoredblockdiagindex (A)
35
+ D[I], V[I] = $ f (@view (A[I]), alg. alg)
36
+ end
37
+ for I in eachunstoredblockdiagindex (A)
38
+ # TODO : Support setting `LinearAlgebra.I` directly, and/or
39
+ # using `FillArrays.Eye`.
40
+ V[I] = LinearAlgebra. I (first (blocksizes (A)[Int .(Tuple (I))... ]))
41
+ end
42
+ return (D, V)
43
+ end
44
+ end
45
+ end
46
+
47
+ for f in [:eig_vals! , :eigh_vals! ]
48
+ @eval begin
49
+ function MatrixAlgebraKit. initialize_output (
50
+ :: typeof ($ f), A:: AbstractBlockSparseMatrix , alg:: BlockPermutedDiagonalAlgorithm
51
+ )
52
+ return similar (A, axes (A, 1 ))
53
+ end
54
+ function MatrixAlgebraKit. $f (
55
+ A:: AbstractBlockSparseMatrix , D, alg:: BlockPermutedDiagonalAlgorithm
56
+ )
57
+ for I in eachblockstoredindex (A)
58
+ D[I] = $ f (@view! (A[I]), alg. alg)
59
+ end
60
+ return D
43
61
end
44
62
end
45
63
end
0 commit comments