Skip to content

Commit

Permalink
Fix type instability in chebinterp (#19)
Browse files Browse the repository at this point in the history
* initial commit

* Update interp.jl

* Update src/interp.jl

Co-authored-by: Steven G. Johnson <stevenj@mit.edu>

---------

Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
  • Loading branch information
lxvm and stevengj committed Jan 24, 2024
1 parent dc4902b commit 35eb4f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/interp.jl
Expand Up @@ -80,7 +80,7 @@ function droptol(coefs::Array{<:Any,N}, tol::Real) where {N}
newsize = ntuple(Val{N}()) do dim
n = size(coefs, dim)
while n > 1
r = ntuple(i -> i == dim ? (n:n) : (1:size(coefs,i)), Val{N}())
r = let n=n; ntuple(i -> i == dim ? (n:n) : (1:size(coefs,i)), Val{N}()); end
any(c -> infnorm(c) abstol, @view coefs[CartesianIndices(r)]) && break
n -= 1
end
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Expand Up @@ -149,3 +149,8 @@ end
@test interp([0.1,0.22]) 3.2*cos(0.55)
@test chebgradient(interp, [0.1,0.2])[2] == [2*cos(0.55), 0]
end

@testset "inference" begin
@inferred FastChebInterp.droptol(rand(5,5), 0.0)
@inferred chebinterp(rand(5,5), (0,0), (1,1))
end

0 comments on commit 35eb4f5

Please sign in to comment.