From e32497828c23bbfe1e43b89be3dc9d7447590379 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Wed, 31 Jan 2024 17:02:20 +0530 Subject: [PATCH 1/2] Mildly improve type-stability in chebyshev_clenshaw --- src/LinearAlgebra/clenshaw.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LinearAlgebra/clenshaw.jl b/src/LinearAlgebra/clenshaw.jl index 1d1d9d30..3fd633ca 100644 --- a/src/LinearAlgebra/clenshaw.jl +++ b/src/LinearAlgebra/clenshaw.jl @@ -224,13 +224,13 @@ function chebyshev_clenshaw(c::AbstractVector, x) return first(c) * oneunit(float(x)) end - x = 2x + y = 2x bk1,bk2 = zero(T),zero(T) @inbounds for k = N:-1:2 - bk2, bk1 = bk1, muladd(x,bk1,c[k]-bk2) + bk2, bk1 = bk1, muladd(y,bk1,c[k]-bk2) end - muladd(x/2,bk1,c[1]-bk2) + muladd(x,bk1,c[1]-bk2) end From 5c23593dd730a95a8f323587a2d544da16633168 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 2 Feb 2024 00:45:21 +0530 Subject: [PATCH 2/2] Fix return type --- src/LinearAlgebra/clenshaw.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LinearAlgebra/clenshaw.jl b/src/LinearAlgebra/clenshaw.jl index 3fd633ca..9081c55a 100644 --- a/src/LinearAlgebra/clenshaw.jl +++ b/src/LinearAlgebra/clenshaw.jl @@ -217,9 +217,9 @@ sineshaw(c::AbstractVector,θ::AbstractMatrix) = promote_type(eltype(c),eltype( function chebyshev_clenshaw(c::AbstractVector, x) - N,T = length(c),promote_type(eltype(c),typeof(x)) + N,T = length(c),promote_type(eltype(c),float(typeof(x))) if N == 0 - return zero(float(x) * oneunit(eltype(c))) + return zero(T) elseif N == 1 # avoid issues with NaN x return first(c) * oneunit(float(x)) end