Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
actions: write
contents: read
strategy:
fail-fast: true # TODO: toggle
fail-fast: false # TODO: toggle
matrix:
version:
- '1.10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function DI.value_and_pushforward!(
DI.check_prep(f, prep, backend, x, tx, contexts...)
# dy cannot be passed anyway
y, new_ty = DI.value_and_pushforward(f, prep, backend, x, tx, contexts...)
foreach(copyto!, ty, new_ty)
foreach(copy!, ty, new_ty)
return y, ty
end

Expand All @@ -123,7 +123,7 @@ function DI.pushforward!(
DI.check_prep(f, prep, backend, x, tx, contexts...)
# dy cannot be passed anyway
new_ty = DI.pushforward(f, prep, backend, x, tx, contexts...)
foreach(copyto!, ty, new_ty)
foreach(copy!, ty, new_ty)
return ty
end

Expand Down Expand Up @@ -198,7 +198,7 @@ function DI.gradient!(
contexts::Vararg{DI.Constant, C},
) where {F, SIG, B, C}
DI.check_prep(f, prep, backend, x, contexts...)
return copyto!(grad, DI.gradient(f, prep, backend, x, contexts...))
return copy!(grad, DI.gradient(f, prep, backend, x, contexts...))
end

function DI.value_and_gradient!(
Expand All @@ -211,7 +211,7 @@ function DI.value_and_gradient!(
) where {F, SIG, B, C}
DI.check_prep(f, prep, backend, x, contexts...)
y, new_grad = DI.value_and_gradient(f, prep, backend, x, contexts...)
return y, copyto!(grad, new_grad)
return y, copy!(grad, new_grad)
end

## Jacobian
Expand Down Expand Up @@ -291,7 +291,7 @@ function DI.jacobian!(
contexts::Vararg{DI.Constant, C},
) where {F, C}
DI.check_prep(f, prep, backend, x, contexts...)
return copyto!(jac, DI.jacobian(f, prep, backend, x, contexts...))
return copy!(jac, DI.jacobian(f, prep, backend, x, contexts...))
end

function DI.value_and_jacobian!(
Expand All @@ -304,5 +304,5 @@ function DI.value_and_jacobian!(
) where {F, C}
DI.check_prep(f, prep, backend, x, contexts...)
y, new_jac = DI.value_and_jacobian(f, prep, backend, x, contexts...)
return y, copyto!(jac, new_jac)
return y, copy!(jac, new_jac)
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function DI.value_and_pullback(
) where {F, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
(; df!, context_shadows, ty_copy) = prep
copyto!(only(ty_copy), only(ty))
copy!(only(ty_copy), only(ty))
mode = reverse_noprimal(backend)
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(1))
dy = only(ty_copy)
Expand All @@ -59,7 +59,7 @@ function DI.value_and_pullback(
) where {F, B, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
(; df!, context_shadows, ty_copy) = prep
foreach(copyto!, ty_copy, ty)
foreach(copy!, ty_copy, ty)
mode = reverse_noprimal(backend)
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(B))
ty = ty_copy
Expand All @@ -83,7 +83,7 @@ function DI.value_and_pullback(
) where {F, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
(; df!, context_shadows, ty_copy) = prep
copyto!(only(ty_copy), only(ty))
copy!(only(ty_copy), only(ty))
mode = reverse_noprimal(backend)
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(1))
dx = make_zero(x) # allocates
Expand All @@ -106,7 +106,7 @@ function DI.value_and_pullback(
) where {F, B, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
(; df!, context_shadows, ty_copy) = prep
foreach(copyto!, ty_copy, ty)
foreach(copy!, ty_copy, ty)
mode = reverse_noprimal(backend)
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(B))
tx = ntuple(_ -> make_zero(x), Val(B)) # allocates
Expand All @@ -130,7 +130,7 @@ function DI.value_and_pullback!(
) where {F, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
(; df!, context_shadows, ty_copy) = prep
copyto!(only(ty_copy), only(ty))
copy!(only(ty_copy), only(ty))
mode = reverse_noprimal(backend)
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(1))
dx = only(tx)
Expand All @@ -155,7 +155,7 @@ function DI.value_and_pullback!(
) where {F, B, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
(; df!, context_shadows, ty_copy) = prep
foreach(copyto!, ty_copy, ty)
foreach(copy!, ty_copy, ty)
mode = reverse_noprimal(backend)
f!_and_df! = get_f_and_df_prepared!(df!, f!, backend, Val(B))
make_zero!(tx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function DI.jacobian!(
DI.check_prep(f, prep, backend, x, contexts...)
(; relstep, absstep, dir) = prep
fc = DI.fix_tail(f, map(DI.unwrap, contexts)...)
return copyto!(
return copy!(
jac,
finite_difference_jacobian(
fc, x, prep.cache; jac_prototype = jac, relstep, absstep, dir
Expand All @@ -425,7 +425,7 @@ function DI.value_and_jacobian!(
y = fc(x)
return (
y,
copyto!(
copy!(
jac,
finite_difference_jacobian(
fc, x, prep.cache, y; jac_prototype = jac, relstep, absstep, dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function DI.gradient!(
contexts::Vararg{DI.Context, C},
) where {C}
DI.check_prep(f, prep, backend, x, contexts...)
return copyto!(grad, DI.gradient(f, prep, backend, x, contexts...))
return copy!(grad, DI.gradient(f, prep, backend, x, contexts...))
end

function DI.value_and_gradient!(
Expand All @@ -149,7 +149,7 @@ function DI.value_and_gradient!(
) where {C}
DI.check_prep(f, prep, backend, x, contexts...)
y, new_grad = DI.value_and_gradient(f, prep, backend, x, contexts...)
return y, copyto!(grad, new_grad)
return y, copy!(grad, new_grad)
end

## Jacobian
Expand Down Expand Up @@ -193,7 +193,7 @@ function DI.jacobian!(
contexts::Vararg{DI.Context, C},
) where {C}
DI.check_prep(f, prep, backend, x, contexts...)
return copyto!(jac, DI.jacobian(f, prep, backend, x, contexts...))
return copy!(jac, DI.jacobian(f, prep, backend, x, contexts...))
end

function DI.value_and_jacobian!(
Expand All @@ -206,7 +206,7 @@ function DI.value_and_jacobian!(
) where {C}
DI.check_prep(f, prep, backend, x, contexts...)
y, new_jac = DI.value_and_jacobian(f, prep, backend, x, contexts...)
return y, copyto!(jac, new_jac)
return y, copy!(jac, new_jac)
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function DI.value_and_gradient!(
result = DiffResult(zero(eltype(x)), (grad,))
result = gradient!(result, fc, x)
y = DR.value(result)
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
return y, grad
else
prep = DI.prepare_gradient_nokwarg(Val(true), f, backend, x, contexts...)
Expand Down Expand Up @@ -397,7 +397,7 @@ function DI.value_and_gradient!(
end
result = gradient!(result, fc, x, prep.config, Val(false))
y = DR.value(result)
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
return y, grad
end

Expand Down Expand Up @@ -472,7 +472,7 @@ function DI.value_and_jacobian!(
result = DiffResult(y, (jac,))
result = jacobian!(result, fc, x)
y = DR.value(result)
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
return y, jac
else
prep = DI.prepare_jacobian_nokwarg(Val(true), f, backend, x, contexts...)
Expand Down Expand Up @@ -566,7 +566,7 @@ function DI.value_and_jacobian!(
end
result = jacobian!(result, fc, x, prep.config, Val(false))
y = DR.value(result)
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
return y, jac
end

Expand Down Expand Up @@ -761,8 +761,8 @@ function DI.value_gradient_and_hessian!(
result = DiffResult(oneunit(eltype(x)), (grad, hess))
result = hessian!(result, fc, x)
y = DR.value(result)
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
hess === DR.hessian(result) || copyto!(hess, DR.hessian(result))
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
hess === DR.hessian(result) || copy!(hess, DR.hessian(result))
return (y, grad, hess)
else
prep = DI.prepare_hessian_nokwarg(Val(true), f, backend, x, contexts...)
Expand Down Expand Up @@ -864,8 +864,8 @@ function DI.value_gradient_and_hessian!(
end
result = hessian!(result, fc, x, prep.result_config, Val(false))
y = DR.value(result)
grad === DR.gradient(result) || copyto!(grad, DR.gradient(result))
hess === DR.hessian(result) || copyto!(hess, DR.hessian(result))
grad === DR.gradient(result) || copy!(grad, DR.gradient(result))
hess === DR.hessian(result) || copy!(hess, DR.hessian(result))
return (y, grad, hess)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function DI.value_and_pushforward!(
) where {F, C}
DI.check_prep(f, prep, backend, x, tx, contexts...)
y, new_ty = DI.value_and_pushforward(f, prep, backend, x, tx, contexts...)
foreach(copyto!, ty, new_ty)
foreach(copy!, ty, new_ty)
return y, ty
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function DI.value_and_pushforward!(
Dual(x, dx_righttype),
map(Dual_unwrap, contexts, prep.context_tangents)...,
)
dy === dy_righttype || copyto!(dy, dy_righttype)
dy === dy_righttype || copy!(dy, dy_righttype)
end
return y, ty
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function DI.value_and_pullback!(
) where {F, C}
DI.check_prep(f, prep, backend, x, ty, contexts...)
y, new_tx = DI.value_and_pullback(f, prep, backend, x, ty, contexts...)
foreach(copyto!, tx, new_tx)
foreach(copy!, tx, new_tx)
return y, tx
end

Expand Down Expand Up @@ -162,7 +162,7 @@ function DI.value_and_gradient!(
prep.cache, f, x, map(DI.unwrap, contexts)...;
prep.args_to_zero
)
copyto!(grad, new_grad)
copy!(grad, new_grad)
return y, grad
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function DI.value_and_pullback(
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
dy = only(ty)
# Prepare cotangent to add after the forward pass.
dy_righttype_after = copyto!(prep.dy_righttype, dy)
dy_righttype_after = copy!(prep.dy_righttype, dy)
# Run the reverse-pass and return the results.
y_after, (_, _, _, dx) = value_and_pullback!!(
prep.cache,
Expand All @@ -69,7 +69,7 @@ function DI.value_and_pullback(
map(DI.unwrap, contexts)...;
prep.args_to_zero
)
copyto!(y, y_after)
copy!(y, y_after)
return y, (_copy_output(dx),)
end

Expand All @@ -84,7 +84,7 @@ function DI.value_and_pullback(
) where {F, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
tx = map(ty) do dy
dy_righttype_after = copyto!(prep.dy_righttype, dy)
dy_righttype_after = copy!(prep.dy_righttype, dy)
y_after, (_, _, _, dx) = value_and_pullback!!(
prep.cache,
dy_righttype_after,
Expand All @@ -95,7 +95,7 @@ function DI.value_and_pullback(
map(DI.unwrap, contexts)...;
prep.args_to_zero
)
copyto!(y, y_after)
copy!(y, y_after)
_copy_output(dx)
end
return y, tx
Expand All @@ -113,7 +113,7 @@ function DI.value_and_pullback!(
) where {F, C}
DI.check_prep(f!, y, prep, backend, x, ty, contexts...)
_, new_tx = DI.value_and_pullback(f!, y, prep, backend, x, ty, contexts...)
foreach(copyto!, tx, new_tx)
foreach(copy!, tx, new_tx)
return y, tx
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function DI.value_and_jacobian!(
result = jacobian!(result, f, x, prep.config)
end
y = DR.value(result)
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
return y, jac
end

Expand Down Expand Up @@ -302,7 +302,7 @@ function DI.value_and_jacobian!(
result = DiffResult(y, (jac,))
result = jacobian!(result, fc, x, prep.config)
y = DR.value(result)
jac === DR.jacobian(result) || copyto!(jac, DR.jacobian(result))
jac === DR.jacobian(result) || copy!(jac, DR.jacobian(result))
return y, jac
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function DI.hessian!(
)

for b in eachindex(batched_results[a])
copyto!(
copy!(
view(compressed_matrix, :, 1 + ((a - 1) * B + (b - 1)) % N),
vec(batched_results[a][b]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function _sparse_jacobian_aux!(
)

for b in eachindex(batched_results[a])
copyto!(
copy!(
view(compressed_matrix, :, 1 + ((a - 1) * B + (b - 1)) % N),
vec(batched_results[a][b]),
)
Expand Down Expand Up @@ -365,7 +365,7 @@ function _sparse_jacobian_aux!(
if eltype(x) <: Complex
batched_results[a][b] .= conj.(batched_results[a][b])
end
copyto!(
copy!(
view(compressed_matrix, 1 + ((a - 1) * B + (b - 1)) % N, :),
vec(batched_results[a][b]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function _sparse_jacobian_aux!(
)

for b in eachindex(batched_results_forward[a])
copyto!(
copy!(
view(compressed_matrix_forward, :, 1 + ((a - 1) * Bf + (b - 1)) % Nf),
vec(batched_results_forward[a][b]),
)
Expand All @@ -267,7 +267,7 @@ function _sparse_jacobian_aux!(
if eltype(x) <: Complex
batched_results_reverse[a][b] .= conj.(batched_results_reverse[a][b])
end
copyto!(
copy!(
view(compressed_matrix_reverse, 1 + ((a - 1) * Br + (b - 1)) % Nr, :),
vec(batched_results_reverse[a][b]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function DI.value_and_gradient!(
) where {C}
DI.check_prep(f, prep, backend, x, contexts...)
y, new_grad = DI.value_and_gradient(f, prep, backend, x, contexts...)
return y, copyto!(grad, new_grad)
return y, copy!(grad, new_grad)
end

function DI.gradient!(
Expand All @@ -144,7 +144,7 @@ function DI.gradient!(
contexts::Vararg{DI.GeneralizedConstant, C},
) where {C}
DI.check_prep(f, prep, backend, x, contexts...)
return copyto!(grad, DI.gradient(f, prep, backend, x, contexts...))
return copy!(grad, DI.gradient(f, prep, backend, x, contexts...))
end

end
Loading
Loading