Skip to content

Commit a9bfb41

Browse files
authored
Remove all @inbounds annotations (#970)
* Remove `@inbounds` * Bump version
1 parent 73100a0 commit a9bfb41

File tree

16 files changed

+122
-122
lines changed

16 files changed

+122
-122
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StatsBase"
22
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
33
authors = ["JuliaStats"]
4-
version = "0.34.6"
4+
version = "0.34.7"
55

66
[deps]
77
AliasTables = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"

src/counts.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitR
3131
m1 = last(levels)
3232
b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::UnitRange{<:Integer}
3333

34-
@inbounds for xi in x
34+
for xi in x
3535
if m0 <= xi <= m1
3636
r[xi - b] += 1
3737
end
@@ -53,7 +53,7 @@ function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitR
5353
m1 = last(levels)
5454
b = m0 - 1
5555

56-
@inbounds for i in eachindex(xv, wv)
56+
for i in eachindex(xv, wv)
5757
xi = xv[i]
5858
if m0 <= xi <= m1
5959
r[xi - b] += wv[i]
@@ -287,9 +287,9 @@ function addcounts_dict!(cm::Dict{T}, x) where T
287287
for v in x
288288
index = ht_keyindex2!(cm, v)
289289
if index > 0
290-
@inbounds cm.vals[index] += 1
290+
cm.vals[index] += 1
291291
else
292-
@inbounds Base._setindex!(cm, 1, v, -index)
292+
Base._setindex!(cm, 1, v, -index)
293293
end
294294
end
295295
return cm
@@ -323,17 +323,17 @@ end
323323
function _addcounts!(::Type{T}, cm::Dict{T}, x; alg = :ignored) where T <: Union{UInt8, UInt16, Int8, Int16}
324324
counts = zeros(Int, 2^(8sizeof(T)))
325325

326-
@inbounds for xi in x
326+
for xi in x
327327
counts[Int(xi) - typemin(T) + 1] += 1
328328
end
329329

330330
for (i, c) in zip(typemin(T):typemax(T), counts)
331331
if c != 0
332332
index = ht_keyindex2!(cm, i)
333333
if index > 0
334-
@inbounds cm.vals[index] += c
334+
cm.vals[index] += c
335335
else
336-
@inbounds Base._setindex!(cm, c, i, -index)
336+
Base._setindex!(cm, c, i, -index)
337337
end
338338
end
339339
end
@@ -354,7 +354,7 @@ function _addcounts_radix_sort_loop!(cm::Dict{T}, sx::AbstractVector{T}) where T
354354

355355
# now the data is sorted: can just run through and accumulate values before
356356
# adding into the Dict
357-
@inbounds for i in start_i+1:lastindex(sx)
357+
for i in start_i+1:lastindex(sx)
358358
sxi = sx[i]
359359
if !isequal(last_sx, sxi)
360360
cm[last_sx] = get(cm, last_sx, 0) + i - start_i
@@ -397,8 +397,8 @@ function addcounts!(cm::Dict{T}, x::AbstractArray{T}, wv::AbstractVector{W}) whe
397397
z = zero(W)
398398

399399
for i in eachindex(xv, wv)
400-
@inbounds xi = xv[i]
401-
@inbounds wi = wv[i]
400+
xi = xv[i]
401+
wi = wv[i]
402402
cm[xi] = get(cm, xi, z) + wi
403403
end
404404
return cm

src/cov.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function _symmetrize!(a::DenseMatrix)
66
m, n = size(a)
77
m == n || error("a must be a square matrix.")
88
for j = 1:n
9-
@inbounds for i = j+1:n
9+
for i = j+1:n
1010
vl = a[i,j]
1111
vr = a[j,i]
1212
a[i,j] = a[j,i] = middle(vl, vr)

src/deprecates.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function make_alias_table!(w::AbstractVector, wsum,
7171

7272
ac = n / wsum
7373
for i = 1:n
74-
@inbounds a[i] = w[i] * ac
74+
a[i] = w[i] * ac
7575
end
7676

7777
larges = Vector{Int}(undef, n)
@@ -80,7 +80,7 @@ function make_alias_table!(w::AbstractVector, wsum,
8080
ks = 0 # actual number of smalls
8181

8282
for i = 1:n
83-
@inbounds ai = a[i]
83+
ai = a[i]
8484
if ai > 1.0
8585
larges[kl+=1] = i # push to larges
8686
elseif ai < 1.0
@@ -91,8 +91,8 @@ function make_alias_table!(w::AbstractVector, wsum,
9191
while kl > 0 && ks > 0
9292
s = smalls[ks]; ks -= 1 # pop from smalls
9393
l = larges[kl]; kl -= 1 # pop from larges
94-
@inbounds alias[s] = l
95-
@inbounds al = a[l] = (a[l] - 1.0) + a[s]
94+
alias[s] = l
95+
al = a[l] = (a[l] - 1.0) + a[s]
9696
if al > 1.0
9797
larges[kl+=1] = l # push to larges
9898
else
@@ -102,7 +102,7 @@ function make_alias_table!(w::AbstractVector, wsum,
102102

103103
# this loop should be redundant, except for rounding
104104
for i = 1:ks
105-
@inbounds a[smalls[i]] = 1.0
105+
a[smalls[i]] = 1.0
106106
end
107107
nothing
108108
end

src/deviation.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function counteq(a::AbstractArray, b::AbstractArray)
1313
length(b) == n || throw(DimensionMismatch("Inconsistent lengths."))
1414
c = 0
1515
for i in eachindex(a, b)
16-
@inbounds if a[i] == b[i]
16+
if a[i] == b[i]
1717
c += 1
1818
end
1919
end
@@ -32,7 +32,7 @@ function countne(a::AbstractArray, b::AbstractArray)
3232
length(b) == n || throw(DimensionMismatch("Inconsistent lengths."))
3333
c = 0
3434
for i in eachindex(a, b)
35-
@inbounds if a[i] != b[i]
35+
if a[i] != b[i]
3636
c += 1
3737
end
3838
end
@@ -51,7 +51,7 @@ function sqL2dist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number
5151
length(b) == n || throw(DimensionMismatch("Input dimension mismatch"))
5252
r = 0.0
5353
for i in eachindex(a, b)
54-
@inbounds r += abs2(a[i] - b[i])
54+
r += abs2(a[i] - b[i])
5555
end
5656
return r
5757
end
@@ -79,7 +79,7 @@ function L1dist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number
7979
length(b) == n || throw(DimensionMismatch("Input dimension mismatch"))
8080
r = 0.0
8181
for i in eachindex(a, b)
82-
@inbounds r += abs(a[i] - b[i])
82+
r += abs(a[i] - b[i])
8383
end
8484
return r
8585
end
@@ -98,7 +98,7 @@ function Linfdist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number
9898
length(b) == n || throw(DimensionMismatch("Input dimension mismatch"))
9999
r = 0.0
100100
for i in eachindex(a, b)
101-
@inbounds v = abs(a[i] - b[i])
101+
v = abs(a[i] - b[i])
102102
if r < v
103103
r = v
104104
end
@@ -119,8 +119,8 @@ function gkldiv(a::AbstractArray{T}, b::AbstractArray{T}) where T<:AbstractFloat
119119
n = length(a)
120120
r = 0.0
121121
for i in eachindex(a, b)
122-
@inbounds ai = a[i]
123-
@inbounds bi = b[i]
122+
ai = a[i]
123+
bi = b[i]
124124
if ai > 0
125125
r += (ai * log(ai / bi) - ai + bi)
126126
else

src/hist.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ function push!(h::Histogram{T,N},xs::NTuple{N,Real},w::Real) where {T,N}
312312
h.isdensity && error("Density histogram must have float-type weights")
313313
idx = binindex(h, xs)
314314
if checkbounds(Bool, h.weights, idx...)
315-
@inbounds h.weights[idx...] += w
315+
h.weights[idx...] += w
316316
end
317317
h
318318
end
319319

320320
function push!(h::Histogram{T,N},xs::NTuple{N,Real},w::Real) where {T<:AbstractFloat,N}
321321
idx = binindex(h, xs)
322322
if checkbounds(Bool, h.weights, idx...)
323-
@inbounds h.weights[idx...] += h.isdensity ? w / binvolume(h, idx) : w
323+
h.weights[idx...] += h.isdensity ? w / binvolume(h, idx) : w
324324
end
325325
h
326326
end
@@ -329,14 +329,14 @@ push!(h::AbstractHistogram{T,N},xs::NTuple{N,Real}) where {T,N} = push!(h,xs,one
329329

330330

331331
function append!(h::AbstractHistogram{T,N}, vs::NTuple{N,AbstractVector}) where {T,N}
332-
@inbounds for i in eachindex(vs...)
332+
for i in eachindex(vs...)
333333
xs = _multi_getindex(i, vs...)
334334
push!(h, xs, one(T))
335335
end
336336
h
337337
end
338338
function append!(h::AbstractHistogram{T,N}, vs::NTuple{N,AbstractVector}, wv::AbstractVector) where {T,N}
339-
@inbounds for i in eachindex(wv, vs...)
339+
for i in eachindex(wv, vs...)
340340
xs = _multi_getindex(i, vs...)
341341
push!(h, xs, wv[i])
342342
end
@@ -434,7 +434,7 @@ Calculate the norm of histogram `h` as the absolute value of its integral.
434434
SumT = norm_type(h)
435435
v_0 = 1
436436
s_0 = zero(SumT)
437-
@inbounds @nloops(
437+
@nloops(
438438
$N, i, weights,
439439
d -> begin
440440
v_{$N-d+1} = v_{$N-d} * _edge_binvolume(SumT, edges[d], i_d)
@@ -493,7 +493,7 @@ arrays appropriately. See description of `normalize` for details. Returns `h`.
493493
# Divide weights by bin volume, for :pdf also divide by sum of weights
494494
SumT = norm_type(h)
495495
vs_0 = (mode == :pdf) ? sum(SumT, weights) : one(SumT)
496-
@inbounds @nloops $N i weights d->(vs_{$N-d+1} = vs_{$N-d} * _edge_binvolume(SumT, edges[d], i_d)) begin
496+
@nloops $N i weights d->(vs_{$N-d+1} = vs_{$N-d} * _edge_binvolume(SumT, edges[d], i_d)) begin
497497
(@nref $N weights i) /= $(Symbol("vs_$N"))
498498
for A in aux_weights
499499
(@nref $N A i) /= $(Symbol("vs_$N"))

src/misc.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function rle(v::AbstractVector{T}) where T
2929
cl = 1
3030

3131
i = 2
32-
@inbounds while i <= n
32+
while i <= n
3333
vi = v[i]
3434
if isequal(vi, cv)
3535
cl += 1
@@ -67,7 +67,7 @@ function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) w
6767

6868
r = Vector{T}(undef, n)
6969
p = 0
70-
@inbounds for i = 1 : m
70+
for i = 1 : m
7171
j = lens[i]
7272
j >= 0 || throw(ArgumentError("lengths must be non-negative"))
7373
v = vals[i]
@@ -89,7 +89,7 @@ the index of its first occurrence in `a`.
8989
function indexmap(a::AbstractArray{T}) where T
9090
d = Dict{T,Int}()
9191
for i = 1 : length(a)
92-
@inbounds k = a[i]
92+
k = a[i]
9393
if !haskey(d, k)
9494
d[k] = i
9595
end
@@ -108,7 +108,7 @@ function levelsmap(a::AbstractArray{T}) where T
108108
d = Dict{T,Int}()
109109
index = 1
110110
for i = 1 : length(a)
111-
@inbounds k = a[i]
111+
k = a[i]
112112
if !haskey(d, k)
113113
d[k] = index
114114
index += 1
@@ -171,7 +171,7 @@ function _indicatormat_dense(x::AbstractArray{T}, c::AbstractArray{T}) where T
171171
n = length(x)
172172
r = zeros(Bool, m, n)
173173
o = 0
174-
@inbounds for i = 1 : n
174+
for i = 1 : n
175175
xi = x[i]
176176
r[o + d[xi]] = true
177177
o += m
@@ -187,7 +187,7 @@ function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T
187187
n = length(x)
188188

189189
rinds = Vector{Int}(undef, n)
190-
@inbounds for i = 1 : n
190+
for i = 1 : n
191191
rinds[i] = d[x[i]]
192192
end
193193
return sparse(rinds, 1:n, true, m, n)

0 commit comments

Comments
 (0)