o
    "j
                     @   s>   d dl mZ d dlmZ d dlmZ d dlmZ d	ddZdS )
    )_legacy_C_ops)check_variable_and_dtype)LayerHelper)in_dynamic_modenonec                 C   s   t |trdddd| }|du rtdt r"t| d|S t| dd	d
gd d|i}t	di t
 }|jdd}||}|jdd| id|i|d |S )a  Marks a tensor as being part of the loss calculation for IPU.

    This operator is used to handle on the (final) loss of a model so that
    it is used as the start of backpropagation.

    When `reduction` is `none`, return raw `Out`.

    When `reduction` is `mean`, return

    .. math::
        Out = MEAN(Out)

    When `reduction` is `sum`, return

    .. math::
        Out = SUM(Out)

    Parameters:
        x (Variable): The input tensor. The shapes is [N, *], where N is batch size and `*` means any number of
             additional dimensions. It's data type should be float32, float64 on CPU and float16, float32 on IPU.
        reduction(str|int, optional): Reduce the loss output. Supported string values are: 'sum', 'mean', 'none'
                            the corresponding int values are 0, 1, 2 respectively. The default value is "none".

    Returns:
        Variable: The loss ``Tensor`` with the specified reduction applied.

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> paddle.enable_static()
            >>> loss = paddle.static.data(name="loss", shape=[-1, 1], dtype="float32")
            >>> out = paddle.incubate.identity_loss(loss, reduction=1)
    r         )summeanr   NzUnsupported reduction type.	reductionxZfloat32Zfloat64identity_loss)Zinput_param_nameXZOut)typeZinputsZoutputsattrs)r   )
isinstancestrgetlower	Exceptionr   r   r   r   r   localsZinput_dtypeZ"create_variable_for_type_inferenceZ	append_op)r   r   r   helperZdtypeout r   X/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/incubate/nn/loss.pyr      s   
$
r   N)r   )	Zpaddler   Zpaddle.base.data_feederr   Zpaddle.base.layer_helperr   Zpaddle.frameworkr   r   r   r   r   r   <module>   s
   