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

rework gmam #110

Merged
merged 6 commits into from
Nov 22, 2024
Merged

rework gmam #110

merged 6 commits into from
Nov 22, 2024

Conversation

oameye
Copy link
Member

@oameye oameye commented Jul 29, 2024

Making the interpolation in place results in a significant speedup:

using Dierckx, LinearAlgebra
using CriticalTransitions: anorm, fix_ends, geometric_action
using Optim
N = 101
arclength = 1.0
xx = range(-1.0, 1.0; length=N)
yy = 0.3 .* (-xx .^ 2 .+ 1)
init = Matrix([xx yy]')

function interpolate_path(path, N)
    s = zeros(N)
    @inbounds for j in 2:N
        @fastmath s[j] = s[j - 1] + norm(path[:, j] - path[:, j - 1])
    end
    s_length = s / s[end]
    interp = ParametricSpline(s_length, path; k=3)
    return reduce(hcat, [interp(x) for x in range(0, 1.0; length=N)])
end


function interpolate_path!(path, α, s)
    α[2:end] .= vec(sqrt.(sum(diff(path; dims=2) .^ 2; dims=1)))
    α .= cumsum(α; dims=1)
    α .= α ./ α[end]
    interp = ParametricSpline(α, path)
    path .= Matrix(interp(s))
    return nothing
end

using BenchmarkTools
alpha = zeros(N)
arc = range(0, 1.0; length=N)
@benchmark interpolate_path($init, $N)
@benchmark interpolate_path!($init, $alpha, $arc)

image

benchmark/interpolations.jl Outdated Show resolved Hide resolved
examples/gmam_Maierstein.jl Outdated Show resolved Hide resolved
@oameye
Copy link
Member Author

oameye commented Aug 7, 2024

Try out StochasticDiffEq.@muladd

@oameye oameye merged commit c21acf6 into main Nov 22, 2024
6 checks passed
@oameye oameye deleted the arc-lenght-integration branch November 22, 2024 13:31
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.

1 participant