pub struct PadOperation<'c> { /* private fields */ }
Expand description

A pad operation. Tensor pad operation.

tensor.pad is an operation that pads the source tensor with given low and high padding config.

The PadOp operation supports the following arguments:

  • source: the “base” tensor on which to pad.
  • low: A list contains the padding along the start of each dimension, i.e low.
  • high: A list contains the padding along the end of each dimension, i.e. high.
  • nofold: indicates that the operation should not be folded when source and result types are equal.

The result tensor dimensions are low + dim + high along that dimension. The number of elements of low and high must match the rank of the input tensor. They can be either a constant or a dynamic value.

The region of the tensor.pad operation returns the value to use for the padding. The arguments of the region represent the index of the source being accessed. There should be as many arguments as the rank of the source tensor. The value yield-ed by the region is used as the value of the view at the given position.

If nofold is set, the padding operation will not be folded away even if the source type and the padded type have the same static shape. This can be used, e.g., for packing or promotion to faster memory.

Example 1:

  %pad_value = ... : f32
  %0 = tensor.pad %0 low[1, 2] high[2, 3] {
  ^bb0(%arg0 : index, %arg1 : index):
    tensor.yield %pad_value : f32
  } : tensor<?x?xf32> to tensor<?x?xf32>

Example 2:

  %pad_value = ... : f32
  %0 = tensor.pad %arg0 low[2, %arg1, 3, 3] high[3, 3, %arg1, 2] {
  ^bb0(%arg2: index, %arg3: index, %arg4: index, %arg5: index):
      tensor.yield %pad_value : f32
  } : tensor<1x2x2x?xf32> to tensor<6x?x?x?xf32>

Example 3:

  %pad_value = ... : f32
  %0 = tensor.pad %arg0 low[0, 0] high[%ub0, %ub1] {
  ^bb0(%arg1: index, %arg2: index):
    tensor.yield %pad_value : f32
  } : tensor<2x3xf32> to tensor<?x?xf32>

Example 4:

  // Force a padded value to be always exist with `nofold`.
  %pad_value = ... : f32
  %0 = tensor.pad %arg0 nofold low[0, 0] high[0, 0] {
  ^bb0(%arg1: index, %arg2: index):
    tensor.yield %pad_value : f32
  } : tensor<2x3xf32> to tensor<2x3xf32>

Implementations§

source§

impl<'c> PadOperation<'c>

source

pub fn name() -> &'static str

Returns a name.

source

pub fn as_operation(&self) -> &Operation<'c>

Returns a generic operation.

source

pub fn builder( context: &'c Context, location: Location<'c> ) -> PadOperationBuilder<'c, Unset, Unset, Unset, Unset, Unset, Unset, Unset>

Creates a builder.

source

pub fn result(&self) -> Result<OperationResult<'c, '_>, Error>

source

pub fn source(&self) -> Result<Value<'c, '_>, Error>

source

pub fn low(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>

source

pub fn high(&self) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>

source

pub fn region(&self) -> Result<RegionRef<'c, '_>, Error>

source

pub fn static_low(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_static_low(&mut self, value: Attribute<'c>)

source

pub fn static_high(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_static_high(&mut self, value: Attribute<'c>)

source

pub fn nofold(&self) -> Result<Attribute<'c>, Error>

source

pub fn set_nofold(&mut self, value: Attribute<'c>)

source

pub fn remove_nofold(&mut self) -> Result<(), Error>

Trait Implementations§

source§

impl<'c> From<PadOperation<'c>> for Operation<'c>

source§

fn from(operation: PadOperation<'c>) -> Self

Converts to this type from the input type.
source§

impl<'c> TryFrom<Operation<'c>> for PadOperation<'c>

§

type Error = Error

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

fn try_from(operation: Operation<'c>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for PadOperation<'c>

§

impl<'c> !Send for PadOperation<'c>

§

impl<'c> !Sync for PadOperation<'c>

§

impl<'c> Unpin for PadOperation<'c>

§

impl<'c> UnwindSafe for PadOperation<'c>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.