-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
faster bin index for uniform edge #613
Conversation
notice this also makes multi-dimensional faster automatically. I hope @ianshmean is as happy as I am rn ;)
|
I gave this a try locally and it is a performance regression in our use case. Our bins are a |
@Octogonapus interesting, any chance to paste a MWE here? |
using Images, TestImages, FileIO, Rotations, CoordinateTransformations, StatsBase, BenchmarkTools
img = Gray.(testimage("lighthouse"));
tfm = Translation(125,250) ∘ LinearMap(RotMatrix(pi/50)) ∘ Translation(-125,-250);
img_rotated = warp(img, tfm);
fixed = collect(reinterpret(UInt8, img[50:300, 50:300]));
moving = collect(reinterpret(UInt8, img_rotated[50:300, 50:300]));
step = UInt8(16);
h = fit(Histogram, (vec(fixed), vec(moving)), (0x00:step:0xff, 0x00:step:0xff));
@benchmark append!(h, (vec(fixed), vec(moving))) Baseline:
This patch without my fix:
This patch with my fix:
|
implemented in https://github.com/Moelf/FHist.jl julia> a = rand(10^5);
julia> using BenchmarkTools
julia> using FHist, StatsBase
julia> @benchmark Hist1D($a, -3:0.01:3)
BenchmarkTools.Trial: 9057 samples with 1 evaluation.
Range (min … max): 117.353 μs … 1.412 ms ┊ GC (min … max): 0.00% … 82.64%
Time (median): 547.890 μs ┊ GC (median): 0.00%
Time (mean ± σ): 550.589 μs ± 32.415 μs ┊ GC (mean ± σ): 0.07% ± 1.59%
█
▂▂▂▂▁▂▂▁▁▁▂▁▁▁▂▁▁▂▂▁▁▁▂▁▁▁▁▁▁▂▁▂▁▁▁▂▁▁▂▁▁▁▂▁▂▁▁▁▂▂▂▁▁▂▁▃█▆█▅ ▂
117 μs Histogram: frequency by time 572 μs <
Memory estimate: 14.58 KiB, allocs estimate: 6.
julia> @benchmark fit(Histogram, $a, -3:0.01:3)
BenchmarkTools.Trial: 1995 samples with 1 evaluation.
Range (min … max): 2.457 ms … 2.635 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 2.482 ms ┊ GC (median): 0.00%
Time (mean ± σ): 2.505 ms ± 40.487 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
▄█▅▁
▂▂▃▃▃▅████▅▅▅▅▄▄▃▃▃▃▃▃▂▂▂▂▂▂▂▁▂▁▂▂▂▂▂▃▃▄▅▆▆▄▃▃▃▃▃▂▃▂▂▂▂▂▂▂ ▃
2.46 ms Histogram: frequency by time 2.61 ms <
Memory estimate: 4.89 KiB, allocs estimate: 2.
|
see #563
before:
after: