Skip to content

array API: add empty, empty_like (pure aliases), astype, matrix_transpose#3729

Merged
zcbenz merged 2 commits into
ml-explore:mainfrom
katlun-lgtm:array-api-pure-aliases
Jun 21, 2026
Merged

array API: add empty, empty_like (pure aliases), astype, matrix_transpose#3729
zcbenz merged 2 commits into
ml-explore:mainfrom
katlun-lgtm:array-api-pure-aliases

Conversation

@katlun-lgtm

Copy link
Copy Markdown
Contributor

Summary

This is a focused split from #3684, containing only the ops where the implementation is straightforward.

empty / empty_like — pure aliases via m.attr("empty") = m.attr("zeros") and m.attr("empty_like") = m.attr("zeros_like"), following the pattern established in #3678. MLX does not expose uninitialized memory, so zeros are the correct semantic match per the array API spec.

astype — thin free-function wrapper around mx::astype, exposing the Array API §2.0 astype(x, dtype) signature alongside the existing array.astype method.

matrix_transpose — transposes the last two dimensions via mx::swapaxes(a, -2, -1) with an ndim >= 2 guard.

Files changed

  • python/src/ops.cpp — register all four ops in init_ops()
  • docs/src/python/ops.rst — add entries in alphabetical order
  • python/tests/test_ops.pytest_array_api_creation (empty/empty_like) and test_astype_and_matrix_transpose

Related

Split from #3684 per reviewer feedback from @zcbenz.

@katlun-lgtm katlun-lgtm mentioned this pull request Jun 20, 2026
4 tasks
@katlun-lgtm katlun-lgtm force-pushed the array-api-pure-aliases branch from b592fca to 35273e1 Compare June 20, 2026 10:07
katlun-lgtm and others added 2 commits June 21, 2026 17:56
empty/empty_like are pure aliases of zeros/zeros_like via
m.attr("empty") = m.attr("zeros"), matching the pattern from ml-explore#3678.
MLX does not expose uninitialized memory so zeros is the correct
semantic match.

astype exposes mx::astype as a free function (Array API §2.0).
matrix_transpose transposes the last two dimensions and validates
ndim >= 2.

Docs and tests included.

Part of the array API split from ml-explore#3684.
@zcbenz zcbenz force-pushed the array-api-pure-aliases branch from 35273e1 to b4c72ab Compare June 21, 2026 09:02
@zcbenz zcbenz merged commit 602b535 into ml-explore:main Jun 21, 2026
16 checks passed
@katlun-lgtm katlun-lgtm deleted the array-api-pure-aliases branch June 21, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants