File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ def round_float(
114
114
)
115
115
116
116
should_round_away = d > srbits
117
- case RoundMode .StochasticNearly :
117
+ case RoundMode .StochasticFastest :
118
118
should_round_away = delta > (0.5 + srbits ) * 2.0 ** - srnumbits
119
119
case RoundMode .StochasticFast :
120
120
should_round_away = delta > srbits * 2.0 ** - srnumbits
Original file line number Diff line number Diff line change @@ -95,11 +95,11 @@ def round_ndarray(
95
95
96
96
should_round_away = d > srbits
97
97
case RoundMode .StochasticFast :
98
- assert srbits is not None
99
- should_round_away = delta > srbits * 2.0 ** - srnumbits
100
- case RoundMode .StochasticNearly :
101
98
assert srbits is not None
102
99
should_round_away = delta > (2 * srbits + 1 ) * 2.0 ** - (1 + srnumbits )
100
+ case RoundMode .StochasticFastest :
101
+ assert srbits is not None
102
+ should_round_away = delta > srbits * 2.0 ** - srnumbits
103
103
104
104
isignificand = np .where (should_round_away , isignificand + 1 , isignificand )
105
105
Original file line number Diff line number Diff line change @@ -17,14 +17,20 @@ class RoundMode(Enum):
17
17
TiesToEven = 4 #: Round to nearest, ties to even
18
18
TiesToAway = 5 #: Round to nearest, ties away from zero
19
19
Stochastic = 6 #: Stochastic rounding
20
- StochasticFast = 7 #: Stochastic rounding - faster, but biased.
21
- StochasticNearly = 8 #: Stochastic rounding - incorrect, see [Note 1].
20
+ StochasticFast = 7 #: Stochastic rounding - faster, but biased, see [Note 1] .
21
+ StochasticFastest = 8 #: Stochastic rounding - incorrect, see [Note 1].
22
22
23
23
24
24
# [Note 1]:
25
- # StochasticNearly implements a stochastic rounding scheme that is unbiased in
25
+ # StochasticFast implements a stochastic rounding scheme that is unbiased in
26
26
# infinite precision, but biased when the quantity to be rounded is computed to
27
27
# a finite precision.
28
+ #
29
+ # StochasticFastest implements a stochastic rounding scheme that is biased
30
+ # (the rounded value is on average farther from zero than the true value).
31
+ #
32
+ # With a lot of SRbits (say 8 or more), these biases are negligible, and there
33
+ # may be some efficiency advantage in using StochasticFast or StochasticFastest.
28
34
29
35
30
36
class FloatClass (Enum ):
You can’t perform that action at this time.
0 commit comments