Skip to content

ENH: add mparray backend - #963

Merged
lucascolley merged 2 commits into
data-apis:mainfrom
mdhaber:mparray
Sep 2, 2026
Merged

ENH: add mparray backend#963
lucascolley merged 2 commits into
data-apis:mainfrom
mdhaber:mparray

Conversation

@mdhaber

@mdhaber mdhaber commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Reference issue

Toward scipy/scipy#24840

What does this implement/fix?

This adds MPArray as a tested backend of array-api-extra.

Additional information

Skipping CI until conda-forge has the latest MPArray release (v0.2.0 recently released on PyPI), but tests are passing locally with the editable install.

Are there other things I should do (e.g. update documentation somewhere)?

AI Generation Disclosure

I told ChatGPT to work mparray into the testing. It made some changes so I could see what was needed, then I changed almost everything in some way.

@mdhaber
mdhaber marked this pull request as draft September 1, 2026 21:30
@lucascolley
lucascolley self-requested a review September 1, 2026 21:31
atol=1e-11,
)

@pytest.mark.skip_xp_backend(Backend.MPARRAY, reason="negative zero not supported")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a fundamental limitation of mpmath, it seems. I don't think fixing it is high priority.

Comment thread tests/main/test_lazy.py
Backend.TORCH_GPU, reason="device->host copy"
),
pytest.mark.skip_xp_backend(Backend.SPARSE, reason="densification"),
pytest.mark.skip_xp_backend(Backend.MPARRAY, reason="precision loss"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how as_numpy=True should work. I think np.asarray(my_mparray) currently wraps my_mparray as the only element of an object array. Instead, it could:

  • Extract the underlying object array, but I don't think that's what this is supposed to do.
  • Converted the underlying object array to a numerical NumPy array, but it risks precision loss.
  • Raise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue on the mparray side for this one, given that it isn't entirely clear which way to go yet. That would be sufficient to move forward here



@pytest.mark.skip_xp_backend(Backend.TORCH_GPU, reason="device->host copy")
@pytest.mark.skip_xp_backend(Backend.MPARRAY, reason="mparray lacks __array_ufunc__")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want compiled ufuncs to work on these if they don't preserve the precision; it's probably better to fail. (However, mparray.special will provide a lot of special functions, and scipy.special will be able to delegate to them.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that seems fine to me

Comment thread pixi.toml
Comment thread pixi.toml Outdated
Comment thread tests/main/test_at.py

@lucascolley lucascolley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great to see how small a diff this requires :)

Comment thread src/array_api_extra/_set.py Outdated
Comment thread tests/main/test_at.py
@lucascolley

Copy link
Copy Markdown
Member

why does mparray require Python >=3.13? If that has to stay, we'll probably want to split the backends feature into deps which work back to oldest supported Python, and deps which don't

@mdhaber

mdhaber commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

No, I've been trying to fix the Python 3.13 requirement. It was added because mparray wasn't passing all array-api-tests with NumPy <= 2.5 (mdhaber/mparray#17):

The 2024.12 standard specified that meshgrid and broadcast_arrays should return lists rather than tuples. NumPy < 2.5.2 is supposed to conform to the 2024.12 version of the standard but returns tuples anyway, causing the tests to fail. So I pinned NumPy >= 2.5.2, but that rules out Python 3.10/3.11 unless we want to skip the tests.

But for now, that will just mean we don't run array-api-tests in CI with Python 3.10/3.11. There's no other incompatibility, so now I'm just waiting for mparray 0.2.2 to propagate to conda-forge, then I can update this PR.

@lucascolley lucascolley added enhancement New feature or request testing labels Sep 2, 2026
@mdhaber
mdhaber marked this pull request as ready for review September 2, 2026 17:34
@mdhaber

mdhaber commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I'm happy with this if you are. I can open up issues in the mparray repo about the as_numpy and __array_ufunc__ skips if you're concerned about them.

@lucascolley
lucascolley self-requested a review September 2, 2026 19:30
@lucascolley lucascolley added this to the 0.11.3 milestone Sep 2, 2026

@lucascolley lucascolley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented about one upstream issue that would be nice, otherwise this looks great, thanks Matt!

@lucascolley lucascolley changed the title ENH: add mparray backend ENH: add mparray backend Sep 2, 2026
@mdhaber

mdhaber commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @lucascolley. Opened mdhaber/mparray#22 to remind us to consider lazy_apply(..., as_numpy=True).

@lucascolley
lucascolley merged commit 2072436 into data-apis:main Sep 2, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants