From 2b9266217549eae3735757cf21618295b1276627 Mon Sep 17 00:00:00 2001 From: Ashutosh Bharambe Date: Mon, 7 Oct 2024 08:41:07 +0000 Subject: [PATCH] chore(DataInterpolations): fix formatting --- src/interpolation_caches.jl | 17 ++++++++--------- src/parameter_caches.jl | 2 +- test/interpolation_tests.jl | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/interpolation_caches.jl b/src/interpolation_caches.jl index 4059604a..0baa65ad 100644 --- a/src/interpolation_caches.jl +++ b/src/interpolation_caches.jl @@ -461,10 +461,10 @@ function CubicSpline(u::uType, end function CubicSpline(u::uType, - t; - extrapolate = false, cache_parameters = false, - assume_linear_t = 1e-2) where {uType <: - AbstractMatrix} + t; + extrapolate = false, cache_parameters = false, + assume_linear_t = 1e-2) where {uType <: + AbstractMatrix} 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) @@ -474,12 +474,13 @@ function CubicSpline(u::uType, tA = Tridiagonal(dl, d_tmp, du) # zero for element type of d, which we don't know yet - ax = axes(u)[1:end-1] + ax = axes(u)[1:(end - 1)] typed_zero = zero(6(u[ax..., begin + 2] - u[ax..., begin + 1]) / h[begin + 2] - - 6(u[ax..., begin + 1] - u[ax..., begin]) / h[begin + 1]) + 6(u[ax..., begin + 1] - u[ax..., begin]) / h[begin + 1]) h_ = reshape(h, 1, :) - d = 6*((u[ax..., 3:n+1] - u[ax..., 2:n]) ./ h_[:, 3:n+1]) - 6*((u[ax..., 2:n] - u[ax..., 1:n-1]) ./ h_[:, 2:n]) + d = 6 * ((u[ax..., 3:(n + 1)] - u[ax..., 2:n]) ./ h_[:, 3:(n + 1)]) - + 6 * ((u[ax..., 2:n] - u[ax..., 1:(n - 1)]) ./ h_[:, 2:n]) d = cat(typed_zero, d, typed_zero; dims = ndims(d)) z = (tA \ d')' @@ -517,8 +518,6 @@ function CubicSpline( CubicSpline(u, t, I, p, h[1:(n + 1)], z, extrapolate, cache_parameters, assume_linear_t) end - - """ BSplineInterpolation(u, t, d, pVecType, knotVecType; extrapolate = false, safetycopy = true) diff --git a/src/parameter_caches.jl b/src/parameter_caches.jl index 6f3826ef..09362e58 100644 --- a/src/parameter_caches.jl +++ b/src/parameter_caches.jl @@ -120,7 +120,7 @@ function cubic_spline_parameters(u::AbstractVector, h, z, idx) end function cubic_spline_parameters(u::AbstractArray, h, z, idx) - ax = axes(u)[1:end-1] + ax = axes(u)[1:(end - 1)] c₁ = (u[ax..., idx + 1] / h[idx + 1] - z[ax..., idx + 1] * h[idx + 1] / 6) c₂ = (u[ax..., idx] / h[idx + 1] - z[ax..., idx] * h[idx + 1] / 6) return c₁, c₂ diff --git a/test/interpolation_tests.jl b/test/interpolation_tests.jl index 97e2a8d4..861f0aa7 100644 --- a/test/interpolation_tests.jl +++ b/test/interpolation_tests.jl @@ -600,11 +600,11 @@ end @test_throws DataInterpolations.ExtrapolationError A(-2.0) @test_throws DataInterpolations.ExtrapolationError A(2.0) - @testset "AbstractMatrix" begin - t = 0.1:0.1:1.0 + @testset "AbstractMatrix" begin + t = 0.1:0.1:1.0 u = [sin.(t) cos.(t)]' |> collect c = CubicSpline(u, t) - t_test = 0.1:0.05:1.0 + t_test = 0.1:0.05:1.0 u_test = reduce(hcat, c.(t_test)) @test isapprox(u_test[1, :], sin.(t_test), atol = 1e-3) @test isapprox(u_test[2, :], cos.(t_test), atol = 1e-3)