Skip to content

Commit

Permalink
Transpose elements in copy_transpose! (JuliaLang#52116)
Browse files Browse the repository at this point in the history
  • Loading branch information
maltezfaria committed Nov 14, 2023
1 parent 1a885c4 commit 4bc45a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/transpose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function copy_transpose!(B::AbstractVecOrMat, ir_dest::AbstractRange{Int}, jr_de
for jsrc in jr_src
jdest = first(jr_dest)
for isrc in ir_src
B[idest,jdest] = A[isrc,jsrc]
B[idest,jdest] = transpose(A[isrc,jsrc])
jdest += step(jr_dest)
end
idest += step(ir_dest)
Expand Down
15 changes: 15 additions & 0 deletions stdlib/LinearAlgebra/test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -681,4 +681,19 @@ end
@test sprint(Base.print_matrix, Adjoint(o)) == sprint(Base.print_matrix, OneHotVecOrMat((1,2), (1,4)))
end

@testset "copy_transpose!" begin
# scalar case
A = [randn() for _ in 1:2, _ in 1:3]
At = copy(transpose(A))
B = zero.(At)
LinearAlgebra.copy_transpose!(B, axes(B, 1), axes(B, 2), A, axes(A, 1), axes(A, 2))
@test B == At
# matrix of matrices
A = [randn(2,3) for _ in 1:2, _ in 1:3]
At = copy(transpose(A))
B = zero.(At)
LinearAlgebra.copy_transpose!(B, axes(B, 1), axes(B, 2), A, axes(A, 1), axes(A, 2))
@test B == At
end

end # module TestAdjointTranspose

0 comments on commit 4bc45a7

Please sign in to comment.