custom_reduce

Function custom_reduce 

Source
pub fn custom_reduce<T, F>(
    input: &DenseND<T>,
    axes: &[Axis],
    init_value: T,
    reduce_fn: F,
) -> Result<DenseND<T>>
where T: Clone + Num + AddAssign, F: Fn(T, T) -> T,
Expand description

Custom reduction operation with user-defined reduction function

§Arguments

  • input - Input tensor
  • axes - Axes along which to reduce (empty = reduce all)
  • init_value - Initial value for the reduction
  • reduce_fn - Binary reduction function: (accumulator, element) -> new_accumulator

§Example

// Compute product along axis 0
custom_reduce(&tensor, &[0], 1.0, |acc, x| acc * x)?;