diff --git a/stdlib/LinearAlgebra/src/triangular.jl b/stdlib/LinearAlgebra/src/triangular.jl index 18c2edf15eb54..6ed9e43d6f507 100644 --- a/stdlib/LinearAlgebra/src/triangular.jl +++ b/stdlib/LinearAlgebra/src/triangular.jl @@ -181,6 +181,9 @@ end Array(A::AbstractTriangular) = Matrix(A) parent(A::UpperOrLowerTriangular) = A.data +# For strided matrices, we may only loop over the filled triangle +copy(A::UpperOrLowerTriangular{<:Any, <:StridedMaybeAdjOrTransMat}) = copyto!(similar(A), A) + # then handle all methods that requires specific handling of upper/lower and unit diagonal function Matrix{T}(A::LowerTriangular) where T diff --git a/stdlib/LinearAlgebra/test/triangular.jl b/stdlib/LinearAlgebra/test/triangular.jl index 69011e69167a3..97bf756044c66 100644 --- a/stdlib/LinearAlgebra/test/triangular.jl +++ b/stdlib/LinearAlgebra/test/triangular.jl @@ -1007,6 +1007,7 @@ end L = MT(A) B .= 0 copyto!(B, L) + @test copy(L) == B @test L * 2 == 2 * L == 2B @test L/2 == B/2 @test 2\L == 2\B @@ -1032,6 +1033,7 @@ end U = MT(A) B .= 0 copyto!(B, U) + @test copy(U) == B @test U * 2 == 2 * U == 2B @test U/2 == B/2 @test 2\U == 2\B