oneflow.nn.ReplicationPad1d

class oneflow.nn.ReplicationPad1d(padding)

Pads the input tensor using replication of the input boundary.

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

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

Parameters

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

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

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

    \(W_{out} = W_{in} + \text{padding_left} + \text{padding_right}\)

For example:

>>> import numpy as np
>>> import oneflow as flow
>>> m = flow.nn.ReplicationPad1d((2, 2))
>>> input = flow.tensor(np.arange(18).reshape((2, 3, 3)).astype(np.float32))
>>> out = m(input)
>>> out
tensor([[[ 0.,  0.,  0.,  1.,  2.,  2.,  2.],
         [ 3.,  3.,  3.,  4.,  5.,  5.,  5.],
         [ 6.,  6.,  6.,  7.,  8.,  8.,  8.]],

        [[ 9.,  9.,  9., 10., 11., 11., 11.],
         [12., 12., 12., 13., 14., 14., 14.],
         [15., 15., 15., 16., 17., 17., 17.]]], dtype=oneflow.float32)