o
    Ne5                     @   sd   d dl mZ d dlmZ d dlmZ d dlZd dlm	Z	 g Z
dd Zdd	 Ze	d
d Zdd ZdS )    )LayerHelperBase)convert_dtype)_dygraph_tracerN)contextmanagerc                 C   sd   t | tr| tjtjtjfv r| j} ntd| j | dv r#t| } ntdt|  t	
|  dS )ak  
    Set default dtype. The default dtype is initially float32.

    Args:
        d(string|np.dtype): the dtype to make the default. It only
                            supports float16, float32 and float64.

    Returns:
        None.

    Examples:
        .. code-block:: python

            import paddle
            paddle.set_default_dtype("float32")

    zMset_default_dtype only supports [float16, float32, float64] , but received %s)float16float32float64r   r   r   N)
isinstancetypenpr   r   r   __name__	TypeErrorstrr   set_default_dtype)d r   JD:\Projects\ConvertPro\env\Lib\site-packages\paddle/framework/framework.pyr      s    

r   c                   C   s   t  S )a1  
    Get the current default dtype. The default dtype is initially float32.

    Args:
        None.
    Returns:
        String, this global dtype only supports float16, float32, float64.

    Examples:
        .. code-block:: python

            import paddle
            paddle.get_default_dtype()
    )r   get_default_dtyper   r   r   r   r   K   s   r   c                 c   s>    t  }|r|j}| |_z	dV  W ||_dS ||_w dV  dS )a/  
    Create a context which enables or disables dygraph gradient calculation.

    Args:
        mode(bool): whether to enable (`True`), or disable (`False`) grad.

    Examples:
        .. code-block:: python

            import paddle
            x = paddle.ones([3, 2])
            x.stop_gradient = False
            with paddle.set_grad_enabled(False):
                y = x * 2
                with paddle.set_grad_enabled(True):
                    z = x * 2
            print(y.stop_gradient)   # True
            print(z.stop_gradient)   # False
    Nr   Z	_has_grad)modetracerZ	prev_moder   r   r   set_grad_enabled]   s   
r   c                  C   s   t  } | r| jS dS )a+  
    Returns whether current dygraph gradient calculation mode is enabled.

    Returns:
        bool: True if current dygraph gradient calculation mode is enabled, otherwise false.

    Examples:
        .. code-block:: python

            import paddle

            # Dygraph gradient calculation mode is enabled by default.
            paddle.is_grad_enabled() # True

            with paddle.set_grad_enabled(False):
                paddle.is_grad_enabled() # False

            paddle.enable_static()
            paddle.is_grad_enabled() # False
    Fr   )r   r   r   r   is_grad_enabled   s   r   )Zpaddle.fluid.layer_helper_baser   Zpaddle.fluid.data_feederr   Zpaddle.fluid.frameworkr   numpyr   
contextlibr   __all__r   r   r   r   r   r   r   r   <module>   s   2
!