@@ -103,22 +103,63 @@ function lu!(A::HermOrSym{T}, pivot::Union{RowMaximum,NoPivot,RowNonZero} = lupi
103
103
lu! (A. data, pivot; check, allowsingular)
104
104
end
105
105
106
- # reusing LU object
107
106
# 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
108
109
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
115
138
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
+ """
116
151
function lu! (F:: LU{<:Any,<:AbstractMatrix} , A; check:: Bool = true , allowsingular:: Bool = false )
117
152
copyto! (F. factors, A)
118
153
return generic_lufact! (F. factors, lupivottype (eltype (A)), F. ipiv; check, allowsingular)
119
154
end
120
155
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
122
163
123
164
# for backward compatibility
124
165
# TODO : remove towards Julia v2
0 commit comments