Add copy keyword to mx.asarray#3510
Conversation
zcbenz
left a comment
There was a problem hiding this comment.
The copy parameter only makes sense if the framework supports in-place operation and you want to make a deep copy whose content would stay unchanged when the original copied array got an in-place update. But since MLX has no in-place operation and the supposed use case would never happen.
So I think the best way to support copy parameter is to simply throw when copy=False is passed and return create_array(a, dtype) otherwise like before. Because copy=False means shallow-copy which makes no sense in MLX, and code using copy=True|None would stay semantically correct.
074ec2b to
7e60107
Compare
|
Makes sense, reworked it that way: |
zcbenz
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
Proposed changes
mx.asarraydoesn't accept thecopykeyword from the array-API spec. References #3484.This adds
copyas a keyword-only argument. MLX has no in-place operations, so a non-copying conversion isn't meaningful:copy=FalseraisesValueError, andcopy=Trueor unspecified behave the same as before.The
from_dlpackhalf of #3484 is left out, since PR #3495 reworks dlpack consumption through themx.array(...)constructor and the namespace wiring depends on that landing.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes