Ë
    •\;jG  ã                   óp   — d dl mZ ddlmZmZ ddlmZmZmZ ddl	m
Z
 g Z G d„ de
«      Z G d	„ d
e«      Zy)é    )Ú_C_opsé   )ÚcoreÚ	framework)Ú_current_expected_placeÚin_dygraph_modeÚin_dynamic_or_pir_modeé   )ÚInitializerc                   ó,   ‡ — e Zd ZdZdˆ fd„	Zdd„Zˆ xZS )ÚConstantInitializerz�Implements the constant initializer

    Args:
        value (float32, optional): constant value to initialize the variable. Default: 0.0.

    c                 óF   •— |€J ‚t         ‰| �  «        || _        || _        y ©N)ÚsuperÚ__init__Ú_valueÚ
_force_cpu)ÚselfÚvalueÚ	force_cpuÚ	__class__s      €úgG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/nn/initializer/constant.pyr   zConstantInitializer.__init__&   s(   ø€ ØÐ Ð Ð Ü‰ÑÔØˆŒØ#ˆ�ó    c                 óÄ  — ddl }| j                  |«      }t        |t        j                  t        j
                  |j                  j                  |j                  j                  j                  f«      sJ ‚t        |t        j                  |j                  j                  f«      sJ ‚t        «       r´t        «       }| j                  rt        j                  «       }t        «       rAt!        j"                  ||j$                  t'        | j(                  «      |j*                  |«       yt!        j,                  |j$                  t'        | j(                  «      |j*                  |«      S |j/                  dd|i|j$                  t1        |j*                  «      t'        | j(                  «      t3        t'        | j(                  «      «      | j                  dœd¬«      }||_        |S )aK  Initialize the input tensor with constant.

        Args:
            var(Tensor): Tensor that needs to be initialized.
            block(Block, optional): The block in which initialization ops
                   should be added. Used in static graph only, default None.

        Returns:
            The initialization op
        r   NÚfill_constantÚOut)ÚshapeÚdtyper   Ú	str_valuer   T)ÚtypeÚoutputsÚattrsÚstop_gradient)ÚpaddleÚ_check_blockÚ
isinstancer   ÚVariableÚEagerParamBaseÚpirÚOpResultr   ÚParameterMetaÚBlockr	   r   r   ÚCPUPlacer   r   Úfull_r   Úfloatr   r   ÚfullÚ	append_opÚintÚstrÚop)r   ÚvarÚblockr$   Úplacer4   s         r   ÚforwardzConstantInitializer.forward,   sq  € ó 	à×!Ñ! %Ó(ˆäØä×"Ñ"Ü×(Ñ(Ø—
‘
×#Ñ#Ø—
‘
—‘×-Ñ-ð	ô
ð 	
ð 
ô ˜%¤)§/¡/°6·:±:×3CÑ3CÐ!DÔEÐEÐEä!Ô#Ü+Ó-ˆEØ�ŠÜŸ™›�ÜÔ Ü—‘Ø˜Ÿ™¤E¨$¯+©+Ó$6¸¿	¹	À5ôð ä—{‘{Ø—I‘Iœu T§[¡[Ó1°3·9±9¸eóð ð —‘Ø$Ø ˜à ŸY™YÜ  §¡›^Ü" 4§;¡;Ó/Ü!$¤U¨4¯;©;Ó%7Ó!8Ø!%§¡ñð #ð !ó ˆBð ˆCŒFØˆIr   )ç        Fr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r8   Ú__classcell__©r   s   @r   r   r      s   ø„ ñõ$÷6r   r   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚConstanta  Implement the constant initializer.

    Args:
        value (float32|float64, optional): constant value to initialize the parameter. Default: 0.0.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> import paddle.nn as nn

            >>> paddle.seed(2023)
            >>> data = paddle.rand([30, 10, 2], dtype='float32')
            >>> linear = nn.Linear(2,
            ...                     4,
            ...                     weight_attr=nn.initializer.Constant(value=2.0))
            >>> res = linear(data)
            >>> print(linear.weight)
            Parameter containing:
            Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
            [[2., 2., 2., 2.],
             [2., 2., 2., 2.]])

    c                 óB   •— |€t        d«      ‚t        ‰| �	  |d¬«       y )Nzvalue must not be none.F)r   r   )Ú
ValueErrorr   r   )r   r   r   s     €r   r   zConstant.__init__   s&   ø€ Øˆ=ÜÐ6Ó7Ð7Ü‰Ñ˜u°ÐÕ6r   )r9   )r:   r;   r<   r=   r   r>   r?   s   @r   rA   rA   e   s   ø„ ñ÷27ñ 7r   rA   N)r$   r   Úbaser   r   Úbase.frameworkr   r   r	   Úinitializerr   Ú__all__r   rA   © r   r   Ú<module>rI      s=   ðõ ç #÷ñ õ %à
€ôD˜+ô DôN7Ð"õ 7r   