BUG: torch.maximum: does not accept `float` for `x1`

Open
#410 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python, pytorch
Domain
tooling

Research direction

Start at scipy/sparse/linalg/_isolve/iterative.py:_get_atol_rtol and trace the vendored array-api-compat 1.14 torch.maximum wrapper shown in the traceback. Reproduce xp.maximum(0.0, tensor) with the affected PyTorch backend and compare its behavior with the linked Array API specification. Done means the documented scalar-and-array call no longer raises this TypeError.

Written by the indexing model from the issue text.

Description

scipy/sparse/linalg/_isolve/iterative.py:25: in _get_atol_rtol
    atol = xp.maximum(atol, rtol * b_norm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        atol       = 0.0
        b_norm     = tensor([], size=(0, 1), dtype=torch.float32)
        name       = 'cg'
        rtol       = 0.0015
        xp         = <module 'scipy._external.array_api_compat.torch' from '/Users/lucascolley/ghq/github.com/scipy/scipy/build-cpu-install/usr/lib/python3.13/site-packages/scipy/_external/array_api_compat/torch/__init__.py'>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x1 = 0.0, x2 = tensor([], size=(0, 1), dtype=torch.float32), kwargs = {}

    @_wraps(f)
    def _f(x1, x2, /, **kwargs):
        x1, x2 = _fix_promotion(x1, x2)
>       return f(x1, x2, **kwargs)
               ^^^^^^^^^^^^^^^^^^^
E       TypeError: maximum(): argument 'input' (position 1) must be Tensor, not float

This is with array-api-compat at the vendored 1.14 tag in SciPy.

This contradicts https://data-apis.org/array-api/2025.12/API_specification/generated/array_api.maximum.html#maximum.

Dominant language
Python
Stars
131
Forks
49
Avg merge
2d 8h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from data-apis/array-api-compat

All issues in data-apis/array-api-compat

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.