Skip to content

Commit 2262c6c

Browse files
committed
Formatting
1 parent 2203988 commit 2262c6c

File tree

4 files changed

+76
-38
lines changed

4 files changed

+76
-38
lines changed

ext/DataInterpolationsRegularizationToolsExt.jl

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Abstrac
7474
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
7575
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
7676
cache_parameters::Bool = false)
77-
extrapolation_left, extrapolation_right = munge_extrapolation(
77+
extrapolation_left,
78+
extrapolation_right = munge_extrapolation(
7879
extrapolation, extrapolation_left, extrapolation_right)
7980
u, t = munge_data(u, t; check_sorted = t̂, sorted_arg_name = ("third", ""))
8081
M = _mapping_matrix(t̂, t)
8182
Wls½ = LA.diagm(sqrt.(wls))
8283
Wr½ = LA.diagm(sqrt.(wr))
83-
û, λ, Aitp = _reg_smooth_solve(
84+
û, λ,
85+
Aitp = _reg_smooth_solve(
8486
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
8587
extrapolation_right, cache_parameters)
8688
RegularizationSmooth(
@@ -100,15 +102,17 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, d::Int = 2;
100102
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
101103
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
102104
cache_parameters::Bool = false)
103-
extrapolation_left, extrapolation_right = munge_extrapolation(
105+
extrapolation_left,
106+
extrapolation_right = munge_extrapolation(
104107
extrapolation, extrapolation_left, extrapolation_right)
105108
u, t = munge_data(u, t)
106109
= t
107110
N = length(t)
108111
M = Array{Float64}(LA.I, N, N)
109112
Wls½ = Array{Float64}(LA.I, N, N)
110113
Wr½ = Array{Float64}(LA.I, N - d, N - d)
111-
û, λ, Aitp = _reg_smooth_solve(
114+
û, λ,
115+
Aitp = _reg_smooth_solve(
112116
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
113117
extrapolation_right, cache_parameters)
114118
RegularizationSmooth(u,
@@ -137,14 +141,16 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Abstrac
137141
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
138142
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
139143
cache_parameters::Bool = false)
140-
extrapolation_left, extrapolation_right = munge_extrapolation(
144+
extrapolation_left,
145+
extrapolation_right = munge_extrapolation(
141146
extrapolation, extrapolation_left, extrapolation_right)
142147
u, t = munge_data(u, t; check_sorted = t̂, sorted_arg_name = ("third", ""))
143148
N, N̂ = length(t), length(t̂)
144149
M = _mapping_matrix(t̂, t)
145150
Wls½ = Array{Float64}(LA.I, N, N)
146151
Wr½ = Array{Float64}(LA.I, N̂ - d, N̂ - d)
147-
û, λ, Aitp = _reg_smooth_solve(
152+
û, λ,
153+
Aitp = _reg_smooth_solve(
148154
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
149155
extrapolation_right, cache_parameters)
150156
RegularizationSmooth(u,
@@ -174,14 +180,16 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Abstrac
174180
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
175181
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
176182
cache_parameters::Bool = false)
177-
extrapolation_left, extrapolation_right = munge_extrapolation(
183+
extrapolation_left,
184+
extrapolation_right = munge_extrapolation(
178185
extrapolation, extrapolation_left, extrapolation_right)
179186
u, t = munge_data(u, t; check_sorted = t̂, sorted_arg_name = ("third", ""))
180187
N, N̂ = length(t), length(t̂)
181188
M = _mapping_matrix(t̂, t)
182189
Wls½ = LA.diagm(sqrt.(wls))
183190
Wr½ = Array{Float64}(LA.I, N̂ - d, N̂ - d)
184-
û, λ, Aitp = _reg_smooth_solve(
191+
û, λ,
192+
Aitp = _reg_smooth_solve(
185193
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
186194
extrapolation_right, cache_parameters)
187195
RegularizationSmooth(u,
@@ -212,15 +220,17 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing
212220
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
213221
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
214222
cache_parameters::Bool = false)
215-
extrapolation_left, extrapolation_right = munge_extrapolation(
223+
extrapolation_left,
224+
extrapolation_right = munge_extrapolation(
216225
extrapolation, extrapolation_left, extrapolation_right)
217226
u, t = munge_data(u, t)
218227
= t
219228
N = length(t)
220229
M = Array{Float64}(LA.I, N, N)
221230
Wls½ = LA.diagm(sqrt.(wls))
222231
Wr½ = Array{Float64}(LA.I, N - d, N - d)
223-
û, λ, Aitp = _reg_smooth_solve(
232+
û, λ,
233+
Aitp = _reg_smooth_solve(
224234
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
225235
extrapolation_right, cache_parameters)
226236
RegularizationSmooth(u,
@@ -251,15 +261,17 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing
251261
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
252262
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
253263
cache_parameters::Bool = false)
254-
extrapolation_left, extrapolation_right = munge_extrapolation(
264+
extrapolation_left,
265+
extrapolation_right = munge_extrapolation(
255266
extrapolation, extrapolation_left, extrapolation_right)
256267
u, t = munge_data(u, t)
257268
= t
258269
N = length(t)
259270
M = Array{Float64}(LA.I, N, N)
260271
Wls½ = LA.diagm(sqrt.(wls))
261272
Wr½ = LA.diagm(sqrt.(wr))
262-
û, λ, Aitp = _reg_smooth_solve(
273+
û, λ,
274+
Aitp = _reg_smooth_solve(
263275
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
264276
extrapolation_right, cache_parameters)
265277
RegularizationSmooth(u,
@@ -289,7 +301,8 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing
289301
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
290302
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
291303
cache_parameters::Bool = false)
292-
extrapolation_left, extrapolation_right = munge_extrapolation(
304+
extrapolation_left,
305+
extrapolation_right = munge_extrapolation(
293306
extrapolation, extrapolation_left, extrapolation_right)
294307
u, t = munge_data(u, t)
295308
= t
@@ -298,7 +311,8 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing
298311
wls, wr = _weighting_by_kw(t, d, wls)
299312
Wls½ = LA.diagm(sqrt.(wls))
300313
Wr½ = LA.diagm(sqrt.(wr))
301-
û, λ, Aitp = _reg_smooth_solve(
314+
û, λ,
315+
Aitp = _reg_smooth_solve(
302316
u, t̂, d, M, Wls½, Wr½, λ, alg, extrapolation_left,
303317
extrapolation_right, cache_parameters)
304318
RegularizationSmooth(u,

src/interpolation_caches.jl

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ function LinearInterpolation(
5050
u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None,
5151
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
5252
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2)
53-
extrapolation_left, extrapolation_right = munge_extrapolation(
53+
extrapolation_left,
54+
extrapolation_right = munge_extrapolation(
5455
extrapolation, extrapolation_left, extrapolation_right)
5556
u, t = munge_data(u, t)
5657
p = LinearParameterCache(u, t, cache_parameters)
@@ -120,7 +121,8 @@ function QuadraticInterpolation(
120121
u, t, mode; extrapolation::ExtrapolationType.T = ExtrapolationType.None,
121122
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
122123
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2)
123-
extrapolation_left, extrapolation_right = munge_extrapolation(
124+
extrapolation_left,
125+
extrapolation_right = munge_extrapolation(
124126
extrapolation, extrapolation_left, extrapolation_right)
125127
u, t = munge_data(u, t)
126128
linear_lookup = seems_linear(assume_linear_t, t)
@@ -190,7 +192,8 @@ function LagrangeInterpolation(
190192
extrapolation::ExtrapolationType.T = ExtrapolationType.None,
191193
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
192194
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None)
193-
extrapolation_left, extrapolation_right = munge_extrapolation(
195+
extrapolation_left,
196+
extrapolation_right = munge_extrapolation(
194197
extrapolation, extrapolation_left, extrapolation_right)
195198
u, t = munge_data(u, t)
196199
if n != length(t) - 1
@@ -263,7 +266,8 @@ function AkimaInterpolation(
263266
u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None,
264267
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
265268
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2)
266-
extrapolation_left, extrapolation_right = munge_extrapolation(
269+
extrapolation_left,
270+
extrapolation_right = munge_extrapolation(
267271
extrapolation, extrapolation_left, extrapolation_right)
268272
u, t = munge_data(u, t)
269273
linear_lookup = seems_linear(assume_linear_t, t)
@@ -350,7 +354,8 @@ function ConstantInterpolation(
350354
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
351355
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
352356
cache_parameters = false, assume_linear_t = 1e-2)
353-
extrapolation_left, extrapolation_right = munge_extrapolation(
357+
extrapolation_left,
358+
extrapolation_right = munge_extrapolation(
354359
extrapolation, extrapolation_left, extrapolation_right)
355360
u, t = munge_data(u, t)
356361
A = ConstantInterpolation(
@@ -420,7 +425,8 @@ function SmoothedConstantInterpolation(
420425
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
421426
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
422427
cache_parameters = false, assume_linear_t = 1e-2)
423-
extrapolation_left, extrapolation_right = munge_extrapolation(
428+
extrapolation_left,
429+
extrapolation_right = munge_extrapolation(
424430
extrapolation, extrapolation_left, extrapolation_right)
425431
u, t = munge_data(u, t)
426432
p = SmoothedConstantParameterCache(
@@ -502,7 +508,8 @@ function QuadraticSpline(
502508
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
503509
cache_parameters = false, assume_linear_t = 1e-2) where {uType <:
504510
AbstractVector{<:Number}}
505-
extrapolation_left, extrapolation_right = munge_extrapolation(
511+
extrapolation_left,
512+
extrapolation_right = munge_extrapolation(
506513
extrapolation, extrapolation_left, extrapolation_right)
507514
u, t = munge_data(u, t)
508515

@@ -527,7 +534,8 @@ function QuadraticSpline(
527534
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false,
528535
assume_linear_t = 1e-2) where {uType <:
529536
AbstractVector}
530-
extrapolation_left, extrapolation_right = munge_extrapolation(
537+
extrapolation_left,
538+
extrapolation_right = munge_extrapolation(
531539
extrapolation, extrapolation_left, extrapolation_right)
532540
u, t = munge_data(u, t)
533541

@@ -621,7 +629,8 @@ function CubicSpline(u::AbstractVector{<:Number},
621629
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
622630
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false,
623631
assume_linear_t = 1e-2)
624-
extrapolation_left, extrapolation_right = munge_extrapolation(
632+
extrapolation_left,
633+
extrapolation_right = munge_extrapolation(
625634
extrapolation, extrapolation_left, extrapolation_right)
626635
u, t = munge_data(u, t)
627636
n = length(t) - 1
@@ -655,7 +664,8 @@ function CubicSpline(u::AbstractArray{T, N},
655664
extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
656665
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false,
657666
assume_linear_t = 1e-2) where {T, N}
658-
extrapolation_left, extrapolation_right = munge_extrapolation(
667+
extrapolation_left,
668+
extrapolation_right = munge_extrapolation(
659669
extrapolation, extrapolation_left, extrapolation_right)
660670
u, t = munge_data(u, t)
661671
n = length(t) - 1
@@ -693,7 +703,8 @@ function CubicSpline(
693703
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
694704
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false,
695705
assume_linear_t = 1e-2)
696-
extrapolation_left, extrapolation_right = munge_extrapolation(
706+
extrapolation_left,
707+
extrapolation_right = munge_extrapolation(
697708
extrapolation, extrapolation_left, extrapolation_right)
698709
u, t = munge_data(u, t)
699710
n = length(t) - 1
@@ -799,7 +810,8 @@ function BSplineInterpolation(
799810
extrapolation::ExtrapolationType.T = ExtrapolationType.None,
800811
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
801812
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, assume_linear_t = 1e-2)
802-
extrapolation_left, extrapolation_right = munge_extrapolation(
813+
extrapolation_left,
814+
extrapolation_right = munge_extrapolation(
803815
extrapolation, extrapolation_left, extrapolation_right)
804816
u, t = munge_data(u, t)
805817
n = length(t)
@@ -875,7 +887,8 @@ function BSplineInterpolation(
875887
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
876888
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
877889
assume_linear_t = 1e-2)
878-
extrapolation_left, extrapolation_right = munge_extrapolation(
890+
extrapolation_left,
891+
extrapolation_right = munge_extrapolation(
879892
extrapolation, extrapolation_left, extrapolation_right)
880893
u, t = munge_data(u, t)
881894
n = length(t)
@@ -1034,7 +1047,8 @@ function BSplineApprox(
10341047
extrapolation::ExtrapolationType.T = ExtrapolationType.None,
10351048
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
10361049
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, assume_linear_t = 1e-2)
1037-
extrapolation_left, extrapolation_right = munge_extrapolation(
1050+
extrapolation_left,
1051+
extrapolation_right = munge_extrapolation(
10381052
extrapolation, extrapolation_left, extrapolation_right)
10391053
u, t = munge_data(u, t)
10401054
n = length(t)
@@ -1131,7 +1145,8 @@ function BSplineApprox(
11311145
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
11321146
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
11331147
assume_linear_t = 1e-2) where {T, N}
1134-
extrapolation_left, extrapolation_right = munge_extrapolation(
1148+
extrapolation_left,
1149+
extrapolation_right = munge_extrapolation(
11351150
extrapolation, extrapolation_left, extrapolation_right)
11361151
u, t = munge_data(u, t)
11371152
n = length(t)
@@ -1204,8 +1219,9 @@ function BSplineApprox(
12041219
spline_coefficients!(view(sc, i, :), d, k, p[i])
12051220
end
12061221
for k in 2:(n - 1)
1207-
q[ax_u..., k] = u[ax_u..., k] - sc[k, 1] * u[ax_u..., 1] -
1208-
sc[k, h] * u[ax_u..., end]
1222+
q[ax_u...,
1223+
k] = u[ax_u..., k] - sc[k, 1] * u[ax_u..., 1] -
1224+
sc[k, h] * u[ax_u..., end]
12091225
end
12101226
Q = Array{T, N}(undef, size(u)[1:(end - 1)]..., h - 2)
12111227
for i in 2:(h - 1)
@@ -1280,7 +1296,8 @@ function CubicHermiteSpline(
12801296
extrapolation_left::ExtrapolationType.T = ExtrapolationType.None,
12811297
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2)
12821298
@assert length(u)==length(du) "Length of `u` is not equal to length of `du`."
1283-
extrapolation_left, extrapolation_right = munge_extrapolation(
1299+
extrapolation_left,
1300+
extrapolation_right = munge_extrapolation(
12841301
extrapolation, extrapolation_left, extrapolation_right)
12851302
u, t = munge_data(u, t)
12861303
linear_lookup = seems_linear(assume_linear_t, t)
@@ -1385,7 +1402,8 @@ function QuinticHermiteSpline(
13851402
extrapolation_right::ExtrapolationType.T = ExtrapolationType.None,
13861403
cache_parameters = false, assume_linear_t = 1e-2)
13871404
@assert length(u)==length(du)==length(ddu) "Length of `u` is not equal to length of `du` or `ddu`."
1388-
extrapolation_left, extrapolation_right = munge_extrapolation(
1405+
extrapolation_left,
1406+
extrapolation_right = munge_extrapolation(
13891407
extrapolation, extrapolation_left, extrapolation_right)
13901408
u, t = munge_data(u, t)
13911409
linear_lookup = seems_linear(assume_linear_t, t)
@@ -1736,7 +1754,8 @@ function SmoothArcLengthInterpolation(
17361754
t[j + 1] = t[j] + Δt_circle_seg + Δt_line_seg
17371755
end
17381756

1739-
extrapolation_left, extrapolation_right = munge_extrapolation(
1757+
extrapolation_left,
1758+
extrapolation_right = munge_extrapolation(
17401759
extrapolation, extrapolation_left, extrapolation_right)
17411760
linear_lookup = seems_linear(assume_linear_t, t)
17421761

src/interpolation_utils.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ function cumulative_integral(A::AbstractInterpolation{<:Number}, cache_parameter
191191
Base.require_one_based_indexing(A.u)
192192
idxs = cache_parameters ? (1:(length(A.t) - 1)) : (1:0)
193193
return cumsum(_integral(A, idx, t1, t2)
194-
for (idx, t1, t2) in zip(idxs, @view(A.t[begin:(end - 1)]), @view(A.t[(begin + 1):end])))
194+
for (idx, t1, t2) in
195+
zip(idxs, @view(A.t[begin:(end - 1)]), @view(A.t[(begin + 1):end])))
195196
end
196197

197198
function get_parameters(A::LinearInterpolation, idx)
@@ -210,9 +211,11 @@ function get_parameters(A::SmoothedConstantInterpolation, idx)
210211
c_upper = A.p.c[idx + 1]
211212
d_lower, d_upper, c_lower, c_upper
212213
else
213-
d_lower, c_lower = smoothed_constant_interpolation_parameters(
214+
d_lower,
215+
c_lower = smoothed_constant_interpolation_parameters(
214216
A.u, A.t, A.d_max, idx, A.extrapolation_left, A.extrapolation_right)
215-
d_upper, c_upper = smoothed_constant_interpolation_parameters(
217+
d_upper,
218+
c_upper = smoothed_constant_interpolation_parameters(
216219
A.u, A.t, A.d_max, idx + 1, A.extrapolation_left, A.extrapolation_right)
217220
d_lower, d_upper, c_lower, c_upper
218221
end
@@ -410,4 +413,4 @@ function get_transition_ts(A::SmoothedConstantInterpolation)
410413
out
411414
end
412415

413-
get_transition_ts(A::AbstractInterpolation) = A.t
416+
get_transition_ts(A::AbstractInterpolation) = A.t

test/interpolation_tests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ end
10241024
ut1 = Float32[0.1, 0.2, 0.3, 0.4, 0.5]
10251025
ut2 = Float64[0.1, 0.2, 0.3, 0.4, 0.5]
10261026
for u in (ut1, ut2), t in (ut1, ut2)
1027+
10271028
interp = @inferred(LinearInterpolation(ut1, ut2))
10281029
for xs in (u, t)
10291030
ys = @inferred(interp(xs))
@@ -1106,6 +1107,7 @@ f_cubic_spline = c -> square(CubicSpline, c)
11061107
iszero_allocations(u, t) = iszero(@allocated(DataInterpolations.munge_data(u, t)))
11071108

11081109
for T in (String, Union{String, Missing}), dims in 1:3
1110+
11091111
_u0 = convert(Array{T}, reshape(u0, ntuple(i -> i == dims ? 3 : 1, dims)))
11101112

11111113
u, t = @inferred(DataInterpolations.munge_data(_u0, t0))

0 commit comments

Comments
 (0)