Skip to content

Commit fdf3748

Browse files
authored
More documentation movement and cleanup for linalg (#18498)
* More documentation movement and cleanup for linalg Removed square brackets from signatures, added more links, clarified some wording. * Fix docstring for bkfact
1 parent bdb792f commit fdf3748

File tree

7 files changed

+98
-130
lines changed

7 files changed

+98
-130
lines changed

base/docs/helpdb/Base.jl

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,15 +2521,6 @@ Get the system time in seconds since the epoch, with fairly high (typically, mic
25212521
"""
25222522
time()
25232523

2524-
"""
2525-
qr(A [,pivot=Val{false}][;thin=true]) -> Q, R, [p]
2526-
2527-
Compute the (pivoted) QR factorization of `A` such that either `A = Q*R` or `A[:,p] = Q*R`.
2528-
Also see `qrfact`. The default is to compute a thin factorization. Note that `R` is not
2529-
extended with zeros when the full `Q` is requested.
2530-
"""
2531-
qr
2532-
25332524
"""
25342525
TextDisplay(stream)
25352526
@@ -2819,16 +2810,6 @@ retrieved by accessing `m.match` and the captured sequences can be retrieved by
28192810
"""
28202811
match
28212812

2822-
"""
2823-
qrfact!(A [,pivot=Val{false}])
2824-
2825-
`qrfact!` is the same as [`qrfact`](:func:`qrfact`) when `A` is a subtype of
2826-
`StridedMatrix`, but saves space by overwriting the input `A`, instead of creating a copy.
2827-
An `InexactError` exception is thrown if the factorisation produces a number not
2828-
representable by the element type of `A`, e.g. for integer types.
2829-
"""
2830-
qrfact!
2831-
28322813
"""
28332814
coth(x)
28342815
@@ -3037,16 +3018,6 @@ offset `do`. Returns `dest`.
30373018
"""
30383019
copy!(dest,d,src,so,N)
30393020

3040-
"""
3041-
qrfact(A) -> SPQR.Factorization
3042-
3043-
Compute the QR factorization of a sparse matrix `A`. A fill-reducing permutation is used.
3044-
The main application of this type is to solve least squares problems with `\\`. The function
3045-
calls the C library SPQR and a few additional functions from the library are wrapped but not
3046-
exported.
3047-
"""
3048-
qrfact(A)
3049-
30503021
"""
30513022
+(x, y...)
30523023
@@ -3085,19 +3056,6 @@ Reconstruct the matrix `A` from the factorization `F=factorize(A)`.
30853056
"""
30863057
full(F)
30873058

3088-
"""
3089-
full(QRCompactWYQ[, thin=true]) -> Matrix
3090-
3091-
Converts an orthogonal or unitary matrix stored as a `QRCompactWYQ` object, i.e. in the
3092-
compact WY format [^Bischof1987], to a dense matrix.
3093-
3094-
Optionally takes a `thin` Boolean argument, which if `true` omits the columns that span the
3095-
rows of `R` in the QR factorization that are zero. The resulting matrix is the `Q` in a thin
3096-
QR factorization (sometimes called the reduced QR factorization). If `false`, returns a `Q`
3097-
that spans all rows of `R` in its corresponding QR factorization.
3098-
"""
3099-
full(::LinAlg.QRCompactWYQ, ?)
3100-
31013059
"""
31023060
throw(e)
31033061

base/linalg/bunchkaufman.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ end
5757
"""
5858
bkfact(A, uplo::Symbol=:U, symmetric::Bool=issymmetric(A), rook::Bool=false) -> BunchKaufman
5959
60-
Compute the Bunch-Kaufman [^Bunch1977] factorization of a real symmetric or complex Hermitian
60+
Compute the Bunch-Kaufman [^Bunch1977] factorization of a symmetric or Hermitian
6161
matrix `A` and return a `BunchKaufman` object.
6262
`uplo` indicates which triangle of matrix `A` to reference.
6363
If `symmetric` is `true`, `A` is assumed to be symmetric. If `symmetric` is `false`,
64-
`A` is assumed to be complex Hermitian. If `rook` is `true`, rook pivoting is used. If
64+
`A` is assumed to be Hermitian. If `rook` is `true`, rook pivoting is used. If
6565
`rook` is false, rook pivoting is not used.
6666
The following functions are available for
6767
`BunchKaufman` objects: [`size`](:func:`size`), `\\`, [`inv`](:func:`inv`), [`issymmetric`](:func:`issymmetric`), [`ishermitian`](:func:`ishermitian`).

base/linalg/ldlt.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ convert{T,S,U}(::Type{Factorization{T}}, F::LDLt{S,U}) = convert(LDLt{T,U}, F)
1616

1717
# SymTridiagonal
1818
"""
19+
ldltfact!(S::SymTridiagonal) -> LDLt
1920
20-
ldltfact!(::SymTridiagonal) -> LDLt
21-
22-
Same as `ldltfact`, but saves space by overwriting the input `A`, instead of creating a copy.
21+
Same as [`ldltfact`](:func:`ldltfact`), but saves space by overwriting the input `A`, instead of creating a copy.
2322
"""
2423
function ldltfact!{T<:Real}(S::SymTridiagonal{T})
2524
n = size(S,1)
@@ -33,7 +32,7 @@ function ldltfact!{T<:Real}(S::SymTridiagonal{T})
3332
end
3433

3534
"""
36-
ldltfact(::SymTridiagonal) -> LDLt
35+
ldltfact(S::SymTridiagonal) -> LDLt
3736
3837
Compute an `LDLt` factorization of a real symmetric tridiagonal matrix such that `A = L*Diagonal(d)*L'`
3938
where `L` is a unit lower triangular matrix and `d` is a vector. The main use of an `LDLt`

base/linalg/qr.jl

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,21 @@ qrfact!{T<:BlasFloat}(A::StridedMatrix{T}, ::Type{Val{true}}) = QRPivoted(LAPACK
9090
qrfact!{T<:BlasFloat}(A::StridedMatrix{T}) = qrfact!(A, Val{false})
9191

9292
# Generic fallbacks
93+
94+
"""
95+
qrfact!(A, pivot=Val{false})
96+
97+
`qrfact!` is the same as [`qrfact`](:func:`qrfact`) when `A` is a subtype of
98+
`StridedMatrix`, but saves space by overwriting the input `A`, instead of creating a copy.
99+
An [`InexactError`](:obj:`InexactError`) exception is thrown if the factorisation produces a number not
100+
representable by the element type of `A`, e.g. for integer types.
101+
"""
93102
qrfact!(A::StridedMatrix, ::Type{Val{false}}) = qrfactUnblocked!(A)
94103
qrfact!(A::StridedMatrix, ::Type{Val{true}}) = qrfactPivotedUnblocked!(A)
95104
qrfact!(A::StridedMatrix) = qrfact!(A, Val{false})
96105

97106
"""
98-
qrfact(A [,pivot=Val{false}]) -> F
107+
qrfact(A, pivot=Val{false}) -> F
99108
100109
Computes the QR factorization of `A`. The return type of `F` depends on the element type of
101110
`A` and whether pivoting is specified (with `pivot==Val{true}`).
@@ -117,9 +126,9 @@ The individual components of the factorization `F` can be accessed by indexing:
117126
| `F[:p]` | pivot `Vector` | | | ✓ |
118127
| `F[:P]` | (pivot) permutation `Matrix` | | | ✓ |
119128
120-
The following functions are available for the `QR` objects: `size`, `\\`. When `A` is
121-
rectangular, `\\` will return a least squares solution and if the solution is not unique,
122-
the one with smallest norm is returned.
129+
The following functions are available for the `QR` objects: [`size`](:func:`size`)
130+
and [`\\`](:func:`\\`). When `A` is rectangular, `\\` will return a least squares
131+
solution and if the solution is not unique, the one with smallest norm is returned.
123132
124133
Multiplication with respect to either thin or full `Q` is allowed, i.e. both `F[:Q]*F[:R]`
125134
and `F[:Q]*A` are supported. A `Q` matrix can be converted into a regular matrix with
@@ -170,6 +179,14 @@ function qrfact{T}(A::AbstractMatrix{T})
170179
end
171180
qrfact(x::Number) = qrfact(fill(x,1,1))
172181

182+
"""
183+
qr(A, pivot=Val{false}; thin::Bool=true) -> Q, R, [p]
184+
185+
Compute the (pivoted) QR factorization of `A` such that either `A = Q*R` or `A[:,p] = Q*R`.
186+
Also see [`qrfact`](:func:`qrfact`).
187+
The default is to compute a thin factorization. Note that `R` is not
188+
extended with zeros when the full `Q` is requested.
189+
"""
173190
qr(A::Union{Number, AbstractMatrix}, pivot::Union{Type{Val{false}}, Type{Val{true}}}=Val{false}; thin::Bool=true) =
174191
_qr(A, pivot, thin=thin)
175192
function _qr(A::Union{Number, AbstractMatrix}, ::Type{Val{false}}; thin::Bool=true)
@@ -182,22 +199,14 @@ function _qr(A::Union{Number, AbstractMatrix}, ::Type{Val{true}}; thin::Bool=tru
182199
end
183200

184201
"""
185-
qr(v::AbstractVector)
202+
qr(v::AbstractVector) -> w, r
186203
187204
Computes the polar decomposition of a vector.
205+
Returns `w`, a unit vector in the direction of `v`, and
206+
`r`, the norm of `v`.
188207
189-
Input:
190-
191-
- `v::AbstractVector` - vector to normalize
192-
193-
Outputs:
194-
195-
- `w` - A unit vector in the direction of `v`
196-
- `r` - The norm of `v`
197-
198-
See also:
199-
200-
`normalize`, `normalize!`, `LinAlg.qr!`
208+
See also [`normalize`](:func:`normalize`), [`normalize!`](:func:`normalize!`),
209+
and [`LinAlg.qr!](:func:`LinAlg.qr!`).
201210
"""
202211
function qr(v::AbstractVector)
203212
nrm = norm(v)
@@ -211,23 +220,15 @@ function qr(v::AbstractVector)
211220
end
212221

213222
"""
214-
LinAlg.qr!(v::AbstractVector)
223+
LinAlg.qr!(v::AbstractVector) -> w, r
215224
216225
Computes the polar decomposition of a vector. Instead of returning a new vector
217226
as `qr(v::AbstractVector)`, this function mutates the input vector `v` in place.
227+
Returns `w`, a unit vector in the direction of `v` (this is a mutation of `v`),
228+
and `r`, the norm of `v`.
218229
219-
Input:
220-
221-
- `v::AbstractVector` - vector to normalize
222-
223-
Outputs:
224-
225-
- `w` - A unit vector in the direction of `v` (This is a mutation of `v`).
226-
- `r` - The norm of `v`
227-
228-
See also:
229-
230-
`normalize`, `normalize!`, `qr`
230+
See also [`normalize`](:func:`normalize`), [`normalize!`](:func:`normalize!`),
231+
and [`qr`](:func:`qr`).
231232
"""
232233
function qr!(v::AbstractVector)
233234
nrm = norm(v)
@@ -317,6 +318,18 @@ convert{S}(::Type{QRCompactWYQ{S}}, Q::QRCompactWYQ) = QRCompactWYQ(convert(Abst
317318
convert{S}(::Type{AbstractMatrix{S}}, Q::QRCompactWYQ) = convert(QRCompactWYQ{S}, Q)
318319
convert{T}(::Type{Matrix}, A::Union{QRPackedQ{T},QRCompactWYQ{T}}) = A_mul_B!(A, eye(T, size(A.factors, 1), minimum(size(A.factors))))
319320
convert(::Type{Array}, A::Union{QRPackedQ,QRCompactWYQ}) = convert(Matrix, A)
321+
322+
"""
323+
full(A::Union{QRPackedQ,QRCompactWYQ}; thin::Bool=true) -> Matrix
324+
325+
Converts an orthogonal or unitary matrix stored as a `QRCompactWYQ` object, i.e. in the
326+
compact WY format [^Bischof1987], or in the `QRPackedQ` format, to a dense matrix.
327+
328+
Optionally takes a `thin` Boolean argument, which if `true` omits the columns that span the
329+
rows of `R` in the QR factorization that are zero. The resulting matrix is the `Q` in a thin
330+
QR factorization (sometimes called the reduced QR factorization). If `false`, returns a `Q`
331+
that spans all rows of `R` in its corresponding QR factorization.
332+
"""
320333
function full{T}(A::Union{QRPackedQ{T},QRCompactWYQ{T}}; thin::Bool = true)
321334
if thin
322335
convert(Array, A)

base/sparse/cholmod.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,8 @@ factorization `F`. `A` must be a `SparseMatrixCSC`, `Symmetric{SparseMatrixCSC}`
12641264
or `Hermitian{SparseMatrixCSC}`. Note that even if `A` doesn't
12651265
have the type tag, it must still be symmetric or Hermitian.
12661266
1267+
See also [`cholfact`](:func:`cholfact`).
1268+
12671269
!!! note
12681270
This method uses the CHOLMOD library from SuiteSparse, which only supports
12691271
doubles or complex doubles. Input matrices not of those element types will
@@ -1304,16 +1306,17 @@ Compute the Cholesky factorization of a sparse positive definite matrix `A`.
13041306
have the type tag, it must still be symmetric or Hermitian.
13051307
A fill-reducing permutation is used.
13061308
`F = cholfact(A)` is most frequently used to solve systems of equations with `F\\b`,
1307-
but also the methods `diag`, `det`, `logdet` are defined for `F`.
1309+
but also the methods [`diag`](:func:`diag`), [`det`](:func:`det`), and
1310+
[`logdet`](:func:`logdet`) are defined for `F`.
13081311
You can also extract individual factors from `F`, using `F[:L]`.
13091312
However, since pivoting is on by default, the factorization is internally
13101313
represented as `A == P'*L*L'*P` with a permutation matrix `P`;
13111314
using just `L` without accounting for `P` will give incorrect answers.
13121315
To include the effects of permutation,
1313-
it's typically preferable to extact "combined" factors like `PtL = F[:PtL]`
1316+
it's typically preferable to extract "combined" factors like `PtL = F[:PtL]`
13141317
(the equivalent of `P'*L`) and `LtP = F[:UP]` (the equivalent of `L'*P`).
13151318
1316-
Setting optional `shift` keyword argument computes the factorization of
1319+
Setting the optional `shift` keyword argument computes the factorization of
13171320
`A+shift*I` instead of `A`. If the `perm` argument is nonempty,
13181321
it should be a permutation of `1:size(A,1)` giving the ordering to use
13191322
(instead of CHOLMOD's default AMD ordering).
@@ -1359,6 +1362,8 @@ Compute the ``LDL'`` factorization of `A`, reusing the symbolic factorization `F
13591362
`Hermitian{SparseMatrixCSC}`. Note that even if `A` doesn't
13601363
have the type tag, it must still be symmetric or Hermitian.
13611364
1365+
See also [`ldltfact`](:func:`ldltfact`).
1366+
13621367
!!! note
13631368
This method uses the CHOLMOD library from SuiteSparse, which only supports
13641369
doubles or complex doubles. Input matrices not of those element types will
@@ -1399,17 +1404,18 @@ Compute the ``LDL'`` factorization of a sparse matrix `A`.
13991404
have the type tag, it must still be symmetric or Hermitian.
14001405
A fill-reducing permutation is used. `F = ldltfact(A)` is most frequently
14011406
used to solve systems of equations `A*x = b` with `F\\b`. The returned
1402-
factorization object `F` also supports the methods `diag`,
1403-
`det`, and `logdet`. You can extract individual factors from `F` using `F[:L]`.
1407+
factorization object `F` also supports the methods [`diag`](:func:`diag`),
1408+
[`det`](:func:`det`), and [`logdet`](:func:`logdet`).
1409+
You can extract individual factors from `F` using `F[:L]`.
14041410
However, since pivoting is on by default, the factorization is internally
14051411
represented as `A == P'*L*D*L'*P` with a permutation matrix `P`;
14061412
using just `L` without accounting for `P` will give incorrect answers.
1407-
To include the effects of permutation, it is typically preferable to extact
1413+
To include the effects of permutation, it is typically preferable to extract
14081414
"combined" factors like `PtL = F[:PtL]` (the equivalent of
14091415
`P'*L`) and `LtP = F[:UP]` (the equivalent of `L'*P`).
14101416
The complete list of supported factors is `:L, :PtL, :D, :UP, :U, :LD, :DU, :PtLD, :DUP`.
14111417
1412-
Setting optional `shift` keyword argument computes the factorization of
1418+
Setting the optional `shift` keyword argument computes the factorization of
14131419
`A+shift*I` instead of `A`. If the `perm` argument is nonempty,
14141420
it should be a permutation of `1:size(A,1)` giving the ordering to use
14151421
(instead of CHOLMOD's default AMD ordering).

base/sparse/spqr.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,17 @@ function qmult{Tv<:VTypes}(method::Integer, QR::Factorization{Tv}, X::Dense{Tv})
136136
d
137137
end
138138

139+
139140
qrfact(A::SparseMatrixCSC, ::Type{Val{true}}) = factorize(ORDERING_DEFAULT, DEFAULT_TOL, Sparse(A, 0))
141+
142+
"""
143+
qrfact(A) -> SPQR.Factorization
144+
145+
Compute the `QR` factorization of a sparse matrix `A`. A fill-reducing permutation is used.
146+
The main application of this type is to solve least squares problems with `\\`. The function
147+
calls the C library SPQR and a few additional functions from the library are wrapped but not
148+
exported.
149+
"""
140150
qrfact(A::SparseMatrixCSC) = qrfact(A, Val{true})
141151

142152
# With a real lhs and complex rhs with the same precision, we can reinterpret

0 commit comments

Comments
 (0)