Skip to content

Commit

Permalink
Forward copyto! for Adjoint to adjoint! (#51650)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Oct 12, 2023
1 parent a045313 commit 71872d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/src/transpose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,13 @@ function copy_similar(A::TransposeAbsMat, ::Type{T}) where {T}
C = similar(A, T, size(A))
transpose!(C, parent(A))
end

function Base.copyto_unaliased!(deststyle::IndexStyle, dest::AbstractMatrix, srcstyle::IndexCartesian, src::AdjOrTransAbsMat)
if axes(dest) == axes(src)
f! = inplace_adj_or_trans(src)
f!(dest, parent(src))
else
@invoke Base.copyto_unaliased!(deststyle::IndexStyle, dest::AbstractArray, srcstyle::IndexStyle, src::AbstractArray)
end
return dest
end
10 changes: 10 additions & 0 deletions stdlib/LinearAlgebra/test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ end
@test adjoint!(b, a) === b
end

@testset "copyto! uses adjoint!/transpose!" begin
for T in (Float64, ComplexF64), f in (transpose, adjoint), sz in ((5,4), (5,))
S = rand(T, sz)
adjS = f(S)
A = similar(S')
copyto!(A, adjS)
@test A == adjS
end
end

@testset "aliasing with adjoint and transpose" begin
A = collect(reshape(1:25, 5, 5)) .+ rand.().*im
B = copy(A)
Expand Down

0 comments on commit 71872d1

Please sign in to comment.