Skip to content

Commit abb46c5

Browse files
authored
Change in-length check from branch to multiplicative term in rejection loop (#111)
1 parent 5eac73b commit abb46c5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/DynamicDiscreteSamplers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Base.setindex!(w::Weights, v, i::Int) = (_setindex!(w.m, Float64(v), i); w)
201201
k1 = (r>>leading_zeros(len-1))
202202
k2 = _convert(Int, k1<<1+pos)
203203
# TODO for perf: delete the k1 < len check by maintaining all the out of bounds m[k2] equal to 0
204-
k1 < len && rand(rng, UInt64) < m[k2] && return Int(signed(m[k2+1]))
204+
rand(rng, UInt64) < m[k2] * (k1 < len) && return Int(signed(m[k2+1]))
205205
end
206206
end
207207

0 commit comments

Comments
 (0)