Skip to main content

QPad2D

Struct QPad2D 

Source
pub struct QPad2D<const PT: usize, const PB: usize, const PL: usize, const PR: usize> {
    pub pad_value: i8,
}
Expand description

Explicit spatial padding of an NHWC tensor with a constant (C++ QPad2D, TFLite PAD): PT rows above, PB below, PL columns on the left and PR on the right, each holding pad_value in every channel. The convolution layers pad by themselves; this is for models with a separate PAD operator. The output must be H + PT + PB by W + PL + PR, or the call does not compile.

use tinymind::int8::QPad2D;

let input = [[[1i8, 2]; 2]; 1];
let mut padded = [[[0i8; 2]; 3]; 2]; // one row below, one column on the left
QPad2D::<0, 1, 1, 0> { pad_value: -7 }.forward(&input, &mut padded);
assert_eq!(padded, [[[-7, -7], [1, 2], [1, 2]], [[-7, -7]; 3]]);

A padded size that does not add up does not compile:

ⓘ
let input = [[[1i8, 2]; 2]; 1];
let mut padded = [[[0i8; 2]; 4]; 2]; // 4 columns: 2 + 1 + 0 is 3
QPad2D::<0, 1, 1, 0> { pad_value: -7 }.forward(&input, &mut padded);

Fields§

§pad_value: i8

The value every padded element holds: the tensor’s zero point for a real 0.0, as TFLite pads.

Implementations§

Source§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> QPad2D<PT, PB, PL, PR>

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], )

Pad an H x W x C input into an OH x OW x C output.

Trait Implementations§

Source§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Clone for QPad2D<PT, PB, PL, PR>

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 PT: usize, const PB: usize, const PL: usize, const PR: usize> Copy for QPad2D<PT, PB, PL, PR>

Source§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Debug for QPad2D<PT, PB, PL, PR>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Eq for QPad2D<PT, PB, PL, PR>

Source§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> PartialEq for QPad2D<PT, PB, PL, PR>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> StructuralPartialEq for QPad2D<PT, PB, PL, PR>

Auto Trait Implementations§

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Freeze for QPad2D<PT, PB, PL, PR>

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> RefUnwindSafe for QPad2D<PT, PB, PL, PR>

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Send for QPad2D<PT, PB, PL, PR>

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Sync for QPad2D<PT, PB, PL, PR>

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> Unpin for QPad2D<PT, PB, PL, PR>

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> UnsafeUnpin for QPad2D<PT, PB, PL, PR>

§

impl<const PT: usize, const PB: usize, const PL: usize, const PR: usize> UnwindSafe for QPad2D<PT, PB, PL, PR>

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.