L ihddlmZddlmZddlmZddlmZddgZGddeZ Gd deZ y ) )Union)Tensor)_size)ModuleFlatten UnflattencleZdZUdZddgZeed<eed<d dededdffd ZdedefdZ de fd Z xZ S) ra Flattens a contiguous range of dims into a tensor. For use with :class:`~nn.Sequential`, see :meth:`torch.flatten` for details. Shape: - Input: :math:`(*, S_{\text{start}},..., S_{i}, ..., S_{\text{end}}, *)`,' where :math:`S_{i}` is the size at dimension :math:`i` and :math:`*` means any number of dimensions including none. - Output: :math:`(*, \prod_{i=\text{start}}^{\text{end}} S_{i}, *)`. Args: start_dim: first dim to flatten (default = 1). end_dim: last dim to flatten (default = -1). Examples:: >>> input = torch.randn(32, 1, 5, 5) >>> # With default parameters >>> m = nn.Flatten() >>> output = m(input) >>> output.size() torch.Size([32, 25]) >>> # With non-default parameters >>> m = nn.Flatten(0, 2) >>> output = m(input) >>> output.size() torch.Size([160, 5]) start_dimend_dimreturnNc>t|||_||_y)N)super__init__r r )selfr r __class__s ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/nn/modules/flatten.pyrzFlatten.__init__/s " inputcN|j|j|jSz( Runs the forward pass. )flattenr r rrs rforwardzFlatten.forward4s}}T^^T\\::rc:d|jd|jS)A Returns the extra representation of the module. z start_dim=z , end_dim=)r r rs r extra_reprzFlatten.extra_repr:s DNN+:dll^DDr)r) __name__ __module__ __qualname____doc__ __constants__int__annotations__rrrstrr __classcell__rs@rrr sY:!),MN L#C ;V;; ECErceZdZUdZeeeefZddgZe eefe d<e e efe d<de eefde e efddffd Z d dZ d dZd edefd Zdefd ZxZS) r a 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]) dimunflattened_sizer Nct|t|tr|j |n-t|t r|j |n td||_||_ y)Nz'invalid argument type for dim parameter) rr isinstancer%_require_tuple_intr'_require_tuple_tuple TypeErrorr+r,)rr+r,rs rrzUnflatten.__init__vs]  c3   # #$4 5 S !  % %&6 7EF F 0rct|trKt|D]<\}}t|trtddt |j d|zytddt |j z)Nz*unflattened_size must be tuple of tuples, but found element of type  at pos z,unflattened_size must be a tuple of tuples, zbut found type )r.tuple enumerater1typer rridxelems rr0zUnflatten._require_tuple_tuples eU #&u-  T!$.#D6tDz7J7J6K8TWSXYZ   :U 4 456 7  rct|ttfrKt|D]<\}}t|trt ddt |jd|zyt dt |j)Nz(unflattened_size must be tuple of ints, r3r4z9unflattened_size must be a tuple of ints, but found type )r.r5listr6r%r1r7r r8s rr/zUnflatten._require_tuple_ints eeT] +&u-  T!$,#B6tDz7J7J6K8TWSXYZ  GU H\H\G] ^  rrcN|j|j|jSr) unflattenr+r,rs rrzUnflatten.forwardstxx)>)>??rc:d|jd|jS)rzdim=z, unflattened_size=)r+r,rs rrzUnflatten.extra_reprs#dhhZ243H3H2IJJr)r N)r r!r"r#r5r'r% NamedShaper$rr&rrr0r/rrrr(r)s@rr r As,\uS#X'J./M sCxE:-.. 1c? 16;E:rGs< k "1Ef1EhiKiKr