-
Notifications
You must be signed in to change notification settings - Fork 33
Add support for digits
keyword argument of round()
#235
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This only supports the non-negative `digits` option. All other options throw an error. This provides specialized implementations only for `N0f8` and `Fixed{Int8}`. The other types use fallback with floating-point operations and therefore it is slower and less accurate.
Codecov Report
@@ Coverage Diff @@
## master #235 +/- ##
==========================================
+ Coverage 96.24% 96.47% +0.23%
==========================================
Files 6 6
Lines 692 738 +46
==========================================
+ Hits 666 712 +46
Misses 26 26
Continue to review full report at Codecov.
|
Benchmarkusing ColorTypes, BenchmarkTools
image = rand(RGB{N0f8}, 1000, 1000);
function quantize(x::N0f8)
floor(x, digits=1)
end
function quantize(color::AbstractRGB)
mapc(quantize, color)
end
function quantize_f(x::N0f8)
floor(float(x), digits=1) % N0f8
end
function quantize_f(color::AbstractRGB)
mapc(quantize_f, color)
end julia> @benchmark quantize.($image)
BenchmarkTools.Trial:
memory estimate: 2.86 MiB
allocs estimate: 2
--------------
minimum time: 1.504 ms (0.00% GC)
median time: 1.532 ms (0.00% GC)
mean time: 1.731 ms (10.89% GC)
maximum time: 5.461 ms (71.47% GC)
--------------
samples: 2888
evals/sample: 1
julia> @benchmark quantize_f.($image)
BenchmarkTools.Trial:
memory estimate: 2.86 MiB
allocs estimate: 2
--------------
minimum time: 18.977 ms (0.00% GC)
median time: 19.034 ms (0.00% GC)
mean time: 19.298 ms (1.17% GC)
maximum time: 22.876 ms (16.72% GC)
--------------
samples: 260
evals/sample: 1 n4f4 = rand(N4f4, 1000);
n0f8 = rand(N0f8, 1000);
n0f16 = rand(N0f16, 1000);
q3f4 = rand(Q3f4, 1000);
q0f7 = rand(Q0f7, 1000);
q0f15 = rand(Q0f15, 1000); julia> @btime trunc.($n4f4, digits=1); # not optimized
13.199 μs (1 allocation: 1.06 KiB)
julia> @btime trunc.($n0f8, digits=1);
161.658 ns (1 allocation: 1.06 KiB)
julia> @btime trunc.($n0f8, digits=2);
158.163 ns (1 allocation: 1.06 KiB)
julia> @btime trunc.($n0f16, digits=2); # not optimized
15.100 μs (1 allocation: 2.13 KiB)
julia> @btime trunc.($q3f4, digits=1);
221.577 ns (1 allocation: 1.06 KiB)
julia> @btime trunc.($q0f7, digits=1);
126.801 ns (1 allocation: 1.06 KiB)
julia> @btime trunc.($q0f7, digits=2);
222.530 ns (1 allocation: 1.06 KiB)
julia> @btime trunc.($q0f15, digits=2); # not optimized
5.767 μs (1 allocation: 2.13 KiB) |
This changes the behavior as a result, but I think this is rather a bug fix. So, I will merge this. |
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This only supports the non-negative
digits
option. All other options throw an error.This provides specialized implementations only for
N0f8
andFixed{Int8}
. The other types use fallback with floating-point operations and therefore it is slower and less accurate.Fixes #234