Comments (5)
maybe we should have an unsafe_push!()
as the fundamental push so user can manually unlock
it and keep pushing if they're just doing single thread work
from fhist.jl.
Looks like it's searchsortedlast?
function Hist1D(A::AbstractVector, r::AbstractRange{T}) where T <: AbstractFloat
s = step(r)
start = first(r)
start2 = start + 0.5s
stop = last(r)
L = length(r) - 1
counts = zeros(Int, L)
@inbounds for idx in eachindex(A)
# default
i = A[idx]
c = ifelse(i > stop, 0, 1)
c = ifelse(i < start, 0, c)
id = round(Int, (i - start2) / s) + 1
counts[clamp(id, 1, L)] += c
# push!() uses `searchsorted`
# i = A[idx]
# id = searchsortedlast(r, i)
# c = ifelse(i > stop, 0, 1)
# c = ifelse(i < start, 0, c)
# counts[id] += c
end
return Hist1D(Histogram(r, counts))
end
The above took 6.5ms with the default implementation, but 45ms with searchsortedlast
plugged in (as is used for push!()
.
from fhist.jl.
I thought searchsortedlast
is fast over ranges as well
from fhist.jl.
That's what I thought from profiling...
there's some time spent in computing the bin index (good, no binary search), but those percentages don't seem to add up to
from fhist.jl.
And fwiw, above, the manual calculation matches the searchsortedlast for 1e6 events, so we could factor out
@inline function calcbinindex(r::AbstractRange{<:Real}, x::Real)
s = step(r)
start2 = first(r) + 0.5s
return round(Int, (x - start2) / s) + 1
end
and use it in place of searchsortedlast everywhere
from fhist.jl.
Related Issues (20)
- Overflow behavior HOT 2
- TagBot trigger issue HOT 39
- repr in jupyter notebooks
- Constructor using Dict{Symbol, Key} from UnROOT's hist HOT 5
- Plotting example using FHist and Plotly HOT 2
- cumulative reverse order HOT 3
- Should there be a function return sumw2? HOT 4
- Can this be Real? HOT 7
- Weird behavior HOT 1
- Naming of push/unsafe_push HOT 1
- unsafe_push when only 1 thread HOT 1
- implement Hist3D
- High precision bin edges make overfull display HOT 3
- Nonuniform weights? HOT 5
- FHist type-parameter (of eltype) is also used for the weights HOT 7
- Statbox not working on a normalized histogram
- integral should take into account binwidths HOT 4
- Normalize broken ? HOT 1
- normalize, width = true HOT 5
- Is normal that memory allocations happens when filling? HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fhist.jl.