class_docstr: Padding arrays to create a matrix.
class_docstr_tok: ["Padding","arrays","to","create","a","matrix","."]
code: def forward(self, xs):
      xp = backend.get_array_module(*xs)
  
      if self.length is None:
          length = max(len(x) for x in xs)
      else:
          length = self.length
  
      shape = (len(xs), length) + xs[0].shape[1:]
      y = xp.empty(shape, xs[0].dtype)
      if length == 0:
          return (y,)  # y is an empty array
  
      if xp is numpy or any(not x._c_contiguous for x in xs):
          for i, x in enumerate(xs):
              l = len(x)
              if l == length:
                  y[i] = x
              else:
                  y[i, 0:l] = x
                  y[i, l:] = self.padding
      else:
          # This code assumes that all arrays are c_contiguous
          ptr_shape = (Ellipsis,) + (None,) * xs[0].ndim
          ptrs = cuda.cupy.array([x.data for x in xs], numpy.uintp)[
              ptr_shape
          ]
          lengths = cuda.cupy.array([len(x) for x in xs], numpy.int32)[
              ptr_shape
          ]
          base = utils.size_of_shape(xs[0].shape[1:])
          cuda.elementwise(
              "P ptr, int32 length, T pad, int32 base, int32 max_length",
              "T y",
              """
                  int d = i / base % max_length;
                  if (d < length) {
                    y = reinterpret_cast<const T*>(ptr)[i % (base * max_length)];
                  } else {
                    y = pad;
                  }
                  """,
              "pad_sequence_fwd",
          )(ptrs, lengths, self.padding, base, length, y)
  
      return (y,)
  
file_path: chainer/chainer/functions/array/pad_sequence.py
imports: import numpy
  import six
  import chainer
  from chainer import backend
  from chainer.backends import cuda
  from chainer import function_node
  from chainer import utils
  from chainer.utils import type_check
label_desc: Use image node_id 3 for calling the PadSequence obj's underlying member method code with example usage: obj.forward(xs) and returns: y, y