Skip to main content

vectorize

Function vectorize 

Source
pub fn vectorize<T, U, F>(
    f: F,
) -> impl Fn(&Array<T, Ix1>) -> FerrayResult<Array<U, Ix1>>
where T: Element + Copy, U: Element, F: Fn(T) -> U,
Expand description

Wrap a scalar function to operate elementwise on arrays.

Returns a closure that accepts &Array<T, D> and returns FerrayResult<Array<U, D>>, applying f to every element.

This is NumPy’s np.vectorize — in Rust it is essentially .mapv() wrapped as a reusable callable.

§Example

let square = vectorize(|x: f64| x * x);
let result = square(&input_array)?;