o
    #j                     @   sd   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 de
ZG d	d
 d
eZdS )    )_C_ops   )core	framework)_current_expected_placein_dygraph_modein_dynamic_or_pir_mode   )Initializerc                       s,   e Zd ZdZd	 fdd	Zd
ddZ  ZS )ConstantInitializerzImplements the constant initializer

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

            Fc                    s&   |d usJ t    || _|| _d S N)super__init___value
_force_cpu)selfvalue	force_cpu	__class__ _/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/nn/initializer/constant.pyr   &   s   

zConstantInitializer.__init__Nc              	   C   s   ddl }| |}t|tjtj|jj|jjj	fsJ t|tj
|jj
fs'J t rTt }| jr4t }t rGt||jt| j|j| dS t|jt| j|j|S |jdd|i|jt|jt| jtt| j| jd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   NZfill_constantZOut)shapedtyper   Z	str_valuer   T)typeZoutputsattrsZstop_gradient)paddleZ_check_block
isinstancer   VariableZEagerParamBaseZpirZOpResultr   ZParameterMetaZBlockr   r   r   ZCPUPlacer   r   Zfull_r   floatr   r   fullZ	append_opintstrop)r   varblockr   Zplacer$   r   r   r   forward,   sH   
	zConstantInitializer.forward)r   Fr   )__name__
__module____qualname____doc__r   r'   __classcell__r   r   r   r   r      s    r   c                       s"   e Zd ZdZd fdd	Z  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.]])

    r   c                    s$   |d u rt dt j|dd d S )Nzvalue must not be none.F)r   r   )
ValueErrorr   r   )r   r   r   r   r   r      s   zConstant.__init__)r   )r(   r)   r*   r+   r   r,   r   r   r   r   r-   e   s    r-   N)r   r   baser   r   Zbase.frameworkr   r   r   Zinitializerr
   __all__r   r-   r   r   r   r   <module>   s   G