docstr: Function that collect `samples` and adds padding
docstr_tok: ["Function","that","collect","`","samples","`","and","adds","padding"]
code: def encodes(
      self,
      samples,
      pad_idx=1,
      pad_fields=0,
      pad_first=False,
      backwards=False,
  ):
      "Function that collect `samples` and adds padding"
      self.pad_idx = pad_idx
      pad_fields = L(pad_fields)
      max_len_l = pad_fields.map(
          lambda f: max([len(s[f]) for s in samples])
      )
      if backwards:
          pad_first = not pad_first
  
      def _f(field_idx, x):
          if field_idx not in pad_fields:
              return x
          idx = pad_fields.items.index(
              field_idx
          )  # TODO: remove items if L.index is fixed
          sl = (
              slice(-len(x), sys.maxsize)
              if pad_first
              else slice(0, len(x))
          )
          pad = x.new_zeros(max_len_l[idx] - x.shape[0]) + pad_idx
          x1 = torch.cat([pad, x] if pad_first else [x, pad])
          if backwards:
              x1 = x1.flip(0)
          return retain_type(x1, x)
  
      return [
          tuple(map(lambda idxx: _f(*idxx), enumerate(s)))
          for s in samples
      ]
  
imports: from __future__ import annotations
  from ..torch_basics import *
  from ..data.all import *
  from .core import *
label_desc: Use image node_id 1 for calling the Pad_Input obj's underlying member method code with example usage: obj.encodes(samples, pad_idx, pad_fields, pad_first, backwards) and returns: unknown, retain_type, x