forked from numpy/numpy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Transition scheme for safer in-place ufunc operations
In numpy 1.6 and earlier, if you do np.add(int_arr, float_arr, out=int_arr) or int_arr += float_arr then the result will be silently truncated to integer values. This often produces bugs, because it's easy to accidentally end up with an integer array and not realize it. Therefore, there seems to be consensus that we should switch to using same_kind casting by default for in-place ufunc operations. However, just switching this (as was done initially during the 1.7 development cycle) breaks a lot of code, which is rude and violates our deprecation policy. This commit instead adds a special temporary casting rule which acts like "unsafe", but also checks whether each operation would be allowed under "same_kind" rules and issues a DeprecationWarning if not. It also moves NPY_DEFAULT_ASSIGN_CASTING into the formal API instead of leaving it as a #define. This way we can change it later, and any code which references it and is compiled against this version of numpy will automatically switch to whatever we change it too. This avoids the situation where we want to remove the temporary magic value we're using to create DeprecationWarnings now, but can't because it would be an ABI break.
- Loading branch information
Showing
7 changed files
with
82 additions
and
8 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
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
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
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