Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 36167db

Browse files
author
SciML Bot
committed
Apply JuliaFormatter to fix code formatting
- Applied JuliaFormatter with SciML style guide - Formatted 2 files 🤖 Generated by OrgMaintenanceScripts.jl
1 parent f6d22ed commit 36167db

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

ext/OptimizationEnzymeExt.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function set_runtime_activity2(
8585
Enzyme.set_runtime_activity(a, RTA)
8686
end
8787
function_annotation(::Nothing) = Nothing
88-
function_annotation(::AutoEnzyme{<:Any, A}) where A = A
88+
function_annotation(::AutoEnzyme{<:Any, A}) where {A} = A
8989
function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
9090
adtype::AutoEnzyme, p, num_cons = 0;
9191
g = false, h = false, hv = false, fg = false, fgh = false,
@@ -225,9 +225,12 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
225225
if func_annot <: Enzyme.Const
226226
basefunc = Enzyme.Const(basefunc)
227227
elseif func_annot <: Enzyme.Duplicated || func_annot <: Enzyme.BatchDuplicated
228-
basefunc = Enzyme.BatchDuplicated(basefunc, Tuple(make_zero(basefunc) for i in 1:length(x)))
229-
elseif func_annot <: Enzyme.DuplicatedNoNeed || func_annot <: Enzyme.BatchDuplicatedNoNeed
230-
basefunc = Enzyme.BatchDuplicatedNoNeed(basefunc, Tuple(make_zero(basefunc) for i in 1:length(x)))
228+
basefunc = Enzyme.BatchDuplicated(
229+
basefunc, Tuple(make_zero(basefunc) for i in 1:length(x)))
230+
elseif func_annot <: Enzyme.DuplicatedNoNeed ||
231+
func_annot <: Enzyme.BatchDuplicatedNoNeed
232+
basefunc = Enzyme.BatchDuplicatedNoNeed(
233+
basefunc, Tuple(make_zero(basefunc) for i in 1:length(x)))
231234
end
232235
# else
233236
# seeds = Enzyme.onehot(zeros(eltype(x), num_cons))
@@ -241,12 +244,14 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
241244
Enzyme.make_zero!(jc)
242245
end
243246
Enzyme.make_zero!(y)
244-
if func_annot <: Enzyme.Duplicated || func_annot <: Enzyme.BatchDuplicated || func_annot <: Enzyme.DuplicatedNoNeed || func_annot <: Enzyme.BatchDuplicatedNoNeed
247+
if func_annot <: Enzyme.Duplicated || func_annot <: Enzyme.BatchDuplicated ||
248+
func_annot <: Enzyme.DuplicatedNoNeed ||
249+
func_annot <: Enzyme.BatchDuplicatedNoNeed
245250
for bf in basefunc.dval
246251
Enzyme.make_zero!(bf)
247252
end
248253
end
249-
Enzyme.autodiff(fmode, basefunc , BatchDuplicated(y, Jaccache),
254+
Enzyme.autodiff(fmode, basefunc, BatchDuplicated(y, Jaccache),
250255
BatchDuplicated(θ, seeds), Const(p))
251256
for i in eachindex(θ)
252257
if J isa Vector

ext/OptimizationZygoteExt.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function OptimizationBase.instantiate_function(
3030
adtype, soadtype = OptimizationBase.generate_adtype(adtype)
3131

3232
if g == true && f.grad === nothing
33-
prep_grad = prepare_gradient(f.f, adtype, x, Constant(p), strict=Val(false))
33+
prep_grad = prepare_gradient(f.f, adtype, x, Constant(p), strict = Val(false))
3434
function grad(res, θ)
3535
gradient!(f.f, res, prep_grad, adtype, θ, Constant(p))
3636
end
@@ -47,7 +47,7 @@ function OptimizationBase.instantiate_function(
4747

4848
if fg == true && f.fg === nothing
4949
if g == false
50-
prep_grad = prepare_gradient(f.f, adtype, x, Constant(p), strict=Val(false))
50+
prep_grad = prepare_gradient(f.f, adtype, x, Constant(p), strict = Val(false))
5151
end
5252
function fg!(res, θ)
5353
(y, _) = value_and_gradient!(f.f, res, prep_grad, adtype, θ, Constant(p))
@@ -68,7 +68,7 @@ function OptimizationBase.instantiate_function(
6868
hess_sparsity = f.hess_prototype
6969
hess_colors = f.hess_colorvec
7070
if h == true && f.hess === nothing
71-
prep_hess = prepare_hessian(f.f, soadtype, x, Constant(p), strict=Val(false))
71+
prep_hess = prepare_hessian(f.f, soadtype, x, Constant(p), strict = Val(false))
7272
function hess(res, θ)
7373
hessian!(f.f, res, prep_hess, soadtype, θ, Constant(p))
7474
end
@@ -143,7 +143,7 @@ function OptimizationBase.instantiate_function(
143143
cons_jac_prototype = f.cons_jac_prototype
144144
cons_jac_colorvec = f.cons_jac_colorvec
145145
if cons !== nothing && cons_j == true && f.cons_j === nothing
146-
prep_jac = prepare_jacobian(cons_oop, adtype, x, strict=Val(false))
146+
prep_jac = prepare_jacobian(cons_oop, adtype, x, strict = Val(false))
147147
function cons_j!(J, θ)
148148
jacobian!(cons_oop, J, prep_jac, adtype, θ)
149149
if size(J, 1) == 1
@@ -157,7 +157,8 @@ function OptimizationBase.instantiate_function(
157157
end
158158

159159
if f.cons_vjp === nothing && cons_vjp == true && cons !== nothing
160-
prep_pullback = prepare_pullback(cons_oop, adtype, x, (ones(eltype(x), num_cons),), strict=Val(false))
160+
prep_pullback = prepare_pullback(
161+
cons_oop, adtype, x, (ones(eltype(x), num_cons),), strict = Val(false))
161162
function cons_vjp!(J, θ, v)
162163
pullback!(cons_oop, (J,), prep_pullback, adtype, θ, (v,))
163164
end
@@ -169,7 +170,7 @@ function OptimizationBase.instantiate_function(
169170

170171
if cons !== nothing && f.cons_jvp === nothing && cons_jvp == true
171172
prep_pushforward = prepare_pushforward(
172-
cons_oop, adtype, x, (ones(eltype(x), length(x)),), strict=Val(false))
173+
cons_oop, adtype, x, (ones(eltype(x), length(x)),), strict = Val(false))
173174
function cons_jvp!(J, θ, v)
174175
pushforward!(cons_oop, (J,), prep_pushforward, adtype, θ, (v,))
175176
end
@@ -182,7 +183,8 @@ function OptimizationBase.instantiate_function(
182183
conshess_sparsity = f.cons_hess_prototype
183184
conshess_colors = f.cons_hess_colorvec
184185
if cons !== nothing && cons_h == true && f.cons_h === nothing
185-
prep_cons_hess = [prepare_hessian(cons_oop, soadtype, x, Constant(i), strict=Val(false))
186+
prep_cons_hess = [prepare_hessian(
187+
cons_oop, soadtype, x, Constant(i), strict = Val(false))
186188
for i in 1:num_cons]
187189

188190
function cons_h!(H, θ)
@@ -201,7 +203,7 @@ function OptimizationBase.instantiate_function(
201203
if f.lag_h === nothing && cons !== nothing && lag_h == true
202204
lag_extras = prepare_hessian(
203205
lagrangian, soadtype, x, Constant(one(eltype(x))),
204-
Constant(ones(eltype(x), num_cons)), Constant(p), strict=Val(false))
206+
Constant(ones(eltype(x), num_cons)), Constant(p), strict = Val(false))
205207
lag_hess_prototype = zeros(Bool, num_cons, length(x))
206208

207209
function lag_h!(H::AbstractMatrix, θ, σ, λ)
@@ -294,7 +296,8 @@ function OptimizationBase.instantiate_function(
294296
adtype, soadtype = OptimizationBase.generate_sparse_adtype(adtype)
295297

296298
if g == true && f.grad === nothing
297-
extras_grad = prepare_gradient(f.f, adtype.dense_ad, x, Constant(p), strict=Val(false))
299+
extras_grad = prepare_gradient(
300+
f.f, adtype.dense_ad, x, Constant(p), strict = Val(false))
298301
function grad(res, θ)
299302
gradient!(f.f, res, extras_grad, adtype.dense_ad, θ, Constant(p))
300303
end
@@ -311,7 +314,8 @@ function OptimizationBase.instantiate_function(
311314

312315
if fg == true && f.fg === nothing
313316
if g == false
314-
extras_grad = prepare_gradient(f.f, adtype.dense_ad, x, Constant(p), strict=Val(false))
317+
extras_grad = prepare_gradient(
318+
f.f, adtype.dense_ad, x, Constant(p), strict = Val(false))
315319
end
316320
function fg!(res, θ)
317321
(y, _) = value_and_gradient!(
@@ -334,7 +338,7 @@ function OptimizationBase.instantiate_function(
334338
hess_sparsity = f.hess_prototype
335339
hess_colors = f.hess_colorvec
336340
if h == true && f.hess === nothing
337-
prep_hess = prepare_hessian(f.f, soadtype, x, Constant(p), strict=Val(false))
341+
prep_hess = prepare_hessian(f.f, soadtype, x, Constant(p), strict = Val(false))
338342
function hess(res, θ)
339343
hessian!(f.f, res, prep_hess, soadtype, θ, Constant(p))
340344
end
@@ -458,7 +462,8 @@ function OptimizationBase.instantiate_function(
458462
conshess_sparsity = f.cons_hess_prototype
459463
conshess_colors = f.cons_hess_colorvec
460464
if cons !== nothing && f.cons_h === nothing && cons_h == true
461-
prep_cons_hess = [prepare_hessian(cons_oop, soadtype, x, Constant(i), strict=Val(false))
465+
prep_cons_hess = [prepare_hessian(
466+
cons_oop, soadtype, x, Constant(i), strict = Val(false))
462467
for i in 1:num_cons]
463468
colores = getfield.(prep_cons_hess, :coloring_result)
464469
conshess_sparsity = getfield.(colores, :A)
@@ -479,7 +484,7 @@ function OptimizationBase.instantiate_function(
479484
if cons !== nothing && f.lag_h === nothing && lag_h == true
480485
lag_extras = prepare_hessian(
481486
lagrangian, soadtype, x, Constant(one(eltype(x))),
482-
Constant(ones(eltype(x), num_cons)), Constant(p), strict=Val(false))
487+
Constant(ones(eltype(x), num_cons)), Constant(p), strict = Val(false))
483488
lag_hess_prototype = lag_extras.coloring_result.A
484489
lag_hess_colors = lag_extras.coloring_result.color
485490

0 commit comments

Comments
 (0)