
    &Vf                    	   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ ddlmZ  G d de          Z eddg          d             Z G d de          Z eddg          d             Z G d de          Z eddg          d             Z G d de          Z eddg          d             Z G d  d!e          Z ed"d#g          d$             Z G d% d&e          Z eg d'          d(             Z G d) d*e          Z ed+d,g          d-             Z G d. d/e          Z  ed0d1g          dd3            Z! G d4 d5e          Z" ed6d7g          d8             Z# G d9 d:e          Z$ eg d;          d<             Z% G d= d>e          Z& ed?d@g          ddB            Z' G dC dDe          Z( edEdFg          dG             Z) G dH dIe          Z* edJdKg          ddM            Z+ G dN dOe          Z, edPdQg          ddS            Z- G dT dUe          Z. edVdWg          ddX            Z/ G dY dZe          Z0 ed[d\g          	 	 	 dd^            Z1 G d_ d`e          Z2 edadbg          	 	 	 ddc            Z3 G dd dee          Z4 edfdgg          	 	 	 	 ddi            Z5 G dj dke          Z6 edldmg          	 	 	 	 ddn            Z7 G do dpe          Z8 edqdrg          	 	 	 	 dds            Z9 G dt due          Z: edvdwg          	 	 	 	 ddx            Z; G dy dze          Z< ed{d|g          dd~            Z= G d de          Z> eddg          dd            Z? G d de          Z@ eddg          dd            ZA G d de          ZB eddg          dd            ZC G d de          ZD eddg          	 dd            ZE G d de          ZF eddg          dd            ZG G d de          ZH eddg          	 dd            ZI G d de          ZJ eddg          dd            ZK G d de          ZL eddg          	 	 	 	 	 dd            ZM G d de          ZN eddg          dd            ZOddZP G d de          ZQ eddg          d             ZRdS )z>Commonly-used neural network operations not included in NumPy.    N)backend)keras_export)KerasTensor)any_symbolic_tensors)standardize_data_format)#compute_conv_transpose_output_shape)operation_utils)	Operation)reduce_shapec                       e Zd Zd Zd ZdS )Reluc                 @    t           j                            |          S N)r   nnreluselfxs     M/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/ops/nn.pycallz	Relu.call       zq!!!    c                 8    t          |j        |j                  S Ndtyper   shaper   r   s     r   compute_output_speczRelu.compute_output_spec       17!'2222r   N__name__
__module____qualname__r   r    r   r   r   r      2        " " "3 3 3 3 3r   r   zkeras.ops.reluzkeras.ops.nn.reluc                     t          | f          r!t                                          |           S t          j                            |           S )aQ  Rectified linear unit activation function.

    It is defined as `f(x) = max(0, x)`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x1 = keras.ops.convert_to_tensor([-1.0, 0.0, 1.0, 0.2])
    >>> keras.ops.relu(x1)
    array([0.0, 0.0, 1.0, 0.2], dtype=float32)
    )r   r   symbolic_callr   r   r   r   s    r   r   r      sB    $ QD!! 'vv##A&&&:??1r   c                       e Zd Zd Zd ZdS )Relu6c                 @    t           j                            |          S r   )r   r   relu6r   s     r   r   z
Relu6.call2   s    z"""r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zRelu6.compute_output_spec5   r    r   Nr!   r%   r   r   r+   r+   1   s2        # # #3 3 3 3 3r   r+   zkeras.ops.relu6zkeras.ops.nn.relu6c                     t          | f          r!t                                          |           S t          j                            |           S )a  Rectified linear unit activation function with upper bound of 6.

    It is defined as `f(x) = np.clip(x, 0, 6)`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-3.0, -2.0, 0.1, 0.2, 6.0, 8.0])
    >>> keras.ops.relu6(x)
    array([0.0, 0.0, 0.1, 0.2, 6.0, 6.0], dtype=float32)
    )r   r+   r(   r   r   r-   r)   s    r   r-   r-   9   sD    $ QD!! (ww$$Q''':Ar   c                       e Zd Zd Zd ZdS )Sigmoidc                 @    t           j                            |          S r   )r   r   sigmoidr   s     r   r   zSigmoid.callQ   s    z!!!$$$r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zSigmoid.compute_output_specT   r    r   Nr!   r%   r   r   r1   r1   P   s2        % % %3 3 3 3 3r   r1   zkeras.ops.sigmoidzkeras.ops.nn.sigmoidc                     t          | f          r!t                                          |           S t          j                            |           S )ap  Sigmoid activation function.

    It is defined as `f(x) = 1 / (1 + exp(-x))`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-6.0, 1.0, 0.0, 1.0, 6.0])
    >>> keras.ops.sigmoid(x)
    array([0.00247262, 0.7310586, 0.5, 0.7310586, 0.9975274], dtype=float32)

    )r   r1   r(   r   r   r3   r)   s    r   r3   r3   X   sD    & QD!! *yy&&q))):a   r   c                       e Zd Zd Zd ZdS )Softplusc                 @    t           j                            |          S r   )r   r   softplusr   s     r   r   zSoftplus.callq       z""1%%%r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zSoftplus.compute_output_spect   r    r   Nr!   r%   r   r   r7   r7   p   2        & & &3 3 3 3 3r   r7   zkeras.ops.softpluszkeras.ops.nn.softplusc                     t          | f          r!t                                          |           S t          j                            |           S )a  Softplus activation function.

    It is defined as `f(x) = log(exp(x) + 1)`, where `log` is the natural
    logarithm and `exp` is the exponential function.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-0.555, 0.0, 0.555])
    >>> keras.ops.softplus(x)
    array([0.45366603, 0.6931472, 1.008666], dtype=float32)

    )r   r7   r(   r   r   r9   r)   s    r   r9   r9   x   sD    ( QD!! +zz''***:q!!!r   c                       e Zd Zd Zd ZdS )Softsignc                 @    t           j                            |          S r   )r   r   softsignr   s     r   r   zSoftsign.call   r:   r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zSoftsign.compute_output_spec   r    r   Nr!   r%   r   r   r?   r?      r<   r   r?   zkeras.ops.softsignzkeras.ops.nn.softsignc                     t          | f          r!t                                          |           S t          j                            |           S )as  Softsign activation function.

    It is defined as `f(x) = x / (abs(x) + 1)`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-0.100, -10.0, 1.0, 0.0, 100.0])
    >>> keras.ops.softsign(x)
    Array([-0.09090909, -0.90909094, 0.5, 0.0, 0.990099], dtype=float32)

    )r   r?   r(   r   r   rA   r)   s    r   rA   rA      sD    & QD!! +zz''***:q!!!r   c                       e Zd Zd Zd ZdS )Siluc                 @    t           j                            |          S r   )r   r   silur   s     r   r   z	Silu.call   r   r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zSilu.compute_output_spec   r    r   Nr!   r%   r   r   rE   rE      r&   r   rE   )zkeras.ops.siluzkeras.ops.nn.siluzkeras.ops.swishzkeras.ops.nn.swishc                     t          | f          r!t                                          |           S t          j                            |           S )aZ  Sigmoid Linear Unit (SiLU) activation function, also known as Swish.

    The SiLU activation function is computed by the sigmoid function multiplied
    by its input. It is defined as `f(x) = x * sigmoid(x)`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-6.0, 1.0, 0.0, 1.0, 6.0])
    >>> keras.ops.sigmoid(x)
    array([0.00247262, 0.7310586, 0.5, 0.7310586, 0.9975274], dtype=float32)
    >>> keras.ops.silu(x)
    array([-0.0148357, 0.7310586, 0.0, 0.7310586, 5.9851646], dtype=float32)

    )r   rE   r(   r   r   rG   r)   s    r   rG   rG      sB    : QD!! 'vv##A&&&:??1r   c                       e Zd Zd Zd ZdS )
LogSigmoidc                 @    t           j                            |          S r   )r   r   log_sigmoidr   s     r   r   zLogSigmoid.call   s    z%%a(((r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zLogSigmoid.compute_output_spec   r    r   Nr!   r%   r   r   rK   rK      s2        ) ) )3 3 3 3 3r   rK   zkeras.ops.log_sigmoidzkeras.ops.nn.log_sigmoidc                     t          | f          r!t                                          |           S t          j                            |           S )a  Logarithm of the sigmoid activation function.

    It is defined as `f(x) = log(1 / (1 + exp(-x)))`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-0.541391, 0.0, 0.50, 5.0])
    >>> keras.ops.log_sigmoid(x)
    array([-1.0000418, -0.6931472, -0.474077, -0.00671535], dtype=float32)

    )r   rK   r(   r   r   rM   r)   s    r   rM   rM      sD    0 QD!! -||))!,,,:!!!$$$r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )	LeakyRelu皙?c                 V    t                                                       || _        d S r   )super__init__negative_slope)r   rV   	__class__s     r   rU   zLeakyRelu.__init__  s'    ,r   c                 L    t           j                            || j                  S r   )r   r   
leaky_relurV   r   s     r   r   zLeakyRelu.call  s    z$$Q(;<<<r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zLeakyRelu.compute_output_spec  r    r   rR   r"   r#   r$   rU   r   r   __classcell__rW   s   @r   rQ   rQ      s[        - - - - - -= = =3 3 3 3 3 3 3r   rQ   zkeras.ops.leaky_reluzkeras.ops.nn.leaky_relurR   c                     t          | f          r"t          |                              |           S t          j                            | |          S )aF  Leaky version of a Rectified Linear Unit activation function.

    It allows a small gradient when the unit is not active, it is defined as:

    `f(x) = alpha * x for x < 0` or `f(x) = x for x >= 0`.

    Args:
        x: Input tensor.
        negative_slope: Slope of the activation function at x < 0.
            Defaults to `0.2`.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_leaky_relu = keras.ops.leaky_relu(x)
    >>> print(x_leaky_relu)
    array([-0.2,  0. ,  1. ], shape=(3,), dtype=float64)

    )rV   )r   rQ   r(   r   r   rY   )r   rV   s     r   rY   rY     sM    0 QD!! :((66q999:  > BBBr   c                       e Zd Zd Zd ZdS )HardSigmoidc                 @    t           j                            |          S r   )r   r   hard_sigmoidr   s     r   r   zHardSigmoid.call*  s    z&&q)))r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zHardSigmoid.compute_output_spec-  r    r   Nr!   r%   r   r   ra   ra   )  s2        * * *3 3 3 3 3r   ra   zkeras.ops.hard_sigmoidzkeras.ops.nn.hard_sigmoidc                     t          | f          r!t                                          |           S t          j                            |           S )a  Hard sigmoid activation function.

    It is defined as:

    `0 if x < -2.5`, `1 if x > 2.5`, `(0.2 * x) + 0.5 if -2.5 <= x <= 2.5`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_hard_sigmoid = keras.ops.hard_sigmoid(x)
    >>> print(x_hard_sigmoid)
    array([0.3, 0.5, 0.7], shape=(3,), dtype=float64)

    )r   ra   r(   r   r   rc   r)   s    r   rc   rc   1  sD    6 QD!! .}}**1---:""1%%%r   c                       e Zd Zd Zd ZdS )HardSiluc                 @    t           j                            |          S r   )r   r   	hard_silur   s     r   r   zHardSilu.callR  s    z##A&&&r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zHardSilu.compute_output_specU  r    r   Nr!   r%   r   r   rg   rg   Q  s2        ' ' '3 3 3 3 3r   rg   )zkeras.ops.hard_siluzkeras.ops.nn.hard_siluzkeras.ops.hard_swishzkeras.ops.nn.hard_swishc                     t          | f          r!t                                          |           S t          j                            |           S )a  Hard SiLU activation function, also known as Hard Swish.

    It is defined as:

    - `0` if `if x < -3`
    - `x` if `x > 3`
    - `x * (x + 3) / 6` if `-3 <= x <= 3`

    It's a faster, piecewise linear approximation of the silu activation.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-3.0, -1.0, 0.0, 1.0, 3.0])
    >>> keras.ops.hard_silu(x)
    array([-0.0, -0.3333333, 0.0, 0.6666667, 3.0], shape=(5,), dtype=float32)

    )r   rg   r(   r   r   ri   r)   s    r   ri   ri   Y  sE    @ QD!! +zz''***:"""r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Elu      ?c                 V    t                                                       || _        d S r   )rT   rU   alpha)r   rp   rW   s     r   rU   zElu.__init__  s$    


r   c                 N    t           j                            || j                  S )Nrp   )r   r   elurp   r   s     r   r   zElu.call  s    z~~atz~222r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zElu.compute_output_spec  r    r   rn   r\   r^   s   @r   rm   rm   ~  s[             3 3 33 3 3 3 3 3 3r   rm   zkeras.ops.eluzkeras.ops.nn.elurn   c                     t          | f          r"t          |                              |           S t          j                            | |          S )a  Exponential Linear Unit activation function.

    It is defined as:

    `f(x) =  alpha * (exp(x) - 1.) for x < 0`, `f(x) = x for x >= 0`.

    Args:
        x: Input tensor.
        alpha: A scalar, slope of positive section. Defaults to `1.0`.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_elu = keras.ops.elu(x)
    >>> print(x_elu)
    array([-0.63212055, 0., 1.], shape=(3,), dtype=float64)

    rr   )r   rm   r(   r   r   rs   )r   rp   s     r   rs   rs     sH    . QD!! +5zz''***:>>!5>)))r   c                       e Zd Zd Zd ZdS )Seluc                 @    t           j                            |          S r   )r   r   selur   s     r   r   z	Selu.call  r   r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zSelu.compute_output_spec  r    r   Nr!   r%   r   r   rx   rx     r&   r   rx   zkeras.ops.seluzkeras.ops.nn.seluc                     t          | f          r!t                                          |           S t          j                            |           S )a  Scaled Exponential Linear Unit (SELU) activation function.

    It is defined as:

    `f(x) =  scale * alpha * (exp(x) - 1.) for x < 0`,
    `f(x) = scale * x for x >= 0`.

    Args:
        x: Input tensor.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_selu = keras.ops.selu(x)
    >>> print(x_selu)
    array([-1.11133055, 0., 1.05070098], shape=(3,), dtype=float64)

    )r   rx   r(   r   r   rz   r)   s    r   rz   rz     sB    . QD!! 'vv##A&&&:??1r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )GeluTc                 V    t                                                       || _        d S r   )rT   rU   approximate)r   r   rW   s     r   rU   zGelu.__init__  '    &r   c                 L    t           j                            || j                  S r   )r   r   gelur   r   s     r   r   z	Gelu.call  s    zq$"2333r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zGelu.compute_output_spec  r    r   Tr\   r^   s   @r   r~   r~     s[        ' ' ' ' ' '4 4 43 3 3 3 3 3 3r   r~   zkeras.ops.geluzkeras.ops.nn.geluTc                     t          | f          r"t          |                              |           S t          j                            | |          S )a  Gaussian Error Linear Unit (GELU) activation function.

    If `approximate` is `True`, it is defined as:
    `f(x) = 0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))`

    Or if `approximate` is `False`, it is defined as:
    `f(x) = x * P(X <= x) = 0.5 * x * (1 + erf(x / sqrt(2)))`,
    where `P(X) ~ N(0, 1)`.

    Args:
        x: Input tensor.
        approximate: Approximate version of GELU activation. Defaults to `True`.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_gelu = keras.ops.gelu(x)
    >>> print(x_gelu)
    array([-0.15865525, 0., 0.84134475], shape=(3,), dtype=float64)

    )r   r~   r(   r   r   r   )r   r   s     r   r   r     sH    4 QD!! 2K  ..q111:??1k***r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Softmaxc                 V    t                                                       || _        d S r   rT   rU   axisr   r   rW   s     r   rU   zSoftmax.__init__  $    			r   c                 N    t           j                            || j                  S Nr   )r   r   softmaxr   r   s     r   r   zSoftmax.call  s    z!!!$)!444r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zSoftmax.compute_output_spec  r    r   r   r\   r^   s   @r   r   r     s[             5 5 53 3 3 3 3 3 3r   r   zkeras.ops.softmaxzkeras.ops.nn.softmaxr   c                 L   t          |t                    r1| j        |         dk    r t          j        d| d| j         d           t          | f          r"t          |                              |           S t          |t                    r| j        }g }t          |          }d}|t          |          k     rg||v r0d}||v r|||         z  }|dz  }||v |                    |           n |                    ||                    |dz  }|t          |          k     gt          j                            | |          } t          j                            | d          } t          j                            | |          } | S t          j                            | |          S )a  Softmax activation function.

    The elements of the output vector lie within the range `(0, 1)`, and their
    total sum is exactly 1 (excluding the floating point rounding error).

    Each vector is processed independently. The `axis` argument specifies the
    axis along which the function is applied within the input.

    It is defined as:
    `f(x) = exp(x) / sum(exp(x))`

    Args:
        x: Input tensor.
        axis: Integer, axis along which the softmax is applied.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_softmax = keras.ops.softmax(x)
    >>> print(x_softmax)
    array([0.09003057, 0.24472847, 0.66524096], shape=(3,), dtype=float64)

       z"You are using a softmax over axis z of a tensor of shape z. This axis has size 1. The softmax operation will always return the value 1, which is likely not what you intended. Did you mean to use a sigmoid instead?r   r   r   )
isinstanceintr   warningswarnr   r   r(   tuplesetlenappendr   numpyreshaper   r   r   r   original_shape	new_shape	skip_dimsisizes          r   r   r     s   > $ 
!!3!35 5 5$%G5 5 5	
 	
 	
 QD!! .t}}**1---$ 0	II	#n%%%%I~~9nnN1--DFA 9nn   &&&&  !2333Q #n%%%% M!!!Y//Jqr**M!!!^44z!!!$!///r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )
