diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index 89223f597..a5ab74ae2 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -25,7 +25,7 @@ jobs: actions: write contents: read strategy: - fail-fast: true # TODO: toggle + fail-fast: false # TODO: toggle matrix: version: - '1.10' diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/forward_onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/forward_onearg.jl index 98ecc0db2..970ccccda 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/forward_onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/forward_onearg.jl @@ -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 @@ -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 @@ -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!( @@ -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 @@ -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!( @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/reverse_twoarg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/reverse_twoarg.jl index ddf5f774c..42107238d 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/reverse_twoarg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/reverse_twoarg.jl @@ -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) @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt/onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt/onearg.jl index 82b769ef6..890c1d033 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt/onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt/onearg.jl @@ -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 @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl b/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl index 3d3c26f4a..98df39700 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl @@ -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!( @@ -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 @@ -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!( @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceForwardDiffExt/onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceForwardDiffExt/onearg.jl index a0360e68b..53f7e58bd 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceForwardDiffExt/onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceForwardDiffExt/onearg.jl @@ -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...) @@ -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 @@ -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...) @@ -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 @@ -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...) @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_onearg.jl index 61946a0d3..ea7cc62b9 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_onearg.jl @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_twoarg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_twoarg.jl index dc8f8c1f0..805cfb9a5 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_twoarg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/forward_twoarg.jl @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/onearg.jl index ab9818735..3eb8d9c5d 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/onearg.jl @@ -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 @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/twoarg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/twoarg.jl index 2ee11b5ae..c014aa83c 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/twoarg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceMooncakeExt/twoarg.jl @@ -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, @@ -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 @@ -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, @@ -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 @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/onearg.jl index 093ecca9d..c18a3867f 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/onearg.jl @@ -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 @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl b/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl index f5d674cc4..51956c9f7 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl @@ -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]), ) diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl b/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl index 7e30d1439..d21e729c8 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl @@ -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]), ) @@ -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]), ) diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian_mixed.jl b/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian_mixed.jl index 97608a535..baba6963b 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian_mixed.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian_mixed.jl @@ -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]), ) @@ -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]), ) diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceTrackerExt/DifferentiationInterfaceTrackerExt.jl b/DifferentiationInterface/ext/DifferentiationInterfaceTrackerExt/DifferentiationInterfaceTrackerExt.jl index bae79b164..ccc678daa 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceTrackerExt/DifferentiationInterfaceTrackerExt.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceTrackerExt/DifferentiationInterfaceTrackerExt.jl @@ -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!( @@ -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 diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceZygoteExt/DifferentiationInterfaceZygoteExt.jl b/DifferentiationInterface/ext/DifferentiationInterfaceZygoteExt/DifferentiationInterfaceZygoteExt.jl index cf2a0820b..8022177c1 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceZygoteExt/DifferentiationInterfaceZygoteExt.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceZygoteExt/DifferentiationInterfaceZygoteExt.jl @@ -129,14 +129,14 @@ 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!( f, grad, prep::DI.NoGradientPrep, backend::AutoZygote, x, 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 ## Jacobian @@ -171,14 +171,14 @@ 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 function DI.jacobian!( f, jac, prep::DI.NoJacobianPrep, backend::AutoZygote, x, 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 ## HVP @@ -297,7 +297,7 @@ function DI.hessian!( contexts::Vararg{DI.GeneralizedConstant, C}, ) where {C} DI.check_prep(f, prep, backend, x, contexts...) - return copyto!(hess, DI.hessian(f, prep, backend, x, contexts...)) + return copy!(hess, DI.hessian(f, prep, backend, x, contexts...)) end function DI.value_gradient_and_hessian( diff --git a/DifferentiationInterface/src/first_order/jacobian.jl b/DifferentiationInterface/src/first_order/jacobian.jl index 4c64b45bc..2e63de5b0 100644 --- a/DifferentiationInterface/src/first_order/jacobian.jl +++ b/DifferentiationInterface/src/first_order/jacobian.jl @@ -545,7 +545,7 @@ function _jacobian_aux!( ) for b in eachindex(batched_results[a]) - copyto!( + copy!( view(jac, :, 1 + ((a - 1) * B + (b - 1)) % N), vec(batched_results[a][b]) ) end @@ -585,7 +585,7 @@ function _jacobian_aux!( if eltype(x) <: Complex batched_results[a][b] .= conj.(batched_results[a][b]) end - copyto!( + copy!( view(jac, 1 + ((a - 1) * B + (b - 1)) % N, :), vec(batched_results[a][b]) ) end diff --git a/DifferentiationInterface/src/first_order/pullback.jl b/DifferentiationInterface/src/first_order/pullback.jl index 183b15834..0e89be885 100644 --- a/DifferentiationInterface/src/first_order/pullback.jl +++ b/DifferentiationInterface/src/first_order/pullback.jl @@ -409,7 +409,7 @@ function value_and_pullback!( ) where {F, C} check_prep(f, prep, backend, x, ty, contexts...) y, new_tx = value_and_pullback(f, prep, backend, x, ty, contexts...) - foreach(copyto!, tx, new_tx) + foreach(copy!, tx, new_tx) return y, tx end @@ -541,7 +541,7 @@ function value_and_pullback!( ) where {F, C} check_prep(f!, y, prep, backend, x, ty, contexts...) y, new_tx = value_and_pullback(f!, y, prep, backend, x, ty, contexts...) - foreach(copyto!, tx, new_tx) + foreach(copy!, tx, new_tx) return y, tx end diff --git a/DifferentiationInterface/src/first_order/pushforward.jl b/DifferentiationInterface/src/first_order/pushforward.jl index d3922bc0a..c951540e6 100644 --- a/DifferentiationInterface/src/first_order/pushforward.jl +++ b/DifferentiationInterface/src/first_order/pushforward.jl @@ -408,7 +408,7 @@ function value_and_pushforward!( ) where {F, C} check_prep(f, prep, backend, x, tx, contexts...) y, new_ty = value_and_pushforward(f, prep, backend, x, tx, contexts...) - foreach(copyto!, ty, new_ty) + foreach(copy!, ty, new_ty) return y, ty end @@ -506,7 +506,7 @@ function value_and_pushforward!( ) where {F, C} check_prep(f!, y, prep, backend, x, tx, contexts...) y, new_ty = value_and_pushforward(f!, y, prep, backend, x, tx, contexts...) - foreach(copyto!, ty, new_ty) + foreach(copy!, ty, new_ty) return y, ty end diff --git a/DifferentiationInterface/src/second_order/hessian.jl b/DifferentiationInterface/src/second_order/hessian.jl index 5067f78c2..098d68a24 100644 --- a/DifferentiationInterface/src/second_order/hessian.jl +++ b/DifferentiationInterface/src/second_order/hessian.jl @@ -221,7 +221,7 @@ function hessian!( ) for b in eachindex(batched_results[a]) - copyto!( + copy!( view(hess, :, 1 + ((a - 1) * B + (b - 1)) % N), vec(batched_results[a][b]) ) end diff --git a/DifferentiationInterface/src/second_order/hvp.jl b/DifferentiationInterface/src/second_order/hvp.jl index 58afeadbf..eba9a5390 100644 --- a/DifferentiationInterface/src/second_order/hvp.jl +++ b/DifferentiationInterface/src/second_order/hvp.jl @@ -510,7 +510,7 @@ function _gradient_and_hvp_aux!( tx, new_contexts..., ) - return copyto!(grad, new_grad), tg + return copy!(grad, new_grad), tg end ## Reverse over forward @@ -845,5 +845,5 @@ function _gradient_and_hvp_aux!( new_grad, _ = value_and_pullback!( shuffled_gradient, tg, outer_pullback_prep, outer(backend), x, tx, new_contexts... ) - return copyto!(grad, new_grad), tg + return copy!(grad, new_grad), tg end diff --git a/DifferentiationInterface/src/second_order/second_derivative.jl b/DifferentiationInterface/src/second_order/second_derivative.jl index 1e239df10..02febb830 100644 --- a/DifferentiationInterface/src/second_order/second_derivative.jl +++ b/DifferentiationInterface/src/second_order/second_derivative.jl @@ -186,5 +186,5 @@ function value_derivative_and_second_derivative!( new_der, _ = value_and_derivative!( shuffled_derivative, der2, outer_derivative_prep, outer(backend), x, new_contexts... ) - return y, copyto!(der, new_der), der2 + return y, copy!(der, new_der), der2 end diff --git a/DifferentiationInterface/src/utils/context.jl b/DifferentiationInterface/src/utils/context.jl index 2d2575d01..48be906f6 100644 --- a/DifferentiationInterface/src/utils/context.jl +++ b/DifferentiationInterface/src/utils/context.jl @@ -78,7 +78,7 @@ julia> using DifferentiationInterface julia> using ForwardDiff: ForwardDiff -julia> f(x, c) = sum(copyto!(c, x)); +julia> f(x, c) = sum(copy!(c, x)); julia> prep = prepare_gradient(f, AutoForwardDiff(), [1.0, 2.0], Cache(zeros(2))); diff --git a/DifferentiationInterface/test/Back/DifferentiateWith/test.jl b/DifferentiationInterface/test/Back/DifferentiateWith/test.jl index 04d9f5b99..be71f099a 100644 --- a/DifferentiationInterface/test/Back/DifferentiateWith/test.jl +++ b/DifferentiationInterface/test/Back/DifferentiateWith/test.jl @@ -18,12 +18,12 @@ struct ADBreaker{F} end function (adb::ADBreaker)(x::Number) - copyto!(Float64[0], x) # break ForwardDiff and Zygote + copy!(Float64[0], x) # break ForwardDiff and Zygote return adb.f(x) end function (adb::ADBreaker)(x::AbstractArray) - copyto!(similar(x, Float64), x) # break ForwardDiff and Zygote + copy!(similar(x, Float64), x) # break ForwardDiff and Zygote return adb.f(x) end diff --git a/DifferentiationInterface/test/Back/Enzyme/test.jl b/DifferentiationInterface/test/Back/Enzyme/test.jl index 892ac6c78..db259b298 100644 --- a/DifferentiationInterface/test/Back/Enzyme/test.jl +++ b/DifferentiationInterface/test/Back/Enzyme/test.jl @@ -122,7 +122,7 @@ end @testset "MutabilityError" begin f = let cache = [0.0] - x -> sum(copyto!(cache, x)) + x -> sum(copy!(cache, x)) end e = nothing diff --git a/DifferentiationInterface/test/Back/FastDifferentiation/fastdifferentiation.jl b/DifferentiationInterface/test/Back/FastDifferentiation/fastdifferentiation.jl index 86d903faa..08d4c876c 100644 --- a/DifferentiationInterface/test/Back/FastDifferentiation/fastdifferentiation.jl +++ b/DifferentiationInterface/test/Back/FastDifferentiation/fastdifferentiation.jl @@ -36,7 +36,7 @@ test_differentiation( x = rand(10) backend = AutoSparse(AutoFastDifferentiation()) jac_prep = prepare_jacobian(copy, backend, x) - jac!_prep = prepare_jacobian(copyto!, similar(x), backend, x) + jac!_prep = prepare_jacobian(copy!, similar(x), backend, x) hess_prep = prepare_hessian(x -> sum(abs2, x), backend, x) @test sparsity_pattern(jac_prep) == Diagonal(trues(10)) @test sparsity_pattern(jac!_prep) == Diagonal(trues(10)) diff --git a/DifferentiationInterface/test/Back/FiniteDiff/test.jl b/DifferentiationInterface/test/Back/FiniteDiff/test.jl index a7f5ad42f..14ee7127f 100644 --- a/DifferentiationInterface/test/Back/FiniteDiff/test.jl +++ b/DifferentiationInterface/test/Back/FiniteDiff/test.jl @@ -77,12 +77,12 @@ end; backend = AutoFiniteDiff(; absstep = 1000, relstep = 0.1) preps = [ prepare_pushforward(identity, backend, 1.0, (1.0,)), - prepare_pushforward(copyto!, [0.0], backend, [1.0], ([1.0],)), + prepare_pushforward(copy!, [0.0], backend, [1.0], ([1.0],)), prepare_derivative(identity, backend, 1.0), prepare_derivative((y, x) -> y .= x, [0.0], backend, 1.0), prepare_gradient(sum, backend, [1.0]), prepare_jacobian(identity, backend, [1.0]), - prepare_jacobian(copyto!, [0.0], backend, [1.0]), + prepare_jacobian(copy!, [0.0], backend, [1.0]), ] for prep in preps @test prep.relstep == 0.1 @@ -97,12 +97,12 @@ end; backend = AutoFiniteDiff(; relstep = 0.1) preps = [ prepare_pushforward(identity, backend, 1.0, (1.0,)), - prepare_pushforward(copyto!, [0.0], backend, [1.0], ([1.0],)), + prepare_pushforward(copy!, [0.0], backend, [1.0], ([1.0],)), prepare_derivative(identity, backend, 1.0), prepare_derivative((y, x) -> y .= x, [0.0], backend, 1.0), prepare_gradient(sum, backend, [1.0]), prepare_jacobian(identity, backend, [1.0]), - prepare_jacobian(copyto!, [0.0], backend, [1.0]), + prepare_jacobian(copy!, [0.0], backend, [1.0]), ] for prep in preps @test prep.relstep == 0.1 diff --git a/DifferentiationInterface/test/Back/ForwardDiff/test.jl b/DifferentiationInterface/test/Back/ForwardDiff/test.jl index ef501aec1..fbb91e083 100644 --- a/DifferentiationInterface/test/Back/ForwardDiff/test.jl +++ b/DifferentiationInterface/test/Back/ForwardDiff/test.jl @@ -106,8 +106,8 @@ end y = [1.0, 1.0] @test DI.overloaded_input_type(prepare_derivative(copy, backend, x)) == ForwardDiff.Dual{ForwardDiff.Tag{typeof(copy), Float64}, Float64, 1} - @test DI.overloaded_input_type(prepare_derivative(copyto!, y, backend, x)) == - Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(copyto!), Float64}, Float64, 1}} + @test DI.overloaded_input_type(prepare_derivative(copy!, y, backend, x)) == + Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(copy!), Float64}, Float64, 1}} # Gradient x = [1.0, 1.0] @@ -118,9 +118,9 @@ end x = [1.0, 0.0, 0.0] @test DI.overloaded_input_type(prepare_jacobian(copy, backend, x)) == ForwardDiff.Dual{ForwardDiff.Tag{typeof(copy), Float64}, Float64, 3} - @test DI.overloaded_input_type(prepare_jacobian(copyto!, similar(x), backend, x)) == - Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(copyto!), Float64}, Float64, 3}} + @test DI.overloaded_input_type(prepare_jacobian(copy!, similar(x), backend, x)) == + Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(copy!), Float64}, Float64, 3}} @test DI.overloaded_input_type( - prepare_jacobian(copyto!, similar(x), sparse_backend, x) - ) == Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(copyto!), Float64}, Float64, 1}} + prepare_jacobian(copy!, similar(x), sparse_backend, x) + ) == Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(copy!), Float64}, Float64, 1}} end; diff --git a/DifferentiationInterface/test/Back/ReverseDiff/test.jl b/DifferentiationInterface/test/Back/ReverseDiff/test.jl index 2043c60f2..c434bd39d 100644 --- a/DifferentiationInterface/test/Back/ReverseDiff/test.jl +++ b/DifferentiationInterface/test/Back/ReverseDiff/test.jl @@ -58,6 +58,6 @@ test_differentiation( # Jacobian @test DI.overloaded_input_type(prepare_jacobian(copy, backend, x)) == ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}} - @test DI.overloaded_input_type(prepare_jacobian(copyto!, similar(x), backend, x)) == + @test DI.overloaded_input_type(prepare_jacobian(copy!, similar(x), backend, x)) == ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}} end; diff --git a/DifferentiationInterface/test/Back/Symbolics/symbolics.jl b/DifferentiationInterface/test/Back/Symbolics/symbolics.jl index 5fe04d8c9..0761c4b9a 100644 --- a/DifferentiationInterface/test/Back/Symbolics/symbolics.jl +++ b/DifferentiationInterface/test/Back/Symbolics/symbolics.jl @@ -38,7 +38,7 @@ test_differentiation( x = rand(10) backend = AutoSparse(AutoSymbolics()) jac_prep = prepare_jacobian(copy, backend, x) - jac!_prep = prepare_jacobian(copyto!, similar(x), backend, x) + jac!_prep = prepare_jacobian(copy!, similar(x), backend, x) hess_prep = prepare_hessian(x -> sum(abs2, x), backend, x) @test sparsity_pattern(jac_prep) == Diagonal(trues(10)) @test sparsity_pattern(jac!_prep) == Diagonal(trues(10)) diff --git a/DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl b/DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl index 1bd40bfa6..36c9be0cf 100644 --- a/DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl +++ b/DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl @@ -147,7 +147,7 @@ end @test hessian(sum ∘ zero, backend, ones(10)) isa AbstractMatrix # mixed backend = MyAutoSparse(MixedMode(adaptive_backends[1], adaptive_backends[2])) - @test jacobian(copyto!, zeros(10), backend, ones(10)) isa AbstractMatrix + @test jacobian(copy!, zeros(10), backend, ones(10)) isa AbstractMatrix end end @@ -156,7 +156,7 @@ end pushforward, sum, AutoSimpleFiniteDiff(), 1, (1, 2) ) @test_throws ArgumentError DifferentiationInterface.overloaded_input( - pushforward, copyto!, [1.0], AutoSimpleFiniteDiff(), [1.0], ([1.0], [1.0]) + pushforward, copy!, [1.0], AutoSimpleFiniteDiff(), [1.0], ([1.0], [1.0]) ) end diff --git a/DifferentiationInterfaceTest/src/scenarios/allocfree.jl b/DifferentiationInterfaceTest/src/scenarios/allocfree.jl index 7abd1b90a..9797cddfc 100644 --- a/DifferentiationInterfaceTest/src/scenarios/allocfree.jl +++ b/DifferentiationInterfaceTest/src/scenarios/allocfree.jl @@ -25,8 +25,8 @@ function sum_scenarios(x::AbstractArray; dx::AbstractArray, dy::Number) ] end -function copyto!_scenarios(x::AbstractArray; dx::AbstractArray, dy::AbstractArray) - f! = copyto! +function copy!_scenarios(x::AbstractArray; dx::AbstractArray, dy::AbstractArray) + f! = copy! y = similar(x) f!(y, x) dy_from_dx = dx @@ -61,7 +61,7 @@ function allocfree_scenarios() scens = vcat( identity_scenarios(x_; dx = dx_, dy = dy_), # sum_scenarios(x_6; dx = dx_6, dy = dy_), - copyto!_scenarios(x_6; dx = dx_6, dy = dy_6), + copy!_scenarios(x_6; dx = dx_6, dy = dy_6), ) return scens end diff --git a/DifferentiationInterfaceTest/src/scenarios/empty.jl b/DifferentiationInterfaceTest/src/scenarios/empty.jl index d699f6728..58f2aab2f 100644 --- a/DifferentiationInterfaceTest/src/scenarios/empty.jl +++ b/DifferentiationInterfaceTest/src/scenarios/empty.jl @@ -10,7 +10,7 @@ function empty_scenarios() Scenario{:derivative, :out}(make_empty!, Float64[], 1.0; res1 = Float64[]), Scenario{:gradient, :out}(sum, Float64[]; res1 = Float64[]), Scenario{:jacobian, :out}(copy, Float64[]; res1 = float.(I(0))), - Scenario{:jacobian, :out}(copyto!, Float64[], Float64[]; res1 = float.(I(0))), + Scenario{:jacobian, :out}(copy!, Float64[], Float64[]; res1 = float.(I(0))), ] return scens end diff --git a/DifferentiationInterfaceTest/src/scenarios/modify.jl b/DifferentiationInterfaceTest/src/scenarios/modify.jl index 5761eb346..3be86bcf3 100644 --- a/DifferentiationInterfaceTest/src/scenarios/modify.jl +++ b/DifferentiationInterfaceTest/src/scenarios/modify.jl @@ -133,7 +133,7 @@ function (mc::WritableClosure{:in})(y, x) x_buffer[1] = copy(x) f(y_buffer[1], x_buffer[1]) y_buffer[1] .*= (a + only(b)) - copyto!(y, y_buffer[1]) + copy!(y, y_buffer[1]) return nothing end @@ -227,14 +227,14 @@ function (sc::StoreInCache{:out})(x, y_cache) # no annotation otherwise Zygote. y_cache[1] = y return y_cache[1] else - copyto!(y_cache, y) + copy!(y_cache, y) return copy(y_cache) end end function (sc::StoreInCache{:in})(y, x, y_cache) sc.f(y_cache, x) - copyto!(y, y_cache) + copy!(y, y_cache) return nothing end @@ -301,7 +301,7 @@ function (sc::MultiplyByConstantAndStoreInCache{:out})(x, constantorcache) newcache[1] = y return newcache[1] else - copyto!(newcache, y) + copy!(newcache, y) return copy(newcache) end end @@ -317,7 +317,7 @@ function (sc::MultiplyByConstantAndStoreInCache{:in})(y, x, constantorcache) end sc.f(newcache, x) newcache .*= (a + only(b)) - copyto!(y, newcache) + copy!(y, newcache) return nothing end