Skip to content

ufunc comparisons are not equivalent to arithmetic comparison operators #77

Closed
@ev-br

Description

@ev-br

Consider

In [1]: import array_api_strict as xp

In [2]: M = 6

In [3]: n = xp.arange(0, M, dtype=xp.float64)

In [4]: n <= (M-1)/2.0
Out[4]: 
Array([ True,  True,  True, False, False,
       False], dtype=array_api_strict.bool)

In [5]: xp.less_equal(n, (M-1)/2.0)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 1
----> 1 xp.less_equal(n, (M-1)/2.0)

File ~/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/array_api_strict/_elementwise_functions.py:539, in less_equal(x1, x2)
    533 def less_equal(x1: Array, x2: Array, /) -> Array:
    534     """
    535     Array API compatible wrapper for :py:func:`np.less_equal <numpy.less_equal>`.
    536 
    537     See its docstring for more information.
    538     """
--> 539     if x1.dtype not in _real_numeric_dtypes or x2.dtype not in _real_numeric_dtypes:
    540         raise TypeError("Only real numeric dtypes are allowed in less_equal")
    541     # Call result type here just to raise on disallowed type combinations

AttributeError: 'float' object has no attribute 'dtype'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions