Skip to content

feat: add shape manipulation ops on Array#6

Open
kerthcet wants to merge 2 commits into
InftyAI:mainfrom
kerthcet:feat/shape-manipulation
Open

feat: add shape manipulation ops on Array#6
kerthcet wants to merge 2 commits into
InftyAI:mainfrom
kerthcet:feat/shape-manipulation

Conversation

@kerthcet

Copy link
Copy Markdown
Member

What this PR does / why we need it

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

Does this PR introduce a user-facing change?


Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings July 21, 2026 23:12
@InftyAI-Agent InftyAI-Agent added needs-triage Indicates an issue or PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. do-not-merge/needs-kind Indicates a PR lacks a label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds shape-manipulation operations to mlxcore::Array and updates host extraction (to_vec) to correctly handle non-contiguous views by materializing a row-contiguous buffer first. This expands the safe Rust surface area over MLX-C’s shape/view operators and makes to_vec semantics consistent for transposed/broadcasted arrays.

Changes:

  • Update Array::to_vec to materialize a row-contiguous copy before reading via raw data pointers (fixing transpose/broadcast cases).
  • Add shape/view ops on Array: contiguous, reshape, broadcast_to, transpose, squeeze, expand_dims.
  • Add unit tests covering reshape/transpose/broadcast/squeeze+expand_dims.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/mlxcore/src/array.rs Outdated
Comment thread crates/mlxcore/src/array.rs
Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings July 22, 2026 07:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment on lines +136 to +139
let contiguous = self.contiguous(&Stream::cpu()).unwrap_or_else(|e| {
panic!("to_vec: failed to make array contiguous: {e}");
});
contiguous.eval();
pub fn expand_dims(&self, axis: i32, stream: &Stream) -> Result<Array> {
error::install();
let mut out = unsafe { sys::mlx_array_new() };
// SAFETY: handle/stream are valid; `op` writes the result into `out`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/needs-kind Indicates a PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. needs-triage Indicates an issue or PR lacks a label and requires one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants