o
    oi>                     @   s   d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	 dedee
ef dedee
ef d	ee
ef d
efddZG dd deZdS )    )Union)ImageModule)Tensortensor)KORNIA_CHECKKORNIA_CHECK_IS_TENSORsrc1alphasrc2betagammareturnc                 C   s   t |  t | t| j|jkd| j d|j  t|tr(t| j|jkd n	t|| j| jd}t|tr@t| j|jkd n	t|| j| jd}t|trXt| j|jkd n	t|| j| jd}| | ||  | S )a  Calculate the weighted sum of two Tensors.

    .. image:: _static/img/add_weighted.png

    The function calculates the weighted sum of two Tensors as follows:

    .. math::
        out = src1 * alpha + src2 * beta + gamma

    Args:
        src1: Tensor with an arbitrary shape, equal to shape of src2.
        alpha: weight of the src1 elements as Union[float, Tensor].
        src2: Tensor with an arbitrary shape, equal to shape of src1.
        beta: weight of the src2 elements as Union[float, Tensor].
        gamma: scalar added to each sum as Union[float, Tensor].

    Returns:
        Weighted Tensor with shape equal to src1 and src2 shapes.

    Example:
        >>> input1 = torch.rand(1, 1, 5, 5)
        >>> input2 = torch.rand(1, 1, 5, 5)
        >>> output = add_weighted(input1, 0.5, input2, 0.5, 1.0)
        >>> output.shape
        torch.Size([1, 1, 5, 5])

    Notes:
        Tensor alpha/beta/gamma have to be with shape broadcastable to src1 and src2 shapes.

    z)src1 and src2 have different shapes. Got z and z%alpha has a different shape than src.)dtypedevicez$beta has a different shape than src.z%gamma has a different shape than src.)r   r   shape
isinstancer   r   r   r   )r   r	   r
   r   r    r   G/home/ubuntu/.local/lib/python3.10/site-packages/kornia/enhance/core.pyadd_weighted   s   !"


r   c                       s`   e Zd ZdZdeeef deeef deeef ddf fddZd	ed
edefddZ  Z	S )AddWeighteda  Calculate the weighted sum of two Tensors.

    The function calculates the weighted sum of two Tensors as follows:

    .. math::
        out = src1 * alpha + src2 * beta + gamma

    Args:
        alpha: weight of the src1 elements as Union[float, Tensor].
        beta: weight of the src2 elements as Union[float, Tensor].
        gamma: scalar added to each sum as Union[float, Tensor].

    Shape:
        - Input1: Tensor with an arbitrary shape, equal to shape of Input2.
        - Input2: Tensor with an arbitrary shape, equal to shape of Input1.
        - Output: Weighted tensor with shape equal to src1 and src2 shapes.

    Example:
        >>> input1 = torch.rand(1, 1, 5, 5)
        >>> input2 = torch.rand(1, 1, 5, 5)
        >>> output = AddWeighted(0.5, 0.5, 1.0)(input1, input2)
        >>> output.shape
        torch.Size([1, 1, 5, 5])

    Notes:
        Tensor alpha/beta/gamma have to be with shape broadcastable to src1 and src2 shapes.

    r	   r   r   r   Nc                    s    t    || _|| _|| _d S N)super__init__r	   r   r   )selfr	   r   r   	__class__r   r   r   n   s   

zAddWeighted.__init__r   r
   c                 C   s   t || j|| j| jS r   )r   r	   r   r   )r   r   r
   r   r   r   forwardt   s   zAddWeighted.forward)
__name__
__module____qualname____doc__r   floatr   r   r   __classcell__r   r   r   r   r   P   s    6r   N)typingr   kornia.corer   Moduler   r   kornia.core.checkr   r   r!   r   r   r   r   r   r   <module>   s$   



7