-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Refactor integration and QuadraticInterpolation
#359
Refactor integration and QuadraticInterpolation
#359
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.
Left one comment. Are we getting any speedup from this implementation of QuadraticInterpolation than the earlier version? Otherwise, Looks good!
@@ -74,6 +74,11 @@ function u_tangent(A::LinearInterpolation, t, Δ) | |||
out | |||
end | |||
|
|||
function _quad_interp_indices(A::QuadraticInterpolation, t::Number, iguess) |
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.
Just to confirm, can't u_tangent
for QuadraticInterpolation be reformulated using α
and β
parameters you added?
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'ts possible, but I suspect this is more efficient. Also, that might break AD types that do not support mutation when those parameters are cached?
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.
And you still need to have the logic somewhere to see which mode (forward/backward looking interpolation) was used for the u
gradient.
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.
Alright, then we can keep this.
using DataInterpolations
using Random
using BenchmarkTools
Random.seed!(2)
t = cumsum(rand(5))
t_eval = range(first(t), last(t), length = 100)
### No cached parameters
## Scalar u
u = rand(5)
A = QuadraticInterpolation(u, t)
@btime A.($t_eval)
# Before:
# 1.110 μs (4 allocations: 1.12 KiB)
# After:
# 1.090 μs (4 allocations: 1.11 KiB)
## Vector u
u = rand(2, 5)
A = QuadraticInterpolation(u, t)
@btime A.($t_eval)
# Before:
# 19.100 μs (2804 allocations: 110.50 KiB)
# After:
# 17.200 μs (2204 allocations: 87.05 KiB)
### Cached parameters
## Scalar u
u = rand(5)
A = QuadraticInterpolation(u, t; cache_parameters = true)
@btime A.($t_eval)
# Before:
# 1.030 μs (4 allocations: 1.12 KiB)
# After:
# 976.471 ns (4 allocations: 1.11 KiB)
## Vector u
u = rand(2, 5)
A = QuadraticInterpolation(u, t; cache_parameters = true)
@btime A.($t_eval)
# Before:
# 10.600 μs (1404 allocations: 55.81 KiB)
# After:
# 4.829 μs (604 allocations: 24.55 KiB) |
@sathvikbhagavan I split this out from #356 for ease of reviewing. I need the
QuadraticInteprolation
refactor for the integration refactor, and the integration refactor for #356.