-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpolar.jl
More file actions
72 lines (60 loc) · 2.55 KB
/
polar.jl
File metadata and controls
72 lines (60 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Polar API
# ---------
function polar!(A::AbstractMatrix, args...; kwargs...)
return left_polar!(A, args...; kwargs...)
end
function polar(A::AbstractMatrix, args...; kwargs...)
return left_polar(A, args...; kwargs...)
end
# Polar functions
# ---------------
"""
left_polar(A; kwargs...) -> W, P
left_polar(A, alg::AbstractAlgorithm) -> W, P
left_polar!(A, [WP]; kwargs...) -> W, P
left_polar!(A, [WP], alg::AbstractAlgorithm) -> W, P
Compute the full polar decomposition of the rectangular matrix `A` of size `(m, n)`
with `m >= n`, such that `A = W * P`. Here, `W` is an isometric matrix (orthonormal columns)
of size `(m, n)`, whereas `P` is a positive (semi)definite matrix of size `(n, n)`.
!!! note
The bang method `left_polar!` optionally accepts the output structure and
possibly destroys the input matrix `A`. Always use the return value of the function
as it may not always be possible to use the provided `WP` as output.
See also [`right_polar(!)`](@ref right_polar).
"""
@functiondef left_polar
"""
right_polar(A; kwargs...) -> P, Wᴴ
right_polar(A, alg::AbstractAlgorithm) -> P, Wᴴ
right_polar!(A, [PWᴴ]; kwargs...) -> P, Wᴴ
right_polar!(A, [PWᴴ], alg::AbstractAlgorithm) -> P, Wᴴ
Compute the full polar decomposition of the rectangular matrix `A` of size `(m, n)`
with `n >= m`, such that `A = P * Wᴴ`. Here, `P` is a positive (semi)definite matrix
of size `(m, m)`, whereas `Wᴴ` is a matrix with orthonormal rows (its adjoint is isometric)
of size `(n, m)`.
!!! note
The bang method `right_polar!` optionally accepts the output structure and
possibly destroys the input matrix `A`. Always use the return value of the function
as it may not always be possible to use the provided `WP` as output.
See also [`left_polar(!)`](@ref left_polar).
"""
@functiondef right_polar
"""
PolarViaSVD(svdalg)
Algorithm for computing the polar decomposition of a matrix `A` via the singular value
decomposition (SVD) of `A`. The `svdalg` argument specifies the SVD algorithm to use.
"""
struct PolarViaSVD{SVDAlg} <: AbstractAlgorithm
svdalg::SVDAlg
end
# Algorithm selection
# -------------------
default_polar_algorithm(A; kwargs...) = default_polar_algorithm(typeof(A); kwargs...)
function default_polar_algorithm(::Type{T}; kwargs...) where {T}
return PolarViaSVD(default_algorithm(svd_compact!, T; kwargs...))
end
for f in (:left_polar!, :right_polar!)
@eval function default_algorithm(::typeof($f), ::Type{A}; kwargs...) where {A}
return default_polar_algorithm(A; kwargs...)
end
end