Skip to content

Commit 5ded761

Browse files
fredrikekretkelman
authored andcommitted
fix and add doctest for eigs and svds (#20493)
* add doctest for eigs and svds * dont show vectors
1 parent d6856af commit 5ded761

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

base/linalg/arnoldi.jl

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ The following keyword arguments are supported:
5050
iterations `niter` and the number of matrix vector multiplications `nmult`, as well as the
5151
final residual vector `resid`.
5252
53+
# Example
54+
55+
```jldoctest
56+
julia> A = spdiagm(1:4);
57+
58+
julia> λ, ϕ = eigs(A, nev = 2);
59+
60+
julia> λ
61+
2-element Array{Float64,1}:
62+
4.0
63+
3.0
64+
```
65+
5366
!!! note
5467
The `sigma` and `which` keywords interact: the description of eigenvalues
5568
searched for by `which` do *not* necessarily refer to the eigenvalues of
@@ -133,13 +146,18 @@ final residual vector `resid`.
133146
134147
# Example
135148
136-
```julia
137-
X = sprand(10, 5, 0.2)
138-
eigs(X, nsv = 2, tol = 1e-3)
149+
```jldoctest
150+
julia> A = speye(4, 4); B = spdiagm(1:4);
151+
152+
julia> λ, ϕ = eigs(A, B, nev = 2);
153+
154+
julia> λ
155+
2-element Array{Float64,1}:
156+
1.0
157+
0.5
139158
```
140159
141160
!!! note
142-
143161
The `sigma` and `which` keywords interact: the description of eigenvalues searched for by
144162
`which` do *not* necessarily refer to the eigenvalue problem ``Av = Bv\\lambda``, but rather
145163
the linear operator constructed by the specification of the iteration mode implied by `sigma`.
@@ -344,17 +362,22 @@ iterations derived from [`eigs`](@ref).
344362
345363
# Example
346364
347-
```julia
348-
X = sprand(10, 5, 0.2)
349-
svds(X, nsv = 2)
365+
```jldoctest
366+
julia> A = spdiagm(1:4);
367+
368+
julia> s = svds(A, nsv = 2)[1];
369+
370+
julia> s[:S]
371+
2-element Array{Float64,1}:
372+
4.0
373+
3.0
350374
```
351375
352376
!!! note "Implementation"
353-
354-
`svds(A)` is formally equivalent to calling [`eigs`](@ref) to perform implicitly restarted
355-
Lanczos tridiagonalization on the Hermitian matrix
356-
``\\begin{pmatrix} 0 & A^\\prime \\\\ A & 0 \\end{pmatrix}``, whose eigenvalues are
357-
plus and minus the singular values of ``A``.
377+
`svds(A)` is formally equivalent to calling [`eigs`](@ref) to perform implicitly restarted
378+
Lanczos tridiagonalization on the Hermitian matrix
379+
``\\begin{pmatrix} 0 & A^\\prime \\\\ A & 0 \\end{pmatrix}``, whose eigenvalues are
380+
plus and minus the singular values of ``A``.
358381
"""
359382
svds(A; kwargs...) = _svds(A; kwargs...)
360383
function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxiter::Int = 1000, ncv::Int = 2*nsv, u0::Vector=zeros(eltype(X),(0,)), v0::Vector=zeros(eltype(X),(0,)))

base/linalg/qr.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ Multiplication with respect to either thin or full `Q` is allowed, i.e. both `F[
136136
and `F[:Q]*A` are supported. A `Q` matrix can be converted into a regular matrix with
137137
[`full`](@ref) which has a named argument `thin`.
138138
139+
# Example
140+
139141
```jldoctest
140142
julia> A = [3.0 -6.0; 4.0 -8.0; 0.0 1.0]
141143
3×2 Array{Float64,2}:

0 commit comments

Comments
 (0)