Skip to content

Commit deb4a95

Browse files
committed
fix: replace copyto! with copy!
1 parent bbc39fd commit deb4a95

33 files changed

Lines changed: 87 additions & 87 deletions

File tree

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/forward_onearg.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function DI.value_and_pushforward!(
107107
DI.check_prep(f, prep, backend, x, tx, contexts...)
108108
# dy cannot be passed anyway
109109
y, new_ty = DI.value_and_pushforward(f, prep, backend, x, tx, contexts...)
110-
foreach(copyto!, ty, new_ty)
110+
foreach(copy!, ty, new_ty)
111111
return y, ty
112112
end
113113

@@ -123,7 +123,7 @@ function DI.pushforward!(
123123
DI.check_prep(f, prep, backend, x, tx, contexts...)
124124
# dy cannot be passed anyway
125125
new_ty = DI.pushforward(f, prep, backend, x, tx, contexts...)
126-
foreach(copyto!, ty, new_ty)
126+
foreach(copy!, ty, new_ty)
127127
return ty
128128
end
129129

@@ -198,7 +198,7 @@ function DI.gradient!(
198198
contexts::Vararg{DI.Constant, C},
199199
) where {F, SIG, B, C}
200200
DI.check_prep(f, prep, backend, x, contexts...)
201-
return copyto!(grad, DI.gradient(f, prep, backend, x, contexts...))
201+
return copy!(grad, DI.gradient(f, prep, backend, x, contexts...))
202202
end
203203

204204
function DI.value_and_gradient!(
@@ -211,7 +211,7 @@ function DI.value_and_gradient!(
211211
) where {F, SIG, B, C}
212212
DI.check_prep(f, prep, backend, x, contexts...)
213213
y, new_grad = DI.value_and_gradient(f, prep, backend, x, contexts...)
214-
return y, copyto!(grad, new_grad)
214+
return y, copy!(grad, new_grad)
215215
end
216216

217217
## Jacobian
@@ -291,7 +291,7 @@ function DI.jacobian!(
291291
contexts::Vararg{DI.Constant, C},
292292
) where {F, C}
293293
DI.check_prep(f, prep, backend, x, contexts...)
294-
return copyto!(jac, DI.jacobian(f, prep, backend, x, contexts...))
294+
return copy!(jac, DI.jacobian(f, prep, backend, x, contexts...))
295295
end
296296

297297
function DI.value_and_jacobian!(
@@ -304,5 +304,5 @@ function DI.value_and_jacobian!(
304304
) where {F, C}
305305
DI.check_prep(f, prep, backend, x, contexts...)
306306
y, new_jac = DI.value_and_jacobian(f, prep, backend, x, contexts...)
307-
return y, copyto!(jac, new_jac)
307+
return y, copy!(jac, new_jac)
308308
end

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/reverse_twoarg.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function DI.value_and_pullback(
3535
) where {F, C}
3636
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
3737
(; df!, context_shadows, ty_copy) = prep
38-
copyto!(only(ty_copy), only(ty))
38+
copy!(only(ty_copy), only(ty))
3939
mode = reverse_noprimal(backend)
4040
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(1))
4141
dy = only(ty_copy)
@@ -59,7 +59,7 @@ function DI.value_and_pullback(
5959
) where {F, B, C}
6060
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
6161
(; df!, context_shadows, ty_copy) = prep
62-
foreach(copyto!, ty_copy, ty)
62+
foreach(copy!, ty_copy, ty)
6363
mode = reverse_noprimal(backend)
6464
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(B))
6565
ty = ty_copy
@@ -83,7 +83,7 @@ function DI.value_and_pullback(
8383
) where {F, C}
8484
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
8585
(; df!, context_shadows, ty_copy) = prep
86-
copyto!(only(ty_copy), only(ty))
86+
copy!(only(ty_copy), only(ty))
8787
mode = reverse_noprimal(backend)
8888
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(1))
8989
dx = make_zero(x) # allocates
@@ -106,7 +106,7 @@ function DI.value_and_pullback(
106106
) where {F, B, C}
107107
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
108108
(; df!, context_shadows, ty_copy) = prep
109-
foreach(copyto!, ty_copy, ty)
109+
foreach(copy!, ty_copy, ty)
110110
mode = reverse_noprimal(backend)
111111
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(B))
112112
tx = ntuple(_ -> make_zero(x), Val(B)) # allocates
@@ -130,7 +130,7 @@ function DI.value_and_pullback!(
130130
) where {F, C}
131131
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
132132
(; df!, context_shadows, ty_copy) = prep
133-
copyto!(only(ty_copy), only(ty))
133+
copy!(only(ty_copy), only(ty))
134134
mode = reverse_noprimal(backend)
135135
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(1))
136136
dx = only(tx)
@@ -155,7 +155,7 @@ function DI.value_and_pullback!(
155155
) where {F, B, C}
156156
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
157157
(; df!, context_shadows, ty_copy) = prep
158-
foreach(copyto!, ty_copy, ty)
158+
foreach(copy!, ty_copy, ty)
159159
mode = reverse_noprimal(backend)
160160
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(B))
161161
make_zero!(tx)

DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt/onearg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function DI.jacobian!(
403403
DI.check_prep(f, prep, backend, x, contexts...)
404404
(; relstep, absstep, dir) = prep
405405
fc = DI.fix_tail(f, map(DI.unwrap, contexts)...)
406-
return copyto!(
406+
return copy!(
407407
jac,
408408
finite_difference_jacobian(
409409
fc, x, prep.cache; jac_prototype = jac, relstep, absstep, dir
@@ -425,7 +425,7 @@ function DI.value_and_jacobian!(
425425
y = fc(x)
426426
return (
427427
y,
428-
copyto!(
428+
copy!(
429429
jac,
430430
finite_difference_jacobian(
431431
fc, x, prep.cache, y; jac_prototype = jac, relstep, absstep, dir

DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function DI.gradient!(
136136
contexts::Vararg{DI.Context, C},
137137
) where {C}
138138
DI.check_prep(f, prep, backend, x, contexts...)
139-
return copyto!(grad, DI.gradient(f, prep, backend, x, contexts...))
139+
return copy!(grad, DI.gradient(f, prep, backend, x, contexts...))
140140
end
141141

142142
function DI.value_and_gradient!(
@@ -149,7 +149,7 @@ function DI.value_and_gradient!(
149149
) where {C}
150150
DI.check_prep(f, prep, backend, x, contexts...)
151151
y, new_grad = DI.value_and_gradient(f, prep, backend, x, contexts...)
152-
return y, copyto!(grad, new_grad)
152+
return y, copy!(grad, new_grad)
153153
end
154154

155155
## Jacobian
@@ -193,7 +193,7 @@ function DI.jacobian!(
193193
contexts::Vararg{DI.Context, C},
194194
) where {C}
195195
DI.check_prep(f, prep, backend, x, contexts...)
196-
return copyto!(jac, DI.jacobian(f, prep, backend, x, contexts...))
196+
return copy!(jac, DI.jacobian(f, prep, backend, x, contexts...))
197197
end
198198

199199
function DI.value_and_jacobian!(
@@ -206,7 +206,7 @@ function DI.value_and_jacobian!(
206206
) where {C}
207207
DI.check_prep(f, prep, backend, x, contexts...)
208208
y, new_jac = DI.value_and_jacobian(f, prep, backend, x, contexts...)
209-
return y, copyto!(jac, new_jac)
209+
return y, copy!(jac, new_jac)
210210
end
211211

212212
end

DifferentiationInterface/ext/DifferentiationInterfaceForwardDiffExt/onearg.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function DI.value_and_gradient!(
298298
result = DiffResult(zero(eltype(x)), (grad,))
299299
result = gradient!(result, fc, x)
300300
y = DR.value(result)
301-
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
301+
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
302302
return y, grad
303303
else
304304
prep = DI.prepare_gradient_nokwarg(Val(true), f, backend, x, contexts...)
@@ -397,7 +397,7 @@ function DI.value_and_gradient!(
397397
end
398398
result = gradient!(result, fc, x, prep.config, Val(false))
399399
y = DR.value(result)
400-
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
400+
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
401401
return y, grad
402402
end
403403

@@ -472,7 +472,7 @@ function DI.value_and_jacobian!(
472472
result = DiffResult(y, (jac,))
473473
result = jacobian!(result, fc, x)
474474
y = DR.value(result)
475-
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
475+
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
476476
return y, jac
477477
else
478478
prep = DI.prepare_jacobian_nokwarg(Val(true), f, backend, x, contexts...)
@@ -566,7 +566,7 @@ function DI.value_and_jacobian!(
566566
end
567567
result = jacobian!(result, fc, x, prep.config, Val(false))
568568
y = DR.value(result)
569-
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
569+
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
570570
return y, jac
571571
end
572572

@@ -761,8 +761,8 @@ function DI.value_gradient_and_hessian!(
761761
result = DiffResult(oneunit(eltype(x)), (grad, hess))
762762
result = hessian!(result, fc, x)
763763
y = DR.value(result)
764-
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
765-
hess === DR.hessian(result) || copyto!(hess, DR.hessian(result))
764+
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
765+
hess === DR.hessian(result) || copy!(hess, DR.hessian(result))
766766
return (y, grad, hess)
767767
else
768768
prep = DI.prepare_hessian_nokwarg(Val(true), f, backend, x, contexts...)
@@ -864,8 +864,8 @@ function DI.value_gradient_and_hessian!(
864864
end
865865
result = hessian!(result, fc, x, prep.result_config, Val(false))
866866
y = DR.value(result)
867-
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
868-
hess === DR.hessian(result) || copyto!(hess, DR.hessian(result))
867+
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
868+
hess === DR.hessian(result) || copy!(hess, DR.hessian(result))
869869
return (y, grad, hess)
870870
end
871871

DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_onearg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function DI.value_and_pushforward!(
7878
) where {F, C}
7979
DI.check_prep(f, prep, backend, x, tx, contexts...)
8080
y, new_ty = DI.value_and_pushforward(f, prep, backend, x, tx, contexts...)
81-
foreach(copyto!, ty, new_ty)
81+
foreach(copy!, ty, new_ty)
8282
return y, ty
8383
end
8484

DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_twoarg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function DI.value_and_pushforward!(
9999
Dual(x, dx_righttype),
100100
map(Dual_unwrap, contexts, prep.context_tangents)...,
101101
)
102-
dy === dy_righttype || copyto!(dy, dy_righttype)
102+
dy === dy_righttype || copy!(dy, dy_righttype)
103103
end
104104
return y, ty
105105
end

DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/onearg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function DI.value_and_pullback!(
7979
) where {F, C}
8080
DI.check_prep(f, prep, backend, x, ty, contexts...)
8181
y, new_tx = DI.value_and_pullback(f, prep, backend, x, ty, contexts...)
82-
foreach(copyto!, tx, new_tx)
82+
foreach(copy!, tx, new_tx)
8383
return y, tx
8484
end
8585

@@ -162,7 +162,7 @@ function DI.value_and_gradient!(
162162
prep.cache, f, x, map(DI.unwrap, contexts)...;
163163
prep.args_to_zero
164164
)
165-
copyto!(grad, new_grad)
165+
copy!(grad, new_grad)
166166
return y, grad
167167
end
168168

DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/twoarg.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function DI.value_and_pullback(
5757
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
5858
dy = only(ty)
5959
# Prepare cotangent to add after the forward pass.
60-
dy_righttype_after = copyto!(prep.dy_righttype, dy)
60+
dy_righttype_after = copy!(prep.dy_righttype, dy)
6161
# Run the reverse-pass and return the results.
6262
y_after, (_, _, _, dx) = value_and_pullback!!(
6363
prep.cache,
@@ -69,7 +69,7 @@ function DI.value_and_pullback(
6969
map(DI.unwrap, contexts)...;
7070
prep.args_to_zero
7171
)
72-
copyto!(y, y_after)
72+
copy!(y, y_after)
7373
return y, (_copy_output(dx),)
7474
end
7575

@@ -84,7 +84,7 @@ function DI.value_and_pullback(
8484
) where {F, C}
8585
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
8686
tx = map(ty) do dy
87-
dy_righttype_after = copyto!(prep.dy_righttype, dy)
87+
dy_righttype_after = copy!(prep.dy_righttype, dy)
8888
y_after, (_, _, _, dx) = value_and_pullback!!(
8989
prep.cache,
9090
dy_righttype_after,
@@ -95,7 +95,7 @@ function DI.value_and_pullback(
9595
map(DI.unwrap, contexts)...;
9696
prep.args_to_zero
9797
)
98-
copyto!(y, y_after)
98+
copy!(y, y_after)
9999
_copy_output(dx)
100100
end
101101
return y, tx
@@ -113,7 +113,7 @@ function DI.value_and_pullback!(
113113
) where {F, C}
114114
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
115115
_, new_tx = DI.value_and_pullback(f!, y, prep, backend, x, ty, contexts...)
116-
foreach(copyto!, tx, new_tx)
116+
foreach(copy!, tx, new_tx)
117117
return y, tx
118118
end
119119

DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/onearg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function DI.value_and_jacobian!(
241241
result = jacobian!(result, f, x, prep.config)
242242
end
243243
y = DR.value(result)
244-
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
244+
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
245245
return y, jac
246246
end
247247

@@ -302,7 +302,7 @@ function DI.value_and_jacobian!(
302302
result = DiffResult(y, (jac,))
303303
result = jacobian!(result, fc, x, prep.config)
304304
y = DR.value(result)
305-
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
305+
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
306306
return y, jac
307307
end
308308

0 commit comments

Comments
 (0)