oneflow.nn.ConstantPad1d

class oneflow.nn.ConstantPad1d(padding)

Pads the input tensor boundaries with a constant value.

The interface is consistent with PyTorch, and referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.ConstantPad1d.html.

For N-dimensional padding, use torch.nn.functional.pad().

Parameters
  • padding (int, list, tuple) – the size of the padding. If is int, uses the same padding in both boundaries. If a 2-tuple, uses (\(\text{padding_left}\), \(\text{padding_right}\))

  • value (int, float) – The constant value used for padding. Defaults to 0.

Shape:
  • Input: \((N, C, W_{in})\)

  • Output: \((N, C, W_{out})\) where

    \(W_{out} = W_{in} + \text{padding\_left} + \text{padding\_right}\)

For example:

>>> import oneflow as flow
>>> import numpy as np

>>> input = flow.tensor(np.arange(8).reshape(2,2,2).astype(np.float32))
>>> m = flow.nn.ConstantPad1d(padding=[1, 2], value=9.9999)
>>> output = m(input)
>>> output
tensor([[[9.9999, 0.0000, 1.0000, 9.9999, 9.9999],
         [9.9999, 2.0000, 3.0000, 9.9999, 9.9999]],

        [[9.9999, 4.0000, 5.0000, 9.9999, 9.9999],
         [9.9999, 6.0000, 7.0000, 9.9999, 9.9999]]], dtype=oneflow.float32)