Skip to content

Commit

Permalink
Update lacpy! and copytotri!
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Nov 1, 2023
1 parent 131bb44 commit 2db81ef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
22 changes: 12 additions & 10 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ normalize(x) = x / norm(x)
normalize(x, p::Real) = x / norm(x, p)

"""
copytotri!(uplo, A, B) -> B
copytotri!(B, A, uplo) -> B
Copies a triangular part of a matrix `A` to another matrix `B`.
`uplo` specifies the part of the matrix `A` to be copied to `B`.
Expand All @@ -1915,26 +1915,28 @@ julia> A = [1 2 ; 3 4];
julia> B = [0 0 ; 0 0];
julia> copytotri!('L', A, B)
julia> copytotri!(B, A, 'L')
2×2 Matrix{Int64}:
1 0
3 4
```
"""
function copytotri!(uplo::AbstractChar, A::AbstractMatrix, B::AbstractMatrix)
function copytotri!(B::AbstractMatrix, A::AbstractMatrix, uplo::AbstractChar)
require_one_based_indexing(A, B)
LinearAlgebra.BLAS.chkuplo(uplo)
m, n = size(A)
m,n = size(A)
m1,n1 = size(B)
(m1 < m || n1 < n) && throw(DimensionMismatch("B of size ($m1,$n1) should have at least the same number of rows and columns than A of size ($m,$n)"))
if uplo == 'U'
@inbounds for j=1:n
@inbounds for i=1:min(j,m)
B[i,j] = A[i,j]
for j=1:n
for i=1:min(j,m)
@inbounds B[i,j] = A[i,j]
end
end
else # uplo == 'L'
@inbounds for j=1:n
@inbounds for i=j:m
B[i,j] = A[i,j]
for j=1:n
for i=j:m
@inbounds B[i,j] = A[i,j]
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7005,7 +7005,7 @@ for (fn, elty) in ((:dlacpy_, :Float64),
# .. Array Arguments ..
# DOUBLE PRECISION A( LDA, * ), B( LDB, * )
# ..
function lacpy!(uplo::AbstractChar, A::AbstractMatrix{$elty}, B::AbstractMatrix{$elty})
function lacpy!(B::AbstractMatrix{$elty}, A::AbstractMatrix{$elty}, uplo::AbstractChar)
require_one_based_indexing(A, B)
chkstride1(A, B)
chkuplo(uplo)
Expand All @@ -7024,7 +7024,7 @@ for (fn, elty) in ((:dlacpy_, :Float64),
end

"""
lacpy!(uplo, A, B) -> B
lacpy!(B, A, uplo) -> B
Copies all or part of a matrix `A` to another matrix `B`.
uplo specifies the part of the matrix `A` to be copied to `B`.
Expand All @@ -7038,12 +7038,12 @@ julia> A = [1. 2. ; 3. 4.];
julia> B = [0. 0. ; 0. 0.];
julia> LAPACK.lacpy!('U', A, B)
julia> LAPACK.lacpy!(B, A, 'U')
2×2 Matrix{Float64}:
1.0 2.0
0.0 4.0
```
"""
lacpy!(uplo::AbstractChar, A::AbstractMatrix, B::AbstractMatrix)
lacpy!(B::AbstractMatrix, A::AbstractMatrix, uplo::AbstractChar)

end # module
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ end
A = rand(n, n)
for uplo in ('L', 'U')
B = zeros(n, n)
copytotri!(uplo, A, B)
copytotri!(B, A, uplo)
C = uplo == 'L' ? tril(A) : triu(A)
@test A == C
@test A C
end
end

Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/test/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,9 @@ end
A = rand(elty, n, n)
for uplo in ('L', 'U', 'N')
B = zeros(elty, n, n)
LinearAlgebra.LAPACK.lacpy!(uplo, A, B)
LinearAlgebra.LAPACK.lacpy!(B, A, uplo)
C = uplo == 'L' ? tril(A) : (uplo == 'U' ? triu(A) : A)
@test A == C
@test A C
end
end
end
Expand Down

0 comments on commit 2db81ef

Please sign in to comment.