Skip to main content

full_like

Function full_like 

Source
pub fn full_like(
    input: impl AsRef<Array>,
    values: impl AsRef<Array>,
    dtype: impl Into<Option<Dtype>>,
) -> Result<Array>
Expand description

An array filled with the given value, with the same shape as the input.

§Params

  • input: Input array to take shape from
  • values: Value(s) to fill the array with
  • dtype: Optional dtype for the output array. Defaults to the dtype of the input array.
  • stream: Stream to run the operation on

§Example

use mlx_rs::{Array, Dtype, ops::full_like};

let a = Array::from_slice(&[1i32, 2, 3], &[3]);
// Fill with same dtype as input
let b = full_like(&a, &Array::from_f32(7.0), None).unwrap();
assert_eq!(b.dtype(), Dtype::Int32);

// Fill with specified dtype
let c = full_like(&a, &Array::from_f32(7.5), Some(Dtype::Float32)).unwrap();
assert_eq!(c.dtype(), Dtype::Float32);