Skip to content

Commit

Permalink
chore: format files
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Nov 6, 2023
1 parent e8df1bc commit 4af8138
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 82 deletions.
16 changes: 8 additions & 8 deletions ext/DataInterpolationsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ else
end

function ChainRulesCore.rrule(::typeof(_interpolate),
A::Union{
LagrangeInterpolation,
AkimaInterpolation,
BSplineInterpolation,
BSplineApprox,
},
t::Number)
A::Union{
LagrangeInterpolation,
AkimaInterpolation,
BSplineInterpolation,
BSplineApprox,
},
t::Number)
deriv = derivative(A, t)
interpolate_pullback(Δ) = (NoTangent(), NoTangent(), deriv * Δ)
return _interpolate(A, t), interpolate_pullback
end

function ChainRulesCore.frule((_, _, Δt), ::typeof(_interpolate), A::AbstractInterpolation,
t::Number)
t::Number)
return _interpolate(A, t), derivative(A, t) * Δt
end

Expand Down
4 changes: 2 additions & 2 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function derivative(A::LagrangeInterpolation{<:AbstractVector}, t::Number)
tmp += k
end
end
der += A.u[j]*tmp
der += A.u[j] * tmp
end
der
end
Expand Down Expand Up @@ -98,7 +98,7 @@ function derivative(A::LagrangeInterpolation{<:AbstractMatrix}, t::Number)
tmp += k
end
end
@. der += A.u[:, j]*tmp
@. der += A.u[:, j] * tmp
end
der
end
Expand Down
8 changes: 4 additions & 4 deletions src/integrals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ end

samples(A::LinearInterpolation{<:AbstractVector}) = (0, 1)
function _integral(A::LinearInterpolation{<:AbstractVector{<:Number}},
idx::Number,
t::Number)
idx::Number,
t::Number)
t1 = A.t[idx]
t2 = A.t[idx + 1]
u1 = A.u[idx]
Expand All @@ -46,8 +46,8 @@ end

samples(A::QuadraticInterpolation{<:AbstractVector}) = (0, 1)
function _integral(A::QuadraticInterpolation{<:AbstractVector{<:Number}},
idx::Number,
t::Number)
idx::Number,
t::Number)
A.mode == :Backward && idx > 1 && (idx -= 1)
idx = min(length(A.t) - 2, idx)
t1 = A.t[idx]
Expand Down
42 changes: 21 additions & 21 deletions src/interpolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ struct QuadraticSpline{uType, tType, tAType, dType, zType, FT, T} <:
end

