diff --git a/src/triangular.jl b/src/triangular.jl index b0af1c34..595a524d 100644 --- a/src/triangular.jl +++ b/src/triangular.jl @@ -623,7 +623,8 @@ end copytrito!(dest, U, U isa UpperOrUnitUpperTriangular ? 'L' : 'U') return dest end -@propagate_inbounds function _copy!(dest::StridedMatrix, U::UpperOrLowerTriangular{<:Any, <:StridedMatrix}) +@propagate_inbounds function _copy!(dest::StridedMatrix, + U::Union{UnitUpperOrUnitLowerTriangular, UpperOrLowerTriangularStrided}) U2 = Base.unalias(dest, U) copy_unaliased!(dest, U2) return dest @@ -656,7 +657,7 @@ end end dest end -@inline function copy_unaliased!(dest::StridedMatrix, U::UpperOrUnitUpperTriangular{<:Any, <:StridedMatrix}) +@inline function copy_unaliased!(dest::StridedMatrix, U::UpperOrUnitUpperTriangular) @boundscheck checkbounds(dest, axes(U)...) for col in axes(dest,2) @inbounds copy_unaliased_stored!(dest, U, col) @@ -666,7 +667,7 @@ end end return dest end -@inline function copy_unaliased!(dest::StridedMatrix, L::LowerOrUnitLowerTriangular{<:Any, <:StridedMatrix}) +@inline function copy_unaliased!(dest::StridedMatrix, L::LowerOrUnitLowerTriangular) @boundscheck checkbounds(dest, axes(L)...) for col in axes(dest,2) for row in firstindex(dest,1):col-1 diff --git a/test/triangular.jl b/test/triangular.jl index c5dca32d..f7de5c10 100644 --- a/test/triangular.jl +++ b/test/triangular.jl @@ -6,6 +6,7 @@ isdefined(Main, :pruned_old_LA) || @eval Main include("prune_old_LA.jl") using Test, LinearAlgebra, Random using LinearAlgebra: errorbounds, transpose!, BandIndex +using Test: GenericArray const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test") @@ -650,6 +651,16 @@ end @test_throws "cannot set index in the upper triangular part" copyto!(A, B) end end + + @testset "partly initialized unit triangular" begin + for T in (UnitUpperTriangular, UnitLowerTriangular) + isupper = T == UnitUpperTriangular + M = Matrix{BigFloat}(undef, 2, 2) + M[1+!isupper,1+isupper] = 3 + U = T(GenericArray(M)) + @test copyto!(similar(M), U) == U + end + end end @testset "getindex with Integers" begin