Skip to content

Prevent zero-copy adoption across dtype conversion - #4367

Draft
declanhealy2 wants to merge 1 commit into
ml-explore:mainfrom
declanhealy2:radar/fix-zero-copy-dtype
Draft

Prevent zero-copy adoption across dtype conversion#4367
declanhealy2 wants to merge 1 commit into
ml-explore:mainfrom
declanhealy2:radar/fix-zero-copy-dtype

Conversation

@declanhealy2

Copy link
Copy Markdown
Contributor

When a NumPy buffer is adopted through the zero-copy path, the current conversion code can return a view with the destination dtype even when the source dtype differs. This corrupts values, for example float64 input requested as complex64.

The patch passes the source MLX dtype into the no-copy check and rejects adoption when source and destination dtypes differ, allowing the existing conversion path to preserve values.

Focused validation: python python/tests/test_zero_copy.py (7 passed).

Radar observed this through Array-API backend parity; no Radar tolerance or test was weakened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants