Skip to content

Commit 0653044

Browse files
jishnubKristofferC
authored andcommitted
Unalias source from dest in copytrito (#54474)
(cherry picked from commit 72d644f)
1 parent e8662da commit 0653044

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

stdlib/LinearAlgebra/src/generic.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,7 @@ function copytrito!(B::AbstractMatrix, A::AbstractMatrix, uplo::AbstractChar)
19351935
m,n = size(A)
19361936
m1,n1 = size(B)
19371937
(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)"))
1938+
A = Base.unalias(B, A)
19381939
if uplo == 'U'
19391940
for j=1:n
19401941
for i=1:min(j,m)

stdlib/LinearAlgebra/test/generic.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,14 @@ end
654654
C = uplo == 'L' ? tril(A) : triu(A)
655655
@test B C
656656
end
657+
@testset "aliasing" begin
658+
M = Matrix(reshape(1:36, 6, 6))
659+
A = view(M, 1:5, 1:5)
660+
A2 = Matrix(A)
661+
B = view(M, 2:6, 2:6)
662+
copytrito!(B, A, 'U')
663+
@test UpperTriangular(B) == UpperTriangular(A2)
664+
end
657665
end
658666

659667
@testset "immutable arrays" begin

0 commit comments

Comments
 (0)