-
Notifications
You must be signed in to change notification settings - Fork 33
Specialize multiplication for Fixed
#220
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #220 +/- ##
==========================================
+ Coverage 91.01% 91.29% +0.28%
==========================================
Files 6 6
Lines 534 563 +29
==========================================
+ Hits 486 514 +28
- Misses 48 49 +1
Continue to review full report at Codecov.
|
BenchmarkSee x_q0f7 = collect(rand(Q0f7, 1000, 1000)); y_q0f7 = collect(rand(Q0f7, 1000, 1000));
x_q0f15 = collect(rand(Q0f15, 1000, 1000)); y_q0f15 = collect(rand(Q0f15, 1000, 1000));
x_q3f4 = collect(rand(Q3f4, 1000, 1000)); y_q3f4 = collect(rand(Q3f4, 1000, 1000));
x_q3f12 = collect(rand(Q3f12, 1000, 1000)); y_q3f12 = collect(rand(Q3f12, 1000, 1000));
z_q3f4 = Q3f4.( rand(1000, 1000));
z_q3f12 = Q3f12.(rand(1000, 1000));
julia> @btime $x_q0f7 .* $y_q0f7;
96.199 μs (2 allocations: 976.70 KiB)
julia> @btime $x_q0f15 .* $y_q0f15;
796.499 μs (2 allocations: 1.91 MiB)
julia> @btime saturating_mul.($x_q3f4, $y_q3f4);
155.601 μs (2 allocations: 976.70 KiB)
julia> @btime saturating_mul.($x_q3f12, $y_q3f12);
909.100 μs (2 allocations: 1.91 MiB)
julia> @btime checked_mul.($x_q3f4, $z_q3f4);
1.575 ms (2 allocations: 976.70 KiB)
julia> @btime checked_mul.($x_q3f12, $z_q3f12);
1.881 ms (2 allocations: 1.91 MiB)
julia> x_f32 = rand(Float32, 1000, 1000);
julia> @btime $x_f32 .% Q0f7;
762.600 μs (2 allocations: 976.70 KiB) cf. v0.8.4 ( julia> @btime $x_q0f7 .* $y_q0f7;
77.900 μs (2 allocations: 976.70 KiB)
julia> @btime $x_q0f15 .* $y_q0f15;
758.600 μs (2 allocations: 1.91 MiB) I feel we can improve it a bit more. The |
5dbd0cd
to
2f9710b
Compare
This provides the multiplication compatible with v0.8 and earlier as `mul_with_rounding(x, y, RoundNearestTiesUp)`. This also provides the rounding-down version `mul_with_rounding(x, y, RoundDown)`. The function is informative and not exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't worked through the details of how you've implemented this, but since all you're doing is adding tests and getting much better performance, there's definitely no reason to avoid merging this.
As an additional note for later readers, the default As for the In order to address the operations related to division, I will first merge this. |
)" This specializes most of the multiplication for `Fixed` and avoids floating point operations. A major change is that the rounding mode is changed from `RoundNearestTiesUp` to `RoundNearest`. The existing `RoundNearestTiesUp` and `RoundDown` modes are now supported by the new unexported function `mul_with_rounding`. This also improves `rem`. Unlike multiplication for `Normed`, the wrapping arithmetic is the default for `Fixed`.
)" This specializes most of the multiplication for `Fixed` and avoids floating point operations. A major change is that the rounding mode is changed from `RoundNearestTiesUp` to `RoundNearest`. The existing `RoundNearestTiesUp` and `RoundDown` modes are now supported by the new unexported function `mul_with_rounding`. This also improves `rem`. Unlike multiplication for `Normed`, the wrapping arithmetic is the default for `Fixed`.
)" This specializes most of the multiplication for `Fixed` and avoids floating point operations. A major change is that the rounding mode is changed from `RoundNearestTiesUp` to `RoundNearest`. The existing `RoundNearestTiesUp` and `RoundDown` modes are now supported by the new unexported function `mul_with_rounding`. This also improves `rem`. Unlike multiplication for `Normed`, the wrapping arithmetic is the default for `Fixed`.
)" This specializes most of the multiplication for `Fixed` and avoids floating point operations. A major change is that the rounding mode is changed from `RoundNearestTiesUp` to `RoundNearest`. The existing `RoundNearestTiesUp` and `RoundDown` modes are now supported by the new unexported function `mul_with_rounding`. This also improves `rem`. Unlike multiplication for `Normed`, the wrapping arithmetic is the default for `Fixed`.
)" This specializes most of the multiplication for `Fixed` and avoids floating point operations. A major change is that the rounding mode is changed from `RoundNearestTiesUp` to `RoundNearest`. The existing `RoundNearestTiesUp` and `RoundDown` modes are now supported by the new unexported function `mul_with_rounding`. This also improves `rem`. Unlike multiplication for `Normed`, the wrapping arithmetic is the default for `Fixed`.
This is a sequel to PR #213. This specializes most of the multiplication for
Fixed
and avoids floating point operations.A major change is that the rounding mode is changed from
RoundNearestTiesUp
toRoundNearest
. The existingRoundNearestTiesUp
andRoundDown
(the latter was noted in a comment) modes are now supported by the new unexported functionmul_with_rounding
.Unlike multiplication for
Normed
, the wrapping arithmetic is the default forFixed
.This PR also improves
rem
.Fixes #173, Fixes #219