|
| 1 | +function MAK.copy_input(::typeof(MAK.eig_full), t::AbstractTensorMap) |
| 2 | + return copy_oftype(t, factorisation_scalartype(MAK.eig_full!, t)) |
| 3 | +end |
| 4 | + |
| 5 | +function factorisation_scalartype(::typeof(MAK.eig_full!), t::AbstractTensorMap) |
| 6 | + T = complex(scalartype(t)) |
| 7 | + return promote_type(ComplexF32, typeof(zero(T) / sqrt(abs2(one(T))))) |
| 8 | +end |
| 9 | + |
| 10 | +function MAK.check_input(::typeof(MAK.eig_full!), t::AbstractTensorMap, (D, V)) |
| 11 | + domain(t) == codomain(t) || |
| 12 | + throw(ArgumentError("Eigenvalue decomposition requires square input tensor")) |
| 13 | + Tc = complex(scalartype(t)) |
| 14 | + |
| 15 | + (D isa DiagonalTensorMap && |
| 16 | + scalartype(D) == Tc && |
| 17 | + fuse(domain(t)) == space(D, 1)) || |
| 18 | + throw(ArgumentError("`eig_full!` requires diagonal tensor D with isomorphic domain and complex `scalartype`")) |
| 19 | + |
| 20 | + V isa AbstractTensorMap && |
| 21 | + scalartype(V) == Tc && |
| 22 | + space(V) == (codomain(t) ← codomain(D)) || |
| 23 | + throw(ArgumentError("`eig_full!` requires square tensor V with isomorphic domain and complex `scalartype`")) |
| 24 | + |
| 25 | + return nothing |
| 26 | +end |
| 27 | + |
| 28 | +function MAK.initialize_output(::typeof(MAK.eig_full!), t::AbstractTensorMap, |
| 29 | + ::MAK.LAPACK_EigAlgorithm) |
| 30 | + Tc = complex(scalartype(t)) |
| 31 | + V_diag = fuse(domain(t)) |
| 32 | + return DiagonalTensorMap{Tc}(undef, V_diag), similar(t, Tc, domain(t) ← V_diag) |
| 33 | +end |
| 34 | + |
| 35 | +function MAK.eig_full!(t::AbstractTensorMap, (D, V), alg::MAK.LAPACK_EigAlgorithm) |
| 36 | + MAK.check_input(MAK.eig_full!, t, (D, V)) |
| 37 | + foreachblock(t, D, V) do (_, (b, d, v)) |
| 38 | + d′, v′ = MAK.eig_full!(b, (d, v), alg) |
| 39 | + # deal with the case where the output is not the same as the input |
| 40 | + d === d′ || copyto!(d, d′) |
| 41 | + v === v′ || copyto!(v, v′) |
| 42 | + return nothing |
| 43 | + end |
| 44 | + return D, V |
| 45 | +end |
| 46 | + |
| 47 | +function MAK.default_eig_algorithm(::TensorMap{<:LinearAlgebra.BlasFloat}; kwargs...) |
| 48 | + return MAK.LAPACK_Expert(; kwargs...) |
| 49 | +end |
0 commit comments