Skip to content

Reuse du2 of Tridiagonal matrix for pivoting in lu! if extant #47564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions stdlib/LinearAlgebra/src/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,14 @@ function lu!(A::Tridiagonal{T,V}, pivot::Union{RowMaximum,NoPivot} = RowMaximum(
if dl === du
throw(ArgumentError("off-diagonals of `A` must not alias"))
end
du2 = fill!(similar(d, max(0, n-2)), 0)::V
# Check if Tridiagonal matrix already has du2 for pivoting
has_du2_defined = isdefined(A, :du2) && length(A.du2) == max(0, n-2)
if has_du2_defined
du2 = A.du2::V
else
du2 = similar(d, max(0, n-2))::V
end
fill!(du2, 0)

@inbounds begin
for i = 1:n
Expand Down Expand Up @@ -582,7 +589,7 @@ function lu!(A::Tridiagonal{T,V}, pivot::Union{RowMaximum,NoPivot} = RowMaximum(
end
end
end
B = Tridiagonal{T,V}(dl, d, du, du2)
B = has_du2_defined ? A : Tridiagonal{T,V}(dl, d, du, du2)
check && checknonsingular(info, pivot)
return LU{T,Tridiagonal{T,V},typeof(ipiv)}(B, ipiv, convert(BlasInt, info))
end
Expand Down