-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from tomwhite/overflow-bug
Fix overflow bug exposed by Hypothesis failures
- Loading branch information
Showing
4 changed files
with
25 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from functools import reduce | ||
import operator | ||
from typing import Sequence | ||
|
||
|
||
def prod(iterable: Sequence[int]) -> int: | ||
"""Implementation of `math.prod()` all Python versions.""" | ||
try: | ||
from math import prod as mathprod # Python 3.8 | ||
|
||
return mathprod(iterable) | ||
except ImportError: | ||
return reduce(operator.mul, iterable, 1) |
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import numpy as np | ||
from rechunker.compat import prod | ||
|
||
|
||
def test_prod(): | ||
assert prod(()) == 1 | ||
assert prod((2,)) == 2 | ||
assert prod((2, 3)) == 6 | ||
n = np.iinfo(np.int64).max | ||
assert prod((n, 2)) == n * 2 |