|
66 | 66 | DPNPAngle, |
67 | 67 | DPNPBinaryFunc, |
68 | 68 | DPNPBinaryFuncOutKw, |
| 69 | + DPNPBinaryTwoOutputsFunc, |
69 | 70 | DPNPFix, |
70 | 71 | DPNPImag, |
71 | 72 | DPNPReal, |
|
102 | 103 | "cumulative_prod", |
103 | 104 | "cumulative_sum", |
104 | 105 | "diff", |
| 106 | + "divmod", |
105 | 107 | "divide", |
106 | 108 | "ediff1d", |
107 | 109 | "fabs", |
@@ -1630,6 +1632,100 @@ def diff(a, n=1, axis=-1, prepend=None, append=None): |
1630 | 1632 | ) |
1631 | 1633 |
|
1632 | 1634 |
|
| 1635 | +_DIVMOD_DOCSTRING = r""" |
| 1636 | +Calculates the quotient and the remainder for each element :math:`x1_i` of the |
| 1637 | +input array `x1` with the respective element :math:`x2_i` of the input array |
| 1638 | +`x2`. |
| 1639 | +
|
| 1640 | +For full documentation refer to :obj:`numpy.divmod`. |
| 1641 | +
|
| 1642 | +Parameters |
| 1643 | +---------- |
| 1644 | +x1 : {dpnp.ndarray, usm_ndarray} |
| 1645 | + Dividend input array, expected to have a real-valued floating-point data |
| 1646 | + type. |
| 1647 | +x2 : {dpnp.ndarray, usm_ndarray} |
| 1648 | + Divisor input array, expected to have a real-valued floating-point data |
| 1649 | + type. |
| 1650 | +out1 : {None, dpnp.ndarray, usm_ndarray}, optional |
| 1651 | + Output array for the quotient to populate. Array must have the same shape |
| 1652 | + as `x` and the expected data type. |
| 1653 | +
|
| 1654 | + Default: ``None``. |
| 1655 | +out2 : {None, dpnp.ndarray, usm_ndarray}, optional |
| 1656 | + Output array for the remainder to populate. Array must have the same shape |
| 1657 | + as `x` and the expected data type. |
| 1658 | +
|
| 1659 | + Default: ``None``. |
| 1660 | +out : tuple of None, dpnp.ndarray, or usm_ndarray, optional |
| 1661 | + A location into which the result is stored. If provided, it must be a tuple |
| 1662 | + and have length equal to the number of outputs. Each provided array must |
| 1663 | + have the same shape as `x` and the expected data type. |
| 1664 | + It is prohibited to pass output arrays through `out` keyword when either |
| 1665 | + `out1` or `out2` is passed. |
| 1666 | +
|
| 1667 | + Default: ``(None, None)``. |
| 1668 | +order : {None, "C", "F", "A", "K"}, optional |
| 1669 | + Memory layout of the newly output array, if parameter `out` is ``None``. |
| 1670 | +
|
| 1671 | + Default: ``"K"``. |
| 1672 | +
|
| 1673 | +Returns |
| 1674 | +------- |
| 1675 | +quotient : dpnp.ndarray |
| 1676 | + Element-wise quotient resulting from floor division. |
| 1677 | +remainder : dpnp.ndarray |
| 1678 | + Element-wise remainder from floor division. |
| 1679 | +
|
| 1680 | +Limitations |
| 1681 | +----------- |
| 1682 | +Parameters `where`, `dtype` and `subok` are supported with their default values. |
| 1683 | +Keyword argument `kwargs` is currently unsupported. |
| 1684 | +Otherwise ``NotImplementedError`` exception will be raised. |
| 1685 | +
|
| 1686 | +Notes |
| 1687 | +----- |
| 1688 | +At least one of `x1` or `x2` must be an array. |
| 1689 | +
|
| 1690 | +If ``x1.shape != x2.shape``, they must be broadcastable to a common shape |
| 1691 | +(which becomes the shape of the output). |
| 1692 | +
|
| 1693 | +Equivalent to :math:`(x1 // x2, x1 \% x2)`, but faster because it avoids |
| 1694 | +redundant work. It is used to implement the Python built-in function ``divmod`` |
| 1695 | +on :class:`dpnp.ndarray`. |
| 1696 | +
|
| 1697 | +Complex dtypes are not supported, they will raise a ``TypeError``. |
| 1698 | +
|
| 1699 | +See Also |
| 1700 | +-------- |
| 1701 | +:obj:`dpnp.floor_divide` : Equivalent to Python's :math:`//` operator. |
| 1702 | +:obj:`dpnp.remainder` : Equivalent to Python's :math:`\%` operator. |
| 1703 | +:obj:`dpnp.modf` : Equivalent to ``divmod(x, 1)`` for positive `x` with the |
| 1704 | + return values switched. |
| 1705 | +
|
| 1706 | +Examples |
| 1707 | +-------- |
| 1708 | +>>> import dpnp as np |
| 1709 | +>>> np.divmod(np.arange(5), 3) |
| 1710 | +(array([0, 0, 0, 1, 1]), array([0, 1, 2, 0, 1])) |
| 1711 | +
|
| 1712 | +The Python built-in function ``divmod`` function can be used as a shorthand for |
| 1713 | +``np.divmod`` on :class:`dpnp.ndarray`. |
| 1714 | +
|
| 1715 | +>>> x = np.arange(5) |
| 1716 | +>>> divmod(x, 3) |
| 1717 | +(array([0, 0, 0, 1, 1]), array([0, 1, 2, 0, 1])) |
| 1718 | +
|
| 1719 | +""" |
| 1720 | + |
| 1721 | +divmod = DPNPBinaryTwoOutputsFunc( |
| 1722 | + "divmod", |
| 1723 | + ufi._divmod_result_type, |
| 1724 | + ufi._divmod, |
| 1725 | + _DIVMOD_DOCSTRING, |
| 1726 | +) |
| 1727 | + |
| 1728 | + |
1633 | 1729 | def ediff1d(ary, to_end=None, to_begin=None): |
1634 | 1730 | """ |
1635 | 1731 | The differences between consecutive elements of an array. |
@@ -2065,6 +2161,7 @@ def ediff1d(ary, to_end=None, to_begin=None): |
2065 | 2161 | See Also |
2066 | 2162 | -------- |
2067 | 2163 | :obj:`dpnp.remainder` : Remainder complementary to floor_divide. |
| 2164 | +:obj:`dpnp.divmod` : Simultaneous floor division and remainder. |
2068 | 2165 | :obj:`dpnp.divide` : Standard division. |
2069 | 2166 | :obj:`dpnp.floor` : Round a number to the nearest integer toward minus infinity. |
2070 | 2167 | :obj:`dpnp.ceil` : Round a number to the nearest integer toward infinity. |
@@ -2445,7 +2542,7 @@ def ediff1d(ary, to_end=None, to_begin=None): |
2445 | 2542 | """ |
2446 | 2543 |
|
2447 | 2544 | frexp = DPNPUnaryTwoOutputsFunc( |
2448 | | - "_frexp", |
| 2545 | + "frexp", |
2449 | 2546 | ufi._frexp_result_type, |
2450 | 2547 | ufi._frexp, |
2451 | 2548 | _FREXP_DOCSTRING, |
@@ -3207,7 +3304,7 @@ def interp(x, xp, fp, left=None, right=None, period=None): |
3207 | 3304 | """ |
3208 | 3305 |
|
3209 | 3306 | ldexp = DPNPBinaryFunc( |
3210 | | - "_ldexp", |
| 3307 | + "ldexp", |
3211 | 3308 | ufi._ldexp_result_type, |
3212 | 3309 | ufi._ldexp, |
3213 | 3310 | _LDEXP_DOCSTRING, |
@@ -3487,7 +3584,7 @@ def interp(x, xp, fp, left=None, right=None, period=None): |
3487 | 3584 | """ |
3488 | 3585 |
|
3489 | 3586 | modf = DPNPUnaryTwoOutputsFunc( |
3490 | | - "_modf", |
| 3587 | + "modf", |
3491 | 3588 | ufi._modf_result_type, |
3492 | 3589 | ufi._modf, |
3493 | 3590 | _MODF_DOCSTRING, |
@@ -4344,6 +4441,7 @@ def real_if_close(a, tol=100): |
4344 | 4441 | See Also |
4345 | 4442 | -------- |
4346 | 4443 | :obj:`dpnp.fmod` : Calculate the element-wise remainder of division. |
| 4444 | +:obj:`dpnp.divmod` : Simultaneous floor division and remainder. |
4347 | 4445 | :obj:`dpnp.divide` : Standard division. |
4348 | 4446 | :obj:`dpnp.floor` : Round a number to the nearest integer toward minus infinity. |
4349 | 4447 | :obj:`dpnp.floor_divide` : Compute the largest integer smaller or equal to the |
|
0 commit comments