From 710a3d8f4654b51a56abc0967aca256f291d836e Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Tue, 28 Nov 2017 23:44:17 -0800 Subject: [PATCH] More examples for linalg (#24824) * Examples for RowVector * Update example and add which example for eigs --- base/linalg/rowvector.jl | 42 +++++++++++++++++++ .../src/IterativeEigenSolvers.jl | 9 ++++ 2 files changed, 51 insertions(+) diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index 3d37026c05c01..574f48c0e64f1 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -12,6 +12,48 @@ By convention, a vector can be multiplied by a matrix on its left (`A * v`) wher vector can be multiplied by a matrix on its right (such that `v.' * A = (A.' * v).'`). It differs from a `1×n`-sized matrix by the facts that its transpose returns a vector and the inner product `v1.' * v2` returns a scalar, but will otherwise behave similarly. + +# Examples +```jldoctest +julia> a = [1; 2; 3; 4] +4-element Array{Int64,1}: + 1 + 2 + 3 + 4 + +julia> RowVector(a) +1×4 RowVector{Int64,Array{Int64,1}}: + 1 2 3 4 + +julia> a.' +1×4 RowVector{Int64,Array{Int64,1}}: + 1 2 3 4 + +julia> a.'[3] +3 + +julia> a.'[1,3] +3 + +julia> a.'[3,1] +ERROR: BoundsError: attempt to access 1×4 RowVector{Int64,Array{Int64,1}} at index [3, 1] +[...] + +julia> a.'*a +30 + +julia> B = [1 2; 3 4; 5 6; 7 8] +4×2 Array{Int64,2}: + 1 2 + 3 4 + 5 6 + 7 8 + +julia> a.'*B +1×2 RowVector{Int64,Array{Int64,1}}: + 50 60 +``` """ struct RowVector{T,V<:AbstractVector} <: AbstractMatrix{T} vec::V diff --git a/stdlib/IterativeEigenSolvers/src/IterativeEigenSolvers.jl b/stdlib/IterativeEigenSolvers/src/IterativeEigenSolvers.jl index d5e62c2e42da3..e7cdb3f27e52b 100644 --- a/stdlib/IterativeEigenSolvers/src/IterativeEigenSolvers.jl +++ b/stdlib/IterativeEigenSolvers/src/IterativeEigenSolvers.jl @@ -65,6 +65,8 @@ final residual vector `resid`. # Examples ```jldoctest +julia> using IterativeEigenSolvers + julia> A = Diagonal(1:4); julia> λ, ϕ = eigs(A, nev = 2); @@ -73,6 +75,13 @@ julia> λ 2-element Array{Float64,1}: 4.0 3.0 + +julia> λ, ϕ = eigs(A, nev = 2, which=:SM); + +julia> λ +2-element Array{Float64,1}: + 1.0000000000000002 + 2.0 ``` !!! note