Skip to content

equal

Computes the truth value of x1_i == x2_i for each element x1_i of the input array x1 with the respective element x2_i of the input array x2.

Parameters:

Name Type Description Default
x1

first input array. May have any data type.

required
x2

second input array. Must be compatible with x1. May have any data type.

required

Returns:

Name Type Description
out array

an array containing the element-wise results. The returned array is of data type of bool.

Special Cases

For real-valued floating-point operands,

  • If x1_i is NaN or x2_i is NaN, the result is False.
  • If x1_i is +infinity and x2_i is +infinity, the result is True.
  • If x1_i is -infinity and x2_i is -infinity, the result is True.
  • If x1_i is -0 and x2_i is either +0 or -0, the result is True.
  • If x1_i is +0 and x2_i is either +0 or -0, the result is True.
  • If x1_i is a finite number, x2_i is a finite number, and x1_i equals x2_i, the result is True.
  • In the remaining cases, the result is False.

For complex floating-point operands, let a = real(x1_i), b = imag(x1_i), c = real(x2_i), d = imag(x2_i), and

  • If a, b, c, or d is NaN, the result is False.
  • In the remaining cases, the result is the logical AND of the equality comparison between the real values a and c (real components) and between the real values b and d (imaginary components), as described above for real-valued floating-point operands (i.e., a == c AND b == d).

Examples:

>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
>>> b = sparse.COO.from_numpy(np.array([[0, 1], [1, 0]]))
>>> o = sparse.equal(a, b)
>>> o.todense()
array([[ True,  True],
       [ False,  True]])
Source code in sparse/numba_backend/_common.py
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
def equal(x1, x2, /):
    """
    Computes the truth value of ``x1_i == x2_i`` for each element ``x1_i`` of the input array ``x1``
    with the respective element ``x2_i`` of the input array ``x2``.

    Parameters
    ----------
    x1: array
        first input array. May have any data type.
    x2: array
        second input array. Must be compatible with ``x1``. May have any data type.

    Returns
    -------
    out: array
        an array containing the element-wise results. The returned array is of  data type of ``bool``.

    Special Cases
    -------------

    For real-valued floating-point operands,

    - If ``x1_i`` is ``NaN`` or ``x2_i`` is ``NaN``, the result is ``False``.
    - If ``x1_i`` is ``+infinity`` and ``x2_i`` is ``+infinity``, the result is ``True``.
    - If ``x1_i`` is ``-infinity`` and ``x2_i`` is ``-infinity``, the result is ``True``.
    - If ``x1_i`` is ``-0`` and ``x2_i`` is either ``+0`` or ``-0``, the result is ``True``.
    - If ``x1_i`` is ``+0`` and ``x2_i`` is either ``+0`` or ``-0``, the result is ``True``.
    - If ``x1_i`` is a finite number, ``x2_i`` is a finite number, and ``x1_i`` equals ``x2_i``, the result is ``True``.
    - In the remaining cases, the result is ``False``.

    For complex floating-point operands, let ``a = real(x1_i)``, ``b = imag(x1_i)``, ``c = real(x2_i)``,
    ``d = imag(x2_i)``, and

    - If ``a``, ``b``, ``c``, or ``d`` is ``NaN``, the result is ``False``.
    - In the remaining cases, the result is the logical AND of the equality comparison between the real values ``a``
        and ``c`` (real components) and between the real values ``b`` and ``d`` (imaginary components), as described
        above for real-valued  floating-point operands (i.e., ``a == c AND b == d``).

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
    >>> b = sparse.COO.from_numpy(np.array([[0, 1], [1, 0]]))
    >>> o = sparse.equal(a, b)  # doctest: +SKIP
    >>> o.todense()  # doctest: +SKIP
    array([[ True,  True],
           [ False,  True]])
    """
    return x1 == x2