-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
online.jl
89 lines (82 loc) · 2.36 KB
/
online.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import Base: append!, push!
function add_integral_values!(A)
integral_values = cumsum([_integral(A, idx, A.t[idx + 1]) - _integral(A, idx, A.t[idx])
for idx in (length(A.I) - 1):(length(A.t) - 1)])
pop!(A.I)
integral_values .+= last(A.I)
append!(A.I, integral_values)
end
function push!(A::LinearInterpolation{U, T}, u::eltype(U), t::eltype(T)) where {U, T}
push!(A.u, u)
push!(A.t, t)
if A.cache_parameters
slope = linear_interpolation_parameters(A.u, A.t, length(A.t) - 1)
push!(A.p.slope, slope)
add_integral_values!(A)
end
A
end
function push!(A::QuadraticInterpolation{U, T}, u::eltype(U), t::eltype(T)) where {U, T}
push!(A.u, u)
push!(A.t, t)
if A.cache_parameters
l₀, l₁, l₂ = quadratic_interpolation_parameters(A.u, A.t, length(A.t) - 2)
push!(A.p.l₀, l₀)
push!(A.p.l₁, l₁)
push!(A.p.l₂, l₂)
add_integral_values!(A)
end
A
end
function push!(A::ConstantInterpolation{U, T}, u::eltype(U), t::eltype(T)) where {U, T}
push!(A.u, u)
push!(A.t, t)
if A.cache_parameters
add_integral_values!(A)
end
A
end
function append!(
A::LinearInterpolation{U, T}, u::U, t::T) where {
U, T}
length_old = length(A.t)
u, t = munge_data(u, t)
append!(A.u, u)
append!(A.t, t)
if A.cache_parameters
slope = linear_interpolation_parameters.(
Ref(A.u), Ref(A.t), length_old:(length(A.t) - 1))
append!(A.p.slope, slope)
add_integral_values!(A)
end
A
end
function append!(
A::ConstantInterpolation{U, T}, u::U, t::T) where {
U, T}
u, t = munge_data(u, t)
append!(A.u, u)
append!(A.t, t)
if A.cache_parameters
add_integral_values!(A)
end
A
end
function append!(
A::QuadraticInterpolation{U, T}, u::U, t::T) where {
U, T}
length_old = length(A.t)
u, t = munge_data(u, t)
append!(A.u, u)
append!(A.t, t)
if A.cache_parameters
parameters = quadratic_interpolation_parameters.(
Ref(A.u), Ref(A.t), (length_old - 1):(length(A.t) - 2))
l₀, l₁, l₂ = collect.(eachrow(hcat(collect.(parameters)...)))
append!(A.p.l₀, l₀)
append!(A.p.l₁, l₁)
append!(A.p.l₂, l₂)
add_integral_values!(A)
end
A
end