-
-
Notifications
You must be signed in to change notification settings - Fork 46
Format for JuliaFormatter v2 #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -74,14 +74,19 @@ function brusselator_2d_loop(du, u, p) | |||||||||||||
@inbounds for I in CartesianIndices((N, N)) | ||||||||||||||
i, j = Tuple(I) | ||||||||||||||
x, y = xyd_brusselator[I[1]], xyd_brusselator[I[2]] | ||||||||||||||
ip1, im1, jp1, jm1 = limit(i + 1, N), limit(i - 1, N), limit(j + 1, N), | ||||||||||||||
ip1, im1, jp1, | ||||||||||||||
jm1 = limit(i + 1, N), limit(i - 1, N), limit(j + 1, N), | ||||||||||||||
limit(j - 1, N) | ||||||||||||||
du[i, j, 1] = alpha * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] - | ||||||||||||||
4u[i, j, 1]) + | ||||||||||||||
B + | ||||||||||||||
u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] + brusselator_f(x, y) | ||||||||||||||
du[i, j, 2] = alpha * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] - | ||||||||||||||
4u[i, j, 2]) + A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2] | ||||||||||||||
du[i, | ||||||||||||||
j, | ||||||||||||||
1] = alpha * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] - | ||||||||||||||
4u[i, j, 1]) + | ||||||||||||||
B + | ||||||||||||||
u[i, j, 1]^2 * u[i, j, 2] - (A + 1) * u[i, j, 1] + brusselator_f(x, y) | ||||||||||||||
du[i, | ||||||||||||||
j, | ||||||||||||||
2] = alpha * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] - | ||||||||||||||
4u[i, j, 2]) + A * u[i, j, 1] - u[i, j, 1]^2 * u[i, j, 2] | ||||||||||||||
Comment on lines
+87
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
end | ||||||||||||||
end | ||||||||||||||
p = (3.4, 1.0, 10.0, step(xyd_brusselator)) | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,7 +33,8 @@ function SciMLBase.__solve( | |||||
prob.f, autodiff, prob.u0, Constant(prob.p) | ||||||
) | ||||||
|
||||||
fj_scalar = @closure (Jx, x) -> begin | ||||||
fj_scalar = @closure (Jx, | ||||||
x) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
return DifferentiationInterface.value_and_derivative( | ||||||
prob.f, prep, autodiff, x, Constant(prob.p) | ||||||
) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,7 +22,8 @@ function SciMLBase.__solve( | |||||||||||||
termination_condition, alg; abs_norm_supported = false | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
f_wrapped!, u0, resid = NonlinearSolveBase.construct_extension_function_wrapper( | ||||||||||||||
f_wrapped!, u0, | ||||||||||||||
resid = NonlinearSolveBase.construct_extension_function_wrapper( | ||||||||||||||
prob; alias_u0 | ||||||||||||||
) | ||||||||||||||
T = eltype(u0) | ||||||||||||||
|
@@ -48,7 +49,9 @@ function SciMLBase.__solve( | |||||||||||||
|
||||||||||||||
nf = Ref{Int}(0) | ||||||||||||||
|
||||||||||||||
f! = @closure (cfx, cx, user_ctx) -> begin | ||||||||||||||
f! = @closure (cfx, | ||||||||||||||
cx, | ||||||||||||||
user_ctx) -> begin | ||||||||||||||
Comment on lines
+53
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
nf[] += 1 | ||||||||||||||
fx = cfx isa Ptr{Nothing} ? PETSc.unsafe_localarray(T, cfx; read = false) : cfx | ||||||||||||||
x = cx isa Ptr{Nothing} ? PETSc.unsafe_localarray(T, cx; write = false) : cx | ||||||||||||||
|
@@ -76,7 +79,8 @@ function SciMLBase.__solve( | |||||||||||||
) | ||||||||||||||
J_init = zeros(T, 1, 1) | ||||||||||||||
else | ||||||||||||||
jac!, J_init = NonlinearSolveBase.construct_extension_jac( | ||||||||||||||
jac!, | ||||||||||||||
J_init = NonlinearSolveBase.construct_extension_jac( | ||||||||||||||
prob, alg, u0, resid; autodiff, initial_jacobian = Val(true) | ||||||||||||||
) | ||||||||||||||
end | ||||||||||||||
|
@@ -85,7 +89,10 @@ function SciMLBase.__solve( | |||||||||||||
|
||||||||||||||
if J_init isa AbstractSparseMatrix | ||||||||||||||
PJ = PETSc.MatSeqAIJ(J_init) | ||||||||||||||
jac_fn! = @closure (cx, J, _, user_ctx) -> begin | ||||||||||||||
jac_fn! = @closure (cx, | ||||||||||||||
J, | ||||||||||||||
_, | ||||||||||||||
user_ctx) -> begin | ||||||||||||||
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
njac[] += 1 | ||||||||||||||
x = cx isa Ptr{Nothing} ? PETSc.unsafe_localarray(T, cx; write = false) : cx | ||||||||||||||
if J isa PETSc.AbstractMat | ||||||||||||||
|
@@ -102,7 +109,10 @@ function SciMLBase.__solve( | |||||||||||||
snes.user_ctx = (; jacobian = J_init) | ||||||||||||||
else | ||||||||||||||
PJ = PETSc.MatSeqDense(J_init) | ||||||||||||||
jac_fn! = @closure (cx, J, _, user_ctx) -> begin | ||||||||||||||
jac_fn! = @closure (cx, | ||||||||||||||
J, | ||||||||||||||
_, | ||||||||||||||
user_ctx) -> begin | ||||||||||||||
Comment on lines
+113
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||||
njac[] += 1 | ||||||||||||||
x = cx isa Ptr{Nothing} ? PETSc.unsafe_localarray(T, cx; write = false) : cx | ||||||||||||||
jac!(J, x) | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,9 @@ using SciMLBase: SciMLBase, IntervalNonlinearProblem | |||||||||
|
||||||||||
using BracketingNonlinearSolve: Bisection, Brent, Alefeld, Falsi, ITP, Ridder | ||||||||||
|
||||||||||
const DualIntervalNonlinearProblem{T, V, P} = IntervalNonlinearProblem{ | ||||||||||
const DualIntervalNonlinearProblem{T, | ||||||||||
V, | ||||||||||
P} = IntervalNonlinearProblem{ | ||||||||||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
uType, iip, <:Union{<:Dual{T, V, P}, <:AbstractArray{<:Dual{T, V, P}}} | ||||||||||
} where {uType, iip} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,7 +18,7 @@ end | |||||||||
|
||||||||||
@testset for p in 1.1:0.1:100.0 | ||||||||||
@test g(p)≈sqrt(p) atol=1e-3 rtol=1e-3 | ||||||||||
@test ForwardDiff.derivative(g, p)≈1 / (2 * sqrt(p)) atol=1e-3 rtol=1e-3 | ||||||||||
@test ForwardDiff.derivative(g, p)≈1/(2*sqrt(p)) atol=1e-3 rtol=1e-3 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
end | ||||||||||
|
||||||||||
t = (p) -> [sqrt(p[2] / p[1])] | ||||||||||
|
@@ -30,7 +30,7 @@ end | |||||||||
return [sol.u] | ||||||||||
end | ||||||||||
|
||||||||||
@test g2(p)≈[sqrt(p[2] / p[1])] atol=1e-3 rtol=1e-3 | ||||||||||
@test g2(p)≈[sqrt(p[2]/p[1])] atol=1e-3 rtol=1e-3 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
@test ForwardDiff.jacobian(g2, p)≈ForwardDiff.jacobian(t, p) atol=1e-3 rtol=1e-3 | ||||||||||
|
||||||||||
probB = IntervalNonlinearProblem{false}(quadratic_f, (1.0, 2.0), 2.0) | ||||||||||
|
@@ -50,8 +50,8 @@ end | |||||||||
end | ||||||||||
|
||||||||||
@testitem "Tolerance Tests Interval Methods" setup=[RootfindingTestSnippet] tags=[:core] begin | ||||||||||
prob = IntervalNonlinearProblem(quadratic_f, (1.0, 20.0), 2.0) | ||||||||||
ϵ = eps(Float64) # least possible tol for all methods | ||||||||||
prob=IntervalNonlinearProblem(quadratic_f, (1.0, 20.0), 2.0) | ||||||||||
ϵ=eps(Float64) # least possible tol for all methods | ||||||||||
Comment on lines
+53
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||
|
||||||||||
@testset for alg in (Bisection(), Falsi(), ITP(), Muller(), nothing) | ||||||||||
@testset for abstol in [0.1, 0.01, 0.001, 0.0001, 1e-5, 1e-6] | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -73,7 +73,7 @@ include("forward_diff.jl") | |||||
@compat(public, (construct_jacobian_cache,)) | ||||||
@compat(public, | ||||||
(assert_extension_supported_termination_condition, | ||||||
construct_extension_function_wrapper, construct_extension_jac)) | ||||||
construct_extension_function_wrapper, construct_extension_jac)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
|
||||||
export TraceMinimal, TraceWithJacobianConditionNumber, TraceAll | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -118,22 +118,25 @@ function nlls_generate_vjp_function(prob::NonlinearLeastSquaresProblem, sol, uu) | |||||
# nested autodiff as the last resort | ||||||
if SciMLBase.has_vjp(prob.f) | ||||||
if SciMLBase.isinplace(prob) | ||||||
return @closure (du, u, p) -> begin | ||||||
return @closure ( | ||||||
du, u, p) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
resid = Utils.safe_similar(du, length(sol.resid)) | ||||||
prob.f(resid, u, p) | ||||||
prob.f.vjp(du, resid, u, p) | ||||||
du .*= 2 | ||||||
return nothing | ||||||
end | ||||||
else | ||||||
return @closure (u, p) -> begin | ||||||
return @closure ( | ||||||
u, p) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
resid = prob.f(u, p) | ||||||
return reshape(2 .* prob.f.vjp(resid, u, p), size(u)) | ||||||
end | ||||||
end | ||||||
elseif SciMLBase.has_jac(prob.f) | ||||||
if SciMLBase.isinplace(prob) | ||||||
return @closure (du, u, p) -> begin | ||||||
return @closure ( | ||||||
du, u, p) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
J = Utils.safe_similar(du, length(sol.resid), length(u)) | ||||||
prob.f.jac(J, u, p) | ||||||
resid = Utils.safe_similar(du, length(sol.resid)) | ||||||
|
@@ -142,7 +145,8 @@ function nlls_generate_vjp_function(prob::NonlinearLeastSquaresProblem, sol, uu) | |||||
return nothing | ||||||
end | ||||||
else | ||||||
return @closure (u, p) -> begin | ||||||
return @closure (u, | ||||||
p) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
return reshape(2 .* vec(prob.f(u, p))' * prob.f.jac(u, p), size(u)) | ||||||
end | ||||||
end | ||||||
|
@@ -152,7 +156,8 @@ function nlls_generate_vjp_function(prob::NonlinearLeastSquaresProblem, sol, uu) | |||||
select_reverse_mode_autodiff(prob, nothing) : AutoForwardDiff() | ||||||
|
||||||
if SciMLBase.isinplace(prob) | ||||||
return @closure (du, u, p) -> begin | ||||||
return @closure ( | ||||||
du, u, p) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
resid = Utils.safe_similar(du, length(sol.resid)) | ||||||
prob.f(resid, u, p) | ||||||
# Using `Constant` lead to dual ordering issues | ||||||
|
@@ -163,7 +168,8 @@ function nlls_generate_vjp_function(prob::NonlinearLeastSquaresProblem, sol, uu) | |||||
return nothing | ||||||
end | ||||||
else | ||||||
return @closure (u, p) -> begin | ||||||
return @closure (u, | ||||||
p) -> begin | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
v = prob.f(u, p) | ||||||
# Using `Constant` lead to dual ordering issues | ||||||
res = only(DI.pullback(Base.Fix2(prob.f, p), autodiff, u, (v,))) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