-
Notifications
You must be signed in to change notification settings - Fork 54
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
Support MLXArray initialization from nested Swift Arrays #161
Comments
I need to play around with that. We can certainly do it for a fixed number of dimensions (we need an initializer for each number of dimensions). Maybe we can do something fancy with generics and gt an arbitrary number, but I think the types will be tricky. |
MLXArray to nested Swift arrays would also be handy (I find that I'm re-writing this code a lot). |
How do you deal with the return type? |
I’ve just been working with 2D matrices, and flipping between MLXArray and [[Float]], so pretty pedestrian but probably one of the most common use cases. Maybe I missed asArray2, is that already a thing? |
No, not a thing -- just pondering how the types would work. |
Oh I see! Yes, I’d imagine what you have would be useful for T: HasDType in very much the same way asArray works now, but maintaining the shape in Swift’s array. I don’t know how to gracefully handle cases where shape doesn’t match, but I think it would be fair to throw an error much like the other precondition checks in MLX. |
This is mostly a convenience but it can be quite handy and we support it in Python:
The text was updated successfully, but these errors were encountered: