
    ёi                        S SK Jr  S SKJr  S SKJr  S SKrS SKJr  S SKJ	r	J
r
JrJr  \(       a  S SKJr  S SKJr  S S	KJr  SS
 jr\SS j5       r\ S     SS jj5       r\ S       SS jj5       rg)    )annotations)reduce)TYPE_CHECKINGN)_C_ops)_create_tensor_dygraph_tracerdygraph_onlyin_dygraph_mode)Iterable)Tensor)	ShapeLikec                J   [        SS9n[        5       (       aY  [        R                  R                  R                  5          [        R                  " X5      nUR                  U 5        S S S 5        g [        5       R                  SSU 0XS.SU0SS9  g ! , (       d  f       g = f)	Nint64dtypereshape2X)OutXShapeshapeTtypeinputsoutputsattrsstop_gradient)r   r
   paddlebasedygraphno_gradr   reshape_share_underline_tensor_tor   trace_op)xr   x_shapetmp_outs       d/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/utils/transform_parameters.py_inplace_reshape_dygraphr(   %   s    7+G[[  ((*nnQ.G..q1 +* 	""81E" 	# 	
	 +*s   (B
B"c                z   [        U R                  5      S:X  d   eU R                  S   U R                  S   /n[        R                  R                  R                  5          [        R                  " X5      n[        R                  " USS/5      nUR                  U 5        SSS5        g! , (       d  f       g= f)a  
A tool function. Permute date of parameter as a 'columns' stride. Now, it only support 2-D parameter.

Args:
    param(Tensor): The param that will be strided according to 'columns'.

Examples:
   .. code-block:: python

        >>> import paddle
        >>> paddle.seed(100)

        >>> linear = paddle.nn.Linear(2, 3)
        >>> print(linear.weight)
        Parameter containing:
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=False,
               [[ 0.11732829, -0.64161885, -1.06996548],
                [ 0.03456247, -0.29862350, -0.52380574]])

        >>> paddle.nn.utils._stride_column(linear.weight)
        >>> print(linear.weight)

      r   N)	lenr   r   r   r   r    r!   	transposer"   )paramr   reshape_vartranspose_vars       r'   _stride_columnr1   5   s    2 u{{q   [[^U[[^,E				$	$	&nnU2((q!f=007 
'	&	&s   "AB,,
B:c                &   U S   R                   n/ nU  H+  nUR                  UR                  5        [        US/5        M-     [	        US9n[        5       (       aZ  [        R                  R                  R                  5          [        R                  " U S5      nUR                  U5        SSS5        O"[        5       R                  SSU 0SU/0SS0S	S
9  [        U 5       H  u  pt[        XCU   5        M     SUl        U$ ! , (       d  f       N9= f)a  
Flatten parameters to a 1-D Tensor.

Args:
    parameters(Iterable[Tensor]): Iterable Tensors that are trainable parameters of a Layer.
    name(str, optional): The default value is None. Normally there is no need for user to set this
        property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A 1-D Tensor, which represents the parameters of a Layer.


Examples:
   .. code-block:: pycon

        >>> import paddle
        >>> paddle.seed(2023)
        >>> linear = paddle.nn.Linear(10, 15)

        >>> t = paddle.nn.utils.parameters_to_vector(linear.parameters())
        >>> print(t.shape)
        paddle.Size([165])

r   r   Nconcatr   r   axisTr   F)r   appendr   r(   r   r
   r   r   r   r    r   r4   r"   r   r#   	enumerater   )
parametersnamer   origin_shapesr.   outtmpis           r'   parameters_to_vectorr>   V   s    8 qMEMU[[) -  u
%C[[  ((*--
A.C**3/ +* 	""$SEN1+ 	# 	
 j) a(89 *CJ +*s   )D
Dc                   [        U R                  5      S:X  d   e/ n/ nSnU HC  nUR                  nUR                  U5        [        S US5      nXX-  nUR                  U5        ME     [        U5      S:X  a  UR                  S5        [	        5       (       a  [
        R                  R                  R                  5          / n	XPR                  S   :X  a  [        R                  " XS5      n	OBXPR                  S   :  a%  Sn
U H  nU	R                  X
X-    5        X-  n
M     O[        S5      e[        S[        U5      5       H  nX   R                  X   5        M     SSS5        O#[        5       R                  SSU /0SU0SUS	.S
S9  [!        U5       H  u  p[#        XcU   5        M     g! , (       d  f       N1= f)a  
Transform a 1-D Tensor to the input ``parameters`` .

Args:
    vec (Tensor): A 1-D Tensor, which will be sliced and copied to the input ``parameters`` .
    parameters (Iterable[Tensor]): Iterable Tensors that are trainable parameters of a Layer.
    name(str, optional): The default value is None. Normally there is no need for user to set this
        property. For more information, please refer to :ref:`api_guide_Name`.

Examples:
   .. code-block:: python

        >>> import paddle
        >>> weight_attr = paddle.ParamAttr(initializer=paddle.nn.initializer.Constant(3.))
        >>> linear1 = paddle.nn.Linear(10, 15, weight_attr)

        >>> vec = paddle.nn.utils.parameters_to_vector(linear1.parameters())

        >>> linear2 = paddle.nn.Linear(10, 15)
        >>> # copy weight of linear1 to linear2
        >>> paddle.nn.utils.vector_to_parameters(vec, linear2.parameters())
        >>> print((linear1.weight == linear2.weight).all())
        Tensor(shape=[], dtype=bool, place=Place(cpu), stop_gradient=True,
        True)
r+   r   c                
    X-  $ N )r$   ys     r'   <lambda>&vector_to_parameters.<locals>.<lambda>   s    AE    zaThe total_elements of vec should be equal to or larger than the number of elements in parameters.Nsplitr   r   )r5   sectionsTr   )r,   r   r6   r   r
   r   r   r   r    r   rG   
ValueErrorranger"   r   r#   r7   r(   )vecr8   r9   r:   rH   total_elementsr.   r   numelrespointersectionr=   s                r'   vector_to_parametersrQ      s   : syy>QMHNU#)5!4  8}[[  ((*C1-ll3!4))A,.'GJJsW->?@&G  ( !w  1c*o.11*-@ / +*  	""#<J'(3 	# 	
 j) a(89 *1 +*s   B F11
F?)r$   r   r   r   returnNone)r.   r   rR   rS   rA   )r8   Iterable[Tensor]r9   
str | NonerR   r   )rK   r   r8   rT   r9   rU   rR   rS   )
__future__r   	functoolsr   typingr   r   r   paddle.base.frameworkr   r   r	   r
   collections.abcr   r   paddle._typingr   r(   r1   r>   rQ   rB   rF   r'   <module>r\      s    #       ((
  8 8@ 591 1(211 1h BFD:	D:-D:5?D:	D: D:rF   