LogSoftmaxr   c                 V    t                                                       || _        d S r   r   r   s     r   rU   zLogSoftmax.__init__B  r   r   c                 N    t           j                            || j                  S r   )r   r   log_softmaxr   r   s     r   r   zLogSoftmax.callF  s    z%%adi%888r   c                 8    t          |j        |j                  S r   r   r   s     r   r   zLogSoftmax.compute_output_specI  r    r   r   r\   r^   s   @r   r   r   A  s[             9 9 93 3 3 3 3 3 3r   r   zkeras.ops.log_softmaxzkeras.ops.nn.log_softmaxc                    t          | f          r"t          |                              |           S t          |t                    r| j        }g }t          |          }d}|t          |          k     rg||v r0d}||v r|||         z  }|dz  }||v |                    |           n |                    ||                    |dz  }|t          |          k     gt          j
                            | |          } t          j                            | d          } t          j
                            | |          } | S t          j                            | |          S )a  Log-softmax activation function.

    It is defined as:
    `f(x) = x - max(x) - log(sum(exp(x - max(x))))`

    Args:
        x: Input tensor.
        axis: Integer, axis along which the log-softmax is applied.
            Defaults to `-1`.

    Returns:
        A tensor with the same shape as `x`.

    Example:

    >>> x = np.array([-1., 0., 1.])
    >>> x_log_softmax = keras.ops.log_softmax(x)
    >>> print(x_log_softmax)
    array([-2.40760596, -1.40760596, -0.40760596], shape=(3,), dtype=float64)

    r   r   r   r   )r   r   r(   r   r   r   r   r   r   r   r   r   r   r   r   s          r   r   r   M  sg   8 QD!! 1$--a000$ 4	II	#n%%%%I~~9nnN1--DFA 9nn   &&&&  !2333Q #n%%%% M!!!Y//J""12"..M!!!^44z%%ad%333r   c                   2     e Zd Z	 	 	 d fd	Zd Zd Z xZS )MaxPoolNvalidc                     t                                                       || _        || _        |                                | _        || _        d S r   rT   rU   	pool_sizestrideslowerpaddingdata_formatr   r   r   r   r   rW   s        r   rU   zMaxPool.__init__  F     	"}}&r   c                 p    t           j                            || j        | j        | j        | j                  S r   )r   r   max_poolr   r   r   r   r   inputss     r   r   zMaxPool.call  s4    z""NLL
 
 	
r   c                     t          j        |j        | j        | j        | j        | j                  }t          ||j                  S r   	r	   compute_pooling_output_shaper   r   r   r   r   r   r   r   r   output_shapes      r   r   zMaxPool.compute_output_spec  E    &CLNLL
 
 <v|<<<<r   Nr   Nr\   r^   s   @r   r   r     f         ' ' ' ' ' '
 
 
= = = = = = =r   r   zkeras.ops.max_poolzkeras.ops.nn.max_poolr   c                     t          |          }|                                }t          | f          r%t          ||||                              |           S t
          j                            | ||||          S )a  Max pooling operation.

    Args:
        inputs: Tensor of rank N+2. `inputs` has shape
            `(batch_size,) + inputs_spatial_shape + (num_channels,)` if
            `data_format="channels_last"`, or
            `(batch_size, num_channels) + inputs_spatial_shape` if
            `data_format="channels_first"`. Pooling happens over the spatial
            dimensions only.
        pool_size: int or tuple/list of integers of size
            `len(inputs_spatial_shape)`, specifying the size of the pooling
            window for each spatial dimension of the input tensor. If
            `pool_size` is int, then every spatial dimension shares the same
            `pool_size`.
        strides: int or tuple/list of integers of size
            `len(inputs_spatial_shape)`. The stride of the sliding window for
            each spatial dimension of the input tensor. If `strides` is int,
            then every spatial dimension shares the same `strides`.
        padding: string, either `"valid"` or `"same"`. `"valid"` means no
            padding is applied, and `"same"` results in padding evenly to the
            left/right or up/down of the input such that output has the
            same height/width dimension as the input when `strides=1`.
        data_format: A string, either `"channels_last"` or `"channels_first"`.
            `data_format` determines the ordering of the dimensions in the
            inputs. If `data_format="channels_last"`, `inputs` is of shape
            `(batch_size, ..., channels)` while if
            `data_format="channels_first"`, `inputs` is of shape
            `(batch_size, channels, ...)`.

    Returns:
        A tensor of rank N+2, the result of the max pooling operation.
    )r   r   r   r   r(   r   r   r   r   r   r   r   r   s        r   r   r     s~    P *+66KmmooGVI&&  	
 

 -

	  :vy'7KPPPr   c                   2     e Zd Z	 	 	 d fd	Zd Zd Z xZS )AveragePoolNr   c                     t                                                       || _        || _        |                                | _        || _        d S r   r   r   s        r   rU   zAveragePool.__init__  r   r   c                 p    t           j                            || j        | j        | j        | j                  S r   )r   r   average_poolr   r   r   r   r   s     r   r   zAveragePool.call  s4    z&&NLL
 
 	
r   c                     t          j        |j        | j        | j        | j        | j                  }t          ||j                  S r   r   r   s      r   r   zAveragePool.compute_output_spec  r   r   r   r\   r^   s   @r   r   r     r   r   r   zkeras.ops.average_poolzkeras.ops.nn.average_poolc                     t          |          }|                                }t          | f          r%t          ||||                              |           S t
          j                            | ||||          S )a  Average pooling operation.

    Args:
        inputs: Tensor of rank N+2. `inputs` has shape
            `(batch_size,) + inputs_spatial_shape + (num_channels,)` if
            `data_format="channels_last"`, or
            `(batch_size, num_channels) + inputs_spatial_shape` if
            `data_format="channels_first"`. Pooling happens over the spatial
            dimensions only.
        pool_size: int or tuple/list of integers of size
            `len(inputs_spatial_shape)`, specifying the size of the pooling
            window for each spatial dimension of the input tensor. If
            `pool_size` is int, then every spatial dimension shares the same
            `pool_size`.
        strides: int or tuple/list of integers of size
            `len(inputs_spatial_shape)`. The stride of the sliding window for
            each spatial dimension of the input tensor. If `strides` is int,
            then every spatial dimension shares the same `strides`.
        padding: string, either `"valid"` or `"same"`. `"valid"` means no
            padding is applied, and `"same"` results in padding evenly to the
            left/right or up/down of the input such that output has the
            same height/width dimension as the input when `strides=1`.
        data_format: A string, either `"channels_last"` or `"channels_first"`.
            `data_format` determines the ordering of the dimensions in the
            inputs. If `data_format="channels_last"`, `inputs` is of shape
            `(batch_size, ..., channels)` while if
            `data_format="channels_first"`, `inputs` is of shape
            `(batch_size, channels, ...)`.

    Returns:
        A tensor of rank N+2, the result of the average pooling operation.
    )r   r   r   r   r(   r   r   r   r   s        r   r   r     s    Z *+66KmmooGVI&&  	
 

 -

	  :""	7G[  r   c                   4     e Zd Z	 	 	 	 d fd	Zd Zd Z xZS )Convr   r   Nc                     t                                                       || _        |                                | _        || _        || _        d S r   rT   rU   r   r   r   r   dilation_rater   r   r   r   r   rW   s        r   rU   zConv.__init__6  G     	}}&*r   c                 t    t           j                            ||| j        | j        | j        | j                  S )N)r   r   r   r   )r   r   convr   r   r   r   r   r   kernels      r   r   z	Conv.callC  s;    zLL(,  
 
 	
r   c           	          t          j        |j        |j        d         |j        d d         | j        | j        | j        | j                  }t          ||j                  S Nr   r   	r	   compute_conv_output_shaper   r   r   r   r   r   r   r   r   r   r   s       r   r   zConv.compute_output_specM  s^    &@LLL"LL
 
 <v|<<<<r   r   r   Nr   r\   r^   s   @r   r   r   5  i         + + + + + +
 
 

= 
= 
= 
= 
= 
= 
=r   r   zkeras.ops.convzkeras.ops.nn.convr   c                     t          |          }|                                }t          | f          r&t          ||||                              | |          S t
          j                            | |||||          S )aZ  General N-D convolution.

    This ops supports 1D, 2D and 3D convolution.

    Args:
        inputs: Tensor of rank N+2. `inputs` has shape
            `(batch_size,) + inputs_spatial_shape + (num_channels,)` if
            `data_format="channels_last"`, or
            `(batch_size, num_channels) + inputs_spatial_shape` if
            `data_format="channels_first"`.
        kernel: Tensor of rank N+2. `kernel` has shape
            `(kernel_spatial_shape, num_input_channels, num_output_channels)`.
            `num_input_channels` should match the number of channels in
            `inputs`.
        strides: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the strides of the convolution along each spatial
            dimension. If `strides` is int, then every spatial dimension shares
            the same `strides`.
        padding: string, either `"valid"` or `"same"`. `"valid"` means no
            padding is applied, and `"same"` results in padding evenly to the
            left/right or up/down of the input such that output has the
            same height/width dimension as the input when `strides=1`.
        data_format: A string, either `"channels_last"` or `"channels_first"`.
            `data_format` determines the ordering of the dimensions in the
            inputs. If `data_format="channels_last"`, `inputs` is of shape
            `(batch_size, ..., channels)` while if
            `data_format="channels_first"`, `inputs` is of shape
            `(batch_size, channels, ...)`.
        dilation_rate: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the dilation rate to use for dilated convolution. If
            `dilation_rate` is int, then every spatial dimension shares
            the same `dilation_rate`.

    Returns:
        A tensor of rank N+2, the result of the conv operation.
    )r   r   r   r   r(   r   r   r   r   r   r   r   r   r   s         r   r   r   Z  s    Z *+66KmmooGVI&& 
GWk=AAOOF
 
 	
 :??+}  r   c                   4     e Zd Z	 	 	 	 d fd	Zd Zd Z xZS )DepthwiseConvr   r   Nc                     t                                                       || _        |                                | _        || _        || _        d S r   r   r   s        r   rU   zDepthwiseConv.__init__  r   r   c                 r    t           j                            ||| j        | j        | j        | j                  S r   )r   r   depthwise_convr   r   r   r   r   s      r   r   zDepthwiseConv.call  s8    z((LL
 
 	
r   c           	          t          j        |j        |j        d         |j        d         z  |j        d d         | j        | j        | j        | j                  }t          ||j                  S r   r   r   s       r   r   z!DepthwiseConv.compute_output_spec  sj    &@LLv|B//L"LL
 
 <v|<<<<r   r   r\   r^   s   @r   r   r     r   r   r   zkeras.ops.depthwise_convzkeras.ops.nn.depthwise_convc                     t          |          }|                                }t          | f          r&t          ||||                              | |          S t
          j                            | |||||          S )av  General N-D depthwise convolution.

    This ops supports 1D and 2D depthwise convolution.

    Args:
        inputs: Tensor of rank N+2. `inputs` has shape
            `(batch_size,) + inputs_spatial_shape + (num_channels,)` if
            `data_format="channels_last"`, or
            `(batch_size, num_channels) + inputs_spatial_shape` if
            `data_format="channels_first"`.
        kernel: Tensor of rank N+2. `kernel` has shape
            [kernel_spatial_shape, num_input_channels, num_channels_multiplier],
            `num_input_channels` should match the number of channels in
            `inputs`.
        strides: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the strides of the convolution along each spatial
            dimension. If `strides` is int, then every spatial dimension shares
            the same `strides`.
        padding: string, either `"valid"` or `"same"`. `"valid"` means no
            padding is applied, and `"same"` results in padding evenly to the
            left/right or up/down of the input such that output has the
            same height/width dimension as the input when `strides=1`.
        data_format: A string, either `"channels_last"` or `"channels_first"`.
            `data_format` determines the ordering of the dimensions in the
            inputs. If `data_format="channels_last"`, `inputs` is of shape
            `(batch_size, ..., channels)` while if
            `data_format="channels_first"`, `inputs` is of shape
            `(batch_size, channels, ...)`.
        dilation_rate: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the dilation rate to use for dilated convolution. If
            `dilation_rate` is int, then every spatial dimension shares
            the same `dilation_rate`.

    Returns:
        A tensor of rank N+2, the result of the depthwise conv operation.
    )r   r   r   r   r(   r   r   r   r   s         r   r   r     s    d *+66KmmooGVI&& (Wk=
 

-
'
'	( :$$  r   c                   4     e Zd Z	 	 	 	 d fd	Zd Zd Z xZS )SeparableConvr   r   Nc                     t                                                       || _        |                                | _        || _        || _        d S r   r   r   s        r   rU   zSeparableConv.__init__  r   r   c           	      t    t           j                            |||| j        | j        | j        | j                  S r   )r   r   separable_convr   r   r   r   )r   r   depthwise_kernelpointwise_kernels       r   r   zSeparableConv.call  s;    z((LL
 
 	
r   c           
          t          t          ||| j        | j        | j        | j                  j                  }| j        dk    r|j        d         |d<   n|j        d         |d<   t          ||j                  S )Nchannels_lastr   r   r   )	listr   r   r   r   r   r   r   r   )r   r   r   r   r   s        r   r   z!SeparableConv.compute_output_spec  s      "  	
 	
 ../5b9L.4R8LO<v|<<<<r   r   r\   r^   s   @r   r   r     si         + + + + + +	
 	
 	
= = = = = = =r   r   zkeras.ops.separable_convzkeras.ops.nn.separable_convc           	          t          |          }|                                }t          | f          r't          ||||                              | ||          S t
          j                            | ||||||          S )a  General N-D separable convolution.

    This ops supports 1D and 2D separable convolution. `separable_conv` is
    a depthwise conv followed by a pointwise conv.

    Args:
        inputs: Tensor of rank N+2. `inputs` has shape
            `(batch_size,) + inputs_spatial_shape + (num_channels,)` if
            `data_format="channels_last"`, or
            `(batch_size, num_channels) + inputs_spatial_shape` if
            `data_format="channels_first"`.
        depthwise_kernel: Tensor of rank N+2. `depthwise_kernel` has shape
            [kernel_spatial_shape, num_input_channels, num_channels_multiplier],
            `num_input_channels` should match the number of channels in
            `inputs`.
        pointwise_kernel: Tensor of rank N+2. `pointwise_kernel` has shape
            `(*ones_like(kernel_spatial_shape),
            num_input_channels * num_channels_multiplier, num_output_channels)`.
        strides: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the strides of the convolution along each spatial
            dimension. If `strides` is int, then every spatial dimension shares
            the same `strides`.
        padding: string, either `"valid"` or `"same"`. `"valid"` means no
            padding is applied, and `"same"` results in padding evenly to the
            left/right or up/down of the input such that output has the
            same height/width dimension as the input when `strides=1`.
        data_format: A string, either `"channels_last"` or `"channels_first"`.
            `data_format` determines the ordering of the dimensions in the
            inputs. If `data_format="channels_last"`, `inputs` is of shape
            `(batch_size, ..., channels)` while if
            `data_format="channels_first"`, `inputs` is of shape
            `(batch_size, channels, ...)`.
        dilation_rate: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the dilation rate to use for dilated convolution. If
            `dilation_rate` is int, then every spatial dimension shares
            the same `dilation_rate`.

    Returns:
        A tensor of rank N+2, the result of the depthwise conv operation.
    )r   r   r   r   r(   r   r   r   )r   r   r   r   r   r   r   s          r   r   r   $  s    n *+66KmmooGVI&& D	
 

 - 02B
