feat: support more ops#5
Conversation
Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR expands the mlxcore::Array safe wrapper API to cover additional elementwise unary/binary operations and axis-specific reductions, aligning the Rust surface area more closely with the underlying MLX C API.
Changes:
- Add new unary ops on
Array:log,sin,cos,square,tanh. - Add new binary ops on
Array:power,maximum,minimum. - Add axis-specific reductions (
*_axes) via a new sharedreduce_axes_ophelper, plus unit tests covering the added ops.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/kind feature |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
crates/mlxcore/src/array.rs:520
tanhis added as a new unary op but isn’t covered by the newmore_unary_opstest (other new unary ops are). Adding at least one simple assertion (e.g., tanh(0)=0) would help prevent regressions in this binding.
assert_eq!(
b.negative(&s).unwrap().to_vec::<f32>(),
vec![1.0, -2.0, 3.0]
);
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
crates/mlxcore/src/array.rs:343
- The safety comment around
axes_ptris misleading: passing a null pointer does not make dereferencing safe. The key benefit here is avoiding passing a dangling pointer whenaxes.len() == 0; the C side still must not dereference the pointer whenaxes_num == 0. Updating the wording will prevent readers from assuming null makes dereferencing OK.
// For an empty slice `as_ptr()` is non-null but dangling; pass an
// explicit null pointer so the FFI call never hands C a bogus pointer
// even if it were to dereference it with `axes_num == 0`.
Signed-off-by: kerthcet <kerthcet@gmail.com>
|
/lgtm |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
crates/mlxcore/src/array.rs:209
- Rust doesn’t have a
**operator, so this doc comment can be misleading for Rust API consumers. Consider rephrasing to describe the operation without implying an available operator.
/// Elementwise power: `self ** other`.
| /// Elementwise natural logarithm. | ||
| pub fn log(&self, stream: &Stream) -> Result<Array> { | ||
| self.unary_op(stream, sys::mlx_log) | ||
| } |
|
/hold |
|
/unhold |
InftyAI-Agent
left a comment
There was a problem hiding this comment.
Approved: PR has both lgtm and approved labels
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?