Skip to content

Commit b91b8cd

Browse files
improved dense search
1 parent 636a72d commit b91b8cd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/dense.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ times ts (sorted), with values timeseries and derivatives ks
9393
end
9494
@inbounds for j in idx
9595
t = tvals[j]
96-
i = findfirst((x)->tdir*x>=tdir*t,@view ts[i:end])+i-1 # It's in the interval ts[i-1] to ts[i]
96+
i = searchsortedfirst(@view(ts[i:end]),t,rev=tdir<0)+i-1 # It's in the interval ts[i-1] to ts[i]
9797
if ts[i] == t
9898
if idxs == nothing
9999
vals[j] = timeseries[i]
@@ -129,7 +129,7 @@ times ts (sorted), with values timeseries and derivatives ks
129129
@inline function sde_interpolation(tval::Number,id,idxs,deriv)
130130
@unpack ts,timeseries = id
131131
tdir = sign(ts[end]-ts[1])
132-
i = findfirst((x)->tdir*x>=tdir*tval,ts) # It's in the interval ts[i-1] to ts[i]
132+
@inbounds i = searchsortedfirst(ts,tval,rev=tdir<0) # It's in the interval ts[i-1] to ts[i]
133133
@inbounds if ts[i] == tval
134134
if idxs == nothing
135135
val = timeseries[i]
@@ -158,7 +158,7 @@ end
158158
@inline function sde_interpolation!(out,tval::Number,id,idxs,deriv)
159159
@unpack ts,timeseries = id
160160
tdir = sign(ts[end]-ts[1])
161-
@inbounds i = findfirst((x)->tdir*x>=tdir*tval,@view ts[notsaveat_idxs]) # It's in the interval ts[i-1] to ts[i]
161+
@inbounds i = searchsortedfirst(ts,tval,rev=tdir<0) # It's in the interval ts[i-1] to ts[i]
162162
@inbounds if ts[i] == tval
163163
if idxs == nothing
164164
copy!(out,timeseries[i])
@@ -190,7 +190,7 @@ end
190190
i = 2 # Start the search thinking it's between ts[1] and ts[2]
191191
@inbounds for j in idx
192192
t = tvals[j]
193-
i = findfirst((x)->tdir*x>=tdir*t,ts[i:end])+i-1 # It's in the interval ts[i-1] to ts[i]
193+
i = searchsortedfirst(@view(ts[i:end]),t,rev=tdir<0)+i-1 # It's in the interval ts[i-1] to ts[i]
194194
if ts[i] == t
195195
if idxs == nothing
196196
vals[j] = timeseries[i]

0 commit comments

Comments
 (0)