Skip to content

Commit e3e348f

Browse files
Copilotlkdvos
andcommitted
Update docstrings for truncated decompositions with detailed keyword explanations
Co-authored-by: lkdvos <37111893+lkdvos@users.noreply.github.com>
1 parent ce62566 commit e3e348f

3 files changed

Lines changed: 74 additions & 13 deletions

File tree

src/interface/eig.jl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,36 @@ See also [`eig_vals(!)`](@ref eig_vals) and [`eig_trunc(!)`](@ref eig_trunc).
3131
@functiondef eig_full
3232

3333
"""
34-
eig_trunc(A; kwargs...) -> D, V
34+
eig_trunc(A; trunc, kwargs...) -> D, V
3535
eig_trunc(A, alg::AbstractAlgorithm) -> D, V
36-
eig_trunc!(A, [DV]; kwargs...) -> D, V
36+
eig_trunc!(A, [DV]; trunc, kwargs...) -> D, V
3737
eig_trunc!(A, [DV], alg::AbstractAlgorithm) -> D, V
3838
3939
Compute a partial or truncated eigenvalue decomposition of the matrix `A`,
4040
such that `A * V ≈ V * D`, where the (possibly rectangular) matrix `V` contains
4141
a subset of eigenvectors and the diagonal matrix `D` contains the associated eigenvalues,
4242
selected according to a truncation strategy.
4343
44+
## Keyword arguments
45+
The behavior of this function is controlled by the following keyword arguments:
46+
47+
- `trunc`: Specifies the truncation strategy. This can be:
48+
- A `NamedTuple` with fields `atol`, `rtol`, and/or `maxrank`, which will be converted to
49+
a [`TruncationStrategy`](@ref). For details on available truncation strategies, see
50+
[Truncations](@ref).
51+
- A `TruncationStrategy` object directly (e.g., `truncrank(10)`, `trunctol(atol=1e-6)`, or
52+
combinations using `&`).
53+
- `nothing` (default), which keeps all eigenvalues.
54+
55+
- Other keyword arguments are passed to the algorithm selection procedure. If no explicit
56+
`alg` is provided, these keywords are used to select and configure the algorithm through
57+
[`MatrixAlgebraKit.select_algorithm`](@ref). The remaining keywords after algorithm
58+
selection are passed to the algorithm constructor. See [`MatrixAlgebraKit.default_algorithm`](@ref)
59+
for the default algorithm selection behavior.
60+
61+
When `alg` is a [`TruncatedAlgorithm`](@ref), the `trunc` keyword cannot be specified as the
62+
truncation strategy is already embedded in the algorithm.
63+
4464
!!! note
4565
The bang method `eig_trunc!` optionally accepts the output structure and
4666
possibly destroys the input matrix `A`. Always use the return value of the function
@@ -49,7 +69,8 @@ selected according to a truncation strategy.
4969
!!! note
5070
$(docs_eig_note)
5171
52-
See also [`eig_full(!)`](@ref eig_full) and [`eig_vals(!)`](@ref eig_vals).
72+
See also [`eig_full(!)`](@ref eig_full), [`eig_vals(!)`](@ref eig_vals), and
73+
[Truncations](@ref) for more information on truncation strategies.
5374
"""
5475
@functiondef eig_trunc
5576

src/interface/eigh.jl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,35 @@ See also [`eigh_vals(!)`](@ref eigh_vals) and [`eigh_trunc(!)`](@ref eigh_trunc)
3131
@functiondef eigh_full
3232

