Skip to main content

QAvgPool2D

Struct QAvgPool2D 

Source
pub struct QAvgPool2D<const PH: usize, const PW: usize, const SH: usize = PH, const SW: usize = PW> {
    pub qmin: i8,
    pub qmax: i8,
}
Expand description

Average pooling over PH x PW windows at strides SH, SW (default: the window size), no padding: the window’s sum divided by its area, rounded half away from zero, then clamped to [qmin, qmax] (C++ QAvgPool2D).

Fields§

§qmin: i8

Lowest output value.

§qmax: i8

Highest output value.

Implementations§

Source§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> QAvgPool2D<PH, PW, SH, SW>

Source

pub fn forward<const H: usize, const W: usize, const C: usize, const OH: usize, const OW: usize>( &self, input: &[[[i8; C]; W]; H], output: &mut [[[i8; C]; OW]; OH], )

One forward pass; sizes as in QMaxPool2D::forward.

Examples found in repository?
examples/common/imported_cnn_flat_model.rs (line 190)
186pub fn forward(input: &Input) -> [i8; NUM_OUTPUTS] {
187    let mut x0 = [[[0i8; 5]; 10]; 4];
188    CONV1.forward(input, &mut x0);
189    let mut x2 = [[[0i8; 5]; 5]; 2];
190    POOL1.forward(&x0, &mut x2);
191    // `flat`: flatten `pool1` (2x5x5) in NHWC order.
192    let mut x4 = [0i8; 50];
193    for (out, &v) in x4.iter_mut().zip(x2.iter().flatten().flatten()) {
194        *out = v;
195    }
196    let x9 = FC1.forward(&x4).map(|v| qrelu(v, RELU2_ZERO_POINT));
197    let x10 = FC2.forward(&x9);
198    x10.map(|v| apply_lut(v, &OUT_LUT))
199}
More examples
Hide additional examples
examples/common/imported_cnn_driver.rs (line 115)
101fn run_cnn_flat(out: &mut dyn Write) -> io::Result<()> {
102    print_rq(out, "cnn_flat", "conv1", &cnn_flat::CONV1.requantizer)?;
103    print_rq(out, "cnn_flat", "fc1", &cnn_flat::FC1.requantizer)?;
104    print_rq(out, "cnn_flat", "fc2", &cnn_flat::FC2.requantizer)?;
105    writeln!(
106        out,
107        "cnn_flat lut fnv=0x{:08X}",
108        fnv(0x811C_9DC5, &cnn_flat::OUT_LUT)
109    )?;
110    for s in 0..16 {
111        let x: cnn_flat::Input = input(s, cnn_flat::INPUT_SCALE, cnn_flat::INPUT_ZERO_POINT);
112        let mut a1 = [[[0i8; 5]; 10]; 4];
113        cnn_flat::CONV1.forward(&x, &mut a1);
114        let mut p1 = [[[0i8; 5]; 5]; 2];
115        cnn_flat::POOL1.forward(&a1, &mut p1);
116        let mut flat = [0i8; 50];
117        for (o, &v) in flat.iter_mut().zip(p1.iter().flatten().flatten()) {
118            *o = v;
119        }
120        let h1 = cnn_flat::FC1
121            .forward(&flat)
122            .map(|v| qrelu(v, cnn_flat::RELU2_ZERO_POINT));
123        let lg = cnn_flat::FC2.forward(&h1);
124        let mut h = 0x811C_9DC5;
125        h = fnv(h, a1.iter().flatten().flatten());
126        h = fnv(h, p1.iter().flatten().flatten());
127        h = fnv(h, &h1);
128        h = fnv(h, &lg);
129        let y = cnn_flat::forward(&x);
130        writeln!(out, "cnn_flat s={s} layers=0x{h:08X} out={},{}", y[0], y[1])?;
131    }
132    Ok(())
133}

Trait Implementations§

Source§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Clone for QAvgPool2D<PH, PW, SH, SW>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Copy for QAvgPool2D<PH, PW, SH, SW>

Source§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Debug for QAvgPool2D<PH, PW, SH, SW>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Forget for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Freeze for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Move for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> RefUnwindSafe for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Send for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Sync for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> Unpin for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> UnsafeUnpin for QAvgPool2D<PH, PW, SH, SW>

§

impl<const PH: usize, const PW: usize, const SH: usize, const SW: usize> UnwindSafe for QAvgPool2D<PH, PW, SH, SW>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.