Skip to content

Commit

Permalink
faster bin index for uniform edge
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed Oct 29, 2020
1 parent 1c3f3d7 commit 7a1eff0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/hist.jl
Expand Up @@ -234,6 +234,15 @@ binindex(h::Histogram{T,N}, xs::NTuple{N,Real}) where {T,N} =
end
end

@inline function _edge_binindex(edge::AbstractRange, closed::Symbol, x::Real)
n = if closed == :right
ceil(Int, (x-first(edge)) / step(edge))
else
n = round(Int, (x - first(edge)) / step(edge) + 1)
x < edge[n] ? n - 1 : n
end
clamp(n, 1, length(edge))
end

binvolume(h::AbstractHistogram{T,1}, binidx::Integer) where {T} = binvolume(h, (binidx,))
binvolume(::Type{V}, h::AbstractHistogram{T,1}, binidx::Integer) where {V,T} = binvolume(V, h, (binidx,))
Expand Down

0 comments on commit 7a1eff0

Please sign in to comment.