Skip to content

Commit 72d644f

Browse files
authored
Unalias source from dest in copytrito (#54474)
1 parent 9ea4536 commit 72d644f

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
@@ -2012,6 +2012,7 @@ function copytrito!(B::AbstractMatrix, A::AbstractMatrix, uplo::AbstractChar)
20122012
m,n = size(A)
20132013
m1,n1 = size(B)
20142014
(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)"))
2015+
A = Base.unalias(B, A)
20152016
if uplo == 'U'
20162017
for j=1:n
20172018
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)