From 72d644fd7dbc6e6b75518132b88cd848ab8e2d65 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 16 May 2024 02:30:53 +0530 Subject: [PATCH] Unalias source from dest in copytrito (#54474) --- stdlib/LinearAlgebra/src/generic.jl | 1 + stdlib/LinearAlgebra/test/generic.jl | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/stdlib/LinearAlgebra/src/generic.jl b/stdlib/LinearAlgebra/src/generic.jl index 43913807c89e8..6296d3016d56c 100644 --- a/stdlib/LinearAlgebra/src/generic.jl +++ b/stdlib/LinearAlgebra/src/generic.jl @@ -2012,6 +2012,7 @@ function copytrito!(B::AbstractMatrix, A::AbstractMatrix, uplo::AbstractChar) m,n = size(A) m1,n1 = size(B) (m1 < m || n1 < n) && throw(DimensionMismatch(lazy"B of size ($m1,$n1) should have at least the same number of rows and columns than A of size ($m,$n)")) + A = Base.unalias(B, A) if uplo == 'U' for j=1:n for i=1:min(j,m) diff --git a/stdlib/LinearAlgebra/test/generic.jl b/stdlib/LinearAlgebra/test/generic.jl index 6318b8e405ede..ba4bdb1845255 100644 --- a/stdlib/LinearAlgebra/test/generic.jl +++ b/stdlib/LinearAlgebra/test/generic.jl @@ -654,6 +654,14 @@ end C = uplo == 'L' ? tril(A) : triu(A) @test B ≈ C end + @testset "aliasing" begin + M = Matrix(reshape(1:36, 6, 6)) + A = view(M, 1:5, 1:5) + A2 = Matrix(A) + B = view(M, 2:6, 2:6) + copytrito!(B, A, 'U') + @test UpperTriangular(B) == UpperTriangular(A2) + end end @testset "immutable arrays" begin