Skip to content

Commit 58d5263

Browse files
authored
Fix errant lmul! for tridiagonal and triangular (JuliaLang#55546)
This method is incorrect. Firstly, the current implementation doesn't act in-place. Secondly, the result can't be stored in-place into a triangular matrix in general. This PR changes the implementation to convert the tridiagonal matrix to a `Diagonal` or a `Bidiagonal` one before attempting the `lmul!`. Currently, ```julia julia> T = Tridiagonal([1,2], [1,2,3], [1,2]); U = UpperTriangular(fill(2, 3, 3)); julia> lmul!(T, U) 3×3 Matrix{Int64}: 2 4 4 2 6 10 0 4 10 julia> U # not updated 3×3 UpperTriangular{Int64, Matrix{Int64}}: 2 2 2 ⋅ 2 2 ⋅ ⋅ 2 julia> parent(U) # except for the underlying storage 3×3 Matrix{Int64}: 2 2 2 0 2 2 0 0 2 ``` After this, ```julia julia> lmul!(T, U) ERROR: ArgumentError: matrix cannot be represented as Bidiagonal ``` I'm unsure if we want this method at all, since there isn't a corresponding `rmul!`, but I've left it there to avoid breakages, if any.
1 parent 4b99e99 commit 58d5263

File tree

2 files changed

+0
-4
lines changed

2 files changed

+0
-4
lines changed

stdlib/LinearAlgebra/src/triangular.jl

-2
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,6 @@ isunit_char(::UnitUpperTriangular) = 'U'
953953
isunit_char(::LowerTriangular) = 'N'
954954
isunit_char(::UnitLowerTriangular) = 'U'
955955

956-
lmul!(A::Tridiagonal, B::AbstractTriangular) = A*full!(B)
957-
958956
# generic fallback for AbstractTriangular matrices outside of the four subtypes provided here
959957
_trimul!(C::AbstractVecOrMat, A::AbstractTriangular, B::AbstractVector) =
960958
lmul!(A, copyto!(C, B))

stdlib/LinearAlgebra/test/triangular.jl

-2
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ Base.getindex(A::MyTriangular, i::Int, j::Int) = A.data[i,j]
442442

443443
debug && println("elty1: $elty1, A1: $t1, B: $eltyB")
444444

445-
Tri = Tridiagonal(rand(eltyB,n-1),rand(eltyB,n),rand(eltyB,n-1))
446-
@test lmul!(Tri,copy(A1)) Tri*M1
447445
Tri = Tridiagonal(rand(eltyB,n-1),rand(eltyB,n),rand(eltyB,n-1))
448446
C = Matrix{promote_type(elty1,eltyB)}(undef, n, n)
449447
mul!(C, Tri, A1)

0 commit comments

Comments
 (0)