Skip to content

Commit 721f077

Browse files
authored
docs for lu!(F::LU,A)
1 parent b8d1ecc commit 721f077

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

src/lu.jl

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,63 @@ function lu!(A::HermOrSym{T}, pivot::Union{RowMaximum,NoPivot,RowNonZero} = lupi
103103
lu!(A.data, pivot; check, allowsingular)
104104
end
105105

106-
#reusing LU object
107106
#lu!(F::LU,A) should be dispatched on the type of matrix stored in the LU factorization.
107+
"""
108+
lu!(F::LU, pivot = RowMaximum(); check = true, allowsingular = false) -> LU
108109
109-
function lu!(F::LU{<:Any,<:StridedMatrix{<:BlasFloat}}, A; check::Bool = true, allowsingular::Bool = false)
110-
copyto!(F.factors, A)
111-
lpt = LAPACK.getrf!(F.factors, F.ipiv; check)
112-
check && _check_lu_success(lpt[3], allowsingular)
113-
return LU{T,typeof(lpt[1]),typeof(lpt[2])}(lpt[1], lpt[2], lpt[3])
114-
end
110+
`lu!` is the same as [`lu`](@ref), but saves space by overwriting the
111+
input `F`, instead of creating a copy.
112+
113+
!!! compat "Julia 1.12"
114+
reusing `LU` factorizations in `lu!` require Julia 1.12 or later.
115+
116+
# Examples
117+
```jldoctest
118+
julia> A = [4. 3.; 6. 3.]
119+
2×2 Matrix{Float64}:
120+
4.0 3.0
121+
6.0 3.0
122+
123+
julia> F = lu(A)
124+
LU{Float64, Matrix{Float64}, Vector{Int64}}
125+
L factor:
126+
2×2 Matrix{Float64}:
127+
1.0 0.0
128+
0.666667 1.0
129+
U factor:
130+
2×2 Matrix{Float64}:
131+
6.0 3.0
132+
0.0 1.0
133+
134+
julia> B = [8 3; 12 3]
135+
2×2 Matrix{Int64}:
136+
8 3
137+
12 3
115138
139+
julia> F2 = lu!(F,A)
140+
LU{Float64, Matrix{Float64}, Vector{Int64}}
141+
L factor:
142+
2×2 Matrix{Float64}:
143+
1.0 0.0
144+
0.666667 1.0
145+
U factor:
146+
2×2 Matrix{Float64}:
147+
12.0 3.0
148+
0.0 1.0
149+
```
150+
"""
116151
function lu!(F::LU{<:Any,<:AbstractMatrix}, A; check::Bool = true, allowsingular::Bool = false)
117152
copyto!(F.factors, A)
118153
return generic_lufact!(F.factors, lupivottype(eltype(A)), F.ipiv; check, allowsingular)
119154
end
120155

121-
156+
#lu!(F::LU,A) should be dispatched on the type of matrix stored in the LU factorization.
157+
function lu!(F::LU{<:Any,<:StridedMatrix{<:BlasFloat}}, A; check::Bool = true, allowsingular::Bool = false)
158+
copyto!(F.factors, A)
159+
lpt = LAPACK.getrf!(F.factors, F.ipiv; check)
160+
check && _check_lu_success(lpt[3], allowsingular)
161+
return LU{T,typeof(lpt[1]),typeof(lpt[2])}(lpt[1], lpt[2], lpt[3])
162+
end
122163

123164
# for backward compatibility
124165
# TODO: remove towards Julia v2

0 commit comments

Comments
 (0)