Skip to main content

avg_pool

Function avg_pool 

Source
pub fn avg_pool<B: Backend, T: Float>(
    x: &Array<B, T>,
    window_shape: &[usize],
    strides: Option<&[usize]>,
    padding: impl Into<Padding>,
    count_include_pad: bool,
) -> Array<B, T>
Expand description

The average over windows of the spatial dimensions of an input (*batch, spatial..., features) (flax.linen.avg_pool). With count_include_pad, padding counts as zeros; otherwise each window is divided by the number of elements it covers.

§Examples

use ruxla_core::lax::Padding;
use ruxla_core::{Array, Native};

let x = Array::<Native, f32>::from_vec(vec![1.0, 3.0, 5.0], [1, 3, 1]);
let y = ruxla_nn::avg_pool(&x, &[2], None, Padding::Same, false);
assert_eq!(y.to_vec(), [2.0, 4.0, 5.0]);
let y = ruxla_nn::avg_pool(&x, &[2], None, Padding::Same, true);
assert_eq!(y.to_vec(), [2.0, 4.0, 2.5]);

§Panics

Panics if the window does not fit the input.