Skip to content

Commit 35ac46f

Browse files
committed
Docstring and function rename
1 parent fbf0c89 commit 35ac46f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/common/sum_tree.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ function Base.empty!(t::SumTree)
131131
t
132132
end
133133

134-
function correct_priority(t::SumTree, leaf_ind)
134+
"""
135+
correct_sample(t::SumTree, leaf_ind)
136+
Check whether the sampled leaf is valid and if not return another valid leaf close to it. Used to correct samples with zero priority which may occur due to numerical errors with floats.
137+
"""
138+
function correct_sample(t::SumTree, leaf_ind)
135139
p = t.tree[leaf_ind]
136140
# walk backwards until p != 0 or until leftmost leaf reached
137141
tmp_ind = leaf_ind
@@ -170,7 +174,7 @@ function Base.get(t::SumTree, v)
170174
if leaf_ind <= t.nparents
171175
leaf_ind += t.capacity
172176
end
173-
p, leaf_ind = correct_priority(t, leaf_ind)
177+
p, leaf_ind = correct_sample(t, leaf_ind)
174178
ind = leaf_ind - t.nparents
175179
real_ind = ind >= t.first ? ind - t.first + 1 : ind + t.capacity - t.first + 1
176180
real_ind, p
@@ -190,4 +194,4 @@ function Random.rand(rng::AbstractRNG, t::SumTree{T}, n::Int) where {T}
190194
inds, priorities
191195
end
192196

193-
Random.rand(t::SumTree, n::Int) = rand(Random.GLOBAL_RNG, t, n)
197+
Random.rand(t::SumTree, n::Int) = rand(Random.GLOBAL_RNG, t, n)

0 commit comments

Comments
 (0)