From 901e95a950cabfed2241422405c24841fad6a9ac Mon Sep 17 00:00:00 2001 From: ocots <66357348+ocots@users.noreply.github.com> Date: Mon, 27 Jul 2026 00:35:27 +0000 Subject: [PATCH] Format .jl files --- src/ad_types.jl | 2 +- src/lie_macro.jl | 16 ++++---- src/time_derivative.jl | 6 +-- .../differential_geometry/test_lift_dg.jl | 22 +++++----- .../differential_geometry/test_macro_dg.jl | 10 ++--- .../differential_geometry/test_poisson_dg.jl | 40 +++++++++---------- .../test_time_derivative_dg.jl | 28 ++++++------- 7 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/ad_types.jl b/src/ad_types.jl index 2685502..80d0c65 100644 --- a/src/ad_types.jl +++ b/src/ad_types.jl @@ -109,7 +109,7 @@ function ad( MDX<:Traits.AbstractMutabilityTrait, MDY<:Traits.AbstractMutabilityTrait, } - _check_not_hvf(X); + _check_not_hvf(X) _check_not_hvf(Y) _check_outofplace(MDX) # static dispatch on type parameter — no runtime call _check_outofplace(MDY) diff --git a/src/lie_macro.jl b/src/lie_macro.jl index 6b210f3..d8e3c78 100644 --- a/src/lie_macro.jl +++ b/src/lie_macro.jl @@ -163,9 +163,9 @@ function _lie_mac( has_var::Val, backend, ) where {TD,VD} - _check_td(a, TD, has_aut); + _check_td(a, TD, has_aut) _check_td(b, TD, has_aut) - _check_vd(a, VD, has_var); + _check_vd(a, VD, has_var) _check_vd(b, VD, has_var) return ad(_as_vf(a, TD, VD), _as_vf(b, TD, VD); ad_backend=backend) end @@ -285,9 +285,9 @@ function _poisson_mac( has_var::Val, backend, ) where {TD,VD} - _check_td(h, TD, has_aut); + _check_td(h, TD, has_aut) _check_td(g, TD, has_aut) - _check_vd(h, VD, has_var); + _check_vd(h, VD, has_var) _check_vd(g, VD, has_var) return Poisson(_as_ham(h, TD, VD), _as_ham(g, TD, VD); ad_backend=backend) end @@ -360,9 +360,9 @@ Parse keyword arguments for the @Lie macro. - `Expr`: Error expression if parsing failed, otherwise `nothing`. """ function __parse_lie_opts(args...) - is_autonomous = Data.__is_autonomous(); + is_autonomous = Data.__is_autonomous() has_aut = false - is_variable = Data.__is_variable(); + is_variable = Data.__is_variable() has_var = false backend_expr = :(CTLie.__dg_ad_backend()) @@ -370,10 +370,10 @@ function __parse_lie_opts(args...) if arg isa Expr && (arg.head === :(=) || arg.head === :kw) key, val = arg.args[1], arg.args[2] if key === :is_autonomous - is_autonomous = val; + is_autonomous = val has_aut = true elseif key === :is_variable - is_variable = val; + is_variable = val has_var = true elseif key === :ad_backend backend_expr = val diff --git a/src/time_derivative.jl b/src/time_derivative.jl index 52f5644..5a49579 100644 --- a/src/time_derivative.jl +++ b/src/time_derivative.jl @@ -108,8 +108,7 @@ Used to differentiate tuple-valued outputs slot-by-slot, since See also: [`CTLie.TimeDeriv_HVF`](@ref), [`CTLie._HVFComp2`](@ref) """ struct _HVFComp1{F} <: Function - ; - X::F; + X::F end """ @@ -123,8 +122,7 @@ Used to differentiate tuple-valued outputs slot-by-slot, since See also: [`CTLie.TimeDeriv_HVF`](@ref), [`CTLie._HVFComp1`](@ref) """ struct _HVFComp2{F} <: Function - ; - X::F; + X::F end (_c::_HVFComp1)(args...) = _c.X(args...)[1] diff --git a/test/suite/differential_geometry/test_lift_dg.jl b/test/suite/differential_geometry/test_lift_dg.jl index 9919f61..559e216 100644 --- a/test/suite/differential_geometry/test_lift_dg.jl +++ b/test/suite/differential_geometry/test_lift_dg.jl @@ -13,7 +13,7 @@ function test_lift_dg() Test.@testset "Lift() - Function → Function" verbose=VERBOSE showtiming=SHOWTIMING begin F(x) = [x[2], -x[1]] H2 = CTLie.Lift(F) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [3.0, 4.0] # H2(x,p) = p' * F(x) = [3,4]·[2,-1] = 6-4 = 2 Test.@test H2(x0, p0) ≈ 2.0 atol=1e-10 @@ -37,7 +37,7 @@ function test_lift_dg() Test.@testset "Lift() - @inferred type-stability" verbose=VERBOSE showtiming=SHOWTIMING begin F(x) = [x[2], -x[1]] H = CTLie.Lift(F) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [3.0, 4.0] Test.@test_nowarn Test.@inferred H(x0, p0) end @@ -46,7 +46,7 @@ function test_lift_dg() F_na(t, x) = [t * x[2], -x[1]] H_na = CTLie.Lift(F_na; is_autonomous=false) t0 = 2.0 - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [3.0, 4.0] Test.@test_nowarn Test.@inferred H_na(t0, x0, p0) end @@ -61,7 +61,7 @@ function test_lift_dg() F(x) = [x[2], -x[1]] H_kw = CTLie.Lift(F; is_autonomous=true, is_variable=false) H_typed = CTLie.Lift(F, Traits.Autonomous, Traits.Fixed) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [3.0, 4.0] Test.@test H_kw(x0, p0) ≈ H_typed(x0, p0) atol=1e-10 end @@ -78,7 +78,7 @@ function test_lift_dg() Test.@test H.f isa CTLie.LiftedHamiltonianFunction # Check correctness - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [3.0, 4.0] # H(x,p) = p'*X(x) = [3,4]·[2,-1] = 6-4 = 2 Test.@test H(x0, p0) ≈ 2.0 atol=1e-10 @@ -95,8 +95,8 @@ function test_lift_dg() F(x, v) = [v[1] * x[2], -x[1]] H = CTLie.Lift(F; is_autonomous=true, is_variable=true) Test.@test H isa Function - x0 = [1.0, 2.0]; - p0 = [3.0, 4.0]; + x0 = [1.0, 2.0] + p0 = [3.0, 4.0] v0 = [2.0] # H(x,p,v) = p' * F(x,v) = [3,4]·[2*2,-1] = 12-4 = 8 Test.@test H(x0, p0, v0) ≈ 8.0 atol=1e-10 @@ -106,9 +106,9 @@ function test_lift_dg() F(t, x, v) = [t * v[1] * x[2], -x[1]] H = CTLie.Lift(F; is_autonomous=false, is_variable=true) Test.@test H isa Function - t0 = 2.0; - x0 = [1.0, 2.0]; - p0 = [3.0, 4.0]; + t0 = 2.0 + x0 = [1.0, 2.0] + p0 = [3.0, 4.0] v0 = [2.0] # H(t,x,p,v) = p' * F(t,x,v) = [3,4]·[2*2*2,-1] = 24-4 = 20 Test.@test H(t0, x0, p0, v0) ≈ 20.0 atol=1e-10 @@ -117,7 +117,7 @@ function test_lift_dg() Test.@testset "Lift() - scalar case" verbose=VERBOSE showtiming=SHOWTIMING begin F(x) = -2 * x # returns scalar (treated as 1D vector) H = CTLie.Lift(F) - x0 = 2.0; + x0 = 2.0 p0 = 3.0 # H(x,p) = p * F(x) = 3 * (-4) = -12 Test.@test H(x0, p0) ≈ -12.0 atol=1e-10 diff --git a/test/suite/differential_geometry/test_macro_dg.jl b/test/suite/differential_geometry/test_macro_dg.jl index d09d0cd..4f6397a 100644 --- a/test/suite/differential_geometry/test_macro_dg.jl +++ b/test/suite/differential_geometry/test_macro_dg.jl @@ -13,8 +13,8 @@ const VERBOSE = isdefined(Main, :TestData) ? Main.TestData.VERBOSE : true const SHOWTIMING = isdefined(Main, :TestData) ? Main.TestData.SHOWTIMING : true # ─── Shared constants used across many testsets ──────────────────────────── -const _Γ = 2; -const _γ = 1; +const _Γ = 2 +const _γ = 1 const _δ = _γ - _Γ # δ = -1 const _t = 1.0 const _x3 = [1.0, 2.0, 3.0] @@ -362,7 +362,7 @@ function test_macro_dg() # ========================================================================= Test.@testset "poisson macro — Hamiltonians, nonautonomous nonfixed" verbose=VERBOSE showtiming=SHOWTIMING begin - t2 = 2.0; + t2 = 2.0 vv = [4.0, 4.0] f = (t, x, p, v) -> t*v[1]*x[2]^2 + 2x[1]^2 + p[1]^2 + v[2] g = (t, x, p, v) -> 3x[2]^2 - x[1]^2 + p[2]^2 + p[1] + t - v[2] @@ -444,7 +444,7 @@ function test_macro_dg() # ========================================================================= Test.@testset "poisson macro — plain functions, nonautonomous nonfixed" verbose=VERBOSE showtiming=SHOWTIMING begin - t2 = 2.0; + t2 = 2.0 vv = 2.0 f = (t, x, p, v) -> 0.5*(x[1]^2 + x[2]^2 + p[1]^2 + v) g = (t, x, p, v) -> 0.5*(x[1]^2 + x[2]^2 + p[2]^2 + v) @@ -501,7 +501,7 @@ function test_macro_dg() Test.@test mac_Hf_v(_x2, _p2, vv) ≈ ref_v(_x2, _p2, vv) atol=1e-6 # Function + Hamiltonian, nonautonomous nonfixed - t2 = 2.0; + t2 = 2.0 vv = 2.0 h_tv = (t, x, p, v) -> t*x[2]^2 + 2x[1]^2 + p[1]^2 + v g_tv = (t, x, p, v) -> 3x[2]^2 - x[1]^2 + p[2]^2 + v diff --git a/test/suite/differential_geometry/test_poisson_dg.jl b/test/suite/differential_geometry/test_poisson_dg.jl index 25092f2..6f45b51 100644 --- a/test/suite/differential_geometry/test_poisson_dg.jl +++ b/test/suite/differential_geometry/test_poisson_dg.jl @@ -20,7 +20,7 @@ function test_poisson_dg() G(x, p) = p[2]^2 / 2 + x[2] PH = CTLie.Poisson(H, G) PG = CTLie.Poisson(G, H) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [0.5, 1.0] Test.@test PH(x0, p0) ≈ -PG(x0, p0) atol=1e-6 end @@ -31,7 +31,7 @@ function test_poisson_dg() G(x, p) = p[1] # ∇pG = [1,0], ∇xG = 0 # {H,G} = ∇pH · ∇xG - ∇xH · ∇pG = 0·0 - [1,0]·[1,0] = -1 PB = CTLie.Poisson(H, G) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [0.5, 1.0] Test.@test PB(x0, p0) ≈ -1.0 atol=1e-6 end @@ -57,8 +57,8 @@ function test_poisson_dg() H(t, x, p) = t * p[1] G(t, x, p) = x[1] PB = CTLie.Poisson(H, G; is_autonomous=false, is_variable=false) - t0 = 3.0; - x0 = [1.0, 2.0]; + t0 = 3.0 + x0 = [1.0, 2.0] p0 = [0.5, 1.0] Test.@test PB(t0, x0, p0) ≈ t0 atol=1e-6 end @@ -69,8 +69,8 @@ function test_poisson_dg() H(x, p, v) = v[1] * p[1] G(x, p, v) = x[1] PB = CTLie.Poisson(H, G; is_autonomous=true, is_variable=true) - x0 = [1.0, 2.0]; - p0 = [0.5, 1.0]; + x0 = [1.0, 2.0] + p0 = [0.5, 1.0] v0 = [2.0] Test.@test PB(x0, p0, v0) ≈ v0[1] atol=1e-6 end @@ -81,9 +81,9 @@ function test_poisson_dg() H(t, x, p, v) = t * v[1] * p[1] G(t, x, p, v) = x[1] PB = CTLie.Poisson(H, G; is_autonomous=false, is_variable=true) - t0 = 3.0; - x0 = [1.0, 2.0]; - p0 = [0.5, 1.0]; + t0 = 3.0 + x0 = [1.0, 2.0] + p0 = [0.5, 1.0] v0 = [2.0] Test.@test PB(t0, x0, p0, v0) ≈ t0 * v0[1] atol=1e-6 end @@ -107,7 +107,7 @@ function test_poisson_dg() H(x, p) = p[1]^2 / 2 + x[1]^2 G(x, p) = x[1] * p[1] PB = CTLie.Poisson(H, G) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [0.5, 1.0] Test.@test (Test.@inferred PB(x0, p0)) isa Float64 end @@ -116,8 +116,8 @@ function test_poisson_dg() H(x, p, v) = v[1] * p[1]^2 / 2 + x[1]^2 G(x, p, v) = x[1] * p[1] PB = CTLie.Poisson(H, G; is_autonomous=true, is_variable=true) - x0 = [1.0, 2.0]; - p0 = [0.5, 1.0]; + x0 = [1.0, 2.0] + p0 = [0.5, 1.0] v0 = [2.0] Test.@test (Test.@inferred PB(x0, p0, v0)) isa Float64 end @@ -126,8 +126,8 @@ function test_poisson_dg() H(t, x, p) = t * p[1] G(t, x, p) = x[1] PB = CTLie.Poisson(H, G; is_autonomous=false, is_variable=false) - t0 = 3.0; - x0 = [1.0, 2.0]; + t0 = 3.0 + x0 = [1.0, 2.0] p0 = [0.5, 1.0] Test.@test (Test.@inferred PB(t0, x0, p0)) isa Float64 end @@ -136,9 +136,9 @@ function test_poisson_dg() H(t, x, p, v) = t * v[1] * p[1]^2 / 2 + x[1] G(t, x, p, v) = x[1] * p[1] PB = CTLie.Poisson(H, G; is_autonomous=false, is_variable=true) - t0 = 3.0; - x0 = [1.0, 2.0]; - p0 = [0.5, 1.0]; + t0 = 3.0 + x0 = [1.0, 2.0] + p0 = [0.5, 1.0] v0 = [2.0] Test.@test (Test.@inferred PB(t0, x0, p0, v0)) isa Float64 end @@ -150,7 +150,7 @@ function test_poisson_dg() ad_backend=ADTypes.AutoForwardDiff() ) PB = CTLie.Poisson(H, G; ad_backend=backend) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [0.5, 1.0] val = PB(x0, p0) Test.@test val isa Number @@ -163,7 +163,7 @@ function test_poisson_dg() # Autonomous, Fixed PB_af_typed = CTLie.Poisson(H, G, Traits.Autonomous, Traits.Fixed) PB_af_kwargs = CTLie.Poisson(H, G; is_autonomous=true, is_variable=false) - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [0.5, 1.0] Test.@test PB_af_typed(x0, p0) ≈ PB_af_kwargs(x0, p0) atol=1e-6 @@ -197,7 +197,7 @@ function test_poisson_dg() H(x, p) = 0.5 * (p^2 + x^2) G(x, p) = x PB = CTLie.Poisson(H, G) - x0 = 1.0; + x0 = 1.0 p0 = 3.0 # {H, G} = ∂H/∂p * ∂G/∂x - ∂H/∂x * ∂G/∂p = p * 1 - x * 0 = p Test.@test PB(x0, p0) ≈ 3.0 atol=1e-6 diff --git a/test/suite/differential_geometry/test_time_derivative_dg.jl b/test/suite/differential_geometry/test_time_derivative_dg.jl index da98524..afc788e 100644 --- a/test/suite/differential_geometry/test_time_derivative_dg.jl +++ b/test/suite/differential_geometry/test_time_derivative_dg.jl @@ -45,7 +45,7 @@ function test_time_derivative_dg() # internal functor (callable struct, not closure) Test.@test dX.f isa CTLie.TimeDeriv_VF # ∂/∂t [t*x2, -t*x1] = [x2, -x1] - t0 = 2.0; + t0 = 2.0 x0 = [1.0, 2.0] Test.@test isapprox(dX(t0, x0), [x0[2], -x0[1]]; atol=1e-6) dX(t0, x0) # warm-up @@ -80,8 +80,8 @@ function test_time_derivative_dg() (t, x, v) -> [t * v[1] * x[2], -x[1]]; is_autonomous=false, is_variable=true ) dX = CTLie.∂ₜ(X) - t0 = 2.0; - x0 = [1.0, 2.0]; + t0 = 2.0 + x0 = [1.0, 2.0] v0 = [3.0] Test.@test isapprox(dX(t0, x0, v0), [v0[1] * x0[2], 0.0]; atol=1e-6) end @@ -98,7 +98,7 @@ function test_time_derivative_dg() Test.@test dH isa Data.Hamiltonian Test.@test dH isa Data.AbstractHamiltonian{Traits.NonAutonomous,Traits.Fixed} # ∂/∂t [t * p'x] = p'x - x0 = [1.0, 2.0]; + x0 = [1.0, 2.0] p0 = [3.0, 4.0] Test.@test dH(2.0, x0, p0) ≈ p0' * x0 atol=1e-6 dH(2.0, x0, p0) # warm-up @@ -129,9 +129,9 @@ function test_time_derivative_dg() (t, x, p, v) -> t * v[1] * p[1]; is_autonomous=false, is_variable=true ) dH = CTLie.∂ₜ(H) - t0 = 2.0; - x0 = [1.0]; - p0 = [3.0]; + t0 = 2.0 + x0 = [1.0] + p0 = [3.0] v0 = [4.0] Test.@test dH(t0, x0, p0, v0) ≈ v0[1] * p0[1] atol=1e-6 end @@ -150,8 +150,8 @@ function test_time_derivative_dg() Test.@test dX isa Data.AbstractHamiltonianVectorField{ Traits.NonAutonomous,Traits.Fixed,Traits.OutOfPlace } - t0 = 2.0; - x0 = [1.0]; + t0 = 2.0 + x0 = [1.0] p0 = [3.0] dx, dp = dX(t0, x0, p0) Test.@test dx ≈ p0 atol=1e-6 @@ -192,9 +192,9 @@ function test_time_derivative_dg() (t, x, p, v) -> (t * v[1] * p, -x); is_autonomous=false, is_variable=true ) dX = CTLie.∂ₜ(X) - t0 = 2.0; - x0 = [1.0]; - p0 = [3.0]; + t0 = 2.0 + x0 = [1.0] + p0 = [3.0] v0 = [4.0] dx, dp = dX(t0, x0, p0, v0) Test.@test dx ≈ v0[1] .* p0 atol=1e-6 @@ -206,8 +206,8 @@ function test_time_derivative_dg() (t, x, p) -> (t * p, -t * x); is_autonomous=false, is_variable=false ) dX = CTLie.∂ₜ(X) - t0 = 2.0; - x0 = [1.0]; + t0 = 2.0 + x0 = [1.0] p0 = [3.0] dX(t0, x0, p0) # warm-up Test.@test_nowarn Test.@inferred dX(t0, x0, p0)