Add more array API functions#3684
Open
katlun-lgtm wants to merge 1 commit into
Open
Conversation
Adds array API functions toward ml-explore#3484, all built on existing primitives (no core changes): - Elementwise / utility: positive, logical_xor, trunc, count_nonzero, diff - Creation: full_like, empty, empty_like (empty / empty_like return zeros since MLX does not expose uninitialized memory) - Free functions: astype, matrix_transpose, cumulative_sum, cumulative_prod - Inspection: __array_namespace_info__ (capabilities, default_device, default_dtypes, devices, dtypes) Adds them to the ops docs and tests in test_ops.py / test_array.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Adds a batch of array API functions to
mlx.core, all built on existing primitives (no core/Metal changes):Elementwise / utility
positive(a),logical_xor(a, b),trunc(a)count_nonzero(a, /, *, axis=None, keepdims=False)diff(a, /, n=1, axis=-1, *, prepend=None, append=None)Creation
full_like(a, vals, dtype=None)empty(shape, dtype=...),empty_like(a, dtype=None)— these return zeros, since MLX does not expose uninitialized memoryFree-function wrappers
astype(a, dtype)andmatrix_transpose(a)mirror the existing array method/propertycumulative_sum/cumulative_prodwrapcumsum/cumprodwith the array APIaxis(flatten whenNone),dtype, andinclude_initialsemanticsInspection
__array_namespace_info__()returning an object withcapabilities(),default_device(),default_dtypes(),devices(), anddtypes(kind=...)All added to the ops docs and tested in
test_ops.py/test_array.py. Part of #3484.Checklist
clang-formatandblack(the formatters configured in.pre-commit-config.yaml) report no changes on the modified filestest_ops.py:test_array_api_elementwise,test_diff,test_array_api_creation,test_astype_and_matrix_transpose,test_cumulative_sum_prod;test_array.py:test_array_namespace_info)test_ops.py(144) andtest_array.py(75) suites pass with no regressions