function QuadraticSpline(u::uType,
t;
extrapolate = false) where {uType <: AbstractVector{<:Number}}
t;
extrapolate = false) where {uType <: AbstractVector{<:Number}}
u, t = munge_data(u, t)
s = length(t)
dl = ones(eltype(t), s - 1)
Expand Down Expand Up @@ -199,8 +199,8 @@ struct CubicSpline{uType, tType, hType, zType, FT, T} <: AbstractInterpolation{F
end

function CubicSpline(u::uType,
t;
extrapolate = false) where {uType <: AbstractVector{<:Number}}
t;
extrapolate = false) where {uType <: AbstractVector{<:Number}}
u, t = munge_data(u, t)
n = length(t) - 1
h = vcat(0, map(k -> t[k + 1] - t[k], 1:(length(t) - 1)), 0)
Expand Down Expand Up @@ -250,14 +250,14 @@ struct BSplineInterpolation{uType, tType, pType, kType, cType, FT, T} <:
knotVecType::Symbol
extrapolate::Bool
function BSplineInterpolation{FT}(u,
t,
d,
p,
k,
c,
pVecType,
knotVecType,
extrapolate) where {FT}
t,
d,
p,
k,
c,
pVecType,
knotVecType,
extrapolate) where {FT}
new{typeof(u), typeof(t), typeof(p), typeof(k), typeof(c), FT, eltype(u)}(u,
t,
d,
Expand Down Expand Up @@ -348,15 +348,15 @@ struct BSplineApprox{uType, tType, pType, kType, cType, FT, T} <:
knotVecType::Symbol
extrapolate::Bool
function BSplineApprox{FT}(u,
t,
d,
h,
p,
k,
c,
pVecType,
knotVecType,
extrapolate) where {FT}
t,
d,
h,
p,
k,
c,
pVecType,
knotVecType,
extrapolate) where {FT}
new{typeof(u), typeof(t), typeof(p), typeof(k), typeof(c), FT, eltype(u)}(u,
t,
d,
Expand Down
4 changes: 2 additions & 2 deletions src/interpolation_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ end

# BSpline Curve Interpolation
function _interpolate(A::BSplineInterpolation{<:AbstractVector{<:Number}},
t::Number,
iguess)
t::Number,
iguess)
t < A.t[1] && return A.u[1], 1
t > A.t[end] && return A.u[end], lastindex(t)
# change t into param [0 1]
Expand Down
6 changes: 3 additions & 3 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ this function would be the index returned by the previous call to `searchsorted`
See [`sort!`](@ref) for an explanation of the keyword arguments `by`, `lt` and `rev`.
"""
function bracketstrictlymontonic(v::AbstractVector,
x,
guess::T,
o::Base.Order.Ordering)::NTuple{2, keytype(v)} where {T <: Integer}
x,
guess::T,
o::Base.Order.Ordering)::NTuple{2, keytype(v)} where {T <: Integer}
bottom = firstindex(v)
top = lastindex(v)
if guess < bottom || guess > top
Expand Down
84 changes: 42 additions & 42 deletions src/plot_rec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ end
########################################

@recipe function f(::Type{Val{:linear_interp}},
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
seriestype := :path

label --> "Linear fit"
Expand All @@ -54,11 +54,11 @@ end
########################################

@recipe function f(::Type{Val{:quadratic_interp}},
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
seriestype := :path

label --> "Quadratic fit"
Expand All @@ -76,11 +76,11 @@ end
########################################

@recipe function f(::Type{Val{:quadratic_spline}},
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
seriestype := :path

label --> "Quadratic Spline"
Expand All @@ -101,10 +101,10 @@ end
########################################

@recipe function f(::Type{Val{:lagrange_interp}},
x, y, z;
n = length(x) - 1,
plotdensity = 10_000,
denseplot = true)
x, y, z;
n = length(x) - 1,
plotdensity = 10_000,
denseplot = true)
seriestype := :path

label --> "Lagrange Fit"
Expand All @@ -126,11 +126,11 @@ end
########################################

@recipe function f(::Type{Val{:cubic_spline}},
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
x,
y,
z;
plotdensity = 10_000,
denseplot = true)
seriestype := :path

label --> "Cubic Spline"
Expand All @@ -146,12 +146,12 @@ end
end

@recipe function f(::Type{Val{:bspline_interp}},
x, y, z;
d = 5,
pVec = :ArcLen,
knotVec = :Average,
plotdensity = length(x) * 6,
denseplot = true)
x, y, z;
d = 5,
pVec = :ArcLen,
knotVec = :Average,
plotdensity = length(x) * 6,
denseplot = true)
seriestype := :path

label --> "B-Spline"
Expand All @@ -176,13 +176,13 @@ end
########################################

@recipe function f(::Type{Val{:bspline_approx}},
x, y, z;
d = 5,
h = length(x) - 1,
pVec = :ArcLen,
knotVec = :Average,
plotdensity = length(x) * 6,
denseplot = true)
x, y, z;
d = 5,
h = length(x) - 1,
pVec = :ArcLen,
knotVec = :Average,
plotdensity = length(x) * 6,
denseplot = true)
seriestype := :path

label --> "B-Spline"
Expand All @@ -206,11 +206,11 @@ end
########################################

@recipe function f(::Type{Val{:akima}},
x,
y,
z;
plotdensity = length(x) * 6,
denseplot = true)
x,
y,
z;
plotdensity = length(x) * 6,
denseplot = true)
seriestype := :path

label --> "Akima"
Expand Down

0 comments on commit 4af8138

Please sign in to comment.