Skip to content

Commit 73dfde8

Browse files
authored
Forward copyto! for Adjoint to adjoint! (#51650)
1 parent 5723a05 commit 73dfde8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/transpose.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,13 @@ function copy_similar(A::TransposeAbsMat, ::Type{T}) where {T}
210210
C = similar(A, T, size(A))
211211
transpose!(C, parent(A))
212212
end
213+
214+
function Base.copyto_unaliased!(deststyle::IndexStyle, dest::AbstractMatrix, srcstyle::IndexCartesian, src::AdjOrTransAbsMat)
215+
if axes(dest) == axes(src)
216+
f! = inplace_adj_or_trans(src)
217+
f!(dest, parent(src))
218+
else
219+
@invoke Base.copyto_unaliased!(deststyle::IndexStyle, dest::AbstractArray, srcstyle::IndexStyle, src::AbstractArray)
220+
end
221+
return dest
222+
end

test/adjtrans.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,16 @@ end
476476
@test adjoint!(b, a) === b
477477
end
478478

479+
@testset "copyto! uses adjoint!/transpose!" begin
480+
for T in (Float64, ComplexF64), f in (transpose, adjoint), sz in ((5,4), (5,))
481+
S = rand(T, sz)
482+
adjS = f(S)
483+
A = similar(S')
484+
copyto!(A, adjS)
485+
@test A == adjS
486+
end
487+
end
488+
479489
@testset "aliasing with adjoint and transpose" begin
480490
A = collect(reshape(1:25, 5, 5)) .+ rand.().*im
481491
B = copy(A)

0 commit comments

Comments
 (0)