mlx_rs::ops

Function clip_device

Source
pub fn clip_device<'min, 'max>(
    a: impl AsRef<Array>,
    bound: impl ClipBound<'min, 'max>,
    stream: impl AsRef<Stream>,
) -> Result<Array>
Expand description

Clip the values of the array between the given minimum and maximum.

If either a_min or a_max are None, then corresponding edge is ignored. At least one of a_min and a_max cannot be None. The input a and the limits must broadcast with one another.

§Params

  • a: Input array.
  • bound: minimum and/or maximum values to clip the array to.

§Example

use mlx_rs::{Array, ops::clip, array};

let a = array!([1.0, 4.0, 3.0, 8.0, 5.0]);
let expected = array!([2.0, 4.0, 3.0, 6.0, 5.0]);
let clipped = clip(&a, (2.0, 6.0)).unwrap();
assert_eq!(clipped, expected);