Skip to content

Commit 35e00db

Browse files
Merge pull request #32 from ChrisRackauckas/fix-formatting
Apply JuliaFormatter to fix code formatting
2 parents 8ae86b5 + 3b83697 commit 35e00db

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

.JuliaFormatter.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
style = "sciml"
2+
format_markdown = true
3+
format_docstrings = true

docs/make.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ makedocs(
1313
linkcheck = true,
1414
format = Documenter.HTML(
1515
assets = ["assets/favicon.ico"],
16-
canonical = "https://docs.sciml.ai/FindFirstFunctions/stable/",
16+
canonical = "https://docs.sciml.ai/FindFirstFunctions/stable/"
1717
),
18-
pages = ["index.md"],
18+
pages = ["index.md"]
1919
)
2020

2121
deploydocs(repo = "github.com/SciML/FindFirstFunctions.jl"; push_preview = true)

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FindFirstFunctions.findfirstsortedequal
3131

3232
- See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions.
3333
- There are a few community forums:
34-
34+
3535
+ The #diffeq-bridged and #sciml-bridged channels in the
3636
[Julia Slack](https://julialang.org/slack/)
3737
+ The #diffeq-bridged and #sciml-bridged channels in the

src/FindFirstFunctions.jl

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ function _findfirstequal(vpivot::Int64, ptr::Ptr{Int64}, len::Int64)
6363
}
6464
attributes #0 = { alwaysinline }
6565
""",
66-
"entry",
66+
"entry"
6767
),
6868
Int64,
69-
Tuple{Int64,Ptr{Int64},Int64},
69+
Tuple{Int64, Ptr{Int64}, Int64},
7070
vpivot,
7171
ptr,
72-
len,
72+
len
7373
)
7474
end
7575

@@ -87,14 +87,14 @@ function findfirstequal(vpivot::Int64, ivars::DenseVector{Int64})
8787
end
8888

8989
"""
90-
findfirstsortedequal(vars::DenseVector{Int64}, var::Int64)::Union{Int64,Nothing}
90+
findfirstsortedequal(vars::DenseVector{Int64}, var::Int64)::Union{Int64,Nothing}
9191
9292
Note that this differs from `searchsortedfirst` by returning `nothing` when absent.
9393
"""
9494
function findfirstsortedequal(
95-
var::Int64,
96-
vars::DenseVector{Int64},
97-
::Val{basecase} = Base.libllvm_version >= v"17" ? Val(8) : Val(128),
95+
var::Int64,
96+
vars::DenseVector{Int64},
97+
::Val{basecase} = Base.libllvm_version >= v"17" ? Val(8) : Val(128)
9898
) where {basecase}
9999
len = length(vars)
100100
offset = 0
@@ -115,16 +115,16 @@ function findfirstsortedequal(
115115
attributes #0 = { alwaysinline }
116116
!0 = !{}
117117
""",
118-
"entry",
118+
"entry"
119119
),
120120
Int64,
121-
Tuple{Bool,Int64,Int64},
122-
vars[offset+half+1] <= var,
121+
Tuple{Bool, Int64, Int64},
122+
vars[offset + half + 1] <= var,
123123
half + offset,
124-
offset,
124+
offset
125125
)
126126
else
127-
offset = ifelse(vars[offset+half+1] <= var, half + offset, offset)
127+
offset = ifelse(vars[offset + half + 1] <= var, half + offset, offset)
128128
end
129129
len = len - half
130130
end
@@ -139,8 +139,7 @@ end
139139
"""
140140
bracketstrictlymontonic(v, x, guess; lt=<comparison>, by=<transform>, rev=false)
141141
142-
Starting from an initial `guess` index, find indices `(lo, hi)` such that `v[lo] ≤ x ≤
143-
v[hi]` according to the specified order, assuming that `x` is actually within the range of
142+
Starting from an initial `guess` index, find indices `(lo, hi)` such that `v[lo] ≤ x ≤ v[hi]` according to the specified order, assuming that `x` is actually within the range of
144143
values found in `v`. If `x` is outside that range, either `lo` will be `firstindex(v)` or
145144
`hi` will be `lastindex(v)`.
146145
@@ -157,11 +156,11 @@ this function would be the index returned by the previous call to `searchsorted`
157156
See `Base.sort!` for an explanation of the keyword arguments `by`, `lt` and `rev`.
158157
"""
159158
function bracketstrictlymontonic(
160-
v::AbstractVector,
161-
x,
162-
guess::T,
163-
o::Base.Order.Ordering,
164-
)::NTuple{2,keytype(v)} where {T<:Integer}
159+
v::AbstractVector,
160+
x,
161+
guess::T,
162+
o::Base.Order.Ordering
163+
)::NTuple{2, keytype(v)} where {T <: Integer}
165164
bottom = firstindex(v)
166165
top = lastindex(v)
167166
if guess < bottom || guess > top
@@ -206,21 +205,21 @@ function looks_linear(v; threshold = 1e-2)
206205
N = length(v)
207206
x_span = x_f - x_0
208207
mean_x_dist = x_span / (N - 1)
209-
norm_var =
210-
sum((x_i - x_0 - (i - 1) * mean_x_dist)^2 for (i, x_i) in enumerate(v)) /
211-
(N * x_span^2)
208+
norm_var = sum((x_i - x_0 - (i - 1) * mean_x_dist)^2 for (i, x_i) in enumerate(v)) /
209+
(N * x_span^2)
212210
norm_var < threshold^2
213211
end
214212

