Add bitwise elementwise specifications #54
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR
&,|,^,~,>>, and<<.Notes
The specifications follow the same form as other elementwise functions.
Functional bitwise APIs are, while not ubiquitous, commonly implemented across array libraries. The principle impetus for their inclusion is to have functional equivalents of operators (as discussed and endorsed during a prior consortium meeting).
This PR induces a slightly different naming convention. NumPy (and its followers) splits its namespace into non-prefixed and prefixed APIs (e.g.,
right_shiftvsbitwise_and). TensorFlow puts everything under atf.bitwisenamespace, while also using abitwise_prefix for certain APIs.This PR chooses to simply put all bitwise operations under a
bitwise_prefix. This matches, and is consistent with, the current convention of using alogical_prefix for logical operations.This PR currently requires that
x2for bothright_shiftandleft_shifthave nonnegative elements. NumPy's docs forleft_shiftstate that this is required; although, from the interpreter, no error is thrown if a negativex2is provided. TensorFlow states that negativex2results in implementation-dependent behavior.This PR takes the stance that negative
x2for eitherleft_shiftandright_shiftis probably a mistake and should not be permitted. Hence, the included requirements thatx2be greater than or equal to0.