def default_collate(batch):
 if torch.is_tensor(batch[0]):
  return torch.cat([t.unsqueeze(0) for t in batch], 0)
 elif isinstance(batch[0], int):
  return torch.LongTensor(batch)
 elif isinstance(batch[0], float):
  return torch.DoubleTensor(batch)
 elif isinstance(batch[0], str):
  return batch
 elif isinstance(batch[0], collections.Iterable):
  transposed = zip(*batch)
  return [default_collate(samples) for samples in transposed]
 raise TypeError('batch must contain tensors, numbers, or lists; found {}'.format(type(batch[0])))

def default_collate ( batch ) : if torch . is_tensor ( batch [ 0 ] ) : return torch . cat ( [ t . unsqueeze ( 0 ) for t in batch ] , 0 ) elif isinstance ( batch [ 0 ] , int ) : return torch . LongTensor ( batch ) elif isinstance ( batch [ 0 ] , float ) : return torch . DoubleTensor ( batch ) elif isinstance ( batch [ 0 ] , str ) : return batch elif isinstance ( batch [ 0 ] , collections . Iterable ) : transposed = zip ( * batch ) return [ default_collate ( samples ) for samples in transposed ] raise TypeError ( 'batch must contain tensors, numbers, or lists; found {}' . format ( type ( batch [ 0 ] ) ) )
puts each data field into a tensor with outer dimension batch size .