215213
"""
216214
Guesser(v::AbstractVector; looks_linear_threshold = 1e-2)
217215
218-
Wrapper of the searched vector `v` which makes an informed guess
216+
Wrapper of the searched vector `v` which makes an informed guess
219217
for `searchsorted*correlated` by either
220-
- Exploiting that `v` is sufficiently evenly spaced
221-
- Using the previous outcome of `searchsorted*correlated`
218+
219+
- Exploiting that `v` is sufficiently evenly spaced
220+
- Using the previous outcome of `searchsorted*correlated`
222221
"""
223-
struct Guesser{T<:AbstractVector}
222+
struct Guesser{T <: AbstractVector}
224223
v::T
225224
idx_prev::Base.RefValue{Int}
226225
linear_lookup::Bool
@@ -261,7 +260,7 @@ end
261260
An accelerated `findfirst` on sorted vectors using a bracketed search. Requires a `guess::Union{<:Integer, Guesser}`
262261
to start the search from.
263262
"""
264-
function searchsortedfirstcorrelated(v::AbstractVector, x, guess::T) where {T<:Integer}
263+
function searchsortedfirstcorrelated(v::AbstractVector, x, guess::T) where {T <: Integer}
265264
lo, hi = bracketstrictlymontonic(v, x, guess, Base.Order.Forward)
266265
searchsortedfirst(v, x, lo, hi, Base.Order.Forward)
267266
end
@@ -272,7 +271,7 @@ end
272271
An accelerated `findlast` on sorted vectors using a bracketed search. Requires a `guess::Union{<:Integer, Guesser}`
273272
to start the search from.
274273
"""
275-
function searchsortedlastcorrelated(v::AbstractVector, x, guess::T) where {T<:Integer}
274+
function searchsortedlastcorrelated(v::AbstractVector, x, guess::T) where {T <: Integer}
276275
lo, hi = bracketstrictlymontonic(v, x, guess, Base.Order.Forward)
277276
searchsortedlast(v, x, lo, hi, Base.Order.Forward)
278277
end
@@ -281,17 +280,17 @@ searchsortedfirstcorrelated(r::AbstractRange, x, ::Integer) = searchsortedfirst(
281280
searchsortedlastcorrelated(r::AbstractRange, x, ::Integer) = searchsortedlast(r, x)
282281

283282
function searchsortedfirstcorrelated(
284-
v::AbstractVector,
285-
x,
286-
guess::Guesser{T},
287-
) where {T<:AbstractVector}
283+
v::AbstractVector,
284+
x,
285+
guess::Guesser{T}
286+
) where {T <: AbstractVector}
288287
@assert v === guess.v
289288
out = searchsortedfirstcorrelated(v, x, guess(x))
290289
guess.idx_prev[] = out
291290
out
292291
end
293292

294-
function searchsortedlastcorrelated(v::T, x, guess::Guesser{T}) where {T<:AbstractVector}
293+
function searchsortedlastcorrelated(v::T, x, guess::Guesser{T}) where {T <: AbstractVector}
295294
@assert v === guess.v
296295
out = searchsortedlastcorrelated(v, x, guess(x))
297296
guess.idx_prev[] = out

test/runtests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using SafeTestsets, Test
55

66
@safetestset "FindFirstFunctions.jl" begin
77
using FindFirstFunctions
8-
for n = 0:128
8+
for n in 0:128
99
x = unique!(rand(Int, n))
1010
s = sort(x)
1111
for i in eachindex(x)
@@ -15,9 +15,9 @@ using SafeTestsets, Test
1515
end
1616
if length(x) > 0
1717
@test FindFirstFunctions.findfirstequal(x[begin], @view(x[begin:end])) === 1
18-
@test FindFirstFunctions.findfirstequal(x[begin], @view(x[begin+1:end])) ===
18+
@test FindFirstFunctions.findfirstequal(x[begin], @view(x[(begin + 1):end])) ===
1919
nothing
20-
@test FindFirstFunctions.findfirstequal(x[end], @view(x[begin:end-1])) ===
20+
@test FindFirstFunctions.findfirstequal(x[end], @view(x[begin:(end - 1)])) ===
2121
nothing
2222
end
2323
y = rand(Int)
@@ -26,12 +26,12 @@ using SafeTestsets, Test
2626
ff === nothing &&
2727
@test FindFirstFunctions.findfirstsortedequal(y, x) === nothing
2828
end
29-
3029
end
3130

3231
@safetestset "Guesser" begin
3332
using FindFirstFunctions:
34-
Guesser, searchsortedfirstcorrelated, searchsortedlastcorrelated
33+
Guesser, searchsortedfirstcorrelated,
34+
searchsortedlastcorrelated
3535
v = collect(LinRange(0, 10, 4))
3636
guesser_linear = Guesser(v)
3737
guesser_prev = Guesser(v, Ref(1), false)

0 commit comments

Comments
 (0)