From 56a74ff4523704a7bd849d7acdbe196ea9fbb473 Mon Sep 17 00:00:00 2001 From: LuEdRaMo <73906617+LuEdRaMo@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:06:00 -0600 Subject: [PATCH] `zero(::TaylorInterpolant)` (#31) * zero(::TaylorInterpolant) * Minor fix --- src/PlanetaryEphemeris.jl | 2 +- src/interpolation.jl | 9 +++++++++ test/propagation.jl | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/PlanetaryEphemeris.jl b/src/PlanetaryEphemeris.jl index b2700d2..5f82e79 100644 --- a/src/PlanetaryEphemeris.jl +++ b/src/PlanetaryEphemeris.jl @@ -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 diff --git a/src/interpolation.jl b/src/interpolation.jl index eca7587..6ea87e5 100644 --- a/src/interpolation.jl +++ b/src/interpolation.jl @@ -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]) diff --git a/test/propagation.jl b/test/propagation.jl index 948c838..2cad9cd 100644 --- a/test/propagation.jl +++ b/test/propagation.jl @@ -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}