-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
np.prod returns 0 in case of integer overflow (Trac #1629) #2225
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
Comments
@charris wrote on 2010-10-10 I don't see this for current svn on my 64 bit system:
However, it could be that the default accumator on your system is int32? What platform are you on? In any case, you should specify the type of the result, numpy can't tell in advance how big the product is going to be and it could easily be out of range for anything but arbitrary precision integers. |
@rgommers wrote on 2010-10-10 It does depend on whether the platform is 32/64-bit:
But the documentation explains this issue in detail, quoting relevant parts:
There probably was a good reason to implement and document it like this, but that's best asked on the mailing list. I think this ticket can be closed. |
@pv wrote on 2010-10-10 The good reason is that the alternative is checking integer overflow manually, and that the output type of an ufunc should depend only on the input type, not on the input values. |
Milestone changed to |
trac user kilian wrote on 2010-10-11 Ok, thanks for all the comments! I should have read the doc string more carefully first... |
Co-authored-by: NamamiShanker <[email protected]>
Co-authored-by: NamamiShanker <[email protected]>
Co-authored-by: NamamiShanker <[email protected]>
* FIX: Import f2py2e rather than f2py for run_main * FIX: Import f2py2e instead of f2py * ENH: Add F2PY back-end work from gh-22225 Co-authored-by: NamamiShanker <[email protected]> * ENH: Add meson skeleton from gh-2225 Co-authored-by: NamamiShanker <[email protected]> * MAINT: Trim backend.py down to f2py2e flags * ENH: Add a factory function for backends * ENH: Add a distutils backend * ENH: Handle --backends in f2py Defaults to distutils for now * DOC: Add some minor comments in f2py2e * MAINT: Refactor and rework meson.build.src * MAINT: Add objects * MAINT: Cleanup distutils backend * MAINT: Refactor to add everything back to backend Necessary for the meson.build for now. Refactors / cleanup needs better argument handling in f2py2e * MAINT: Fix overly long line * BUG: Construct wrappers for meson backend * MAINT: Rework, simplify template massively * ENH: Truncate meson.build to skeleton only * MAINT: Minor backend housekeeping, name changes * MAINT: Less absolute paths, update setup.py [f2py] * MAINT: Move f2py module name functionality Previously part of np.distutils * ENH: Handle .pyf files * TST: Fix typo in isoFortranEnvMap.f90 * MAINT: Typo in f2py2e support for pyf files * DOC: Add release note for --backend * MAINT: Conditional switch for Python 3.12 [f2py] * MAINT: No absolute paths in backend [f2py-meson] The files are copied over anyway, this makes it easier to extend the generated skeleton * MAINT: Prettier generated meson.build files [f2py] * ENH: Add meson's dependency(blah) to f2py * DOC: Document the new flag * MAINT: Simplify and rename backend template [f2py] Co-authored-by: rgommers <[email protected]> * ENH: Support build_type via --debug [f2py-meson] * MAINT,DOC: Reduce warn,rework doc [f2py-meson] Co-authored-by: rgommers <[email protected]> * ENH: Rework deps: to --dep calls [f2py-meson] Also shows how incremental updates to the parser can be done. * MAINT,DOC: Add --backend to argparse, add docs * MAINT: Rename meson template [f2py-meson] * MAINT: Add meson.build for f2py Should address #22225 (comment) * BLD: remove duplicate f2py handling in meson.build files --------- Co-authored-by: Namami Shanker <[email protected]> Co-authored-by: NamamiShanker <[email protected]> Co-authored-by: rgommers <[email protected]> Co-authored-by: Ralf Gommers <[email protected]>
* FIX: Import f2py2e rather than f2py for run_main * FIX: Import f2py2e instead of f2py * ENH: Add F2PY back-end work from numpygh-22225 Co-authored-by: NamamiShanker <[email protected]> * ENH: Add meson skeleton from numpygh-2225 Co-authored-by: NamamiShanker <[email protected]> * MAINT: Trim backend.py down to f2py2e flags * ENH: Add a factory function for backends * ENH: Add a distutils backend * ENH: Handle --backends in f2py Defaults to distutils for now * DOC: Add some minor comments in f2py2e * MAINT: Refactor and rework meson.build.src * MAINT: Add objects * MAINT: Cleanup distutils backend * MAINT: Refactor to add everything back to backend Necessary for the meson.build for now. Refactors / cleanup needs better argument handling in f2py2e * MAINT: Fix overly long line * BUG: Construct wrappers for meson backend * MAINT: Rework, simplify template massively * ENH: Truncate meson.build to skeleton only * MAINT: Minor backend housekeeping, name changes * MAINT: Less absolute paths, update setup.py [f2py] * MAINT: Move f2py module name functionality Previously part of np.distutils * ENH: Handle .pyf files * TST: Fix typo in isoFortranEnvMap.f90 * MAINT: Typo in f2py2e support for pyf files * DOC: Add release note for --backend * MAINT: Conditional switch for Python 3.12 [f2py] * MAINT: No absolute paths in backend [f2py-meson] The files are copied over anyway, this makes it easier to extend the generated skeleton * MAINT: Prettier generated meson.build files [f2py] * ENH: Add meson's dependency(blah) to f2py * DOC: Document the new flag * MAINT: Simplify and rename backend template [f2py] Co-authored-by: rgommers <[email protected]> * ENH: Support build_type via --debug [f2py-meson] * MAINT,DOC: Reduce warn,rework doc [f2py-meson] Co-authored-by: rgommers <[email protected]> * ENH: Rework deps: to --dep calls [f2py-meson] Also shows how incremental updates to the parser can be done. * MAINT,DOC: Add --backend to argparse, add docs * MAINT: Rename meson template [f2py-meson] * MAINT: Add meson.build for f2py Should address numpy#22225 (comment) * BLD: remove duplicate f2py handling in meson.build files --------- Co-authored-by: Namami Shanker <[email protected]> Co-authored-by: NamamiShanker <[email protected]> Co-authored-by: rgommers <[email protected]> Co-authored-by: Ralf Gommers <[email protected]>
* FIX: Import f2py2e rather than f2py for run_main * FIX: Import f2py2e instead of f2py * ENH: Add F2PY back-end work from gh-22225 * ENH: Add meson skeleton from gh-2225 * MAINT: Trim backend.py down to f2py2e flags * ENH: Add a factory function for backends * ENH: Add a distutils backend * ENH: Handle --backends in f2py Defaults to distutils for now * DOC: Add some minor comments in f2py2e * MAINT: Refactor and rework meson.build.src * MAINT: Add objects * MAINT: Cleanup distutils backend * MAINT: Refactor to add everything back to backend Necessary for the meson.build for now. Refactors / cleanup needs better argument handling in f2py2e * MAINT: Fix overly long line * BUG: Construct wrappers for meson backend * MAINT: Rework, simplify template massively * ENH: Truncate meson.build to skeleton only * MAINT: Minor backend housekeeping, name changes * MAINT: Less absolute paths, update setup.py [f2py] * MAINT: Move f2py module name functionality Previously part of np.distutils * ENH: Handle .pyf files * TST: Fix typo in isoFortranEnvMap.f90 * MAINT: Typo in f2py2e support for pyf files * DOC: Add release note for --backend * MAINT: Conditional switch for Python 3.12 [f2py] * MAINT: No absolute paths in backend [f2py-meson] The files are copied over anyway, this makes it easier to extend the generated skeleton * MAINT: Prettier generated meson.build files [f2py] * ENH: Add meson's dependency(blah) to f2py * DOC: Document the new flag * MAINT: Simplify and rename backend template [f2py] * ENH: Support build_type via --debug [f2py-meson] * MAINT,DOC: Reduce warn,rework doc [f2py-meson] * ENH: Rework deps: to --dep calls [f2py-meson] Also shows how incremental updates to the parser can be done. * MAINT,DOC: Add --backend to argparse, add docs * MAINT: Rename meson template [f2py-meson] * MAINT: Add meson.build for f2py Should address #22225 (comment) * BLD: remove duplicate f2py handling in meson.build files --------- Co-authored-by: Rohit Goswami <[email protected]> Co-authored-by: Namami Shanker <[email protected]> Co-authored-by: NamamiShanker <[email protected]> Co-authored-by: rgommers <[email protected]> Co-authored-by: Ralf Gommers <[email protected]>
* FIX: Import f2py2e rather than f2py for run_main * FIX: Import f2py2e instead of f2py * ENH: Add F2PY back-end work from numpygh-22225 Co-authored-by: NamamiShanker <[email protected]> * ENH: Add meson skeleton from numpygh-2225 Co-authored-by: NamamiShanker <[email protected]> * MAINT: Trim backend.py down to f2py2e flags * ENH: Add a factory function for backends * ENH: Add a distutils backend * ENH: Handle --backends in f2py Defaults to distutils for now * DOC: Add some minor comments in f2py2e * MAINT: Refactor and rework meson.build.src * MAINT: Add objects * MAINT: Cleanup distutils backend * MAINT: Refactor to add everything back to backend Necessary for the meson.build for now. Refactors / cleanup needs better argument handling in f2py2e * MAINT: Fix overly long line * BUG: Construct wrappers for meson backend * MAINT: Rework, simplify template massively * ENH: Truncate meson.build to skeleton only * MAINT: Minor backend housekeeping, name changes * MAINT: Less absolute paths, update setup.py [f2py] * MAINT: Move f2py module name functionality Previously part of np.distutils * ENH: Handle .pyf files * TST: Fix typo in isoFortranEnvMap.f90 * MAINT: Typo in f2py2e support for pyf files * DOC: Add release note for --backend * MAINT: Conditional switch for Python 3.12 [f2py] * MAINT: No absolute paths in backend [f2py-meson] The files are copied over anyway, this makes it easier to extend the generated skeleton * MAINT: Prettier generated meson.build files [f2py] * ENH: Add meson's dependency(blah) to f2py * DOC: Document the new flag * MAINT: Simplify and rename backend template [f2py] Co-authored-by: rgommers <[email protected]> * ENH: Support build_type via --debug [f2py-meson] * MAINT,DOC: Reduce warn,rework doc [f2py-meson] Co-authored-by: rgommers <[email protected]> * ENH: Rework deps: to --dep calls [f2py-meson] Also shows how incremental updates to the parser can be done. * MAINT,DOC: Add --backend to argparse, add docs * MAINT: Rename meson template [f2py-meson] * MAINT: Add meson.build for f2py Should address numpy#22225 (comment) * BLD: remove duplicate f2py handling in meson.build files --------- Co-authored-by: Namami Shanker <[email protected]> Co-authored-by: NamamiShanker <[email protected]> Co-authored-by: rgommers <[email protected]> Co-authored-by: Ralf Gommers <[email protected]>
Original ticket http://projects.scipy.org/numpy/ticket/1629 on 2010-10-10 by trac user kilian, assigned to unknown.
I am using np.prod to calculate the number of elements of a sparse matrix (np.prod(C.shape)) and I noticed the following behavior: In case the result is greater than 2**31, zero is returned. Instead, the result should be converted to int long int (or at least an exception should be raised).
The text was updated successfully, but these errors were encountered: