class_docstr: 目前支持 ``[paddle.tensor([3, 2], paddle.tensor([2, 1])]`` 类似的输入，若内部元素不为 :class:`paddle.Tensor` ，则必须含有 :meth:`tolist` 方法。
  
      >>> PaddleTensorPadder.pad([np.array([3, 4]), np.array([1])], pad_val=-100)
      [[   3.    4.]
       [   1. -100.]]
      >>> PaddleTensorPadder.pad([paddle.to_tensor([3, 4]), paddle.to_tensor([1])], pad_val=-100)
      tensor([[   3,    4],
              [   1, -100]])
  :param pad_val: pad 的值。
  :param ele_dtype: 用于检测当前 field 的元素类型是否可以转换为 :class:`paddle.Tensor` 类型；
  :param dtype: 输出的数据的 dtype 是什么。如 :class:`int`, :class:`float`, :class:`int32` 等；
class_docstr_tok: ["\u76ee\u524d\u652f\u6301","``","[","paddle.tensor","(","[","3",",","2","]",",","paddle.tensor","(","[","2",",","1","]",")","]","``","\u7c7b\u4f3c\u7684\u8f93\u5165\uff0c\u82e5\u5185\u90e8\u5143\u7d20\u4e0d\u4e3a",":","class",":","`","paddle.Tensor","`","\uff0c\u5219\u5fc5\u987b\u542b\u6709",":","meth",":","`","tolist","`","\u65b9\u6cd5\u3002",">",">",">","PaddleTensorPadder.pad","(","[","np.array","(","[","3",",","4","]",")",",","np.array","(","[","1","]",")","]",",","pad_val=-100",")","[","[","3",".","4",".","]","[","1",".","-100",".","]","]",">",">",">","PaddleTensorPadder.pad","(","[","paddle.to_tensor","(","[","3",",","4","]",")",",","paddle.to_tensor","(","[","1","]",")","]",",","pad_val=-100",")","tensor","(","[","[","3",",","4","]",",","[","1",",","-100","]","]",")",":","param","pad_val",":","pad","\u7684\u503c\u3002",":","param","ele_dtype",":","\u7528\u4e8e\u68c0\u6d4b\u5f53\u524d","field","\u7684\u5143\u7d20\u7c7b\u578b\u662f\u5426\u53ef\u4ee5\u8f6c\u6362\u4e3a",":","class",":","`","paddle.Tensor","`","\u7c7b\u578b\uff1b",":","param","dtype",":","\u8f93\u51fa\u7684\u6570\u636e\u7684","dtype","\u662f\u4ec0\u4e48\u3002\u5982",":","class",":","`","int","`",",",":","class",":","`","float","`",",",":","class",":","`","int32","`","\u7b49\uff1b"]
docstr: 将 ``batch_field`` 数据 转为 :class:`paddle.Tensor` 并 pad 到相同长度。
  
  :param batch_field: 输入的某个 field 的 batch 数据。
  :param pad_val: 需要填充的值
  :param dtype: 数据的类型
docstr_tok: ["\u5c06","``","batch_field","``","\u6570\u636e","\u8f6c\u4e3a",":","class",":","`","paddle.Tensor","`","\u5e76","pad","\u5230\u76f8\u540c\u957f\u5ea6\u3002",":","param","batch_field",":","\u8f93\u5165\u7684\u67d0\u4e2a","field","\u7684","batch","\u6570\u636e\u3002",":","param","pad_val",":","\u9700\u8981\u586b\u5145\u7684\u503c",":","param","dtype",":","\u6570\u636e\u7684\u7c7b\u578b"]
code: def pad(batch_field, pad_val=0, dtype=None):
      """
      将 ``batch_field`` 数据 转为 :class:`paddle.Tensor` 并 pad 到相同长度。
  
      :param batch_field: 输入的某个 field 的 batch 数据。
      :param pad_val: 需要填充的值
      :param dtype: 数据的类型
      """
      try:
          if not isinstance(batch_field[0], paddle.Tensor):
              batch_field = [
                  np.array(field.tolist()) for field in batch_field
              ]
          else:
              if dtype is None:
                  dtype = batch_field[0].dtype
      except AttributeError:
          raise RuntimeError(
              f"If the field is not a paddle.Tensor (it is {type(batch_field[0])}), "
              f"it must have tolist() method."
          )
  
      shapes = [field.shape for field in batch_field]
      if len(batch_field) < 2:
          max_shape = [len(batch_field)] + list(shapes[0])
      else:
          max_shape = [len(batch_field)] + [
              max(*_) for _ in zip(*shapes)
          ]
  
      if isinstance(batch_field[0], paddle.Tensor):
          array = paddle.full(
              max_shape, fill_value=pad_val, dtype=dtype
          )
      else:
          array = np.full(
              max_shape, fill_value=pad_val, dtype=batch_field[0].dtype
          )
      for i, field in enumerate(batch_field):
          slices = (i,) + tuple(slice(0, s) for s in shapes[i])
          array[slices] = field
      tensor = paddle.to_tensor(array, dtype=dtype)
      return tensor
  
imports: from inspect import isclass
  import numpy
  from fastNLP.envs.imports import _NEED_IMPORT_PADDLE
  from .padder import Padder
  from .utils import is_number_or_numpy_number, is_number, is_numpy_number_dtype, is_numpy_generic_class, get_padded_numpy_array
  from .exceptions import *
label_desc: Use image node_id 2 for calling the PaddleTensorPadder obj's underlying member method code with example usage: obj.pad(batch_field, pad_val, dtype) and returns: tensor