Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2088,26 +2088,32 @@ julia> copytrito!(B, A, 'L')
function copytrito!(B::AbstractMatrix, A::AbstractMatrix, uplo::AbstractChar)
require_one_based_indexing(A, B)
BLAS.chkuplo(uplo)
B === A && return B
m,n = size(A)
A = Base.unalias(B, A)
if uplo == 'U'
LAPACK.lacpy_size_check(size(B), (n < m ? n : m, n))
# extract the parents for UpperTriangular matrices
Bv, Av = uppertridata(B), uppertridata(A)
for j in axes(A,2), i in axes(A,1)[begin : min(j,end)]
# extract the parents for UpperTriangular matrices
Bv, Av = uppertridata(B), uppertridata(A)
@inbounds Bv[i,j] = Av[i,j]
end
else # uplo == 'L'
LAPACK.lacpy_size_check(size(B), (m, m < n ? m : n))
# extract the parents for LowerTriangular matrices
Bv, Av = lowertridata(B), lowertridata(A)
for j in axes(A,2), i in axes(A,1)[j:end]
# extract the parents for LowerTriangular matrices
Bv, Av = lowertridata(B), lowertridata(A)
@inbounds Bv[i,j] = Av[i,j]
end
end
return B
end
# Forward LAPACK-compatible strided matrices to lacpy
function copytrito!(B::StridedMatrixStride1{T}, A::StridedMatrixStride1{T}, uplo::AbstractChar) where {T<:BlasFloat}
require_one_based_indexing(A, B)
BLAS.chkuplo(uplo)
B === A && return B
A = Base.unalias(B, A)
LAPACK.lacpy!(B, A, uplo)
return B
end
9 changes: 9 additions & 0 deletions test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -879,4 +879,13 @@ end
@test mul!(copy!(similar(v), v), v, 2, 2, 0) == 4v
end

@testset "aliasing in copytrito! for strided matrices" begin
M = rand(4, 1)
A = view(M, 1:3, 1:1)
A2 = copy(A)
B = view(M, 2:4, 1:1)
copytrito!(B, A, 'L')
@test B == A2
end

end # module TestGeneric