C
C	D :$$  r   c                   4     e Zd Z	 	 	 	 d fd	Zd Zd Z xZS )ConvTransposer   Nr   c                     t                                                       || _        || _        |                                | _        || _        || _        d S r   )rT   rU   r   output_paddingr   r   r   r   )r   r   r   r   r   r   rW   s         r   rU   zConvTranspose.__init__p  sO     	,}}&*r   c           	      ~    t           j                            ||| j        | j        | j        | j        | j                  S r   )r   r   conv_transposer   r   r   r   r   r   s      r   r   zConvTranspose.call  s@    
 z((LL
 
 	
r   c           
          |j         d d         }|j         d         }t          |j         ||| j        | j        | j        | j        | j                  }t          ||j                  S )Nr   r   )	r   r   r   r   r   r   r   r   r   )r   r   r   kernel_sizefiltersr   s         r   r   z!ConvTranspose.compute_output_spec  sk    l3B3',r":LLL	
 	
 <v|<<<<r   r   NNr   r\   r^   s   @r   r   r   o  si         + + + + + +
 
 
= = = = = = =r   r   zkeras.ops.conv_transposezkeras.ops.nn.conv_transposec           	          t          |          }|                                }t          | f          r't          |||||                              | |          S t
          j                            | ||||||          S )a^	  General N-D convolution transpose.

    Also known as de-convolution. This ops supports 1D, 2D and 3D convolution.

    Args:
        inputs: Tensor of rank N+2. `inputs` has shape
            `(batch_size,) + inputs_spatial_shape + (num_channels,)` if
            `data_format="channels_last"`, or
            `(batch_size, num_channels) + inputs_spatial_shape` if
            `data_format="channels_first"`.
        kernel: Tensor of rank N+2. `kernel` has shape
            [kernel_spatial_shape, num_output_channels, num_input_channels],
            `num_input_channels` should match the number of channels in
            `inputs`.
        strides: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the strides of the convolution along each spatial
            dimension. If `strides` is int, then every spatial dimension shares
            the same `strides`.
        padding: string, either `"valid"` or `"same"`. `"valid"` means no
            padding is applied, and `"same"` results in padding evenly to the
            left/right or up/down of the input such that output has the
            same height/width dimension as the input when `strides=1`.
        output_padding: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the amount of padding along the height and width of
            the output tensor. Can be a single integer to specify the same
            value for all spatial dimensions. The amount of output padding
            along a given dimension must be lower than the stride along that
            same dimension. If set to `None` (default), the output shape is
            inferred.
        data_format: A string, either `"channels_last"` or `"channels_first"`.
            `data_format` determines the ordering of the dimensions in the
            inputs. If `data_format="channels_last"`, `inputs` is of shape
            `(batch_size, ..., channels)` while if
            `data_format="channels_first"`, `inputs` is of shape
            `(batch_size, channels, ...)`.
        dilation_rate: int or int tuple/list of `len(inputs_spatial_shape)`,
            specifying the dilation rate to use for dilated convolution. If
            `dilation_rate` is int, then every spatial dimension shares
            the same `dilation_rate`.

    Returns:
        A tensor of rank N+2, the result of the conv operation.
    )r   r   r   r   r(   r   r   r   )r   r   r   r   r   r   r   s          r   r   r     s    t *+66KmmooGVI&& (Wnk=
 

-
'
'	( :$$  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )OneHotr   NFc                     t                                                       || _        || _        |pt	          j                    | _        || _        d S r   )rT   rU   num_classesr   r   floatxr   sparse)r   r  r   r   r  rW   s        r   rU   zOneHot.__init__  sG    &	.gn..
r   c                 r    t           j                            || j        | j        | j        | j                  S )Nr   r   r  )r   r   one_hotr  r   r   r  r   s     r   r   zOneHot.call  s9    z!!*; " 
 
 	
r   c                    t          t          |dg                     }| j        dk    r|                    | j                   nq| j        dk    r9| j        t          |          k     r!|                    | j        | j                   n-t          dt          |j                   d| j         d          t          || j
        | j                  S )Nr   r   r   axis must be -1 or between [0, ), but received .r   r  r   getattrr   r   r  r   insert
ValueErrorr   r   r   r  )r   r   x_shapes      r   r   zOneHot.compute_output_spec  s    wq'2..//9??NN4+,,,,Y!^^	CLL 8 8NN49d&67777)#ag,, ) ) I) ) )   7$*T[IIIIr   r   NFr\   r^   s   @r   r  r    sb             
 
 
J J J J J J Jr   r  zkeras.ops.one_hotzkeras.ops.nn.one_hotFc                     t          | f          r&t          ||||                              |           S t          j                            | |||pt          j                    |          S )ax  Converts integer tensor `x` into a one-hot tensor.

    The one-hot encoding is a representation where each integer value is
    converted into a binary vector with a length equal to `num_classes`,
    and the index corresponding to the integer value is marked as 1, while
    all other indices are marked as 0.

    Args:
        x: Integer tensor to be encoded. The shape can be
            arbitrary, but the dtype should be integer.
        num_classes: Number of classes for the one-hot encoding.
        axis: Axis along which the encoding is performed. Defaults to
            `-1`, which represents the last axis.
        dtype: (Optional) Data type of the output tensor. If not
            provided, it defaults to the default data type of the backend.
        sparse: Whether to return a sparse tensor; for backends that support
            sparse tensors.

    Returns:
        Integer tensor: One-hot encoded tensor with the same shape as `x`
        except for the specified `axis` dimension, which will have
        a length of `num_classes`. The dtype of the output tensor
        is determined by `dtype` or the default data type of the backend.

    Example:

    >>> x = keras.ops.convert_to_tensor([1, 3, 2, 0])
    >>> one_hot(x, num_classes=4)
    array([[0. 1. 0. 0.]
           [0. 0. 0. 1.]
           [0. 0. 1. 0.]
           [1. 0. 0. 0.]], shape=(4, 4), dtype=float32)
    r  )r   r  r(   r   r   r	  r  )r   r  r   r   r  s        r   r	  r	    s    F QD!! d%
 
 

-

	 :	'w~''    r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )BinaryCrossentropyFc                 V    t                                                       || _        d S r   )rT   rU   from_logits)r   r  rW   s     r   rU   zBinaryCrossentropy.__init__9  r   r   c                 P    t           j                            ||| j                  S )Nr  )r   r   binary_crossentropyr  r   targetoutputs      r   r   zBinaryCrossentropy.call=  s+    z--F(8 . 
 
 	
r   c                     |j         |j         k    rt          d|j          d|j                    t          |j         |j                  S )NQArguments `target` and `output` must have the same shape. Received: target.shape=, output.shape=r   )r   r  r   r   r  s      r   r   z&BinaryCrossentropy.compute_output_specB  sd    <6<''L &L L=C\L L  
 6<v|<<<<r   Fr\   r^   s   @r   r  r  8  s[        ' ' ' ' ' '
 
 

= = = = = = =r   r  zkeras.ops.binary_crossentropyz keras.ops.nn.binary_crossentropyc                     t          | |f          r$t          |                              | |          S t          j                            | ||          S )a  Computes binary cross-entropy loss between target and output tensor.

    The binary cross-entropy loss is commonly used in binary
    classification tasks where each input sample belongs to one
    of the two classes. It measures the dissimilarity between the
    target and output probabilities or logits.

    Args:
        target: The target tensor representing the true binary labels.
            Its shape should match the shape of the `output` tensor.
        output: The output tensor representing the predicted probabilities
            or logits. Its shape should match the shape of the
            `target` tensor.
        from_logits: (optional) Whether `output` is a tensor of logits or
            probabilities.
            Set it to `True` if `output` represents logits; otherwise,
            set it to `False` if `output` represents probabilities.
            Defaults to`False`.

    Returns:
        Integer tensor: The computed binary cross-entropy loss between
        `target` and `output`.

    Example:

    >>> target = keras.ops.convert_to_tensor([0, 1, 1, 0])
    >>> output = keras.ops.convert_to_tensor([0.1, 0.9, 0.8, 0.2])
    >>> binary_crossentropy(target, output)
    array([0.10536054 0.10536054 0.22314355 0.22314355],
          shape=(4,), dtype=float32)
    r  )r   r  r(   r   r   r  )r  r  r  s      r   r  r  L  sj    L VV,-- 
