Skip to content

Commit 7b4100d

Browse files
committed
Some temporary updates related to JuliaDiff/TaylorSeries.jl#361
1 parent 64f596a commit 7b4100d

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

src/parse_eqs.jl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ mutable struct BookKeeping
3535
v_array4 :: Vector{Symbol}
3636
v_preamb :: Vector{Union{Symbol,Expr}}
3737
retvar :: Symbol
38+
numaux :: Int
3839

3940
function BookKeeping()
4041
return new(Dict{Symbol, Expr}(), Dict{Union{Symbol,Expr}, Number}(),
4142
Dict{Symbol, Expr}(), Symbol[], Symbol[], Symbol[], Symbol[], Symbol[], Symbol[],
42-
Union{Symbol,Expr}[], :nothing)
43+
Union{Symbol,Expr}[], :nothing, 0)
4344
end
4445
end
4546

@@ -343,7 +344,7 @@ function _preamble_body(fnbody, fnargs)
343344
bkkeep = BookKeeping()
344345

345346
# Rename vars to have the body in non-indexed form; bkkeep has different entries
346-
# for bookkeeping variables/symbolds, including indexed ones
347+
# for bookkeeping variables/symbols, including indexed ones
347348
fnbody, bkkeep.d_indx = _rename_indexedvars(fnbody)
348349

349350
# Create `newfnbody` which corresponds to `fnbody`, cleaned (without irrelevant comments)
@@ -372,7 +373,7 @@ function _preamble_body(fnbody, fnargs)
372373
newfnbody = subs(newfnbody, bkkeep.d_indx)
373374

374375
# Define retvar; for scalar eqs is the last entry included in v_newvars
375-
bkkeep.retvar = length(fnargs) == 3 ? subs(bkkeep.v_newvars[end], bkkeep.d_indx) : fnargs[1]
376+
bkkeep.retvar = length(fnargs) == 3 ? subs(bkkeep.v_newvars[end-bkkeep.numaux], bkkeep.d_indx) : fnargs[1]
376377

377378
return defspreamble, defsprealloc, newfnbody, bkkeep
378379
end
@@ -836,10 +837,11 @@ function _replacecalls!(bkkeep::BookKeeping, fnold::Expr, newvar::Symbol)
836837
end
837838

838839
elseif ll == 3
839-
# Binary call; no auxiliary expressions needed
840+
# Binary call
840841
newarg2 = fnold.args[3]
841842

842843
# Replacements
844+
# @show TaylorSeries._dict_binary_calls[dcall]
843845
fnexpr, def_fnexpr, aux_fnexpr = TaylorSeries._dict_binary_calls[dcall]
844846
fnexpr = subs(fnexpr,
845847
Dict(:_res => newvar, :_arg1 => newarg1, :_arg2 => newarg2, :_k => :ord))
@@ -861,6 +863,28 @@ function _replacecalls!(bkkeep::BookKeeping, fnold::Expr, newvar::Symbol)
861863
# Dict(:_res => newvar, :_arg1 => :(constant_term($(newarg1))),
862864
# :_arg2 => :(constant_term($(newarg2))), :_k => :ord))
863865

866+
# Auxiliary expression
867+
if aux_fnexpr.head != :nothing
868+
newaux = genname()
869+
870+
aux_alloc = :( _res = Taylor1($(aux_fnexpr.args[2]), order) )
871+
aux_alloc = subs(aux_alloc,
872+
Dict(:_res => newaux, :_arg1 => :(constant_term($(newarg1))), :_aux => newaux))
873+
874+
aux_fnexpr = Expr(:block,
875+
:(TaylorSeries.zero!(_res)),
876+
:(_res.coeffs[1] = $(aux_fnexpr.args[2])) )
877+
aux_fnexpr = subs(aux_fnexpr,
878+
Dict(:_res => newaux, :_arg1 => :(constant_term($(newarg1))), :_aux => newaux))
879+
880+
fnexpr = subs(fnexpr, Dict(:_aux => newaux))
881+
if newvar bkkeep.v_arraydecl
882+
push!(bkkeep.v_arraydecl, newaux)
883+
else
884+
bkkeep.numaux += 1
885+
push!(bkkeep.v_newvars, newaux)
886+
end
887+
end
864888
else
865889
# Recognized call, but not a unary or binary call; copy expression
866890
fnexpr = :($newvar = $fnold)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This file is part of the TaylorIntegration.jl package; MIT licensed
22

33
testfiles = (
4+
"solution.jl",
45
"one_ode.jl",
56
"many_ode.jl",
67
"complex.jl",

test/taylorize.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ import Logging: Warn
246246
end
247247

248248

249-
# Pendulum integrtf = 100.0
249+
# # Pendulum integration
250250
@testset "Integration of the pendulum and DiffEqs interface" begin
251251
@taylorize function pendulum!(dx::Array{T,1}, x::Array{T,1}, p, t) where {T}
252252
dx[1] = x[2]
@@ -1303,7 +1303,7 @@ import Logging: Warn
13031303
_tmax = tf
13041304
_q0 = q0TN
13051305
_params = nothing
1306-
_maxsteps = 3000
1306+
_maxsteps = 100
13071307
_T = eltype(_t0)
13081308
_U = eltype(_q0)
13091309
# Initialize the vector of Taylor1 expansions
@@ -1317,12 +1317,13 @@ import Logging: Warn
13171317
end
13181318
# Determine if specialized jetcoeffs! method exists
13191319
__parse_eqs, __rv = TaylorIntegration._determine_parsing!(true, kepler1!, _t, _x, _dx, _params);
1320+
@test __parse_eqs
13201321
# Re-initialize the Taylor1 expansions
13211322
_t = _t0 + Taylor1( _T, _order )
13221323
_x .= Taylor1.( _q0, _order )
13231324
_dx .= Taylor1.( zero.(_q0), _order)
1324-
solTN = @inferred TaylorIntegration._taylorinteg!(Val(true), kepler1!, _t, _x, _dx, _q0, _t0, _tmax, _abstol, __rv, _params; parse_eqs=__parse_eqs, maxsteps=_maxsteps)
1325-
solTN2 = @inferred TaylorIntegration._taylorinteg!(Val(false), kepler1!, _t, _x, _dx, _q0, _t0, _tmax, _abstol, __rv, _params; parse_eqs=__parse_eqs, maxsteps=_maxsteps)
1325+
solTN = @test_logs((Warn, max_iters_reached()), @inferred TaylorIntegration._taylorinteg!(Val(true), kepler1!, _t, _x, _dx, _q0, _t0, _tmax, _abstol, __rv, _params; parse_eqs=__parse_eqs, maxsteps=_maxsteps) )
1326+
solTN2 = @test_logs((Warn, max_iters_reached()), @inferred TaylorIntegration._taylorinteg!(Val(false), kepler1!, _t, _x, _dx, _q0, _t0, _tmax, _abstol, __rv, _params; parse_eqs=__parse_eqs, maxsteps=_maxsteps) )
13261327
@test solTN isa TaylorSolution{typeof(_t0), eltype(_q0), ndims(solTN.x), typeof(solTN.t), typeof(solTN.x), typeof(solTN.p), Nothing, Nothing, Nothing}
13271328
@test solTN2 isa TaylorSolution{typeof(_t0), eltype(_q0), ndims(solTN.x), typeof(solTN.t), typeof(solTN.x), Nothing, Nothing, Nothing, Nothing}
13281329
end

0 commit comments

Comments
 (0)