Skip to content

Commit 7409a1c

Browse files
authored
Fix pivoted cholesky docstrings (#41298)
1 parent 0189772 commit 7409a1c

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

stdlib/LinearAlgebra/src/cholesky.jl

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ positive semi-definite matrix `A`. This is the return type of [`cholesky(_, Val(
110110
the corresponding matrix factorization function.
111111
112112
The triangular Cholesky factor can be obtained from the factorization `F::CholeskyPivoted`
113-
via `F.L` and `F.U`, and the permutation via `F.p`, where `A[F.p, F.p] ≈ F.U' * F.U ≈ F.L * F.L'`,
114-
or alternatively `A ≈ F.U[:, F.p]' * F.U[:, F.p] ≈ F.L[F.p, :] * F.L[F.p, :]'`.
113+
via `F.L` and `F.U`, and the permutation via `F.p`, where `A[F.p, F.p] ≈ Ur' * Ur ≈ Lr * Lr'`
114+
with `Ur = F.U[1:F.rank, :]` and `Lr = F.L[:, 1:F.rank]`, or alternatively
115+
`A ≈ Up' * Up ≈ Lp * Lp'` with `Up = F.U[1:F.rank, invperm(F.p)]` and
116+
`Lp = F.L[invperm(F.p), 1:F.rank]`.
115117
116118
The following functions are available for `CholeskyPivoted` objects:
117119
[`size`](@ref), [`\\`](@ref), [`inv`](@ref), [`det`](@ref), and [`rank`](@ref).
@@ -120,25 +122,28 @@ Iterating the decomposition produces the components `L` and `U`.
120122
121123
# Examples
122124
```jldoctest
123-
julia> A = [4. 12. -16.; 12. 37. -43.; -16. -43. 98.]
124-
3×3 Matrix{Float64}:
125-
4.0 12.0 -16.0
126-
12.0 37.0 -43.0
127-
-16.0 -43.0 98.0
125+
julia> X = [1.0, 2.0, 3.0, 4.0];
128126
129-
julia> C = cholesky(A, Val(true))
127+
julia> A = X * X';
128+
129+
julia> C = cholesky(A, Val(true), check = false)
130130
CholeskyPivoted{Float64, Matrix{Float64}}
131-
U factor with rank 3:
132-
3×3 UpperTriangular{Float64, Matrix{Float64}}:
133-
9.89949 -4.34366 -1.61624
134-
⋅ 4.25825 1.1694
135-
⋅ ⋅ 0.142334
131+
U factor with rank 1:
132+
4×4 UpperTriangular{Float64, Matrix{Float64}}:
133+
4.0 2.0 3.0 1.0
134+
⋅ 0.0 6.0 2.0
135+
⋅ ⋅ 9.0 3.0
136+
⋅ ⋅ ⋅ 1.0
136137
permutation:
137-
3-element Vector{Int64}:
138-
3
138+
4-element Vector{Int64}:
139+
4
139140
2
141+
3
140142
1
141143
144+
julia> C.U[1:C.rank, :]' * C.U[1:C.rank, :] ≈ A[C.p, C.p]
145+
true
146+
142147
julia> l, u = C; # destructuring via iteration
143148
144149
julia> l == C.L && u == C.U
@@ -403,8 +408,9 @@ and return a [`CholeskyPivoted`](@ref) factorization. The matrix `A` can either
403408
or [`Hermitian`](@ref) [`StridedMatrix`](@ref) or a *perfectly* symmetric or Hermitian `StridedMatrix`.
404409
405410
The triangular Cholesky factor can be obtained from the factorization `F` via `F.L` and `F.U`,
406-
and the permutation via `F.p`, where `A[F.p, F.p] ≈ F.U' * F.U ≈ F.L * F.L'`, or alternatively
407-
`A ≈ F.U[:, F.p]' * F.U[:, F.p] ≈ F.L[F.p, :] * F.L[F.p, :]'`.
411+
and the permutation via `F.p`, where `A[F.p, F.p] ≈ Ur' * Ur ≈ Lr * Lr'` with `Ur = F.U[1:F.rank, :]`
412+
and `Lr = F.L[:, 1:F.rank]`, or alternatively `A ≈ Up' * Up ≈ Lp * Lp'` with
413+
`Up = F.U[1:F.rank, invperm(F.p)]` and `Lp = F.L[invperm(F.p), 1:F.rank]`.
408414
409415
The following functions are available for `CholeskyPivoted` objects:
410416
[`size`](@ref), [`\\`](@ref), [`inv`](@ref), [`det`](@ref), and [`rank`](@ref).
@@ -421,26 +427,26 @@ validity (via [`issuccess`](@ref)) lies with the user.
421427
422428
# Examples
423429
```jldoctest
424-
julia> A = [4. 12. -16.; 12. 37. -43.; -16. -43. 98.]
425-
3×3 Matrix{Float64}:
426-
4.0 12.0 -16.0
427-
12.0 37.0 -43.0
428-
-16.0 -43.0 98.0
430+
julia> X = [1.0, 2.0, 3.0, 4.0];
431+
432+
julia> A = X * X';
429433
430-
julia> C = cholesky(A, Val(true))
434+
julia> C = cholesky(A, Val(true), check = false)
431435
CholeskyPivoted{Float64, Matrix{Float64}}
432-
U factor with rank 3:
433-
3×3 UpperTriangular{Float64, Matrix{Float64}}:
434-
9.89949 -4.34366 -1.61624
435-
⋅ 4.25825 1.1694
436-
⋅ ⋅ 0.142334
436+
U factor with rank 1:
437+
4×4 UpperTriangular{Float64, Matrix{Float64}}:
438+
4.0 2.0 3.0 1.0
439+
⋅ 0.0 6.0 2.0
440+
⋅ ⋅ 9.0 3.0
441+
⋅ ⋅ ⋅ 1.0
437442
permutation:
438-
3-element Vector{Int64}:
439-
3
443+
4-element Vector{Int64}:
444+
4
440445
2
446+
3
441447
1
442448
443-
julia> C.U[:, C.p]' * C.U[:, C.p] ≈ A
449+
julia> C.U[1:C.rank, :]' * C.U[1:C.rank, :] ≈ A[C.p, C.p]
444450
true
445451
446452
julia> l, u = C; # destructuring via iteration

0 commit comments

Comments
 (0)