3333
"""
34-
eigh_trunc(A; kwargs...) -> D, V
34+
eigh_trunc(A; trunc, kwargs...) -> D, V
3535
eigh_trunc(A, alg::AbstractAlgorithm) -> D, V
36-
eigh_trunc!(A, [DV]; kwargs...) -> D, V
36+
eigh_trunc!(A, [DV]; trunc, kwargs...) -> D, V
3737
eigh_trunc!(A, [DV], alg::AbstractAlgorithm) -> D, V
3838
3939
Compute a partial or truncated eigenvalue decomposition of the symmetric or hermitian matrix
4040
`A`, such that `A * V ≈ V * D`, where the isometric matrix `V` contains a subset of the
4141
orthogonal eigenvectors and the real diagonal matrix `D` contains the associated eigenvalues,
42-
selected according to a truncation strategy.
42+
selected according to a truncation strategy.
43+
44+
## Keyword arguments
45+
The behavior of this function is controlled by the following keyword arguments:
46+
47+
- `trunc`: Specifies the truncation strategy. This can be:
48+
- A `NamedTuple` with fields `atol`, `rtol`, and/or `maxrank`, which will be converted to
49+
a [`TruncationStrategy`](@ref). For details on available truncation strategies, see
50+
[Truncations](@ref).
51+
- A `TruncationStrategy` object directly (e.g., `truncrank(10)`, `trunctol(atol=1e-6)`, or
52+
combinations using `&`).
53+
- `nothing` (default), which keeps all eigenvalues.
54+
55+
- Other keyword arguments are passed to the algorithm selection procedure. If no explicit
56+
`alg` is provided, these keywords are used to select and configure the algorithm through
57+
[`MatrixAlgebraKit.select_algorithm`](@ref). The remaining keywords after algorithm
58+
selection are passed to the algorithm constructor. See [`MatrixAlgebraKit.default_algorithm`](@ref)
59+
for the default algorithm selection behavior.
60+
61+
When `alg` is a [`TruncatedAlgorithm`](@ref), the `trunc` keyword cannot be specified as the
62+
truncation strategy is already embedded in the algorithm.
4363
4464
!!! note
4565
The bang method `eigh_trunc!` optionally accepts the output structure and
@@ -49,7 +69,8 @@ selected according to a truncation strategy.
4969
!!! note
5070
$(docs_eigh_note)
5171
52-
See also [`eigh_full(!)`](@ref eigh_full) and [`eigh_vals(!)`](@ref eigh_vals).
72+
See also [`eigh_full(!)`](@ref eigh_full), [`eigh_vals(!)`](@ref eigh_vals), and
73+
[Truncations](@ref) for more information on truncation strategies.
5374
"""
5475
@functiondef eigh_trunc
5576

src/interface/svd.jl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,45 @@ See also [`svd_full(!)`](@ref svd_full), [`svd_vals(!)`](@ref svd_vals) and
4141
"""
4242
@functiondef svd_compact
4343

44-
# TODO: decide if we should have `svd_trunc!!` instead
4544
"""
46-
svd_trunc(A; kwargs...) -> U, S, Vᴴ
45+
svd_trunc(A; trunc, kwargs...) -> U, S, Vᴴ
4746
svd_trunc(A, alg::AbstractAlgorithm) -> U, S, Vᴴ
48-
svd_trunc!(A, [USVᴴ]; kwargs...) -> U, S, Vᴴ
47+
svd_trunc!(A, [USVᴴ]; trunc, kwargs...) -> U, S, Vᴴ
4948
svd_trunc!(A, [USVᴴ], alg::AbstractAlgorithm) -> U, S, Vᴴ
5049
5150
Compute a partial or truncated singular value decomposition (SVD) of `A`, such that
5251
`A * (Vᴴ)' = U * S`. Here, `U` is an isometric matrix (orthonormal columns) of size
5352
`(m, k)`, whereas `Vᴴ` is a matrix of size `(k, n)` with orthonormal rows and `S` is a
5453
square diagonal matrix of size `(k, k)`, with `k` is set by the truncation strategy.
5554
55+
## Keyword arguments
56+
The behavior of this function is controlled by the following keyword arguments:
57+
58+
- `trunc`: Specifies the truncation strategy. This can be:
59+
- A `NamedTuple` with fields `atol`, `rtol`, and/or `maxrank`, which will be converted to
60+
a [`TruncationStrategy`](@ref). For details on available truncation strategies, see
61+
[Truncations](@ref).
62+
- A `TruncationStrategy` object directly (e.g., `truncrank(10)`, `trunctol(atol=1e-6)`, or
63+
combinations using `&`).
64+
- `nothing` (default), which keeps all singular values.
65+
66+
- Other keyword arguments are passed to the algorithm selection procedure. If no explicit
67+
`alg` is provided, these keywords are used to select and configure the algorithm through
68+
[`MatrixAlgebraKit.select_algorithm`](@ref). The remaining keywords after algorithm
69+
selection are passed to the algorithm constructor. See [`MatrixAlgebraKit.default_algorithm`](@ref)
70+
for the default algorithm selection behavior.
71+
72+
When `alg` is a [`TruncatedAlgorithm`](@ref), the `trunc` keyword cannot be specified as the
73+
truncation strategy is already embedded in the algorithm.
74+
5675
!!! note
5776
The bang method `svd_trunc!` optionally accepts the output structure and
5877
possibly destroys the input matrix `A`. Always use the return value of the function
5978
as it may not always be possible to use the provided `USVᴴ` as output.
6079
61-
62-
See also [`svd_full(!)`](@ref svd_full), [`svd_compact(!)`](@ref svd_compact) and
63-
[`svd_vals(!)`](@ref svd_vals).
80+
See also [`svd_full(!)`](@ref svd_full), [`svd_compact(!)`](@ref svd_compact),
81+
[`svd_vals(!)`](@ref svd_vals), and [Truncations](@ref) for more information on
82+
truncation strategies.
6483
"""
6584
@functiondef svd_trunc
6685

0 commit comments

Comments
 (0)