Skip to content

Commit

Permalink
Run JuliaFormatter.format()
Browse files Browse the repository at this point in the history
Using JuliaFormatter v1.0.47
  • Loading branch information
LilithHafner committed Feb 14, 2024
1 parent 7661c97 commit 5095877
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
8 changes: 5 additions & 3 deletions ext/DataInterpolationsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ module DataInterpolationsChainRulesCoreExt

if isdefined(Base, :get_extension)
using DataInterpolations: _interpolate, derivative, AbstractInterpolation,
LagrangeInterpolation, AkimaInterpolation, BSplineInterpolation, BSplineApprox
LagrangeInterpolation, AkimaInterpolation,
BSplineInterpolation, BSplineApprox
using ChainRulesCore
else
using ..DataInterpolations: _interpolate, derivative, AbstractInterpolation,
LagrangeInterpolation, AkimaInterpolation, BSplineInterpolation, BSplineApprox
LagrangeInterpolation, AkimaInterpolation,
BSplineInterpolation, BSplineApprox
using ..ChainRulesCore
end

Expand All @@ -15,7 +17,7 @@ function ChainRulesCore.rrule(::typeof(_interpolate),
LagrangeInterpolation,
AkimaInterpolation,
BSplineInterpolation,
BSplineApprox,
BSplineApprox
},
t::Number)
deriv = derivative(A, t)
Expand Down
5 changes: 3 additions & 2 deletions ext/DataInterpolationsOptimExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module DataInterpolationsOptimExt

using DataInterpolations
import DataInterpolations: munge_data,
Curvefit, CurvefitCache, _interpolate, get_show, derivative, ExtrapolationError,
integral, IntegralNotFoundError
Curvefit, CurvefitCache, _interpolate, get_show, derivative,
ExtrapolationError,
integral, IntegralNotFoundError

isdefined(Base, :get_extension) ? (using Optim, ForwardDiff) :
(using ..Optim, ..ForwardDiff)
Expand Down
6 changes: 4 additions & 2 deletions ext/DataInterpolationsRegularizationToolsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module DataInterpolationsRegularizationToolsExt

using DataInterpolations
import DataInterpolations: munge_data,
_interpolate, RegularizationSmooth, get_show, derivative, integral
_interpolate, RegularizationSmooth, get_show, derivative,
integral
using LinearAlgebra

isdefined(Base, :get_extension) ? (import RegularizationTools as RT) :
Expand Down Expand Up @@ -243,7 +244,8 @@ end
# wls::Symbol, d::Int=2; λ::Real=1.0, alg::Symbol=:gcv_svd)

