Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zero(::TaylorInterpolant) #31

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading