Skip to content

Commit

Permalink
more generic custom searchsortedfirst
Browse files Browse the repository at this point in the history
  • Loading branch information
longemen3000 committed Feb 22, 2024
1 parent b518ed2 commit 16c77dd
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ struct ChebyshevRange{R,T}
coeffs::T
end

function searchsortedfirst(xx::Tuple,x)
for (i,xi) in pairs(xx)
if xi >= x
return i
end
end
return length(xx)
end

searchsortedfirst(xx,x) = Base.searchsortedfirst(xx,x)
#overload of searchsortedfirst to also match the first element.
searchsortedfirst(xx::Tuple,x) = searchsortedfirst(SVector(xx),x)
searchsortedfirst(xx,x) = Base.searchsortedfirst(xx,x) + isequal(x,first(xx))

#evaluation of ranges of chebyshev coefficients
function cheb_eval(Base.@specialize(cheb), Base.@specialize(x̃))
Expand All @@ -38,20 +31,12 @@ function cheb_eval(Base.@specialize(cheb), Base.@specialize(x̃))
return cheb_eval(Cₙi,x̄)
end

function cheb_xrange(x̃range,x̃,reverse = false)
if !reverse
function cheb_xrange(x̃range,x̃)
imax = searchsortedfirst(x̃range, x̃)
imin = imax - 1
x̃minᵢ = x̃range[imin]
x̃maxᵢ = x̃range[imax]
i = imin
else
imax = searchsortedfirst(x̃range, x̃)
imin = imax - 1
x̃minᵢ = x̃range[imin]
x̃maxᵢ = x̃range[imax]
i = imin
end
= (2*- (x̃maxᵢ + x̃minᵢ)) / (x̃maxᵢ - x̃minᵢ)
return x̄,i
end
Expand Down

0 comments on commit 16c77dd

Please sign in to comment.