Skip to content
Merged
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 src/ad_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions src/lie_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -360,20 +360,20 @@ 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())

for arg in 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
Expand Down
6 changes: 2 additions & 4 deletions src/time_derivative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand All @@ -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]
Expand Down
22 changes: 11 additions & 11 deletions test/suite/differential_geometry/test_lift_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/suite/differential_geometry/test_macro_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
40 changes: 20 additions & 20 deletions test/suite/differential_geometry/test_poisson_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions test/suite/differential_geometry/test_time_derivative_dg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand 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
Expand All @@ -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
Expand Down Expand 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down