support python mlx.array creation from list of mlx.array's
Proposed changes
Adds support for python mlx.array create from list of mlx.array's. Trying to tackle issue 287.
Checklist
Put an x in the boxes that apply.
- [x] I have read the CONTRIBUTING document
- [x] I have run
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes - [x] I have added tests that prove my fix is effective or that my feature works
- [ ] I have updated the necessary documentation (if needed)
Thanks for adding this. I was thinking we should use concatenate and have this be part of the compute graph rather than force an eval.
Concretely when you do mx.array([a1, ...]), it's basically using concatenate under the hood. Does that make sense?
@awni Thanks. I see, yeah that makes sense. I am gonna renovate the code a bit.
Hi @awni ! May I bug you to review again? Thanks! And... Happy New Year 🥳
Hi @Alex-X-W ,
There's two things I think we need to fix with this:
- The main point to using stack is to avoid needing to eval the input arrays. I see that you eval them then get the raw pointer based on the type and copy it. That should change to be much simpler. Just put the arrays in a vector, the stack will handle type promotion.
- If you are creating an array from a big list (or list of lists) of python scalars it will be really inefficient to convert these to arrays and do a stack. I would change the code so that when there is no nested array it follows a different path and puts the values in vector of the appropriate type and then uses the array constructor.
Thank you @awni for the pointers! They all make sense to me. Please help take another look, thanks!
PS checked cpu/gpu tests pass + formatting passes