From 35eb4f518b5706d4d07e462c09dbcb15e880cfe2 Mon Sep 17 00:00:00 2001 From: Lorenzo Van Munoz <66997677+lxvm@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:50:44 -0500 Subject: [PATCH] Fix type instability in chebinterp (#19) * initial commit * Update interp.jl * Update src/interp.jl Co-authored-by: Steven G. Johnson --------- Co-authored-by: Steven G. Johnson --- src/interp.jl | 2 +- test/runtests.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/interp.jl b/src/interp.jl index 31c048b..d8c405d 100644 --- a/src/interp.jl +++ b/src/interp.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 6d96b74..8e8187a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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