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

Refactor integration and QuadraticInterpolation #359

Merged
merged 4 commits into from
Nov 17, 2024

Conversation

SouthEndMusic
Copy link
Member

@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.

Copy link
Member

@sathvikbhagavan sathvikbhagavan left a 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)
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Member

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.

@SouthEndMusic
Copy link
Member Author

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)

@ChrisRackauckas ChrisRackauckas merged commit 96d017d into SciML:master Nov 17, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants