Skip to content

Commit 64eeee0

Browse files
authored
feat: copyto! compile (#937)
1 parent 93eedf8 commit 64eeee0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/ConcreteRArray.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,19 @@ function Base.copyto!(dest::AbstractConcreteArray, src::AbstractConcreteArray)
381381
return dest
382382
end
383383

384+
function mycopyto!(dest, src)
385+
dest .= src # use broadcasting instead of copyto!
386+
return nothing
387+
end
388+
389+
function Base.copyto!(
390+
dest::Union{AnyConcreteIFRTArray,AnyConcretePJRTArray}, src::AbstractConcreteArray
391+
)
392+
fn = compile(mycopyto!, (dest, src))
393+
fn(dest, src)
394+
return dest
395+
end
396+
384397
for aType in (:ConcretePJRTArray, :ConcreteIFRTArray)
385398
@eval begin
386399
function Base.copyto!(

test/basic.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,3 +1006,11 @@ mulpi(x) = π * x
10061006
y = @jit mulpi(x)
10071007
@test all(Array(y) .≈ π)
10081008
end
1009+
1010+
@testset "copyto! ConcreteArray" begin
1011+
x_ra = Reactant.to_rarray(ones(4, 4))
1012+
y_ra = Reactant.to_rarray(zeros(2, 2))
1013+
copyto!(view(x_ra, 1:2, 1:2), y_ra)
1014+
@test Array(x_ra) ==
1015+
[0.0 0.0 1.0 1.0; 0.0 0.0 1.0 1.0; 1.0 1.0 1.0 1.0; 1.0 1.0 1.0 1.0]
1016+
end

0 commit comments

Comments
 (0)