Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add array #25

Merged
merged 12 commits into from
Apr 17, 2024
Merged

feat(api): add array #25

merged 12 commits into from
Apr 17, 2024

Conversation

minghuaw
Copy link
Collaborator

This is an initial implementation of the safe rust wrapper of mlx array.

Below are some problems found that should probably be discussed (and hopefully resolved)

  1. The c api doesn't expose c++ exceptions, which would cause a fatal runtime error
    fatal runtime error: Rust cannot catch foreign exceptions
  2. The Array type should probably NOT implement the Clone trait? Because the c struct mlx_array is atomically reference counted but not protected by Mutex
  3. A good type alias for num_complex::Complex<f32>, c64 (the current one) or complex64. Complex64 should probably be avoided because num_complex::Complex64 is actually num_complex::Complex<f64>

There is one thing that we probably want to double check after implementing ops

For mlx_array_data_* methods, the mlx doc says

Array must be evaluated, otherwise returns NULL.

@minghuaw minghuaw marked this pull request as draft April 17, 2024 04:07
@minghuaw minghuaw marked this pull request as ready for review April 17, 2024 04:23
@minghuaw minghuaw changed the base branch from main to dev April 17, 2024 04:23
Copy link
Contributor

@dcvz dcvz left a comment

Choose a reason for hiding this comment

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

It's looking pretty good! Left some comments around. I usually also like to add rust code examples in the docs -- but I know that's cumbersome, so feel free to not do it.

Looking awesome!

src/array.rs Outdated Show resolved Hide resolved
src/array.rs Outdated Show resolved Hide resolved
src/array.rs Show resolved Hide resolved
src/array.rs Show resolved Hide resolved
src/array.rs Outdated Show resolved Hide resolved
src/array.rs Show resolved Hide resolved
src/array.rs Show resolved Hide resolved
src/array.rs Outdated Show resolved Hide resolved
src/array.rs Outdated Show resolved Hide resolved
src/array.rs Show resolved Hide resolved
@dcvz dcvz mentioned this pull request Apr 17, 2024
src/array.rs Show resolved Hide resolved
@minghuaw minghuaw merged commit be3f3c6 into dev Apr 17, 2024
3 checks passed
@minghuaw minghuaw deleted the api/array branch April 17, 2024 16:18
minghuaw added a commit that referenced this pull request Jul 16, 2024
* deny unused_unsafe

* init impl of rust wrapper of array

* moved TODO

* fmt and fix clippy

* rename c64 to complex64 and itemsize() to item_size()

* rename ptr to c_array

* restore Clone and Copy derive for Dtype

* added 2d array unit test

* moved Dtype to mod dtype

* fn from_slice infer dim from shape

* check dim in rust

* as_slice returns None if not evaled
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