-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: add np.divmod ufunc #9063
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
ENH: add np.divmod ufunc #9063
Changes from all commits
c9d1f9e
d51b538
6144637
a148978
8fbf75e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,7 @@ Arithmetic operations | |
mod | ||
modf | ||
remainder | ||
divmod | ||
|
||
Handling complex numbers | ||
------------------------ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,6 +510,7 @@ Math operations | |
remainder | ||
mod | ||
fmod | ||
divmod | ||
absolute | ||
fabs | ||
rint | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1290,6 +1290,7 @@ def add_newdoc(place, name, doc): | |
See Also | ||
-------- | ||
remainder : Remainder complementary to floor_divide. | ||
divmod : Simultaneous floor division and remainder. | ||
divide : Standard division. | ||
floor : Round a number to the nearest integer toward minus infinity. | ||
ceil : Round a number to the nearest integer toward infinity. | ||
|
@@ -2474,6 +2475,11 @@ def add_newdoc(place, name, doc): | |
----- | ||
For integer input the return values are floats. | ||
|
||
See Also | ||
-------- | ||
divmod : ``divmod(x, 1)`` is equivalent to ``modf`` with the return values | ||
switched, except it always has a positive remainder. | ||
|
||
Examples | ||
-------- | ||
>>> np.modf([0, 3.5]) | ||
|
@@ -2541,6 +2547,8 @@ def add_newdoc(place, name, doc): | |
""" | ||
Numerical positive, element-wise. | ||
|
||
.. versionadded:: 1.13.0 | ||
|
||
Parameters | ||
---------- | ||
x : array_like or scalar | ||
|
@@ -2843,6 +2851,7 @@ def add_newdoc(place, name, doc): | |
See Also | ||
-------- | ||
floor_divide : Equivalent of Python ``//`` operator. | ||
divmod : Simultaneous floor division and remainder. | ||
fmod : Equivalent of the Matlab(TM) ``rem`` function. | ||
divide, floor | ||
|
||
|
@@ -2860,6 +2869,47 @@ def add_newdoc(place, name, doc): | |
|
||
""") | ||
|
||
add_newdoc('numpy.core.umath', 'divmod', | ||
""" | ||
Return element-wise quotient and remainder simultaneously. | ||
|
||
.. versionadded:: 1.13.0 | ||
|
||
``np.divmod(x, y)`` is equivalent to ``(x // y, x % y)``, but faster | ||
because it avoids redundant work. It is used to implement the Python | ||
built-in function ``divmod`` on NumPy arrays. | ||
|
||
Parameters | ||
---------- | ||
x1 : array_like | ||
Dividend array. | ||
x2 : array_like | ||
Divisor array. | ||
out : tuple of ndarray, optional | ||
Arrays into which the output is placed. Their types are preserved and | ||
must be of the right shape to hold the output. | ||
|
||
Returns | ||
------- | ||
out1 : ndarray | ||
Element-wise quotient resulting from floor division. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The quotient is the result of floor division, but the remainder is a by-product. So I think the current language makes sense (but I'm open to alternatives if you have a concrete suggestion). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced results and byproducts are disjoint sets, but I'm happy to leave this as is based on your rationale. |
||
out2 : ndarray | ||
Element-wise remainder from floor division. | ||
|
||
See Also | ||
-------- | ||
floor_divide : Equivalent to Python's ``//`` operator. | ||
remainder : Equivalent to Python's ``%`` operator. | ||
modf : Equivalent to ``divmod(x, 1)`` for positive ``x`` with the return | ||
values switched. | ||
|
||
Examples | ||
-------- | ||
>>> np.divmod(np.arange(5), 3) | ||
(array([0, 0, 0, 1, 1]), array([0, 1, 2, 0, 1])) | ||
|
||
""") | ||
|
||
add_newdoc('numpy.core.umath', 'right_shift', | ||
""" | ||
Shift the bits of an integer to the right. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth pointing out that the builtin- I'm an idiot, you've already done thisdivmod
now dispatches to thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And before release I'm going to gather all the new ufuncs into a
New ufuncs
section. There are enough of them in the 1.13 release to justify that.