Skip to content

Commit ee4ea74

Browse files
committed
Add docs for findtruncated
1 parent 3438ec0 commit ee4ea74

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docs/src/dev_interface.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ MatrixAlgebraKit.jl provides a developer interface for specifying custom algorit
1010
```@docs; canonical=false
1111
MatrixAlgebraKit.default_algorithm
1212
MatrixAlgebraKit.select_algorithm
13+
MatrixAlgebraKit.findtruncated
14+
MatrixAlgebraKit.findtruncated_sorted
1315
```

src/MatrixAlgebraKit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export LAPACK_HouseholderQR, LAPACK_HouseholderLQ,
3131
export truncrank, trunctol, truncabove, TruncationKeepSorted, TruncationKeepFiltered
3232

3333
VERSION >= v"1.11.0-DEV.469" &&
34-
eval(Expr(:public, :default_algorithm, :select_algorithm))
34+
eval(Expr(:public, :default_algorithm, :findtruncated, :findtruncated_sorted,
35+
:select_algorithm))
3536

3637
include("common/defaults.jl")
3738
include("common/initialization.jl")

src/implementations/truncation.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ end
170170
# findtruncated
171171
# -------------
172172
# specific implementations for finding truncated values
173+
@doc """
174+
MatrixAlgebraKit.findtruncated(values::AbstractVector, strategy::TruncationStrategy)
175+
176+
Generic interface for finding truncated values of the spectrum of a decomposition
177+
based on the `strategy`. The output should be a collection of indices specifying
178+
which values to keep. `MatrixAlgebraKit.findtruncated` is used inside of the default
179+
implementation of [`truncate!`](@ref) to perform the truncation. It does not assume that the
180+
values are sorted. For a version that assumes the values are reverse sorted by
181+
absolute value (which is the standard case for SVD) see
182+
[`MatrixAlgebraKit.findtruncated_sorted`](@ref).
183+
""" findtruncated
184+
185+
@doc """
186+
MatrixAlgebraKit.findtruncated_sorted(values::AbstractVector, strategy::TruncationStrategy)
187+
188+
Like [`MatrixAlgebraKit.findtruncated`](@ref) but assumes that the values are sorted in reverse order by
189+
absolute value. However, note that this assumption is not checked, so passing values that are not sorted
190+
in that way can silently give unexpected results. This is used in the default implementation of
191+
[`svd_trunc!`](@ref).
192+
""" findtruncated_sorted
193+
173194
findtruncated(values::AbstractVector, ::NoTruncation) = Colon()
174195

175196
# TODO: this may also permute the eigenvalues, decide if we want to allow this or not

0 commit comments

Comments
 (0)