|
66 | 66 | "isfinite",
|
67 | 67 | "isinf",
|
68 | 68 | "isnan",
|
| 69 | + "isneginf", |
| 70 | + "isposinf", |
69 | 71 | "less",
|
70 | 72 | "less_equal",
|
71 | 73 | "logical_and",
|
@@ -710,6 +712,134 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
710 | 712 | )
|
711 | 713 |
|
712 | 714 |
|
| 715 | +def isneginf(x, out=None): |
| 716 | + """ |
| 717 | + Test element-wise for negative infinity, return result as bool array. |
| 718 | +
|
| 719 | + For full documentation refer to :obj:`numpy.isneginf`. |
| 720 | +
|
| 721 | + Parameters |
| 722 | + ---------- |
| 723 | + x : {dpnp.ndarray, usm_ndarray} |
| 724 | + Input array. |
| 725 | + out : {None, dpnp.ndarray, usm_ndarray}, optional |
| 726 | + A location into which the result is stored. If provided, it must have a |
| 727 | + shape that the input broadcasts to and a boolean data type. |
| 728 | + If not provided or None, a freshly-allocated boolean array is returned |
| 729 | +
|
| 730 | + Returns |
| 731 | + ------- |
| 732 | + out : dpnp.ndarray |
| 733 | + Boolean array of same shape as ``x``. |
| 734 | +
|
| 735 | + See Also |
| 736 | + -------- |
| 737 | + :obj:`dpnp.isinf` : Test element-wise for positive or negative infinity. |
| 738 | + :obj:`dpnp.isposinf` : Test element-wise for positive infinity, |
| 739 | + return result as bool array. |
| 740 | + :obj:`dpnp.isnan` : Test element-wise for NaN and |
| 741 | + return result as a boolean array. |
| 742 | + :obj:`dpnp.isfinite` : Test element-wise for finiteness. |
| 743 | +
|
| 744 | + Examples |
| 745 | + -------- |
| 746 | + >>> import dpnp as np |
| 747 | + >>> x = np.array(np.inf) |
| 748 | + >>> np.isneginf(-x) |
| 749 | + array(True) |
| 750 | + >>> np.isneginf(x) |
| 751 | + array(False) |
| 752 | +
|
| 753 | + >>> x = np.array([-np.inf, 0., np.inf]) |
| 754 | + >>> np.isneginf(x) |
| 755 | + array([ True, False, False]) |
| 756 | +
|
| 757 | + >>> x = np.array([-np.inf, 0., np.inf]) |
| 758 | + >>> y = np.zeros(x.shape, dtype='bool') |
| 759 | + >>> np.isneginf(x, y) |
| 760 | + array([ True, False, False]) |
| 761 | + >>> y |
| 762 | + array([ True, False, False]) |
| 763 | +
|
| 764 | + """ |
| 765 | + |
| 766 | + is_inf = dpnp.isinf(x) |
| 767 | + try: |
| 768 | + signbit = dpnp.signbit(x) |
| 769 | + except ValueError as e: |
| 770 | + dtype = x.dtype |
| 771 | + raise TypeError( |
| 772 | + f"This operation is not supported for {dtype} values " |
| 773 | + "because it would be ambiguous." |
| 774 | + ) from e |
| 775 | + |
| 776 | + return dpnp.logical_and(is_inf, signbit, out) |
| 777 | + |
| 778 | + |
| 779 | +def isposinf(x, out=None): |
| 780 | + """ |
| 781 | + Test element-wise for positive infinity, return result as bool array. |
| 782 | +
|
| 783 | + For full documentation refer to :obj:`numpy.isposinf`. |
| 784 | +
|
| 785 | + Parameters |
| 786 | + ---------- |
| 787 | + x : {dpnp.ndarray, usm_ndarray} |
| 788 | + Input array. |
| 789 | + out : {None, dpnp.ndarray, usm_ndarray}, optional |
| 790 | + A location into which the result is stored. If provided, it must have a |
| 791 | + shape that the input broadcasts to and a boolean data type. |
| 792 | + If not provided or None, a freshly-allocated boolean array is returned |
| 793 | +
|
| 794 | + Returns |
| 795 | + ------- |
| 796 | + out : dpnp.ndarray |
| 797 | + Boolean array of same shape as ``x``. |
| 798 | +
|
| 799 | + See Also |
| 800 | + -------- |
| 801 | + :obj:`dpnp.isinf` : Test element-wise for positive or negative infinity. |
| 802 | + :obj:`dpnp.isneginf` : Test element-wise for negative infinity, |
| 803 | + return result as bool array. |
| 804 | + :obj:`dpnp.isnan` : Test element-wise for NaN and |
| 805 | + return result as a boolean array. |
| 806 | + :obj:`dpnp.isfinite` : Test element-wise for finiteness. |
| 807 | +
|
| 808 | + Examples |
| 809 | + -------- |
| 810 | + >>> import dpnp as np |
| 811 | + >>> x = np.array(np.inf) |
| 812 | + >>> np.isposinf(x) |
| 813 | + array(True) |
| 814 | + >>> np.isposinf(-x) |
| 815 | + array(False) |
| 816 | +
|
| 817 | + >>> x = np.array([-np.inf, 0., np.inf]) |
| 818 | + >>> np.isposinf(x) |
| 819 | + array([False, False, True]) |
| 820 | +
|
| 821 | + >>> x = np.array([-np.inf, 0., np.inf]) |
| 822 | + >>> y = np.zeros(x.shape, dtype='bool') |
| 823 | + >>> np.isposinf(x, y) |
| 824 | + array([False, False, True]) |
| 825 | + >>> y |
| 826 | + array([False, False, True]) |
| 827 | +
|
| 828 | + """ |
| 829 | + |
| 830 | + is_inf = dpnp.isinf(x) |
| 831 | + try: |
| 832 | + signbit = ~dpnp.signbit(x) |
| 833 | + except ValueError as e: |
| 834 | + dtype = x.dtype |
| 835 | + raise TypeError( |
| 836 | + f"This operation is not supported for {dtype} values " |
| 837 | + "because it would be ambiguous." |
| 838 | + ) from e |
| 839 | + |
| 840 | + return dpnp.logical_and(is_inf, signbit, out) |
| 841 | + |
| 842 | + |
713 | 843 | _LESS_DOCSTRING = """
|
714 | 844 | Computes the less-than test results for each element `x1_i` of
|
715 | 845 | the input array `x1` with the respective element `x2_i` of the input array `x2`.
|
|
0 commit comments