Skip to content

Commit

Permalink
Unalias source from dest in copytrito (#54474)
Browse files Browse the repository at this point in the history
(cherry picked from commit 72d644f)
  • Loading branch information
jishnub authored and KristofferC committed Jun 7, 2024
1 parent e8662da commit 0653044
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,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)
Expand Down
8 changes: 8 additions & 0 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0653044

Please sign in to comment.