Skip to content

Commit 8e808ba

Browse files
committed
add gaugefix keyword to GenericLinearAlgebra extension
1 parent 4d2fd63 commit 8e808ba

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

ext/MatrixAlgebraKitGenericLinearAlgebraExt.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module MatrixAlgebraKitGenericLinearAlgebraExt
22

33
using MatrixAlgebraKit
4-
using MatrixAlgebraKit: sign_safe, check_input, diagview
4+
using MatrixAlgebraKit: sign_safe, check_input, diagview, gaugefix!
55
using GenericLinearAlgebra: svd!, svdvals!, eigen!, eigvals!, Hermitian, qr!
66
using LinearAlgebra: I, Diagonal, lmul!
77

@@ -13,18 +13,26 @@ for f! in (:svd_compact!, :svd_full!, :svd_vals!)
1313
@eval MatrixAlgebraKit.initialize_output(::typeof($f!), A::AbstractMatrix, ::GLA_QRIteration) = nothing
1414
end
1515

16-
function MatrixAlgebraKit.svd_compact!(A::AbstractMatrix, USVᴴ, ::GLA_QRIteration)
16+
function MatrixAlgebraKit.svd_compact!(A::AbstractMatrix, USVᴴ, alg::GLA_QRIteration)
1717
F = svd!(A)
1818
U, S, Vᴴ = F.U, Diagonal(F.S), F.Vt
19-
return MatrixAlgebraKit.gaugefix!(svd_compact!, U, S, Vᴴ, size(A)...)
19+
20+
dogaugefix = get(alg.kwargs, :gaugefix, true)::Bool
21+
dogaugefix && gaugefix!(svd_compact!, U, Vᴴ)
22+
23+
return U, S, Vᴴ
2024
end
2125

22-
function MatrixAlgebraKit.svd_full!(A::AbstractMatrix, USVᴴ, ::GLA_QRIteration)
26+
function MatrixAlgebraKit.svd_full!(A::AbstractMatrix, USVᴴ, alg::GLA_QRIteration)
2327
F = svd!(A; full = true)
2428
U, Vᴴ = F.U, F.Vt
2529
S = MatrixAlgebraKit.zero!(similar(F.S, (size(U, 2), size(Vᴴ, 1))))
2630
diagview(S) .= F.S
27-
return MatrixAlgebraKit.gaugefix!(svd_full!, U, S, Vᴴ, size(A)...)
31+
32+
dogaugefix = get(alg.kwargs, :gaugefix, true)::Bool
33+
dogaugefix && gaugefix!(svd_full!, U, Vᴴ)
34+
35+
return U, S, Vᴴ
2836
end
2937

3038
function MatrixAlgebraKit.svd_vals!(A::AbstractMatrix, S, ::GLA_QRIteration)

src/interface/decompositions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ const LAPACK_EighAlgorithm = Union{
131131
}
132132

133133
"""
134-
GLA_QRIteration()
134+
GLA_QRIteration(; gaugefix::Bool = true)
135135
136136
Algorithm type to denote the GenericLinearAlgebra.jl implementation for computing the
137137
eigenvalue decomposition of a Hermitian matrix, or the singular value decomposition of
138138
a general matrix.
139+
The `gaugefix` keyword can be used to toggle whether or not to fix the gauge of the eigen or
140+
singular vectors, see also [`gaugefix!`](@ref).
139141
"""
140142
@algdef GLA_QRIteration
141143

0 commit comments

Comments
 (0)