""" Solve for the smoothed dependent variables and create spline interpolator """
function _reg_smooth_solve(u::AbstractVector, t̂::AbstractVector, d::Int, M::AbstractMatrix,
function _reg_smooth_solve(
u::AbstractVector, t̂::AbstractVector, d::Int, M::AbstractMatrix,
Wls½::AbstractMatrix, Wr½::AbstractMatrix, λ::Real, alg::Symbol, extrapolate::Bool)
λ = float(λ) # `float` expected by RT
D = _derivative_matrix(t̂, d)
Expand Down
7 changes: 3 additions & 4 deletions src/DataInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function Base.showerror(io::IO, e::IntegralNotFoundError)
end

export LinearInterpolation, QuadraticInterpolation, LagrangeInterpolation,
AkimaInterpolation, ConstantInterpolation, QuadraticSpline, CubicSpline,
BSplineInterpolation, BSplineApprox
AkimaInterpolation, ConstantInterpolation, QuadraticSpline, CubicSpline,
BSplineInterpolation, BSplineApprox

# added for RegularizationSmooth, JJS 11/27/21
### Regularization data smoothing and interpolation
Expand Down Expand Up @@ -106,7 +106,7 @@ struct CurvefitCache{
algType,
pminType,
FT,
T,
T
} <: AbstractInterpolation{FT, T}
u::uType
t::tType
Expand Down Expand Up @@ -139,7 +139,6 @@ end

export Curvefit


# Deprecated April 2020
export ZeroSpline

Expand Down
15 changes: 9 additions & 6 deletions src/interpolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ function QuadraticSpline(u::uType, t; extrapolate = false) where {uType <: Abstr
d_tmp = ones(eltype(t), s)
du = zeros(eltype(t), s - 1)
tA = Tridiagonal(dl, d_tmp, du)
d_ = map(i -> i == 1 ? zeros(eltype(t), size(u[1])) :
2 // 1 * (u[i] - u[i - 1]) / (t[i] - t[i - 1]),
d_ = map(
i -> i == 1 ? zeros(eltype(t), size(u[1])) :
2 // 1 * (u[i] - u[i - 1]) / (t[i] - t[i - 1]),
1:s)
d = transpose(reshape(reduce(hcat, d_), :, s))
z_ = reshape(transpose(tA \ d), size(u[1])..., :)
Expand Down Expand Up @@ -213,8 +214,9 @@ function CubicSpline(u::uType,
typed_zero = zero(6(u[begin + 2] - u[begin + 1]) / h[begin + 2] -
6(u[begin + 1] - u[begin]) / h[begin + 1])

d = map(i -> i == 1 || i == n + 1 ? typed_zero :
6(u[i + 1] - u[i]) / h[i + 1] - 6(u[i] - u[i - 1]) / h[i],
d = map(
i -> i == 1 || i == n + 1 ? typed_zero :
6(u[i + 1] - u[i]) / h[i + 1] - 6(u[i] - u[i - 1]) / h[i],
1:(n + 1))
z = tA \ d
CubicSpline{true}(u, t, h[1:(n + 1)], z, extrapolate)
Expand All @@ -228,8 +230,9 @@ function CubicSpline(u::uType, t; extrapolate = false) where {uType <: AbstractV
d_tmp = 2 .* (h[1:(n + 1)] .+ h[2:(n + 2)])
du = h[2:(n + 1)]
tA = Tridiagonal(dl, d_tmp, du)
d_ = map(i -> i == 1 || i == n + 1 ? zeros(eltype(t), size(u[1])) :
6(u[i + 1] - u[i]) / h[i + 1] - 6(u[i] - u[i - 1]) / h[i],
d_ = map(
i -> i == 1 || i == n + 1 ? zeros(eltype(t), size(u[1])) :
6(u[i + 1] - u[i]) / h[i + 1] - 6(u[i] - u[i - 1]) / h[i],
1:(n + 1))
d = transpose(reshape(reduce(hcat, d_), :, n + 1))
z_ = reshape(transpose(tA \ d), size(u[1])..., :)
Expand Down
10 changes: 6 additions & 4 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ function munge_data(u::AbstractVector, t::AbstractVector)
Tu = Base.nonmissingtype(eltype(u))
Tt = Base.nonmissingtype(eltype(t))
@assert length(t) == length(u)
non_missing_indices = collect(i for i in 1:length(t)
if !ismissing(u[i]) && !ismissing(t[i]))
non_missing_indices = collect(i
for i in 1:length(t)
if !ismissing(u[i]) && !ismissing(t[i]))
newu = Tu.([u[i] for i in non_missing_indices])
newt = Tt.([t[i] for i in non_missing_indices])

Expand All @@ -53,8 +54,9 @@ function munge_data(U::StridedMatrix, t::AbstractVector)
TU = Base.nonmissingtype(eltype(U))
Tt = Base.nonmissingtype(eltype(t))
@assert length(t) == size(U, 2)
non_missing_indices = collect(i for i in 1:length(t)
if !any(ismissing, U[:, i]) && !ismissing(t[i]))
non_missing_indices = collect(i
for i in 1:length(t)
if !any(ismissing, U[:, i]) && !ismissing(t[i]))
newUs = [TU.(U[:, i]) for i in non_missing_indices]
newt = Tt.([t[i] for i in non_missing_indices])

Expand Down
4 changes: 2 additions & 2 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ end

@testset "Matrix case" for u in [
[1.0 2.0 0.0 1.0; 1.0 2.0 0.0 1.0],
["B" "C" "A" "B"; "B" "C" "A" "B"],
["B" "C" "A" "B"; "B" "C" "A" "B"]
]
A = ConstantInterpolation(u, t, dir = :right; extrapolate = true)
@test A(0.5) == u[:, 1]
Expand Down Expand Up @@ -609,7 +609,7 @@ end
0.9836755196317837,
0.8833959853995836,
0.3810348276782708,
0.048062978598861855,
0.048062978598861855
]
us = A.(ts)
@test vs us
Expand Down
10 changes: 5 additions & 5 deletions test/regularization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tolerance = 1e-3
0.1392761732695201,
-0.3312498167413961,
-0.6673268474631847,
-0.9370342562716745,
-0.9370342562716745
]
@test isapprox(A.û, ans, rtol = tolerance)
@test isapprox(A.(tₒ), ans, rtol = tolerance)
Expand All @@ -81,7 +81,7 @@ end
0.05281575111822609,
-0.5333542714497277,
-0.8406745098604134,
-1.0983391396173634,
-1.0983391396173634
]
@test isapprox(A.û, ans, rtol = tolerance)
@test isapprox(A.(tₒ), ans, rtol = tolerance)
Expand All @@ -102,7 +102,7 @@ end
0.09102085384961625,
-0.5640882848240228,
-0.810519277110118,
-1.1159124134900906,
-1.1159124134900906
]
@test isapprox(A.û, ans, rtol = tolerance)
@test isapprox(A.(tₒ), ans, rtol = tolerance)
Expand All @@ -126,7 +126,7 @@ end
0.04756024028728636,
-0.5301034620974782,
-0.8408107101140526,
-1.1058428573417736,
-1.1058428573417736
]
@test isapprox(A.û, ans, rtol = tolerance)
@test isapprox(A.(tₒ), ans, rtol = tolerance)
Expand Down Expand Up @@ -173,7 +173,7 @@ end
-0.676806367664006,
-0.8587832527770329,
-1.0443430843364814,
-1.2309001260104093,
-1.2309001260104093
]
@test isapprox(A.û, ans, rtol = tolerance)
@test isapprox(A.(t̂), ans, rtol = tolerance)
Expand Down
2 changes: 1 addition & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ x = [1.0, 2.0, 3.0, 4.0, 5.0]
LinearInterpolation(x, t),
AkimaInterpolation(x, t),
QuadraticSpline(x, t),
CubicSpline(x, t),
CubicSpline(x, t)
]
test_show_line.(methods)
end
Expand Down

0 comments on commit 5095877

Please sign in to comment.