!k:::HHF
 
 	
 :))K *   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )CategoricalCrossentropyFr   c                 d    t                                                       || _        || _        d S r   rT   rU   r  r   r   r  r   rW   s      r   rU   z CategoricalCrossentropy.__init__|  ,    &			r   c                 \    t           j                            ||| j        | j                  S Nr  r   )r   r   categorical_crossentropyr  r   r  s      r   r   zCategoricalCrossentropy.call  s/    z22F(8ty 3 
 
 	
r   c                    |j         |j         k    rt          d|j          d|j                    t          |j                   dk     rt          d|j          d|j                    t          |j         d d         |j                  S )Nr!  r"  r   zPArguments `target` and `output` must be at least rank 1. Received: target.shape=r   r   )r   r  r   r   r   r  s      r   r   z+CategoricalCrossentropy.compute_output_spec  s    <6<''L &L L=C\L L  
 v|q  L &L L=C\L L  
 6<,FLAAAAr   Fr   r\   r^   s   @r   r&  r&  {  sb             

 
 

B B B B B B Br   r&  z"keras.ops.categorical_crossentropyz%keras.ops.nn.categorical_crossentropyc                     t          | |f          r%t          ||                              | |          S t          j                            | |||          S )a  Computes categorical cross-entropy loss between target and output tensor.

    The categorical cross-entropy loss is commonly used in multi-class
    classification tasks where each input sample can belong to one of
    multiple classes. It measures the dissimilarity
    between the target and output probabilities or logits.

    Args:
        target: The target tensor representing the true categorical labels.
            Its shape should match the shape of the `output` tensor
            except for the last dimension.
        output: The output tensor representing the predicted probabilities
            or logits. Its shape should match the shape of the `target`
            tensor except for the last dimension.
        from_logits: (optional) Whether `output` is a tensor of logits or
            probabilities.
            Set it to `True` if `output` represents logits; otherwise,
            set it to `False` if `output` represents probabilities.
            Defaults to`False`.
        axis: (optional) The axis along which the categorical cross-entropy
            is computed.
            Defaults to `-1`, which corresponds to the last dimension of
            the tensors.

    Returns:
        Integer tensor: The computed categorical cross-entropy loss between
        `target` and `output`.

    Example:

    >>> target = keras.ops.convert_to_tensor(
    ... [[1, 0, 0],
    ...  [0, 1, 0],
    ...  [0, 0, 1]])
    >>> output = keras.ops.convert_to_tensor(
    ... [[0.9, 0.05, 0.05],
    ...  [0.1, 0.8, 0.1],
    ...  [0.2, 0.3, 0.5]])
    >>> categorical_crossentropy(target, output)
    array([0.10536054 0.22314355 0.6931472 ], shape=(3,), dtype=float32)
    r-  )r   r&  r(   r   r   r.  r  r  r  r   s       r   r.  r.    so    ` VV,-- (&#$
 
 

-
'
'	( :..Kd /   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )SparseCategoricalCrossentropyFr   c                 d    t                                                       || _        || _        d S r   r(  r)  s      r   rU   z&SparseCategoricalCrossentropy.__init__  r*  r   c                 \    t           j                            ||| j        | j                  S r,  )r   r   sparse_categorical_crossentropyr  r   r  s      r   r   z"SparseCategoricalCrossentropy.call  s/    z99F(8ty : 
 
 	
r   c                    t          |j                  dk     rt          d|j                   |j        }t          |          t          |j                  k    r|d         dk    r
|d d         }||j        d d         k    rt          d|j         d|j                   t          |j        d d         |j                  S )Nr   zBArgument `output` must be at least rank 1. Received: output.shape=r   zcArguments `target` and `output` must have the same shape up until the last dimension: target.shape=r"  r   )r   r   r  r   r   )r   r  r  target_shapes       r   r   z1SparseCategoricalCrossentropy.compute_output_spec  s    v|q  / &/ /  
 ||FL 1 111l26F!6K6K',L6<,,,L &L L=C\L L  
 6<,FLAAAAr   r0  r\   r^   s   @r   r4  r4    sb             

 
 

B B B B B B Br   r4  z)keras.ops.sparse_categorical_crossentropyz,keras.ops.nn.sparse_categorical_crossentropyc                     t          | |f          r%t          ||                              | |          S t          j                            | |||          S )a  Computes sparse categorical cross-entropy loss.

    The sparse categorical cross-entropy loss is similar to categorical
    cross-entropy, but it is used when the target tensor contains integer
    class labels instead of one-hot encoded vectors. It measures the
    dissimilarity between the target and output probabilities or logits.

    Args:
        target: The target tensor representing the true class labels as
            integers. Its shape should match the shape of the `output`
            tensor except for the last dimension.
        output: The output tensor representing the predicted probabilities
            or logits.
            Its shape should match the shape of the `target` tensor except
            for the last dimension.
        from_logits: (optional) Whether `output` is a tensor of logits
            or probabilities.
            Set it to `True` if `output` represents logits; otherwise,
            set it to `False` if `output` represents probabilities.
            Defaults to`False`.
        axis: (optional) The axis along which the sparse categorical
            cross-entropy is computed.
            Defaults to `-1`, which corresponds to the last dimension
            of the tensors.

    Returns:
        Integer tensor: The computed sparse categorical cross-entropy
        loss between `target` and `output`.

    Example:

    >>> target = keras.ops.convert_to_tensor([0, 1, 2], dtype=int32)
    >>> output = keras.ops.convert_to_tensor(
    ... [[0.9, 0.05, 0.05],
    ...  [0.1, 0.8, 0.1],
    ...  [0.2, 0.3, 0.5]])
    >>> sparse_categorical_crossentropy(target, output)
    array([0.10536056 0.22314355 0.6931472 ], shape=(3,), dtype=float32)
    r-  )r   r4  r(   r   r   r7  r2  s       r   r7  r7    so    \ VV,-- (,#$
 
 

-
'
'	( :55Kd 6   r   c                   .     e Zd Z	 d fd	Zd Zd Z xZS )MultiHotNr   Fc                     |d|v r|                     d          }|t          d           t                      j        di | || _        || _        |pt          j                    | _        || _	        d S )N
num_tokens)Argument `num_classes` must be specified.r%   )
popr  rT   rU   r  r   r   r  r   r  )r   r  r   r   r  kwargsrW   s         r   rU   zMultiHot.__init__%  s     <6#9#9 **\22KHIII""6"""&	.gn..
r   c                 f    t           j                            || j        | j        | j                  S )N)r  r   r   )r   r   	multi_hotr  r   r   r   s     r   r   zMultiHot.call2  s4    z##(*	 $ 
 
 	
r   c                    t          t          |dg                     }| j        dk    r|                    | j                   nq| j        dk    r9| j        t          |          k     r!|                    | j        | j                   n-t          dt          |j                   d| j         d          t          |          dk    r
|d         g}n|d         g|dd          z   }t          ||j
        | j                  S )	Nr   r   r   r  r  r     r  r  )r   r   r  s      r   r   zMultiHot.compute_output_spec:  s	   wvw33449??NN4+,,,,Y!^^	CLL 8 8NN49d&67777)#fl2C2C ) ) I) ) )  
 w<<1r{mGGqzlWQRR[0G7&,t{KKKKr   Nr   NFr\   r^   s   @r   r<  r<  $  se        <A     
 
 
L L L L L L Lr   r<  zkeras.ops.multi_hotzkeras.ops.nn.multi_hotc                 
   |d|v r|                     d          }|t          d          t          | f          r%t          ||||                              |           S t
          j                            | ||||          S )a  Encodes integer labels as multi-hot vectors.

    This function encodes integer labels as multi-hot vectors, where each label
    is mapped to a binary value in the resulting vector.

    Args:
        inputs: Tensor of integer labels to be converted to multi-hot vectors.
        num_classes: Integer, the total number of unique classes.
        axis: (optional) Axis along which the multi-hot encoding should be
            added. Defaults to `-1`, which corresponds to the last dimension.
        dtype: (optional) The data type of the resulting tensor. Default
            is backend's float type.
        sparse: Whether to return a sparse tensor; for backends that support
            sparse tensors.

    Returns:
        Tensor: The multi-hot encoded tensor.

    Example:

    >>> data = keras.ops.convert_to_tensor([0, 4])
    >>> keras.ops.multi_hot(data, num_classes=5)
    array([1.0, 0.0, 0.0, 0.0, 1.0], dtype=float32)

    Nr>  r?  )r@  r  r   r<  r(   r   r   rC  )r   r  r   r   r  rA  s         r   rC  rC  N  s    D |v55jj..DEEEVI&& PT5&99GGOOO:T5&IIIr   c                   ,     e Zd Zd fd	Zd Zd Z xZS )MomentsFc                 r    t                                                       || _        || _        || _        d S r   )rT   rU   axeskeepdimssynchronized)r   rK  rL  rM  rW   s       r   rU   zMoments.__init__|  s5    	 (r   c                 f    t           j                            || j        | j        | j                  S )N)rK  rL  rM  )r   r   momentsrK  rL  rM  r   s     r   r   zMoments.call  s4    z!!]*	 " 
 
 	
r   c                     t          t          |j        | j        | j                  |j                  t          t          |j        | j        | j                  |j                  fS )N)r   rL  r   )r   r   r   rK  rL  r   r   s     r   r   zMoments.compute_output_spec  sl    QW49t}MMMg   QW49t}MMMg  	
 		
r   FFr\   r^   s   @r   rI  rI  {  s[        ) ) ) ) ) )
 
 


 

 

 

 

 

 

r   rI  zkeras.ops.momentszkeras.ops.nn.momentsc                     t          | f          r%t          |||                              |           S t          j                            | |||          S )a!  Calculates the mean and variance of `x`.

    The mean and variance are calculated by aggregating the contents of `x`
    across `axes`. If `x` is 1-D and `axes = [0]` this is just the mean and
    variance of a vector.

    Args:
        x: Input tensor.
        axes: A list of axes which to compute mean and variance.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one.
        synchronized: Only applicable with the TensorFlow backend.
            If `True`, synchronizes the global batch statistics (mean and
            variance) across all devices at each training step in a
            distributed training strategy. If `False`, each replica uses its own
            local batch statistics.

    Returns:
        A tuple containing two tensors - mean and variance.

    Example:

    >>> x = keras.ops.convert_to_tensor([0, 1, 2, 3, 100], dtype="float32")
    >>> keras.ops.moments(x, axes=[0])
    (array(21.2, dtype=float32), array(1553.3601, dtype=float32))

    )rM  )r   rI  r(   r   r   rO  )r   rK  rL  rM  s       r   rO  rO    sb    D QD!! 
tXLAAAOO
 
 	
 :axlKKKr   c                   *     e Zd Z fdZd Zd Z xZS )	BatchNormc                 d    t                                                       || _        || _        d S r   )rT   rU   r   epsilon)r   r   rV  rW   s      r   rU   zBatchNorm.__init__  s+    	r   c           	      D    ||k    rt          d| d| d| d          d S )NArguments `z9` must be a vector of length `x.shape[axis]`. Expected: `z`. Received: `r  r  )r   namer   expected_shapes       r   _check_shapezBatchNorm._check_shape  sW    N""'d ' '/=' '#' ' '   #"r   c                    |j         | j                 f}|                     dt          |j                   |           |                     dt          |j                   |           |)|                     dt          |j                   |           ||ur)|                     dt          |j                   |           t	          |j         |j                  S )Nmeanvarianceoffsetscaler   )r   r   r\  r   r   r   )r   r   r^  r_  r`  ra  r   s          r   r   zBatchNorm.compute_output_spec  s    #%&%
