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

type stability: use dims=n, not dims=[n] #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Feb 4, 2025

Fixes the type-instability (but not the allocations) of #103

@stevengj
Copy link
Member Author

stevengj commented Feb 4, 2025

Weird, this fixes the instability when I call mapslices directly, but not via the function:

using Dierckx, Test
import Dierckx: _derivative
spline = ParametricSpline(1:10, rand(2, 10));
x = 5.1; nu = 1; (; t, c, k, bc, wrk) = spline # extract _derivative parameters

# copy of _derivative, with dims=[2] changed to dims=2
my_derivative(t::Vector{Float64}, c::Matrix{Float64}, k::Int, x::Real, nu::Int, bc::Int, wrk::Vector{Float64}) =
    vec(mapslices(v -> _derivative(t, v, k, x, nu, bc, wrk), c, dims=2))

@inferred vec(mapslices(v -> _derivative(t, v, k, x, nu, bc, wrk), c, dims=2)) # succeeds
@inferred my_derivative(spline.t, spline.c, spline.k, x, nu, spline.bc, spline.wrk) # fails

@jakobnissen suggests that @inferred is only checking the vec function in the first case, so mapslices is still unstable.

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