class_docstr: Unflattens a tensor dim expanding it to a desired shape. For use with :class:`~nn.Sequential`.
  
  * :attr:`dim` specifies the dimension of the input tensor to be unflattened, and it can
    be either `int` or `str` when `Tensor` or `NamedTensor` is used, respectively.
  
  * :attr:`unflattened_size` is the new shape of the unflattened dimension of the tensor and it can be
    a `tuple` of ints or a `list` of ints or `torch.Size` for `Tensor` input;  a `NamedShape`
    (tuple of `(name, size)` tuples) for `NamedTensor` input.
  
  Shape:
      - Input: :math:`(*, S_{\text{dim}}, *)`, where :math:`S_{\text{dim}}` is the size at
        dimension :attr:`dim` and :math:`*` means any number of dimensions including none.
      - Output: :math:`(*, U_1, ..., U_n, *)`, where :math:`U` = :attr:`unflattened_size` and
        :math:`\prod_{i=1}^n U_i = S_{\text{dim}}`.
  
  Args:
      dim (Union[int, str]): Dimension to be unflattened
      unflattened_size (Union[torch.Size, Tuple, List, NamedShape]): New shape of the unflattened dimension
  
  Examples:
      >>> input = torch.randn(2, 50)
      >>> # With tuple of ints
      >>> m = nn.Sequential(
      >>>     nn.Linear(50, 50),
      >>>     nn.Unflatten(1, (2, 5, 5))
      >>> )
      >>> output = m(input)
      >>> output.size()
      torch.Size([2, 2, 5, 5])
      >>> # With torch.Size
      >>> m = nn.Sequential(
      >>>     nn.Linear(50, 50),
      >>>     nn.Unflatten(1, torch.Size([2, 5, 5]))
      >>> )
      >>> output = m(input)
      >>> output.size()
      torch.Size([2, 2, 5, 5])
      >>> # With namedshape (tuple of tuples)
      >>> input = torch.randn(2, 50, names=('N', 'features'))
      >>> unflatten = nn.Unflatten('features', (('C', 2), ('H', 5), ('W', 5)))
      >>> output = unflatten(input)
      >>> output.size()
      torch.Size([2, 2, 5, 5])
class_docstr_tok: ["Unflattens","a","tensor","dim","expanding","it","to","a","desired","shape",".","For","use","with",":","class",":","`","~nn.Sequential","`",".","*",":","attr",":","`","dim","`","specifies","the","dimension","of","the","input","tensor","to","be","unflattened",",","and","it","can","be","either","`","int","`","or","`","str","`","when","`","Tensor","`","or","`","NamedTensor","`","is","used",",","respectively",".","*",":","attr",":","`","unflattened_size","`","is","the","new","shape","of","the","unflattened","dimension","of","the","tensor","and","it","can","be","a","`","tuple","`","of","ints","or","a","`","list","`","of","ints","or","`","torch.Size","`","for","`","Tensor","`","input",";","a","`","NamedShape","`","(","tuple","of","`","(","name",",","size",")","`","tuples",")","for","`","NamedTensor","`","input",".","Shape",":","-","Input",":",":","math",":","`","(","*",",","S_","{","\\text","{","dim","}","}",",","*",")","`",",","where",":","math",":","`","S_","{","\\text","{","dim","}","}","`","is","the","size","at","dimension",":","attr",":","`","dim","`","and",":","math",":","`","*","`","means","any","number","of","dimensions","including","none",".","-","Output",":",":","math",":","`","(","*",",","U_1",",","...",",","U_n",",","*",")","`",",","where",":","math",":","`","U","`","=",":","attr",":","`","unflattened_size","`","and",":","math",":","`","\\prod_","{","i=1","}","^n","U_i","=","S_","{","\\text","{","dim","}","}","`",".","Args",":","dim","(","Union","[","int",",","str","]",")",":","Dimension","to","be","unflattened","unflattened_size","(","Union","[","torch.Size",",","Tuple",",","List",",","NamedShape","]",")",":","New","shape","of","the","unflattened","dimension","Examples",":",">",">",">","input","=","torch.randn","(","2",",","50",")",">",">",">","#","With","tuple","of","ints",">",">",">","m","=","nn.Sequential","(",">",">",">","nn.Linear","(","50",",","50",")",",",">",">",">","nn.Unflatten","(","1",",","(","2",",","5",",","5",")",")",">",">",">",")",">",">",">","output","=","m","(","input",")",">",">",">","output.size","(",")","torch.Size","(","[","2",",","2",",","5",",","5","]",")",">",">",">","#","With","torch.Size",">",">",">","m","=","nn.Sequential","(",">",">",">","nn.Linear","(","50",",","50",")",",",">",">",">","nn.Unflatten","(","1",",","torch.Size","(","[","2",",","5",",","5","]",")",")",">",">",">",")",">",">",">","output","=","m","(","input",")",">",">",">","output.size","(",")","torch.Size","(","[","2",",","2",",","5",",","5","]",")",">",">",">","#","With","namedshape","(","tuple","of","tuples",")",">",">",">","input","=","torch.randn","(","2",",","50",",","names=","(","'N","'",",","'features","'",")",")",">",">",">","unflatten","=","nn.Unflatten","(","'features","'",",","(","(","'","C","'",",","2",")",",","(","'","H","'",",","5",")",",","(","'","W","'",",","5",")",")",")",">",">",">","output","=","unflatten","(","input",")",">",">",">","output.size","(",")","torch.Size","(","[","2",",","2",",","5",",","5","]",")"]
code: def _require_tuple_int(self, input):
      if isinstance(input, (tuple, list)):
          for idx, elem in enumerate(input):
              if not isinstance(elem, int):
                  raise TypeError(
                      "unflattened_size must be tuple of ints, "
                      + f"but found element of type {type(elem).__name__} at pos {idx}"
                  )
          return
      raise TypeError(
          f"unflattened_size must be a tuple of ints, but found type {type(input).__name__}"
      )
  
file_path: pytorch/torch/nn/modules/flatten.py
imports: from .module import Module
  from typing import Tuple, Union
  from torch import Tensor
  from torch.types import _size
label_desc: Use image node_id 3 for calling the Unflatten obj's underlying member method code with example usage: obj._require_tuple_int(input) without return types