From 78172253c11c9f6119d13c3a5dc2b9fe4a0a7d10 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Sat, 21 Mar 2020 07:15:52 +0300 Subject: [PATCH] check dl===du in lu! for Tridiagonal; closes #35167 --- stdlib/LinearAlgebra/src/lu.jl | 3 +++ stdlib/LinearAlgebra/test/lu.jl | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/stdlib/LinearAlgebra/src/lu.jl b/stdlib/LinearAlgebra/src/lu.jl index 5a240478a1123..c770f478d4f4a 100644 --- a/stdlib/LinearAlgebra/src/lu.jl +++ b/stdlib/LinearAlgebra/src/lu.jl @@ -489,6 +489,9 @@ function lu!(A::Tridiagonal{T,V}, pivot::Union{Val{false}, Val{true}} = Val(true dl = A.dl d = A.d du = A.du + if dl === du + throw(ArgumentError("off-diagonals of `A` must not alias")) + end du2 = fill!(similar(d, n-2), 0)::V @inbounds begin diff --git a/stdlib/LinearAlgebra/test/lu.jl b/stdlib/LinearAlgebra/test/lu.jl index 9ff1e7f7388e8..722a69aae6ea7 100644 --- a/stdlib/LinearAlgebra/test/lu.jl +++ b/stdlib/LinearAlgebra/test/lu.jl @@ -93,6 +93,12 @@ dimg = randn(n)/2 @test lud.L*lud.U ≈ Array(d)[lud.p,:] @test AbstractArray(lud) ≈ d @test Array(lud) ≈ d + if eltya != Int + dlu = convert.(eltya, [1, 1]) + dia = convert.(eltya, [-2, -2, -2]) + tri = Tridiagonal(dlu, dia, dlu) + @test_throws ArgumentError lu!(tri) + end end @testset for eltyb in (Float32, Float64, ComplexF32, ComplexF64, Int) b = eltyb == Int ? rand(1:5, n, 2) :