Skip to content

Commit b3750f1

Browse files
interpolation fix
1 parent 231bae7 commit b3750f1

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/dense/generic_dense.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,22 @@ times ts (sorted), with values timeseries and derivatives ks
136136
else
137137
dt = ts[notsaveat_idxs[i]] - ts[notsaveat_idxs[i-1]]
138138
Θ = (t-ts[notsaveat_idxs[i-1]])/dt
139+
139140
if idxs == nothing && eltype(timeseries) <: ArrayPartition
140141
idxs_internal = indices(timeseries[notsaveat_idxs[i-1]])
141142
elseif idxs == nothing && eltype(timeseries) <: AbstractArray
142143
idxs_internal = size(timeseries[notsaveat_idxs[i-1]])
143144
else
144145
idxs_internal = idxs
145146
end
146-
if !id.dense
147+
148+
if typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
149+
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
150+
elseif !id.dense
147151
vals[j] = linear_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],idxs_internal,deriv)
148152
elseif typeof(cache) <: CompositeCache
149153
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache.caches[id.alg_choice[notsaveat_idxs[i-1]]]) # update the kcurrent
150154
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache.caches[id.alg_choice[notsaveat_idxs[i-1]]],idxs_internal,deriv)
151-
elseif typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
152-
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
153155
else
154156
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache) # update the kcurrent
155157
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache,idxs_internal,deriv)
@@ -196,7 +198,13 @@ times ts (sorted), with values timeseries and derivatives ks
196198
else
197199
idxs_internal = idxs
198200
end
199-
if !id.dense
201+
if typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
202+
if eltype(timeseries) <: Union{AbstractArray,ArrayPartition}
203+
ode_interpolant!(vals[j],Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
204+
else
205+
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
206+
end
207+
elseif !id.dense
200208
if eltype(timeseries) <: Union{AbstractArray,ArrayPartition}
201209
linear_interpolant!(vals[j],Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],idxs_internal,deriv)
202210
else
@@ -209,12 +217,6 @@ times ts (sorted), with values timeseries and derivatives ks
209217
else
210218
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache.caches[id.alg_choice[notsaveat_idxs[i-1]]],idxs_internal,deriv)
211219
end
212-
elseif typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
213-
if eltype(timeseries) <: Union{AbstractArray,ArrayPartition}
214-
ode_interpolant!(vals[j],Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
215-
else
216-
vals[j] = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
217-
end
218220
else
219221
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache) # update the kcurrent
220222
if eltype(timeseries) <: Union{AbstractArray,ArrayPartition}
@@ -262,13 +264,13 @@ times ts (sorted), with values timeseries and derivatives ks
262264
else
263265
idxs_internal = idxs
264266
end
265-
if !id.dense
267+
if typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
268+
val = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
269+
elseif !id.dense
266270
val = linear_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],idxs_internal,deriv)
267271
elseif typeof(cache) <: CompositeCache
268272
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache.caches[id.alg_choice[notsaveat_idxs[i-1]]]) # update the kcurrent
269273
val = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache.caches[id.alg_choice[notsaveat_idxs[i-1]]],idxs_internal,deriv)
270-
elseif typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
271-
val = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
272274
else
273275
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache) # update the kcurrent
274276
val = ode_interpolant(Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache,idxs_internal,deriv)
@@ -310,13 +312,13 @@ times ts (sorted), with values timeseries and derivatives ks
310312
else
311313
idxs_internal = idxs
312314
end
313-
if !id.dense
315+
if typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
316+
ode_interpolant!(out,Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
317+
elseif !id.dense
314318
linear_interpolant!(out,Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],idxs_internal,deriv)
315319
elseif typeof(cache) <: CompositeCache
316320
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache.caches[id.alg_choice[notsaveat_idxs[i-1]]]) # update the kcurrent
317321
ode_interpolant!(out,Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache.caches[id.alg_choice[notsaveat_idxs[i-1]]],idxs_internal,deriv)
318-
elseif typeof(cache) <: (DiscreteCache) || typeof(cache) <: DiscreteConstantCache
319-
ode_interpolant!(out,Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],0,cache,idxs_internal,deriv)
320322
else
321323
ode_addsteps!(ks[i],ts[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],dt,f,cache) # update the kcurrent
322324
ode_interpolant!(out,Θ,dt,timeseries[notsaveat_idxs[i-1]],timeseries[notsaveat_idxs[i]],ks[i],cache,idxs_internal,deriv)

0 commit comments

Comments
 (0)