Skip to content

Commit

Permalink
zero(::TaylorInterpolant) (#31)
Browse files Browse the repository at this point in the history
* zero(::TaylorInterpolant)

* Minor fix
  • Loading branch information
LuEdRaMo authored Jan 31, 2024
1 parent 17f8f5b commit 56a74ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PlanetaryEphemeris.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using DelimitedFiles
using JLD2
using Quadmath

import Base: convert, reverse, show, join
import Base: convert, reverse, show, join, zero, iszero
import Dates: julian2datetime
import JLD2: writeas

Expand Down
9 changes: 9 additions & 0 deletions src/interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ function TaylorInterpolant(t0::T, t::SubArray{T, 1}, x::SubArray{Taylor1{U}, N})
return TaylorInterpolant{T, U, N}(t0, t, x)
end

# Definition of zero TaylorInterpolant
function zero(::Type{TaylorInterpolant{T, U, N, VT, X}}) where {T <: Number, U <: Number, N, VT <: AbstractVector{T}, X <: AbstractArray{Taylor1{U}, N}}
return TaylorInterpolant(zero(T), zeros(T, 1), Array{Taylor1{U}, N}(undef, zeros(Int, N)...))
end

function iszero(x::TaylorInterpolant{T, U, N, VT, X}) where {T <: Number, U <: Number, N, VT <: AbstractVector{T}, X <: AbstractArray{Taylor1{U}, N}}
return x == zero(TaylorInterpolant{T, U, N, VT, X})
end

# Custom print
function show(io::IO, interp::T) where {U, V, N, T<:TaylorInterpolant{U,V,N}}
t_range = minmax(interp.t0 + interp.t[1], interp.t0 + interp.t[end])
Expand Down
7 changes: 7 additions & 0 deletions test/propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ using LinearAlgebra: norm
end

@testset "TaylorInterpolant" begin
# Test zero TaylorInterpolant
T = Float64
U = TaylorN{T}
@test iszero(zero(TaylorInterpolant{T, T, 2, Vector{T}, Matrix{Taylor1{T}}}))
@test iszero(zero(TaylorInterpolant{T, U, 2, Vector{T}, Matrix{Taylor1{U}}}))
@test iszero(zero(TaylorInterpolant{T, T, 2, SubArray{T, 1}, SubArray{Taylor1{T}, 2}}))
@test iszero(zero(TaylorInterpolant{T, U, 2, SubArray{T, 1}, SubArray{Taylor1{U}, 2}}))
# Test integration
sol = propagate(5, jd0, nyears, dense; dynamics=PlanetaryEphemeris.trivialdynamics!, order, abstol)
@test sol isa TaylorInterpolant{Float64,Float64,2}
Expand Down

0 comments on commit 56a74ff

Please sign in to comment.