|
1 | 1 | using LinearAlgebra: LinearAlgebra |
2 | | -using .MatrixAlgebra: MatrixAlgebra |
3 | 2 | using MatrixAlgebraKit: MatrixAlgebraKit |
4 | 3 |
|
5 | | -function factorize_with(f, A::AbstractArray, biperm::BlockedPermutation{2}; kwargs...) |
6 | | - # tensor to matrix |
7 | | - A_mat = fusedims(A, biperm) |
8 | | - |
9 | | - # factorization |
10 | | - X, Y = f(A_mat; kwargs...) |
11 | | - |
12 | | - # matrix to tensor |
13 | | - axes_codomain, axes_domain = blockpermute(axes(A), biperm) |
14 | | - axes_X = (axes_codomain..., axes(X, 2)) |
15 | | - axes_Y = (axes(Y, 1), axes_domain...) |
16 | | - return splitdims(X, axes_X), splitdims(Y, axes_Y) |
17 | | -end |
18 | | - |
19 | | -for (f, f_mat) in ( |
20 | | - (:qr, :(MatrixAlgebra.qr)), |
21 | | - (:lq, :(MatrixAlgebra.lq)), |
22 | | - (:left_polar, :(MatrixAlgebra.left_polar)), |
23 | | - (:right_polar, :(MatrixAlgebra.right_polar)), |
24 | | - (:polar, :(MatrixAlgebra.polar)), |
25 | | - (:left_orth, :(MatrixAlgebra.left_orth)), |
26 | | - (:right_orth, :(MatrixAlgebra.right_orth)), |
27 | | - (:orth, :(MatrixAlgebra.orth)), |
28 | | - (:factorize, :(MatrixAlgebra.factorize)), |
| 4 | +for f in ( |
| 5 | + :qr, :lq, :left_polar, :right_polar, :polar, :left_orth, :right_orth, :orth, :factorize |
29 | 6 | ) |
30 | 7 | @eval begin |
31 | 8 | function $f(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwargs...) |
32 | 9 | biperm = blockedperm_indexin(Tuple.((labels_A, labels_codomain, labels_domain))...) |
33 | 10 | return $f(A, biperm; kwargs...) |
34 | 11 | end |
35 | 12 | function $f(A::AbstractArray, biperm::BlockedPermutation{2}; kwargs...) |
36 | | - return factorize_with($f_mat, A, biperm; kwargs...) |
| 13 | + # tensor to matrix |
| 14 | + A_mat = fusedims(A, biperm) |
| 15 | + |
| 16 | + # factorization |
| 17 | + X, Y = MatrixAlgebra.$f(A_mat; kwargs...) |
| 18 | + |
| 19 | + # matrix to tensor |
| 20 | + axes_codomain, axes_domain = blockpermute(axes(A), biperm) |
| 21 | + axes_X = (axes_codomain..., axes(X, 2)) |
| 22 | + axes_Y = (axes(Y, 1), axes_domain...) |
| 23 | + return splitdims(X, axes_X), splitdims(Y, axes_Y) |
37 | 24 | end |
38 | 25 | end |
39 | 26 | end |
@@ -209,9 +196,7 @@ function eigvals(A::AbstractArray, labels_A, labels_codomain, labels_domain; kwa |
209 | 196 | biperm = blockedperm_indexin(Tuple.((labels_A, labels_codomain, labels_domain))...) |
210 | 197 | return eigvals(A, biperm; kwargs...) |
211 | 198 | end |
212 | | -function eigvals( |
213 | | - A::AbstractArray, biperm::BlockedPermutation{2}; ishermitian=nothing, kwargs... |
214 | | -) |
| 199 | +function eigvals(A::AbstractArray, biperm::BlockedPermutation{2}; kwargs...) |
215 | 200 | A_mat = fusedims(A, biperm) |
216 | 201 | return MatrixAlgebra.eigvals!(A_mat; kwargs...) |
217 | 202 | end |
|
0 commit comments