"3"3U;;;*eHN&;&;UCCChfl(;(;UCCCguU['9'95AAA17!'2222r   )r"   r#   r$   rU   r\  r   r]   r^   s   @r   rT  rT    sV            
  3 3 3 3 3 3 3r   rT  zkeras.ops.batch_normalizationz keras.ops.nn.batch_normalizationMbP?c           	          t          | ||||f          r't          ||                              | ||||          S t          j                            | ||||||          S )a  Normalizes `x` by `mean` and `variance`.

    This op is typically used by the batch normalization step in a neural
    network. It normalizes the input tensor along the given axis.

    Args:
        x: Input tensor.
        mean: A mean vector of the same length as the `axis` dimension of the
            input thensor.
        variance: A variance vector of the same length as the `axis` dimension
            of the input tensor.
        axis: Integer, the axis that should be normalized.
        offset: An offset vector of the same length as the `axis` dimension of
            the input tensor. If not `None`, `offset` is added to the normalized
            tensor. Defaults to `None`.
        scale: A scale vector of the same length as the `axis` dimension of the
            input tensor. If not `None`, the normalized tensor is multiplied by
            `scale`. Defaults to `None`.
        epsilon: Small float added to variance to avoid dividing by zero.
            Defaults to 1e-3.

    Returns:
        The normalized tensor.

    Example:

    >>> x = keras.ops.convert_to_tensor(
    ...     [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9]]
    ... )
    >>> keras.ops.batch_normalization(
    ...     x,
    ...     mean=[0.4, 0.5, 0.6],
    ...     variance=[0.67, 0.67, 0.67],
    ...     axis=-1
    ... )
    array([[-3.6624e-01, -3.6624e-01, -3.6624e-01],
           [-4.6445e-09,  0.0000e+00, -1.8578e-08],
           [ 3.6624e-01,  3.6624e-01,  3.6624e-01]])

    )r   rT  r(   r   r   batch_normalization)r   r^  r_  r   r`  ra  rV  s          r   rd  rd    sx    b Qh>?? 
w''55tXvu
 
 	
 :))	44  r   c                   2     e Zd Zd fd	Zd Zd Zd Z xZS )CTCLossr   c                 V    t                                                       || _        d S r   )rT   rU   
mask_index)r   rh  rW   s     r   rU   zCTCLoss.__init__  s$    $r   c                 R    t           j                            ||||| j                  S r   )r   r   ctc_lossrh  )r   r  r  target_lengthoutput_lengths        r   r   zCTCLoss.call  s)    z""FM=$/
 
 	
r   c                 b    |d         |d         k    rt          d| d| d| d| d	          d S )Nr   rX  z` and `z8` must have the same first dimension. Received shapes: `z`.rY  )r   name1shape1name2shape2s        r   _check_shape_first_dimzCTCLoss._check_shape_first_dim  sk    !9q	!!?e ? ?E ? ?%+? ?4:? ? ?   "!r   c                 <   |                      d|j        d|j                   |                      d|j        d|j                   |                      d|j        d|j                   t          j        |j        d          }t          |j        d         f|          S )Nr  r  rk  rl  float32r   r   )rr  r   r   result_typer   r   )r   r  r  rk  rl  r   s         r   r   zCTCLoss.compute_output_spec'  s    ##flHfl	
 	
 	
 	##]0(FL	
 	
 	
 	##]0(FL	
 	
 	
 #FL)<<FLO-U;;;;r   r   )r"   r#   r$   rU   r   rr  r   r]   r^   s   @r   rf  rf    sj        % % % % % %
 
 

  < < < < < < <r   rf  zkeras.ops.ctc_losszkeras.ops.nn.ctc_lossc                     t          | |||f          r%t          |                              | |||          S t          j                            | ||||          S )al  CTC (Connectionist Temporal Classification) loss.

    Args:
        target: A tensor of shape `(batch_size, max_length)` containing
            the true labels in integer format.
        output: A tensor of shape `(batch_size, max_length, num_classes)`
            containing logits (the output of your model).
        target_length: A tensor of shape `(batch_size,)` containing the
            true label lengths.
        output_length: A tensor of shape `(batch_size,)` containing the
            output lengths.
        mask_index: The index of the mask character in the vocabulary.
            Defaults to `0`.
    )r   rf  r(   r   r   rj  )r  r  rk  rl  rh  s        r   rj  rj  5  sm    , VV]MJKK 
z""00FM=
 
 	
 :}j  r   c                   6     e Zd Z	 	 	 	 	 d	 fd	Zd Zd Z xZS )
	CTCDecodegreedyd   r   TNc                     t                                                       || _        || _        || _        || _        || _        d S r   )rT   rU   strategy
beam_width	top_pathsmerge_repeatedrh  )r   r}  r~  r  r  rh  rW   s         r   rU   zCTCDecode.__init__U  sC     	 $",$r   c           	          t           j                            ||| j        | j        | j        | j        | j                  S )Nr}  r~  r  r  rh  )r   r   
ctc_decoder}  r~  r  r  rh  )r   r   sequence_lengthss      r   r   zCTCDecode.calld  sA    z$$]n. % 
 
 	
r   c                     |j         }| j        dk    rd}n| j        }t          j        |j        d          }t          ||d         |d         fd          t          |d         |f|          fS )Nrz  r   rt  r   int32r   )r   r}  r  r   ru  r   r   )r   r   r  inputs_shaper  r   s         r   r   zCTCDecode.compute_output_speco  s    |=H$$III#FL)<<LO\!_=W   a)4EBBB	
 	
