-
Notifications
You must be signed in to change notification settings - Fork 53
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
Improve Taylor1{TaylorN{T}}
mixtures
#333
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks @lbenet for adding these improvements to the handling of mixtures! Looks like this will really help TaylorIntegration.jl and NEOs.jl. I left a couple of comments about some minor stuff, but otherwise LGTM!
src/arithmetic.jl
Outdated
# function ($f)(a::Taylor1{TaylorN{T}}, b::Taylor1{TaylorN{S}}) where | ||
# {T<:NumberNotSeries, S<:NumberNotSeries} | ||
# R = promote_type(T,S) | ||
# return ($f)(convert(Taylor1{TaylorN{R}}, a), convert(Taylor1{TaylorN{R}}, b)) | ||
# end | ||
|
||
# function ($f)(a::Taylor1{TaylorN{T}}, b::Taylor1{TaylorN{T}}) where | ||
# {T<:NumberNotSeries} | ||
# if (a.order != b.order) || any(get_order.(a[:]) .!= get_order.(b[:])) | ||
# a, b = fixorder(a, b) | ||
# end | ||
# res = Taylor1(zero( constant_term(a)), a.order ) | ||
# for ordT in eachindex(a) | ||
# ($fc)(res, a, b, ordT) | ||
# end | ||
# return res | ||
# end | ||
|
||
# function ($fc)(res::Taylor1{TaylorN{T}}, a::Taylor1{TaylorN{T}}, | ||
# b::Taylor1{TaylorN{T}}, ordT::Int) where {T<:NumberNotSeries} | ||
# # Sanity | ||
# zero!(res, a, ordT) | ||
# @inbounds for ordQ in eachindex(a[ordT]) | ||
# $(fc)(res[ordT], a[ordT], b[ordT], ordQ) | ||
# end | ||
# return nothing | ||
# end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these lines intended to stay commented as they are, or does it make sense for them to be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I wanted to have more specific methods, but something didn't work (ambiguities?). For the time being I'll leave them there, but if they are not needed, I'll remove them.
# v = Array{typeof(aux)}(undef, length(a.coeffs)) | ||
# @__dot__ v = a.coeffs / b | ||
# return $T(v, a.order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these commented lines are meant to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they should be eventually removed. I think I kept them to check performance. I shall keep this conversation open, to remember eventually remove them if not needed.
# R = typeof(aux) | ||
# coeffs = Array{R}(undef, length(b.coeffs)) | ||
# @__dot__ coeffs = b.coeffs / a | ||
# return Taylor1(coeffs, b.order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above
If I remember correctly, I think it was suggested in an offline discussion that it probably makes sense to add specialized evaluate methods for mixtures, is that still the case? |
be646bb
to
0c5c8c0
Compare
Sorry for the long delay to get back to your comments... I have implemented most of your suggestions. About the comments, I think I left them there because I was testing improving performance, but either didn't get better results, or got some sort of ambiguities/errors. I left those conversations unresolved, to come back later to them. |
Many thanks for addressing the comments! I agree that probably there's room left to improve performance, probably we can merge this as a first step and then try to get further performance gains in future PRs. Thus, as it stands now, it's probably worth bumping at least the patch version? |
9e17ecc
to
09e773e
Compare
I've removed some methods of In pass, I also checked if there were invalidations triggered by |
This follows the discussion from PerezHz/PlanetaryEphemeris.jl#30 (comment) The following is the example used, using this branch julia> using TaylorSeries
julia> x = Taylor1.([rand(3) for _ in 1:5, __ in 1:2])
5×2 Matrix{Taylor1{Float64}}:
0.0991832863555554 + 0.6683889089955399 t + 0.7967925292561205 t² + 𝒪(t³) … 0.489775369583631 + 0.1409952219760241 t + 0.7373398449922951 t² + 𝒪(t³)
...
julia> dq = TaylorSeries.set_variables("dq", order=2, numvars=2);
julia> x(3.04 + dq[1])
5×2 Matrix{TaylorN{Float64}}:
9.494723408075362 + 5.512887486872753 dq₁ + 0.7967925292561205 dq₁² + 𝒪(‖x‖³) … 7.732600755871539 + 4.624021479529178 dq₁ + 0.7373398449922951 dq₁² + 𝒪(‖x‖³)
...
julia> @code_warntype x(3.04 + dq[1])
MethodInstance for (::Matrix{Taylor1{Float64}})(::TaylorN{Float64})
from (p::Array{Taylor1{T}})(x) where T<:Number @ TaylorSeries ~/.julia/dev/TaylorSeries/src/evaluate.jl:102
Static Parameters
T = Float64
Arguments
p::Matrix{Taylor1{Float64}}
x::TaylorN{Float64}
Body::Any
1 ─ %1 = Base.broadcasted(TaylorSeries.evaluate, p, x)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}, Nothing, typeof(evaluate), Tuple{Matrix{Taylor1{Float64}}, TaylorN{Float64}}}
│ %2 = Base.materialize(%1)::Any
└── return %2
julia> @which evaluate(x, 3.04 + dq[1])
evaluate(x::AbstractArray{Taylor1{T}}, δt::S) where {T<:Number, S<:Number}
@ TaylorSeries ~/.julia/dev/TaylorSeries/src/evaluate.jl:42 The method quoted uses broadcasting, so I guess that is the problem. |
@PerezHz I think I have solved the issue you reported. I have checked that all the changes do not induce invalidations, and that tests pass in TaylorIntegration. In my opinion this is ready to be merged, except for tagging the new version; I am in favor of bumping a new minor version. Do you see anything that still has to be addressed? |
@lbenet LGTM! I think there's further improvements to be made in the in-place methods like |
Great! So I'll bump the patch version, merge, and then release the new version! |
for Taylor1{TaylorN{T}}
and fix tests
(fixing certain type instability)
94a41e4
to
a4a2e4c
Compare
This PR defines some specialized methods on
Taylor1{TaylorN{T}}
. This specialization is aimed to improve jet transport Taylor integrations.