r   rz  r{  r   TNr\   r^   s   @r   ry  ry  T  sl         % % % % % %	
 	
 	

 
 
 
 
 
 
r   ry  zkeras.ops.ctc_decodezkeras.ops.nn.ctc_decoderz  r{  c           	          t          | |f          r(t          |||||                              | |          S t          j                            | ||||||          S )a;  Decodes the output of a CTC model.

    Args:
        inputs: A tensor of shape `(batch_size, max_length, num_classes)`
            containing the logits (the output of the model).
            They should *not* be normalized via softmax.
        sequence_lengths: A tensor of shape `(batch_size,)` containing the
            sequence lengths for the batch.
        strategy: A string for the decoding strategy. Supported values are
            `"greedy"` and `"beam_search"`.
        beam_width: An integer scalar beam width used in beam search.
            Defaults to 100.
        top_paths: An integer scalar, the number of top paths to return.
            Defaults to 1.
        merge_repeated: A boolean scalar, whether to merge repeated
            labels in the output. Defaults to `True`.
        mask_index: An integer scalar, the index of the mask character in
            the vocabulary. Defaults to `None`.

    Returns:
        A tuple containing:
        - The tensor representing the list of decoded sequences. If
            `strategy="greedy"`, the shape is `(1, batch_size, max_length)`. If
            `strategy="beam_seatch"`, the shape is
            `(top_paths, batch_size, max_length)`. Note that: `-1` indicates the
            blank label.
        - If `strategy="greedy"`, a tensor of shape `(batch_size, 1)`
            representing the negative of the sum of the probability logits for
            each sequence. If `strategy="beam_seatch"`, a tensor of shape
            `(batch_size, top_paths)` representing the log probability for each
            sequence.
    r  )r   sequence_lengthr}  r~  r  r  rh  )r   ry  r(   r   r   r  )r   r  r}  r~  r  r  rh  s          r   r  r  ~  s    ` V%5677 2!)!
 
 
 - 0
1
1	2 :  (% !   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )	Normalizer   rE  c                 d    t                                                       || _        || _        d S r   )rT   rU   r   order)r   r   r  rW   s      r   rU   zNormalize.__init__  s+    	


r   c                 ,    t          |j                  S )Nr   )r   r   r   s     r   r   zNormalize.compute_output_spec  s    ))))r   c                 :    t          || j        | j                  S )Nr   r  )
_normalizer   r  r   s     r   r   zNormalize.call  s    !$)4:>>>>r   r   rE  )r"   r#   r$   rU   r   r   r]   r^   s   @r   r  r    s[             
* * *? ? ? ? ? ? ?r   r  zkeras.ops.normalizezkeras.ops.nn.normalizerE  c                     t          | f          r$t          ||                              |           S t          | ||          S )a  Normalizes `x` over the specified axis.

    It is defined as: `normalize(x) = x / max(norm(x), epsilon)`.

    Args:
        x: Input tensor.
        axis: The axis or axes along which to perform normalization.
            Default to -1.
        order: The exponent value in the norm formulation.
            Defaults to 2.

    Returns:
        The normalized array.

    Example:

    >>> x = keras.ops.convert_to_tensor([[1, 2, 3], [4, 5, 6]])
    >>> x_norm = keras.ops.math.normalize(x)
    >>> print(x_norm)
    array([[0.26726124 0.5345225  0.8017837 ]
           [0.45584232 0.5698029  0.68376344]], shape=(2, 3), dtype=float32)

    r  )r   r  r(   r  )r   r   r  s      r   	normalizer    sM    < QD!! Bd%000>>qAAAad%0000r   c                    t          |t                    r|dk    st          d|           t          j        |           } t          | j                  dk    r!t          j                            | d          } t          j	                    }t          j
                            | ||d          }t          j                            ||          }t          j                            | |          S )Nr   z6Argument `order` must be an int >= 1. Received: order=r   r   T)ordr   rL  )r   r   r  r   convert_to_tensorr   r   r   expand_dimsrV  linalgnormmaximumdivide)r   r   r  rV  r  denoms         r   r  r    s    eS!! 
!LULL
 
 	
 	!!$$A
17||qM%%aa%00oG>qe$FFDM!!$00E=5)))r   c                   *     e Zd Z fdZd Zd Z xZS )PSNRc                 V    t                                                       || _        d S r   )rT   rU   max_val)r   r  rW   s     r   rU   zPSNR.__init__   s&     	r   c                 P    t           j                            ||| j                  S )Nx1x2r  )r   r   psnrr  r   r  r  s      r   r   z	PSNR.call  s*    zL  
 
 	
r   c                     t          |j                  t          |j                  k    rt          d          t          d          S )NzInputs must have the same rankr%   r  )r   r   r  r   r  s      r   r   zPSNR.compute_output_spec  s=    rx==CMM))=>>>$$$$r   r\   r^   s   @r   r  r    sV            
 
 
% % % % % % %r   r  zkeras.ops.psnrzkeras.ops.nn.psnrc                     t          | |f          r#t          |                              | |          S t          j                            | ||          S )a:  Peak Signal-to-Noise Ratio (PSNR) function.

    This function computes the Peak Signal-to-Noise Ratio between two signals,
    `x1` and `x2`. PSNR is a measure of the quality of a reconstructed signal.
    The higher the PSNR, the closer the reconstructed signal is to the original
    signal. Note that it can become negative when the signal power is
    smaller that the noise power.

    Args:
        x1: The first input signal.
        x2: The second input signal. Must have the same shape as `x1`.
        max_val: The maximum possible value in the signals.

    Returns:
        float: The PSNR value between `x1` and `x2`.

    Examples:

    >>> x1 = keras.random.normal((2, 4, 4, 3))
    >>> x2 = keras.random.normal((2, 4, 4, 3))
    >>> max_val = 1.0
    >>> keras.ops.nn.psnr(x1, x2, max_val)
    -3.1697404
    )r   r  r(   r   r   r  r  s      r   r  r    sk    F 	
    
 

-B

	  :??

  r   r[   ru   r   r   r   r   r   r  r#  r0  rF  rQ  )NNrb  rv  r  r  )S__doc__r   	keras.srcr   keras.src.api_exportr   keras.src.backendr   r   r   &keras.src.backend.common.backend_utilsr   keras.src.opsr	   keras.src.ops.operationr
   keras.src.ops.operation_utilsr   r   r   r+   r-   r1   r3   r7   r9   r?   rA   rE   rG   rK   rM   rQ   rY   ra   rc   rg   ri   rm   rs   rx   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r&  r.  r4  r7  r<  rC  rI  rO  rT  rd  rf  rj  ry  r  r  r  r  r  r  r%   r   r   <module>r     s   D D        - - - - - - ) ) ) ) ) ) 2 2 2 2 2 2 5 5 5 5 5 5      * ) ) ) ) ) - - - - - - 6 6 6 6 6 63 3 3 3 39 3 3 3 !4566  76,3 3 3 3 3I 3 3 3  "6788  98,3 3 3 3 3i 3 3 3 "$:;<<! ! =<!.3 3 3 3 3y 3 3 3 #%<=>>" " ?>"03 3 3 3 3y 3 3 3 #%<=>>" " ?>".3 3 3 3 39 3 3 3      43 3 3 3 3 3 3 3 " % % %.	3 	3 	3 	3 	3	 	3 	3 	3 %'@ABBC C C CBC83 3 3 3 3) 3 3 3  # & & &43 3 3 3 3y 3 3 3    # # #:	3 	3 	3 	3 	3) 	3 	3 	3  2344* * * 54*63 3 3 3 39 3 3 3 !4566  766	3 	3 	3 	3 	39 	3 	3 	3 !4566+ + + 76+<	3 	3 	3 	3 	3i 	3 	3 	3 "$:;<<<0 <0 <0 =<<0~	3 	3 	3 	3 	3 	3 	3 	3 " ,4 ,4 ,4 ,4^= = = = =i = = =D #%<=>> 0Q 0Q 0Q ?>0Qf= = = = =) = = =D  #  2 2 2 2j"= "= "= "= "=9 "= "= "=J !4566 4 4 4 764n"= "= "= "= "=I "= "= "=J "%  9 9 9 9x(= (= (= (= (=I (= (= (=V "%  B B B BJ,= ,= ,= ,= ,=I ,= ,= ,=^ "%  B B B BJJ J J J JY J J J> "$:;<<, , , =<,^= = = = = = = =( '* & & & &RB B B B Bi B B B6 ,/ 0 0 0 0fB B B B BI B B B< 36 . . . .b'L 'L 'L 'L 'Ly 'L 'L 'LT    ;@$J $J $J $JN
 
 
 
 
i 
 
 
8  !L !L !L !LH3 3 3 3 3	 3 3 32 '*  ?C2 2 2 2j< < < < <i < < <@     2'
 '
 '
 '
 '
	 '
 '
 '
T !  : : : :z
? 
? 
? 
? 
?	 
? 
? 
?   1 1 1 1:* * * *% % % % %9 % % %,  * * * * *r   