
    2VhLi                    *   d dl Z d dl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 d dlmZ d dlmZ  G d de      Z eddg      dLd       ZdMd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      dNd&       Z! G d' d(e      Z" G d) d*e      Z# ed+d,g      d-        Z$ ed.d/g      dNd0       Z% G d1 d2e      Z& ed3d4g      dNd5       Z' G d6 d7e      Z( ed8d9g      dNd:       Z) G d; d<e      Z* ed=d>g      	 dOd?       Z+ G d@ dAe      Z, edBdCg      dPdD       Z- G dE dFe      Z. edGdHg      dI        Z/ G dJ dKe      Z0 edLdMg      dN        Z1 G dO dPe      Z2 edQdRg      dS        Z3 G dT dUe      Z4 edVdWg      dX        Z5 G dY dZe      Z6 ed[d\g      d]        Z7 G d^ d_e      Z8 ed`dag      db        Z9 G dc dde      Z: ededfg      dg        Z; G dh die      Z< edjdkg      dNdl       Z= G dm dne      Z> edodpg      dNdq       Z? G dr dse      Z@ edtdug      dQdv       ZA G dw dxe      ZB edydzg      dOd{       ZC G d| d}e      ZD ed~dg      dRd       ZE G d de      ZF eddg      d        ZG G d de      ZH eddg      d        ZI G d de      ZJ eddg      dSd       ZK G d de      ZL eddg      d        ZM G d de      ZN eddg      d        ZO G d de      ZP eddg      d        ZQ G d de      ZR eddg      d        ZS G d de      ZT eddg      d        ZU G d de      ZV eddg      d        ZW G d de      ZX eddg      d        ZY G d de      ZZ eddg      d        Z[ G d de      Z\ eddg      d        Z] G d de      Z^ eddg      d        Z_ G d de      Z` eddg      dƄ        Za G dǄ de      Zb eddg      d˄        Zc G d̄ de      Zd eddg      dЄ        Ze G dф de      Zf eddg      dTdՄ       Zg G dք de      Zh eddg      dڄ        Zi G dۄ deh      Zj eddg      d߄        Zk G d de      Zl eddg      d        Zm G d de      Zn eddg      d        Zo G d de      Zp eddg      d        Zq G d de      Zr eddg      dOd       Zs G d de      Zt eddg      dUd       Zu G d de      Zv eddg      dRd       Zw G d de      Zx ed dg      dRd       Zy G d de      Zz eddg      dTd       Z{ G d d	e      Z| ed
dg      dTd       Z} G d de      Z~ eddg      dVd       Z G d de      Z eddg      dW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      dOd*       Z G d+ d,e      Z ed-d.g      d/        Z G d0 d1e      Z ed2d3g      d4        Z G d5 d6e      Z ed7d8g      d9        Z G d: d;e      Z ed<d=g      d>        Z G d? d@e      Z edAdBg      dC        Z G dD dEe      Z edFdGg      dOdH       Z G dI dJe      Z edKdLg      dM        Z G dN dOe      Z edPdQg      dOdR       Z G dS dTe      Z edUdVg      dOdW       Z G dX dYe      Z edZd[g      d\        Z G d] d^e      Z ed_d`g      da        Z G db dce      Z edddeg      df        Z G dg dhe      Z edidjg      dk        Z G dl dme      Z edndog      dOdp       Z G dq dre      Z edsdtg      du        Z G dv dwe      Z edxdyg      dXdz       Z G d{ d|e      Z ed}d~g      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      	 dYd       Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z edÐdg      dZdń       Z G dƄ de      Z edȐdg      dʄ        Z G d˄ de      Z ed͐dg      d[dτ       Z G dЄ de      Z edҐdg      dԄ        Z G dՄ de      Z edאdg      dNdل       Z G dڄ de      Z edܐdg      dސdߜd       Z G d de      Z eddg      d[d       Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d\d       Z G d de      Z eddg      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      dOd       Z G d de      Z eddg      dOd       Z G d de      Z eddg      d        Z G d de      Z eddg      d]d       Z G d de      Z edd g      d[d!       Z G d" d#e      Z ed$d%g      d^d&       Z G d' d(e      Z ed)d*g      d+        Z G d, d-e      Z ed.d/g      d0        Z G d1 d2e      Z ed3d4g      d5        Z G d6 d7e      Z ed8d9g      d:        Z G d; d<e      Z ed=d>g      dOd?       Z G d@ dAe      Z edBdCg      dD        Z G dE dFe      Z edGdHg      dOdI       Z G dJ dKe      Z edLdMg      dTdN       Z G dO dPe      Z edQg      d_dR       Z G dS dTe      Z  edUdVg      dW        Z G dX dYe      Z edZd[g      d\        Z G d] d^e      Z ed_d`g      da        Z G db dce      Z edddeg      df        Z G dg dhe      Z edidjg      dk        Z	 G dl dme      Z
 edndog      dQdp       Z G dq dre      Z edsdtg      dTdu       Z G dv dwe      Z edxdyg      dTdz       Z G d{ d|e      Z ed}d~g      dNd       Z G d de      Z eddg      d        Z G d de      Z eddg      dOd       Z G d de      Z eddg      dOd       Z G d de      Z eddg      d        Z G d de      Z eddg      d        Z G d de      Z eddg      d`d       Z G d de      Z eddg      d        Z G d de      Z  eddg      dVd       Z! G d de      Z" eddg      dad       Z# G d de      Z$ eddg      dTd       Z% G d de      Z& eddg      dTd       Z' G d de      Z( eddg      d        Z) G d de      Z* eddg      d        Z+ G d de      Z, edÐdg      dń        Z- edƐdg      dddȜdɄ       Z. G dʄ de      Z/ ed̐dg      d΄        Z0 G dτ de      Z1 edѐdg      dRdӄ       Z2 G dԄ de      Z3 ed֐dg      d؄        Z4 G dل de      Z5 edېdg      d݄        Z6 G dބ de      Z7 eddg      d        Z8 G d de      Z9 eddg      d        Z: G d de      Z; eddg      d        Z< G d de      Z= eddg      d        Z> G d de      Z? eddg      d        Z@ G d de      ZA eddg      d        ZB G d de      ZC eddg      d         ZD G d de      ZE eddg      dOd       ZF G d de      ZG edd	g      dOd
       ZH G d de      ZI eddg      dNd       ZJ G d de      ZK eddg      dNd       ZL G d de      ZM eddg      dNd       ZN G d de      ZO eddg      dOd       ZP G d d e      ZQ ed!d"g      dOd#       ZR G d$ d%e      ZS ed&d'g      dad(       ZT G d) d*e      ZU ed+d,g      d-        ZV G d. d/e      ZW ed0d1g      d2        ZX G d3 d4e      ZY ed5d6g      dbd7       ZZ G d8 d9e      Z[ ed:d;g      dTd<       Z\ G d= d>e      Z] ed?d@g      dA        Z^ G dB dCe      Z_ edDdEg      dQdF       Z` G dG dHe      Za edIdJg      dcdK       Zby(d      N)backend)keras_exportKerasTensor)any_symbolic_tensors)dtypes)canonicalize_axis)to_tuple_or_list)operation_utils)	Operation)broadcast_shapes)reduce_shapec                   ,     e Zd Zd fd	Zd Zd Z xZS )Rot90c                 >    t         |           || _        || _        y N)super__init__kaxes)selfr   r   	__class__s      C/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/ops/numpy.pyr   zRot90.__init__       	    c                 n    t         j                  j                  || j                  | j                        S )Nr   r   )r   numpyrot90r   r   )r   arrays     r   callz
Rot90.call   s&    }}""5DFF"CCr   c                 r   t        |j                        }t        |      dk  rt        d|       t        | j                        dk7  s| j                  d   | j                  d   k(  rt        d| j                   d      | j                  \  }}||   ||   c||<   ||<   t        ||j                        S )N   zCInput array must have at least 2 dimensions. Received: array.shape=r      zInvalid axes: z3. Axes must be a tuple of two different dimensions.shapedtype)listr&   len
ValueErrorr   r   r'   )r   r    array_shapeaxis1axis2s        r   compute_output_speczRot90.compute_output_spec   s    5;;'{a))47  tyy>Q$))A,$))A,">  ,D D  yyu 	/EK. EKK@@r   r$   )r   r$   __name__
__module____qualname__r   r!   r.   __classcell__r   s   @r   r   r      s    
DAr   r   zkeras.ops.rot90zkeras.ops.numpy.rot90c                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )ak  Rotate an array by 90 degrees in the plane specified by axes.

    This function rotates an array counterclockwise
    by 90 degrees `k` times in the plane specified by `axes`.
    Supports arrays of two or more dimensions.

    Args:
        array: Input array to rotate.
        k: Number of times the array is rotated by 90 degrees.
        axes: A tuple of two integers specifying the
            plane of rotation (defaults to `(0, 1)`).

    Returns:
        Rotated array.

    Examples:

    >>> import numpy as np
    >>> from keras import ops
    >>> m = np.array([[1, 2], [3, 4]])
    >>> rotated = ops.rot90(m)
    >>> rotated
    array([[2, 4],
           [1, 3]])

    >>> m = np.arange(8).reshape((2, 2, 2))
    >>> rotated = ops.rot90(m, k=1, axes=(1, 2))
    >>> rotated
    array([[[1, 3],
            [0, 2]],
           [[5, 7],
            [4, 6]]])
    r   )r   r   symbolic_callr   r   r   )r    r   r   s      r   r   r   0   sC    F UH%qt$22599==u55r   c                     t        |       t        |      k7  ryt        |       } t        |      }|$t        |t              r|g}|D ]  }d| |<   d||<    |r4t	        t        |             D ]  }| |   ||   | |<   ||   | |   ||<    | |k(  S )a  Check if two shapes are equal.

    Args:
        shape1: A list or tuple of integers for first shape to be compared.
        shape2: A list or tuple of integers for second shape to be compared.
        axis: An integer, list, or tuple of integers (optional):
            Axes to ignore during comparison. Defaults to `None`.
        allow_none (bool, optional): If `True`, allows `None` in a shape
            to match any value in the corresponding position of the other shape.
            Defaults to `True`.

    Returns:
        bool: `True` if shapes are considered equal based on the criteria,
        `False` otherwise.

    Examples:

    >>> shape_equal((32, 64, 128), (32, 64, 128))
    True
    >>> shape_equal((32, 64, 128), (32, 64, 127))
    False
    >>> shape_equal((32, 64, None), (32, 64, 128), allow_none=True)
    True
    >>> shape_equal((32, 64, None), (32, 64, 128), allow_none=False)
    False
    >>> shape_equal((32, 64, 128), (32, 63, 128), axis=1)
    True
    >>> shape_equal((32, 64, 128), (32, 63, 127), axis=(1, 2))
    True
    >>> shape_equal((32, 64, 128), (32, 63, 127), axis=[1,2])
    True
    >>> shape_equal((32, 64), (32, 64, 128))
    False
    F)r)   r(   
isinstanceintrange)shape1shape2axis
allow_noneaxis         r   shape_equalrC   X   s    F 6{c&k!&\F&\FdC 6D 	BF2JF2J	 s6{# 	&Aay "1Iq	ay "1Iq			& Vr   c                       e Zd Zd Zd Zy)Absolutec                 @    t         j                  j                  |      S r   )r   r   absoluter   xs     r   r!   zAbsolute.call       }}%%a((r   c                 `    t        |dd      }t        |j                  |j                  |      S NsparseFr'   rM   getattrr   r&   r'   r   rI   rM   s      r   r.   zAbsolute.compute_output_spec   '    He,177!''&AAr   Nr1   r2   r3   r!   r.    r   r   rE   rE          )Br   rE   zkeras.ops.absolutezkeras.ops.numpy.absolutec                     t        | f      rt               j                  |       S t        j                  j                  |       S )ad  Compute the absolute value element-wise.

    `keras.ops.abs` is a shorthand for this function.

    Args:
        x: Input tensor.

    Returns:
        An array containing the absolute value of each element in `x`.

    Example:

    >>> x = keras.ops.convert_to_tensor([-1.2, 1.2])
    >>> keras.ops.absolute(x)
    array([1.2, 1.2], dtype=float32)
    )r   rE   r7   r   r   rG   rI   s    r   rG   rG      s6    $ QD!z''**==!!!$$r   c                       e Zd Zy)AbsNr1   r2   r3   rT   r   r   rY   rY          r   rY   zkeras.ops.abszkeras.ops.numpy.absc                     t        |       S )z#Shorthand for `keras.ops.absolute`.)rG   rW   s    r   absr]      s     A;r   c                       e Zd Zd Zd Zy)Addc                 B    t         j                  j                  ||      S r   )r   r   addr   x1x2s      r   r!   zAdd.call       }}  R((r   c           
      &   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |                  }t        |dd      }t        |dd      }|xr |}	t        |||	      S Nr&   r'   rM   FrN   rP   r   r   result_typetyper   
r   rc   rd   x1_shapex2_shapeoutput_shapeoutput_dtype	x1_sparse	x2_sparseoutput_sparses
             r   r.   zAdd.compute_output_spec       2w+2w+'(;))Bb*Bb*
 B%0	B%0	!/i]
 	
r   NrS   rT   r   r   r_   r_      s    )
r   r_   zkeras.ops.addzkeras.ops.numpy.addc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Add arguments element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        The tensor containing the element-wise sum of `x1` and `x2`.

    Examples:
    >>> x1 = keras.ops.convert_to_tensor([1, 4])
    >>> x2 = keras.ops.convert_to_tensor([5, 6])
    >>> keras.ops.add(x1, x2)
    array([6, 10], dtype=int32)

    `keras.ops.add` also broadcasts shapes:
    >>> x1 = keras.ops.convert_to_tensor(
    ...     [[5, 4],
    ...      [5, 6]]
    ... )
    >>> x2 = keras.ops.convert_to_tensor([5, 6])
    >>> keras.ops.add(x1, x2)
    array([[10 10]
           [10 12]], shape=(2, 2), dtype=int32)
    )r   r_   r7   r   r   ra   rc   rd   s     r   ra   ra      s<    6 RH%u""2r**==R$$r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Allc                 ~    t         |           t        |t              r|g| _        || _        y || _        || _        y r   r   r   r:   r;   r?   keepdimsr   r?   rz   r   s      r   r   zAll.__init__   :    dC DI ! DI r   c                 n    t         j                  j                  || j                  | j                        S Nr?   rz   )r   r   allr?   rz   rH   s     r   r!   zAll.call   /    }}  ]] ! 
 	
r   c                 p    t        t        |j                  | j                  | j                        d      S Nr   boolr'   r   r   r&   r?   rz   rH   s     r   r.   zAll.compute_output_spec   1    YY
 
 	
r   NFr0   r5   s   @r   rw   rw          !

r   rw   zkeras.ops.allzkeras.ops.numpy.allc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Test whether all array elements along a given axis evaluate to `True`.

    Args:
        x: Input tensor.
        axis: An integer or tuple of integers that represent the axis along
            which a logical AND reduction is performed. The default
            (`axis=None`) is to perform a logical AND over all the dimensions
            of the input array. `axis` may be negative, in which case it counts
            for the last to the first axis.
        keepdims: If `True`, axes which are reduced are left in the result as
            dimensions with size one. With this option, the result will
            broadcast correctly against the input array. Defaults to `False`.

    Returns:
        The tensor containing the logical AND reduction over the `axis`.

    Examples:
    >>> x = keras.ops.convert_to_tensor([True, False])
    >>> keras.ops.all(x)
    array(False, shape=(), dtype=bool)

    >>> x = keras.ops.convert_to_tensor([[True, False], [True, True]])
    >>> keras.ops.all(x, axis=0)
    array([ True False], shape=(2,), dtype=bool)

    `keepdims=True` outputs a tensor with dimensions reduced to one.
    >>> x = keras.ops.convert_to_tensor([[True, False], [True, True]])
    >>> keras.ops.all(x, keepdims=True)
    array([[False]], shape=(1, 1), dtype=bool)
    r   )r   rw   r7   r   r   r   rI   r?   rz   s      r   r   r     C    @ QD!x0>>qAA==QTH==r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Anyc                 ~    t         |           t        |t              r|g| _        || _        y || _        || _        y r   ry   r{   s      r   r   zAny.__init__1  r|   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   anyr?   rz   rH   s     r   r!   zAny.call9  r   r   c                 p    t        t        |j                  | j                  | j                        d      S r   r   rH   s     r   r.   zAny.compute_output_spec@  r   r   r   r0   r5   s   @r   r   r   0  r   r   r   c                       e Zd Zd Zd Zy)Anglec                 @    t         j                  j                  |      S r   )r   r   anglerH   s     r   r!   z
Angle.callL      }}""1%%r   c                     t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |j                  |      S Nr'   int64r   	r   standardize_dtyperP   floatxr   ri   floatr   r&   r   rI   r'   s      r   r.   zAngle.compute_output_specO  Y    ))'!Wgnn>N*OPGNN$E&&ue4E177%00r   NrS   rT   r   r   r   r   K      &1r   r   zkeras.ops.anglezkeras.ops.numpy.anglec                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Element-wise angle of a complex tensor.

    Arguments:
        x: Input tensor. Can be real or complex.

    Returns:
        Output tensor of same shape as x. containing the angle of each element
        (in radians).

    Example:
    >>> x = keras.ops.convert_to_tensor([[1 + 3j, 2 - 5j], [4 - 3j, 3 + 2j]])
    >>> keras.ops.angle(x)
    array([[ 1.2490457, -1.19029  ],
       [-0.6435011,  0.5880026]], dtype=float32)
    )r   r   r7   r   r   r   rW   s    r   r   r   X  s6    " QD!w$$Q''==q!!r   zkeras.ops.anyzkeras.ops.numpy.anyc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Test whether any array element along a given axis evaluates to `True`.

    Args:
        x: Input tensor.
        axis: An integer or tuple of integers that represent the axis along
            which a logical OR reduction is performed. The default
            (`axis=None`) is to perform a logical OR over all the dimensions
            of the input array. `axis` may be negative, in which case it counts
            for the last to the first axis.
        keepdims: If `True`, axes which are reduced are left in the result as
            dimensions with size one. With this option, the result will
            broadcast correctly against the input array. Defaults to `False`.

    Returns:
        The tensor containing the logical OR reduction over the `axis`.

    Examples:
    >>> x = keras.ops.convert_to_tensor([True, False])
    >>> keras.ops.any(x)
    array(True, shape=(), dtype=bool)

    >>> x = keras.ops.convert_to_tensor([[True, False], [True, True]])
    >>> keras.ops.any(x, axis=0)
    array([ True  True], shape=(2,), dtype=bool)

    `keepdims=True` outputs a tensor with dimensions reduced to one.
    >>> x = keras.ops.convert_to_tensor([[True, False], [True, True]])
    >>> keras.ops.all(x, keepdims=True)
    array([[False]], shape=(1, 1), dtype=bool)
    r   )r   r   r7   r   r   r   r   s      r   r   r   n  r   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Amaxc                 d    t         |           t        |t              r|g}|| _        || _        y r   ry   r{   s      r   r   zAmax.__init__  -    dC 6D	 r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   amaxr?   rz   rH   s     r   r!   z	Amax.call  s/    }}!!]] " 
 	
r   c                     t        t        |j                  | j                  | j                        |j
                        S Nr   r   r   r   r&   r?   rz   r'   rH   s     r   r.   zAmax.compute_output_spec  .    tyy4==I''
 	
r   r   r0   r5   s   @r   r   r     s    !

r   r   zkeras.ops.amaxzkeras.ops.numpy.amaxc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Returns the maximum of an array or maximum value along an axis.

    Args:
        x: Input tensor.
        axis: Axis along which to compute the maximum.
            By default (`axis=None`), find the maximum value in all the
            dimensions of the input array.
        keepdims: If `True`, axes which are reduced are left in the result as
            dimensions that are broadcast to the size of the original
            input tensor. Defaults to `False`.

    Returns:
        An array with the maximum value. If `axis=None`, the result is a scalar
        value representing the maximum element in the entire array. If `axis` is
        given, the result is an array with the maximum values along
        the specified axis.

    Examples:
    >>> x = keras.ops.convert_to_tensor([[1, 3, 5], [2, 3, 6]])
    >>> keras.ops.amax(x)
    array(6, dtype=int32)

    >>> x = keras.ops.convert_to_tensor([[1, 6, 8], [1, 5, 2]])
    >>> keras.ops.amax(x, axis=0)
    array([1, 6, 8], dtype=int32)

    >>> x = keras.ops.convert_to_tensor([[1, 6, 8], [1, 5, 2]])
    >>> keras.ops.amax(x, axis=1, keepdims=True)
    array([[8], [5]], dtype=int32)
    r   )r   r   r7   r   r   r   r   s      r   r   r     C    @ QD!1??BB==adX>>r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Aminc                 d    t         |           t        |t              r|g}|| _        || _        y r   ry   r{   s      r   r   zAmin.__init__  r   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   aminr?   rz   rH   s     r   r!   z	Amin.call  &    }}!!!$))dmm!LLr   c                     t        t        |j                  | j                  | j                        |j
                        S r   r   rH   s     r   r.   zAmin.compute_output_spec  r   r   r   r0   r5   s   @r   r   r     s    !M
r   r   zkeras.ops.aminzkeras.ops.numpy.aminc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )az  Returns the minimum of an array or minimum value along an axis.

    Args:
        x: Input tensor.
        axis: Axis along which to compute the minimum.
            By default (`axis=None`), find the minimum value in all the
            dimensions of the input array.
        keepdims: If `True`, axes which are reduced are left in the result as
            dimensions that are broadcast to the size of the original
            input tensor. Defaults to `False`.

    Returns:
        An array with the minimum value. If `axis=None`, the result is a scalar
        value representing the minimum element in the entire array. If `axis` is
        given, the result is an array with the minimum values along
        the specified axis.

    Examples:
    >>> x = keras.ops.convert_to_tensor([1, 3, 5, 2, 3, 6])
    >>> keras.ops.amin(x)
    array(1, dtype=int32)

    >>> x = keras.ops.convert_to_tensor([[1, 6, 8], [7, 5, 3]])
    >>> keras.ops.amin(x, axis=0)
    array([1,5,3], dtype=int32)

    >>> x = keras.ops.convert_to_tensor([[1, 6, 8], [7, 5, 3]])
    >>> keras.ops.amin(x, axis=1, keepdims=True)
    array([[1],[3]], dtype=int32)
    r   )r   r   r7   r   r   r   r   s      r   r   r     r   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Appendc                 0    t         |           || _        y r   r   r   r?   r   r?   r   s     r   r   zAppend.__init__      	r   c                 Z    t         j                  j                  ||| j                        S Nr?   )r   r   appendr?   rb   s      r   r!   zAppend.call
  s"    }}##B#;;r   c           
      X   |j                   }|j                   }t        j                  t        |dt	        |            t        |dt	        |                  }| j
                  Nd |v sd |v rd g}n5t        t        j                  |      t        j                  |      z         g}t        ||      S t        ||| j
                  g      st        d| j
                   d| d| d      t        |      }|| j
                     || j
                     z   || j
                  <   t        ||      S )Nr'   r   zA`append` requires inputs to have the same shape except the `axis=z`, but received shape  and .)r&   r   ri   rP   rj   r?   r;   npprodr   rC   r*   r(   )r   rc   rd   rl   rm   r'   rn   s          r   r.   zAppend.compute_output_spec  s   8888""Bb*Bb*
 99x48#3 $v #BGGH$58I$I JK|5998X		{;#9(5*A  H~"*499"58K"KTYY<u55r   r   r0   r5   s   @r   r   r     s    <6r   r   zkeras.ops.appendzkeras.ops.numpy.appendc                     t        | |f      rt        |      j                  | |      S t        j                  j                  | ||      S )aV  Append tensor `x2` to the end of tensor `x1`.

    Args:
        x1: First input tensor.
        x2: Second input tensor.
        axis: Axis along which tensor `x2` is appended to tensor `x1`.
            If `None`, both tensors are flattened before use.

    Returns:
        A tensor with the values of `x2` appended to `x1`.

    Examples:
    >>> x1 = keras.ops.convert_to_tensor([1, 2, 3])
    >>> x2 = keras.ops.convert_to_tensor([[4, 5, 6], [7, 8, 9]])
    >>> keras.ops.append(x1, x2)
    array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)

    When `axis` is specified, `x1` and `x2` must have compatible shapes.
    >>> x1 = keras.ops.convert_to_tensor([[1, 2, 3], [4, 5, 6]])
    >>> x2 = keras.ops.convert_to_tensor([[7, 8, 9]])
    >>> keras.ops.append(x1, x2, axis=0)
    array([[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]], dtype=int32)
    >>> x3 = keras.ops.convert_to_tensor([7, 8, 9])
    >>> keras.ops.append(x1, x3, axis=0)
    Traceback (most recent call last):
        ...
    TypeError: Cannot concatenate arrays with different numbers of
    dimensions: got (2, 3), (3,).
    r   )r   r   r7   r   r   r   )rc   rd   r?   s      r   r   r   '  sE    J RH%4 ..r266==BT22r   c                       e Zd ZddZddZy)ArangeNc                 H    t         j                  j                  ||||      S )Nstepr'   r   r   arange)r   startstopr   r'   s        r   r!   zArange.callR  s     }}##E4d%#HHr   c           	      @   |d|}}t        t        j                  ||z
  |z              g}|et        |dt	        |            t        |dt	        |            g}|%|j                  t        |dt	        |                   t        j                  | }t        ||      S )Nr   r'   r   )	r;   r   ceilrP   rj   r   r   ri   r   )r   r   r   r   r'   rn   dtypes_to_resolves          r   r.   zArange.compute_output_specU  s    <U4EBGGTE\T$9:;<=wU4gtDz2! !((wT
)KL&&(9:E<u55r   Nr$   NrS   rT   r   r   r   r   Q  s    I6r   r   zkeras.ops.arangezkeras.ops.numpy.arangec                 H    t         j                  j                  | |||      S )a  Return evenly spaced values within a given interval.

    `arange` can be called with a varying number of positional arguments:
    * `arange(stop)`: Values are generated within the half-open interval
        `[0, stop)` (in other words, the interval including start but excluding
        stop).
    * `arange(start, stop)`: Values are generated within the half-open interval
        `[start, stop)`.
    * `arange(start, stop, step)`: Values are generated within the half-open
        interval `[start, stop)`, with spacing between values given by step.

    Args:
        start: Integer or real, representing the start of the interval. The
            interval includes this value.
        stop: Integer or real, representing the end of the interval. The
            interval does not include this value, except in some cases where
            `step` is not an integer and floating point round-off affects the
            length of `out`. Defaults to `None`.
        step: Integer or real, represent the spacing between values. For any
            output `out`, this is the distance between two adjacent values,
            `out[i+1] - out[i]`. The default step size is 1. If `step` is
            specified as a position argument, `start` must also be given.
        dtype: The type of the output array. If `dtype` is not given, infer the
            data type from the other input arguments.

    Returns:
        Tensor of evenly spaced values.
        For floating point arguments, the length of the result is
        `ceil((stop - start)/step)`. Because of floating point overflow, this
        rule may result in the last element of out being greater than stop.

    Examples:
    >>> keras.ops.arange(3)
    array([0, 1, 2], dtype=int32)

    >>> keras.ops.arange(3.0)
    array([0., 1., 2.], dtype=float32)

    >>> keras.ops.arange(3, 7)
    array([3, 4, 5, 6], dtype=int32)

    >>> keras.ops.arange(3, 7, 2)
    array([3, 5], dtype=int32)
    r   r   )r   r   r   r'   s       r   r   r   d  s#    \ ==t$eDDr   c                       e Zd Zd Zd Zy)Arccosc                 @    t         j                  j                  |      S r   )r   r   arccosrH   s     r   r!   zArccos.call      }}##A&&r   c                     t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |j                  |      S r   r   r   s      r   r.   zArccos.compute_output_spec  r   r   NrS   rT   r   r   r   r     s    '1r   r   zkeras.ops.arccoszkeras.ops.numpy.arccosc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Trigonometric inverse cosine, element-wise.

    The inverse of `cos` so that, if `y = cos(x)`, then `x = arccos(y)`.

    Args:
        x: Input tensor.

    Returns:
        Tensor of the angle of the ray intersecting the unit circle at the given
        x-coordinate in radians `[0, pi]`.

    Example:
    >>> x = keras.ops.convert_to_tensor([1, -1])
    >>> keras.ops.arccos(x)
    array([0.0, 3.1415927], dtype=float32)
    )r   r   r7   r   r   r   rW   s    r   r   r     s6    $ QD!x%%a((==""r   c                       e Zd Zd Zd Zy)Arccoshc                 @    t         j                  j                  |      S r   )r   r   arccoshrH   s     r   r!   zArccosh.call      }}$$Q''r   c                     t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |j                  |      S r   r   r   s      r   r.   zArccosh.compute_output_spec  r   r   NrS   rT   r   r   r   r     s    (1r   r   zkeras.ops.arccoshzkeras.ops.numpy.arccoshc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Inverse hyperbolic cosine, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as x.

    Example:
    >>> x = keras.ops.convert_to_tensor([10, 100])
    >>> keras.ops.arccosh(x)
    array([2.993223, 5.298292], dtype=float32)
    )r   r   r7   r   r   r   rW   s    r   r   r     6     QD!y&&q))==  ##r   c                       e Zd Zd Zd Zy)Arcsinc                 @    t         j                  j                  |      S r   )r   r   arcsinrH   s     r   r!   zArcsin.call  r   r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S Nr'   r   rM   FrN   r   r   rI   r'   rM   s       r   r.   zArcsin.compute_output_spec  i    ))'!Wgnn>N*OPGNN$E&&ue4EHe,177%??r   NrS   rT   r   r   r   r         '@r   r   zkeras.ops.arcsinzkeras.ops.numpy.arcsinc                     t        | f      rt               j                  |       S t        j                  j                  |       S )ab  Inverse sine, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Tensor of the inverse sine of each element in `x`, in radians and in
        the closed interval `[-pi/2, pi/2]`.

    Example:
    >>> x = keras.ops.convert_to_tensor([1, -1, 0])
    >>> keras.ops.arcsin(x)
    array([ 1.5707964, -1.5707964,  0.], dtype=float32)
    )r   r   r7   r   r   r   rW   s    r   r   r     6      QD!x%%a((==""r   c                       e Zd Zd Zd Zy)Arcsinhc                 @    t         j                  j                  |      S r   )r   r   arcsinhrH   s     r   r!   zArcsinh.call  r   r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zArcsinh.compute_output_spec  r   r   NrS   rT   r   r   r   r         (@r   r   zkeras.ops.arcsinhzkeras.ops.numpy.arcsinhc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a&  Inverse hyperbolic sine, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.

    Example:
    >>> x = keras.ops.convert_to_tensor([1, -1, 0])
    >>> keras.ops.arcsinh(x)
    array([0.88137364, -0.88137364, 0.0], dtype=float32)
    )r   r   r7   r   r   r   rW   s    r   r   r     r   r   c                       e Zd Zd Zd Zy)Arctanc                 @    t         j                  j                  |      S r   )r   r   arctanrH   s     r   r!   zArctan.call   r   r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zArctan.compute_output_spec#  r   r   NrS   rT   r   r   r   r     r   r   r   zkeras.ops.arctanzkeras.ops.numpy.arctanc                     t        | f      rt               j                  |       S t        j                  j                  |       S )aN  Trigonometric inverse tangent, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Tensor of the inverse tangent of each element in `x`, in the interval
        `[-pi/2, pi/2]`.

    Example:
    >>> x = keras.ops.convert_to_tensor([0, 1])
    >>> keras.ops.arctan(x)
    array([0., 0.7853982], dtype=float32)
    )r   r   r7   r   r   r   rW   s    r   r   r   -  r   r   c                       e Zd Zd Zd Zy)Arctan2c                 B    t         j                  j                  ||      S r   )r   r   arctan2rb   s      r   r!   zArctan2.callC      }}$$R,,r   c                 f   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt        j                                     }t        j                  t        |dt        j                                     }t        j                  ||t              }t        ||      S Nr&   r'   r   )	rP   r   r   r   r   r   ri   r   r   )	r   rc   rd   rl   rm   outputs_shapex1_dtypex2_dtyper'   s	            r   r.   zArctan2.compute_output_specF  s    2w+2w+(8<,,B!12
 ,,B!12
 ""8Xu==66r   NrS   rT   r   r   r   r   B  s    -7r   r   zkeras.ops.arctan2zkeras.ops.numpy.arctan2c                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Element-wise arc tangent of `x1/x2` choosing the quadrant correctly.

    The quadrant (i.e., branch) is chosen so that `arctan2(x1, x2)` is the
    signed angle in radians between the ray ending at the origin and passing
    through the point `(1, 0)`, and the ray ending at the origin and passing
    through the point `(x2, x1)`. (Note the role reversal: the "y-coordinate"
    is the first function parameter, the "x-coordinate" is the second.) By IEEE
    convention, this function is defined for `x2 = +/-0` and for either or both
    of `x1` and `x2` `= +/-inf`.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Tensor of angles in radians, in the range `[-pi, pi]`.

    Examples:
    Consider four points in different quadrants:
    >>> x = keras.ops.convert_to_tensor([-1, +1, +1, -1])
    >>> y = keras.ops.convert_to_tensor([-1, -1, +1, +1])
    >>> keras.ops.arctan2(y, x) * 180 / numpy.pi
    array([-135., -45., 45., 135.], dtype=float32)

    Note the order of the parameters. `arctan2` is defined also when x2=0 and
    at several other points, obtaining values in the range `[-pi, pi]`:
    >>> keras.ops.arctan2(
    ...     keras.ops.array([1., -1.]),
    ...     keras.ops.array([0., 0.]),
    ... )
    array([ 1.5707964, -1.5707964], dtype=float32)
    >>> keras.ops.arctan2(
    ...     keras.ops.array([0., 0., numpy.inf]),
    ...     keras.ops.array([+0., -0., numpy.inf]),
    ... )
    array([0., 3.1415925, 0.7853982], dtype=float32)
    )r   r   r7   r   r   r   ru   s     r   r   r   T  s=    N RH%y&&r2..==  R((r   c                       e Zd Zd Zd Zy)Arctanhc                 @    t         j                  j                  |      S r   )r   r   arctanhrH   s     r   r!   zArctanh.call  r   r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zArctanh.compute_output_spec  r   r   NrS   rT   r   r   r	  r	    r   r   r	  zkeras.ops.arctanhzkeras.ops.numpy.arctanhc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zInverse hyperbolic tangent, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r	  r7   r   r   r  rW   s    r   r  r    6     QD!y&&q))==  ##r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Argmaxc                 >    t         |           || _        || _        y r   r   r   r?   rz   r{   s      r   r   zArgmax.__init__      	 r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   argmaxr?   rz   rH   s     r   r!   zArgmax.call  &    }}##ADII#NNr   c                     | j                   rt        |j                  d      S | j                  t        g d      S t        t	        |j                  | j                  g      d      S Nint32r   r   rz   r   r&   r?   r   rH   s     r   r.   zArgmax.compute_output_spec  T    ==qwwg6699r11		{37
 	
r   r   r0   r5   s   @r   r  r        !
O
r   r  zkeras.ops.argmaxzkeras.ops.numpy.argmaxc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a1  Returns the indices of the maximum values along an axis.

    Args:
        x: Input tensor.
        axis: By default, the index is into the flattened tensor, otherwise
            along the specified axis.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one. Defaults to `False`.

    Returns:
        Tensor of indices. It has the same shape as `x`, with the dimension
        along `axis` removed.

    Example:
    >>> x = keras.ops.arange(6).reshape(2, 3) + 10
    >>> x
    array([[10, 11, 12],
           [13, 14, 15]], dtype=int32)
    >>> keras.ops.argmax(x)
    array(5, dtype=int32)
    >>> keras.ops.argmax(x, axis=0)
    array([1, 1, 1], dtype=int32)
    >>> keras.ops.argmax(x, axis=1)
    array([2, 2], dtype=int32)
    r   )r   r  r7   r   r   r  r   s      r   r  r    B    6 QD!4(3AA!DD==x@@r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Argminc                 >    t         |           || _        || _        y r   r  r{   s      r   r   zArgmin.__init__  r  r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   argminr?   rz   rH   s     r   r!   zArgmin.call  r  r   c                     | j                   rt        |j                  d      S | j                  t        g d      S t        t	        |j                  | j                  g      d      S r  r  rH   s     r   r.   zArgmin.compute_output_spec  r  r   r   r0   r5   s   @r   r   r     r  r   r   zkeras.ops.argminzkeras.ops.numpy.argminc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a1  Returns the indices of the minimum values along an axis.

    Args:
        x: Input tensor.
        axis: By default, the index is into the flattened tensor, otherwise
            along the specified axis.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one. Defaults to `False`.

    Returns:
        Tensor of indices. It has the same shape as `x`, with the dimension
        along `axis` removed.

    Example:
    >>> x = keras.ops.arange(6).reshape(2, 3) + 10
    >>> x
    array([[10, 11, 12],
           [13, 14, 15]], dtype=int32)
    >>> keras.ops.argmin(x)
    array(0, dtype=int32)
    >>> keras.ops.argmin(x, axis=0)
    array([0, 0, 0], dtype=int32)
    >>> keras.ops.argmin(x, axis=1)
    array([0, 0], dtype=int32)
    r   )r   r   r7   r   r   r#  r   s      r   r#  r#    r  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Argsortc                 0    t         |           || _        y r   r   r   s     r   r   zArgsort.__init__  r   r   c                 X    t         j                  j                  || j                        S r   )r   r   argsortr?   rH   s     r   r!   zArgsort.call       }}$$QTYY$77r   c                     | j                   4t        t        t        j                  |j
                              gd      S t        |j
                  d      S Nr  r   )r?   r   r;   r   r   r&   rH   s     r   r.   zArgsort.compute_output_spec  s?    99BGGAGG$4 56gFF177'22r   r9   r0   r5   s   @r   r'  r'    s    83r   r'  zkeras.ops.argsortzkeras.ops.numpy.argsortc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a2  Returns the indices that would sort a tensor.

    Args:
        x: Input tensor.
        axis: Axis along which to sort. Defaults to `-1` (the last axis). If
            `None`, the flattened tensor is used.

    Returns:
        Tensor of indices that sort `x` along the specified `axis`.

    Examples:
    One dimensional array:
    >>> x = keras.ops.array([3, 1, 2])
    >>> keras.ops.argsort(x)
    array([1, 2, 0], dtype=int32)

    Two-dimensional array:
    >>> x = keras.ops.array([[0, 3], [3, 2], [4, 5]])
    >>> x
    array([[0, 3],
           [3, 2],
           [4, 5]], dtype=int32)
    >>> keras.ops.argsort(x, axis=0)
    array([[0, 1],
           [1, 0],
           [2, 2]], dtype=int32)
    >>> keras.ops.argsort(x, axis=1)
    array([[0, 1],
           [1, 0],
           [0, 1]], dtype=int32)
    r   )r   r'  r7   r   r   r*  rI   r?   s     r   r*  r*    s?    B QD!D!//22==   ..r   c                       e Zd ZddZddZy)ArrayNc                 D    t         j                  j                  ||      S Nr   )r   r   r    r   s      r   r!   z
Array.call8  s    }}""1E"22r   c                 0    t        |j                  |      S r4  r   r&   r   s      r   r.   zArray.compute_output_spec;  s    177%00r   r   rS   rT   r   r   r2  r2  7  s    31r   r2  zkeras.ops.arrayzkeras.ops.numpy.arrayc                     t        | f      rt               j                  | |      S t        j                  j                  | |      S )a>  Create a tensor.

    Args:
        x: Input tensor.
        dtype: The desired data-type for the tensor.

    Returns:
        A tensor.

    Examples:
    >>> keras.ops.array([1, 2, 3])
    array([1, 2, 3], dtype=int32)

    >>> keras.ops.array([1, 2, 3], dtype="float32")
    array([1., 2., 3.], dtype=float32)
    r   )r   r2  r7   r   r   r    rI   r'   s     r   r    r    ?  s@    $ QD!w$$Qe$44==q..r   c                   0     e Zd Zd fd	ZddZddZ xZS )Averagec                 0    t         |           || _        y r   r   r   s     r   r   zAverage.__init__W  s     	r   c                 Z    t         j                  j                  ||| j                        S )Nweightsr?   )r   r   averager?   )r   rI   r>  s      r   r!   zAverage.call]  s"    }}$$Qdii$HHr   c                    t        |dt        |            t        g}|t        |j                  |j                  d      }| j
                  0t        |j                  | j
                     g|j                  d      }|j                  t        |dt        |                   t        j                  | }| j
                  7|rt        g |      S t        d|j                   d|j                   d      |sr-t        t        |j                  | j
                  g      |      S t        d	| j
                   d
|j                   d| j
                   d|j                  | j
                      d	      )Nr'   Tr@   r   zX`weights` must have the same shape as `x` when `axis=None`, but received `weights.shape=z` and `x.shape=`.r   z2`weights` must have the same size as `x` at `axis=z` but received `weights.shape=z` while x.shape at `z` is `)rP   rj   r   rC   r&   r?   r   r   ri   r   r*   r   )r   rI   r>  r   shape_matchshape_match_on_axisr'   s          r   r.   zAverage.compute_output_spec`  sg   $Qa95A%aggw}}NKyy$&1WWTYY'('--D'# $$WWgtG}%MN""$5699+"2U33 @@G O%%&WWIR1  ?1[QWWDII;7u   $"")-- 1II;fQWWTYY%7$8< r   r   r0   r5   s   @r   r:  r:  V  s    I r   r:  zkeras.ops.averagezkeras.ops.numpy.averagec                     t        | f      rt        |      j                  | |      S t        j                  j                  | ||      S )a,  Compute the weighted average along the specified axis.

    Args:
        x: Input tensor.
        axis: Integer along which to average `x`. The default, `axis=None`,
            will average over all of the elements of the input tensor. If axis
            is negative it counts from the last to the first axis.
        weights: Tensor of weights associated with the values in `x`. Each
            value in `x` contributes to the average according to its
            associated weight. The weights array can either be 1-D (in which
            case its length must be the size of a along the given axis) or of
            the same shape as `x`. If `weights=None` (default), then all data
            in `x` are assumed to have a weight equal to one.

            The 1-D calculation is: `avg = sum(a * weights) / sum(weights)`.
            The only constraint on weights is that `sum(weights)` must not be 0.

    Returns:
        Return the average along the specified axis.

    Examples:
    >>> data = keras.ops.arange(1, 5)
    >>> data
    array([1, 2, 3, 4], dtype=int32)
    >>> keras.ops.average(data)
    array(2.5, dtype=float32)
    >>> keras.ops.average(
    ...     keras.ops.arange(1, 11),
    ...     weights=keras.ops.arange(10, 0, -1)
    ... )
    array(4., dtype=float32)

    >>> data = keras.ops.arange(6).reshape((3, 2))
    >>> data
    array([[0, 1],
           [2, 3],
           [4, 5]], dtype=int32)
    >>> keras.ops.average(
    ...     data,
    ...     axis=1,
    ...     weights=keras.ops.array([1./4, 3./4])
    ... )
    array([0.75, 2.75, 4.75], dtype=float32)
    >>> keras.ops.average(
    ...     data,
    ...     weights=keras.ops.array([1./4, 3./4])
    ... )
    Traceback (most recent call last):
        ...
    ValueError: Axis must be specified when shapes of a and weights differ.
    r   )r>  r=  )r   r:  r7   r   r   r?  )rI   r?   r>  s      r   r?  r?    sF    j QD!D!//7/CC==  G$ ??r   c                       e Zd Zd Zd Zy)Bartlettc                 @    t         j                  j                  |      S r   )r   r   bartlettrH   s     r   r!   zBartlett.call  rJ   r   c                 T    t        |j                  t        j                               S r4  r   r&   r   r   rH   s     r   r.   zBartlett.compute_output_spec      177'..*:;;r   NrS   rT   r   r   rG  rG        )<r   rG  zkeras.ops.bartlettzkeras.ops.numpy.bartlettc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a{  Bartlett window function.
    The Bartlett window is a triangular window that rises then falls linearly.

    Args:
        x: Scalar or 1D Tensor. Window length.

    Returns:
        A 1D tensor containing the Bartlett window values.

    Example:
    >>> x = keras.ops.convert_to_tensor(5)
    >>> keras.ops.bartlett(x)
    array([0. , 0.5, 1. , 0.5, 0. ], dtype=float32)
    )r   rG  r7   r   r   rI  rW   s    r   rI  rI    s6      QD!z''**==!!!$$r   c                       e Zd Zd Zd Zy)Hammingc                 @    t         j                  j                  |      S r   )r   r   hammingrH   s     r   r!   zHamming.call  r   r   c                 T    t        |j                  t        j                               S r4  rK  rH   s     r   r.   zHamming.compute_output_spec  rL  r   NrS   rT   r   r   rP  rP    s    (<r   rP  zkeras.ops.hammingzkeras.ops.numpy.hammingc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Hamming window function.

    The Hamming window is defined as:
    `w[n] = 0.54 - 0.46 * cos(2 * pi * n / (N - 1))` for `0 <= n <= N - 1`.

    Args:
        x: Scalar or 1D Tensor. The window length.

    Returns:
        A 1D tensor containing the Hamming window values.

    Example:
    >>> x = keras.ops.convert_to_tensor(5)
    >>> keras.ops.hamming(x)
    array([0.08, 0.54, 1.  , 0.54, 0.08], dtype=float32)
    )r   rP  r7   r   r   rR  rW   s    r   rR  rR    s6    $ QD!y&&q))==  ##r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Bincountc                 L    t         |           || _        || _        || _        y r   )r   r   r>  	minlengthrM   )r   r>  rX  rM   r   s       r   r   zBincount.__init__  s#    "r   c                     t         j                  j                  || j                  | j                  | j
                        S )Nr>  rX  rM   )r   r   bincountr>  rX  rM   rH   s     r   r!   zBincount.call   s6    }}%%LLnn;;	 & 
 	
r   c                 X   |j                   g}| j                  Mt        j                  | j                        }|j	                  |j                          t        j                  | }nd}t        |dd      }t        t        |j                  d d       d gz   ||xs | j                        S )Nr  rM   Fr9   rN   )r'   r>  r   convert_to_tensorr   r   ri   rP   r   r(   r&   rM   )r   rI   r   r>  r'   x_sparses         r   r.   zBincount.compute_output_spec  s    WWI<<#//=G$$W]]3&&(9:EE1h."$'*t{{
 	
r   Nr   Fr0   r5   s   @r   rV  rV    s    

r   rV  zkeras.ops.bincountzkeras.ops.numpy.bincountc                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a  Count the number of occurrences of each value in a tensor of integers.

    Args:
        x: Input tensor.
            It must be of dimension 1, and it must only contain non-negative
            integer(s).
        weights: Weight tensor.
            It must have the same length as `x`. The default value is `None`.
            If specified, `x` is weighted by it, i.e. if `n = x[i]`,
            `out[n] += weight[i]` instead of the default behavior `out[n] += 1`.
        minlength: An integer.
            The default value is 0. If specified, there will be at least
            this number of bins in the output tensor. If greater than
            `max(x) + 1`, each value of the output at an index higher than
            `max(x)` is set to 0.
        sparse: Whether to return a sparse tensor; for backends that support
            sparse tensors.

    Returns:
        1D tensor where each element gives the number of occurrence(s) of its
        index value in x. Its length is the maximum between `max(x) + 1` and
        minlength.

    Examples:
    >>> x = keras.ops.array([1, 2, 2, 3], dtype="uint8")
    >>> keras.ops.bincount(x)
    array([0, 1, 2, 1], dtype=int32)
    >>> weights = x / 2
    >>> weights
    array([0.5, 1., 1., 1.5], dtype=float64)
    >>> keras.ops.bincount(x, weights=weights)
    array([0., 0.5, 2., 1.5], dtype=float64)
    >>> minlength = (keras.ops.max(x).numpy() + 1) + 2 # 6
    >>> keras.ops.bincount(x, minlength=minlength)
    array([0, 1, 2, 1, 0, 0], dtype=int32)
    rZ  )r   rV  r7   r   r   r[  )rI   r>  rX  rM   s       r   r[  r[    sT    L QD!y

-
	 ==!!	7i "  r   c                   *     e Zd Z fdZd Zd Z xZS )
BitwiseAndc                 "    t         |           y r   r   r   r   r   s    r   r   zBitwiseAnd.__init__H      r   c                 B    t         j                  j                  ||      S r   )r   r   bitwise_andr   rI   ys      r   r!   zBitwiseAnd.callK      }}((A..r   c                     t        j                  |j                  |j                        }t        |j                  |      S r4  r   ri   r'   r   r&   r   rI   rj  r'   s       r   r.   zBitwiseAnd.compute_output_specN  -    ""177AGG4177%00r   r0   r5   s   @r   rb  rb  G      /1r   rb  zkeras.ops.bitwise_andzkeras.ops.numpy.bitwise_andc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )aP  Compute the bit-wise AND of two arrays element-wise.

    Computes the bit-wise AND of the underlying binary representation of the
    integers in the input arrays. This ufunc implements the C/Python operator
    `&`.

    Args:
        x: Input integer tensor.
        y: Input integer tensor.

    Returns:
        Result tensor.
    )r   rb  r7   r   r   rh  rI   rj  s     r   rh  rh  S  <     QF#|))!Q//==$$Q**r   c                   *     e Zd Z fdZd Zd Z xZS )BitwiseInvertc                 "    t         |           y r   rd  re  s    r   r   zBitwiseInvert.__init__h  rf  r   c                 @    t         j                  j                  |      S r   )r   r   bitwise_invertrH   s     r   r!   zBitwiseInvert.callk  s    }}++A..r   c                 D    t        |j                  |j                        S r4  r   r&   r'   rH   s     r   r.   z!BitwiseInvert.compute_output_specn      177!''22r   r0   r5   s   @r   ru  ru  g  s    /3r   ru  zkeras.ops.bitwise_invertzkeras.ops.numpy.bitwise_invertc                     t        | f      rt               j                  |       S t        j                  j                  |       S a5  Compute bit-wise inversion, or bit-wise NOT, element-wise.

    Computes the bit-wise NOT of the underlying binary representation of the
    integers in the input arrays. This ufunc implements the C/Python operator
    `~`.

    Args:
        x: Input integer tensor.

    Returns:
        Result tensor.
    )r   ru  r7   r   r   rx  rW   s    r   rx  rx  r  s6     QD!,,Q//==''**r   c                   *     e Zd Z fdZd Zd Z xZS )
BitwiseNotc                 "    t         |           y r   rd  re  s    r   r   zBitwiseNot.__init__  rf  r   c                 @    t         j                  j                  |      S r   )r   r   bitwise_notrH   s     r   r!   zBitwiseNot.call      }}((++r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zBitwiseNot.compute_output_spec  r{  r   r0   r5   s   @r   r  r    s    ,3r   r  zkeras.ops.bitwise_notzkeras.ops.numpy.bitwise_notc                     t        | f      rt               j                  |       S t        j                  j                  |       S r}  )r   r  r7   r   r   r  rW   s    r   r  r    s6     QD!|))!,,==$$Q''r   c                   *     e Zd Z fdZd Zd Z xZS )	BitwiseOrc                 "    t         |           y r   rd  re  s    r   r   zBitwiseOr.__init__  rf  r   c                 B    t         j                  j                  ||      S r   )r   r   
bitwise_orri  s      r   r!   zBitwiseOr.call      }}''1--r   c                     t        j                  |j                  |j                        }t        |j                  |      S r4  rm  rn  s       r   r.   zBitwiseOr.compute_output_spec  ro  r   r0   r5   s   @r   r  r    s    .1r   r  zkeras.ops.bitwise_orzkeras.ops.numpy.bitwise_orc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )aN  Compute the bit-wise OR of two arrays element-wise.

    Computes the bit-wise OR of the underlying binary representation of the
    integers in the input arrays. This ufunc implements the C/Python operator
    `|`.

    Args:
        x: Input integer tensor.
        y: Input integer tensor.

    Returns:
        Result tensor.
    )r   r  r7   r   r   r  rr  s     r   r  r    <     QF#{((A..==##Aq))r   c                   *     e Zd Z fdZd Zd Z xZS )
BitwiseXorc                 "    t         |           y r   rd  re  s    r   r   zBitwiseXor.__init__  rf  r   c                 B    t         j                  j                  ||      S r   )r   r   bitwise_xorri  s      r   r!   zBitwiseXor.call  rk  r   c                     t        j                  |j                  |j                        }t        |j                  |      S r4  rm  rn  s       r   r.   zBitwiseXor.compute_output_spec  ro  r   r0   r5   s   @r   r  r    rp  r   r  zkeras.ops.bitwise_xorzkeras.ops.numpy.bitwise_xorc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )aP  Compute the bit-wise XOR of two arrays element-wise.

    Computes the bit-wise XOR of the underlying binary representation of the
    integers in the input arrays. This ufunc implements the C/Python operator
    `^`.

    Args:
        x: Input integer tensor.
        y: Input integer tensor.

    Returns:
        Result tensor.
    )r   r  r7   r   r   r  rr  s     r   r  r    rs  r   c                   *     e Zd Z fdZd Zd Z xZS )BitwiseLeftShiftc                 "    t         |           y r   rd  re  s    r   r   zBitwiseLeftShift.__init__  rf  r   c                 B    t         j                  j                  ||      S r   )r   r   bitwise_left_shiftri  s      r   r!   zBitwiseLeftShift.call  s    }}//155r   c                     t        |t              r|j                  }n*t        j                  |j                  |j                        }t        |j                  |      S r4  r:   r;   r'   r   ri   r   r&   rn  s       r   r.   z$BitwiseLeftShift.compute_output_spec  @    aGGE&&qww8E177%00r   r0   r5   s   @r   r  r    s    61r   r  zkeras.ops.bitwise_left_shiftz"keras.ops.numpy.bitwise_left_shiftc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S ap  Shift the bits of an integer to the left.

    Bits are shifted to the left by appending `y` 0s at the right of `x`.
    Since the internal representation of numbers is in binary format, this
    operation is equivalent to multiplying `x` by `2**y`.

    Args:
        x: Input integer tensor.
        y: Input integer tensor.

    Returns:
        Result tensor.
    )r   r  r7   r   r   r  rr  s     r   r  r    s=    " QF#!//155==++Aq11r   c                   *     e Zd Z fdZd Zd Z xZS )	LeftShiftc                 "    t         |           y r   rd  re  s    r   r   zLeftShift.__init__	  rf  r   c                 B    t         j                  j                  ||      S r   )r   r   
left_shiftri  s      r   r!   zLeftShift.call  r  r   c                     t        |t              r|j                  }n*t        j                  |j                  |j                        }t        |j                  |      S r4  r  rn  s       r   r.   zLeftShift.compute_output_spec  r  r   r0   r5   s   @r   r  r    s    .1r   r  zkeras.ops.left_shiftzkeras.ops.numpy.left_shiftc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S r  )r   r  r7   r   r   r  rr  s     r   r  r    r  r   c                   *     e Zd Z fdZd Zd Z xZS )BitwiseRightShiftc                 "    t         |           y r   rd  re  s    r   r   zBitwiseRightShift.__init__,  rf  r   c                 B    t         j                  j                  ||      S r   )r   r   bitwise_right_shiftri  s      r   r!   zBitwiseRightShift.call/  s    }}00A66r   c                     t        |t              r|j                  }n*t        j                  |j                  |j                        }t        |j                  |      S r4  r  rn  s       r   r.   z%BitwiseRightShift.compute_output_spec2  r  r   r0   r5   s   @r   r  r  +  s    71r   r  zkeras.ops.bitwise_right_shiftz#keras.ops.numpy.bitwise_right_shiftc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S aM  Shift the bits of an integer to the right.

    Bits are shifted to the right `y`. Because the internal representation of
    numbers is in binary format, this operation is equivalent to dividing `x` by
    `2**y`.

    Args:
        x: Input integer tensor.
        y: Input integer tensor.

    Returns:
        Result tensor.
    )r   r  r7   r   r   r  rr  s     r   r  r  :  s=    " QF# "00A66==,,Q22r   c                   *     e Zd Z fdZd Zd Z xZS )
RightShiftc                 "    t         |           y r   rd  re  s    r   r   zRightShift.__init__Q  rf  r   c                 B    t         j                  j                  ||      S r   )r   r   right_shiftri  s      r   r!   zRightShift.callT  rk  r   c                     t        |t              r|j                  }n*t        j                  |j                  |j                        }t        |j                  |      S r4  r  rn  s       r   r.   zRightShift.compute_output_specW  r  r   r0   r5   s   @r   r  r  P  s    /1r   r  zkeras.ops.right_shiftzkeras.ops.numpy.right_shiftc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S r  )r   r  r7   r   r   r  rr  s     r   r  r  _  rs  r   c                       e Zd Zd Zd Zy)Blackmanc                 @    t         j                  j                  |      S r   )r   r   blackmanrH   s     r   r!   zBlackman.callt  rJ   r   c                 T    t        |j                  t        j                               S r4  rK  rH   s     r   r.   zBlackman.compute_output_specw  rL  r   NrS   rT   r   r   r  r  s  rM  r   r  zkeras.ops.blackmanzkeras.ops.numpy.blackmanc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Blackman window function.
    The Blackman window is a taper formed by using a weighted cosine.

    Args:
        x: Scalar or 1D Tensor. Window length.

    Returns:
        A 1D tensor containing the Blackman window values.

    Example:
    >>> x = keras.ops.convert_to_tensor(5)
    >>> keras.ops.blackman(x)
    array([-1.3877788e-17,  3.4000000e-01,  1.0000000e+00,  3.4000000e-01,
           -1.3877788e-17], dtype=float32)
    )r   r  r7   r   r   r  rW   s    r   r  r  {  s6    " QD!z''**==!!!$$r   c                   *     e Zd Z fdZd Zd Z xZS )BroadcastToc                 0    t         |           || _        y r   )r   r   r&   )r   r&   r   s     r   r   zBroadcastTo.__init__  s    
r   c                 V    t         j                  j                  || j                        S r   )r   r   broadcast_tor&   rH   s     r   r!   zBroadcastTo.call  s    }}))!TZZ88r   c                     t        |j                  | j                         t        | j                  |j                        S r4  )r   r&   r   r'   rH   s     r   r.   zBroadcastTo.compute_output_spec  s)    $**-4::QWW55r   r0   r5   s   @r   r  r    s    96r   r  zkeras.ops.broadcast_tozkeras.ops.numpy.broadcast_toc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Broadcast a tensor to a new shape.

    Args:
        x: The tensor to broadcast.
        shape: The shape of the desired tensor. A single integer `i` is
            interpreted as `(i,)`.

    Returns:
        A tensor with the desired shape.

    Examples:
    >>> x = keras.ops.array([1, 2, 3])
    >>> keras.ops.broadcast_to(x, (3, 3))
    array([[1, 2, 3],
           [1, 2, 3],
           [1, 2, 3]])
    )r&   )r   r  r7   r   r   r  )rI   r&   s     r   r  r    s;    0 QD!'55a88==%%a//r   c                       e Zd Zd Zd Zy)Ceilc                 @    t         j                  j                  |      S r   )r   r   r   rH   s     r   r!   z	Ceil.call      }}!!!$$r   c                    t        j                  |j                        dk(  rt        j                         }n$t	        j
                  |j                  t              }t        |dd      }t        |j                  ||      S Nr   rM   FrN   
r   r   r'   r   r   ri   r   rP   r   r&   r   s       r   r.   zCeil.compute_output_spec  s\    $$QWW-8NN$E&&qww6EHe,177%??r   NrS   rT   r   r   r  r    s    %@r   r  zkeras.ops.ceilzkeras.ops.numpy.ceilc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the ceiling of the input, element-wise.

    The ceil of the scalar `x` is the smallest integer `i`, such that
    `i >= x`.

    Args:
        x: Input tensor.

    Returns:
        The ceiling of each element in `x`, with float dtype.
    )r   r  r7   r   r   r   rW   s    r   r   r     s6     QD!v##A&&==a  r   c                   *     e Zd Z fdZd Zd Z xZS )Clipc                 >    t         |           || _        || _        y r   )r   r   x_minx_max)r   r  r  r   s      r   r   zClip.__init__  s    

r   c                 l    t         j                  j                  || j                  | j                        S r   )r   r   clipr  r  rH   s     r   r!   z	Clip.call  s#    }}!!!TZZ<<r   c                 |    t        j                  |j                        }|dk(  rd}t        |j                  |      S )Nr   r  r   )r   r   r'   r   r&   r   s      r   r.   zClip.compute_output_spec  s3    ))!''2F?E177%00r   r0   r5   s   @r   r  r    s    
=1r   r  zkeras.ops.clipzkeras.ops.numpy.clipc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Clip (limit) the values in a tensor.

    Given an interval, values outside the interval are clipped to the
    interval edges. For example, if an interval of `[0, 1]` is specified,
    values smaller than 0 become 0, and values larger than 1 become 1.

    Args:
        x: Input tensor.
        x_min: Minimum value.
        x_max: Maximum value.
    Returns:
        The clipped tensor.
    )r   r  r7   r   r   r  )rI   r  r  s      r   r  r    s?     QD!E5!//22==a..r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Concatenatec                 J    t         |           |t        d      || _        y )Nz(`axis` cannot be None for `concatenate`.)r   r   r*   r?   r   s     r   r   zConcatenate.__init__   s&    <GHH	r   c                 X    t         j                  j                  || j                        S r   )r   r   concatenater?   r   xss     r   r!   zConcatenate.call  s     }}(($))(<<r   c           
         |d   j                   }d}d}g }|D ]  }t        |j                   || j                  gd      st        d|j                    d| d      ||j                   | j                     d }n||j                   | j                     z  }|xr t	        |dd      }|j                  t	        |d	t        |                    t        |      }||| j                  <   t        j                  | }t        |||
      S )Nr   Tr?   r@   bEvery value in `xs` must have the same shape except on the `axis` dim. But found element of shape 4, which is different from the first element's shape r   rM   Fr'   rN   )r&   rC   r?   r*   rP   r   rj   r(   r   ri   r   )	r   r  first_shapetotal_size_on_axis
all_sparser   rI   rn   r'   s	            r   r.   zConcatenate.compute_output_spec	  s   ekk
 	CADII;4 !BBC'' K(M,  ")QWWTYY-?-G%)""aggdii&88"#C8U(CJ$$WQa%AB	C  K("4TYY""$56<uZHHr   r   r0   r5   s   @r   r  r    s    =Ir   r  zkeras.ops.concatenatezkeras.ops.numpy.concatenatec                     t        |       rt        |      j                  |       S t        j                  j                  | |      S )zJoin a sequence of tensors along an existing axis.

    Args:
        xs: The sequence of tensors to concatenate.
        axis: The axis along which the tensors will be joined. Defaults to `0`.

    Returns:
        The concatenated tensor.
    r   )r   r  r7   r   r   r  )r  r?   s     r   r  r  $  s<      B%33B77==$$Rd$33r   c                       e Zd Zd Zd Zy)	Conjugatec                 @    t         j                  j                  |      S r   )r   r   	conjugaterH   s     r   r!   zConjugate.call:  s    }}&&q))r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zConjugate.compute_output_spec=  rR   r   NrS   rT   r   r   r  r  9  s    *Br   r  zkeras.ops.conjugatezkeras.ops.numpy.conjugatec                     t        | f      rt               j                  |       S t        j                  j                  |       S )a<  Returns the complex conjugate, element-wise.

    The complex conjugate of a complex number is obtained by changing the sign
    of its imaginary part.

    `keras.ops.conj` is a shorthand for this function.

    Args:
        x: Input tensor.

    Returns:
        The complex conjugate of each element in `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  B  s6     QD!{((++==""1%%r   c                       e Zd Zy)ConjNrZ   rT   r   r   r  r  V  r[   r   r  zkeras.ops.conjzkeras.ops.numpy.conjc                     t        |       S )z$Shorthand for `keras.ops.conjugate`.)r  rW   s    r   conjr  Z  s     Q<r   c                       e Zd Zd Zd Zy)Copyc                 @    t         j                  j                  |      S r   )r   r   copyrH   s     r   r!   z	Copy.calla  r  r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zCopy.compute_output_specd  rR   r   NrS   rT   r   r   r  r  `      %Br   r  zkeras.ops.copyzkeras.ops.numpy.copyc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zdReturns a copy of `x`.

    Args:
        x: Input tensor.

    Returns:
        A copy of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  i  6     QD!v##A&&==a  r   c                       e Zd Zd Zd Zy)Cosc                 @    t         j                  j                  |      S r   )r   r   cosrH   s     r   r!   zCos.cally      }}  ##r   c                     t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |j                  |      S r   r   r   s      r   r.   zCos.compute_output_spec|  r   r   NrS   rT   r   r   r  r  x      $1r   r  zkeras.ops.coszkeras.ops.numpy.cosc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zuCosine, element-wise.

    Args:
        x: Input tensor.

    Returns:
        The corresponding cosine values.
    )r   r  r7   r   r   r  rW   s    r   r  r    6     QD!u""1%%==Qr   c                       e Zd Zd Zd Zy)Coshc                 @    t         j                  j                  |      S r   )r   r   coshrH   s     r   r!   z	Cosh.call  r  r   c                     t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |j                  |      S r   r   r   s      r   r.   zCosh.compute_output_spec  r   r   NrS   rT   r   r   r   r         %1r   r   zkeras.ops.coshzkeras.ops.numpy.coshc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zHyperbolic cosine, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r   r7   r   r   r  rW   s    r   r  r    r  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )CountNonzeroc                 b    t         |           t        |t              r	|f| _        y || _        y r   )r   r   r:   r;   r?   r   s     r   r   zCountNonzero.__init__  s(    dC DIDIr   c                 X    t         j                  j                  || j                        S r   )r   r   count_nonzeror?   rH   s     r   r!   zCountNonzero.call  s     }}**1499*==r   c                 Z    t        t        |j                  | j                        d      S )Nr   r  r   )r   r   r&   r?   rH   s     r   r.   z CountNonzero.compute_output_spec  s$    tyy1
 	
r   r   r0   r5   s   @r   r  r    s    >
r   r  zkeras.ops.count_nonzerozkeras.ops.numpy.count_nonzeroc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )ac  Counts the number of non-zero values in `x` along the given `axis`.

    If no axis is specified then all non-zeros in the tensor are counted.

    Args:
        x: Input tensor.
        axis: Axis or tuple of axes along which to count the number of
            non-zeros. Defaults to `None`.

    Returns:
        int or tensor of ints.

    Examples:
    >>> x = keras.ops.array([[0, 1, 7, 0], [3, 0, 2, 19]])
    >>> keras.ops.count_nonzero(x)
    5
    >>> keras.ops.count_nonzero(x, axis=0)
    array([1, 1, 2, 1], dtype=int64)
    >>> keras.ops.count_nonzero(x, axis=1)
    array([2, 3], dtype=int64)
    r   )r   r  r7   r   r   r
  r0  s     r   r
  r
    s>    8 QD!&44Q77==&&qt&44r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Crossc                 |    t         |           ||| _        || _        || _        y || _        || _        || _        y r   )r   r   axisaaxisbaxisc)r   r  r  r  r?   r   s        r   r   zCross.__init__  s>    DJDJDJDJDJDJr   c                     t         j                  j                  ||| j                  | j                  | j
                        S r   )r   r   crossr  r  r  rb   s      r   r!   z
Cross.call  s+    }}""2r4::tzz4::NNr   c                     t        |j                        }t        |j                        }|| j                     }|| j                     }|| j                  = || j                  = t	        ||      }||dvrt        d|       ||dvrt        d|       |dk(  s|dk(  rdg}ng }|d | j                   |z   || j                  d  z   }t        j                  |j                  |j                        }	t        ||	      S )N)r#      zB`x1`'s dim on `axis={axisa}` must be either 2 or 3, but received: zB`x2`'s dim on `axis={axisb}` must be either 2 or 3, but received: r  r   )r(   r&   r  r  r   r*   r  r   ri   r'   r   )
r   rc   rd   rl   rm   x1_value_sizex2_value_sizern   
value_sizer'   s
             r   r.   zCross.compute_output_spec  s    >> , ,TZZ TZZ '(;$f)D*O-  $f)D*O- 
 A!!3JJ 4::&3l4::<6PP 	 ""288RXX6<u55r   r9   r9   r9   Nr0   r5   s   @r   r  r    s    	O6r   r  zkeras.ops.crosszkeras.ops.numpy.crossc                     t        | |f      rt        ||||      j                  | |      S t        j                  j                  | |||||      S )a  Returns the cross product of two (arrays of) vectors.

    The cross product of `x1` and `x2` in R^3 is a vector
    perpendicular to both `x1` and `x2`. If `x1` and `x2` are arrays of
    vectors, the vectors are defined by the last axis of `x1` and `x2`
    by default, and these axes can have dimensions 2 or 3.

    Where the dimension of either `x1` or `x2` is 2, the third component of
    the input vector is assumed to be zero and the cross product calculated
    accordingly.

    In cases where both input vectors have dimension 2, the z-component of
    the cross product is returned.

    Args:
        x1: Components of the first vector(s).
        x2: Components of the second vector(s).
        axisa: Axis of `x1` that defines the vector(s). Defaults to `-1`.
        axisb: Axis of `x2` that defines the vector(s). Defaults to `-1`.
        axisc: Axis of the result containing the cross product vector(s).
            Ignored if both input vectors have dimension 2, as the return is
            scalar. By default, the last axis.
        axis: If defined, the axis of `x1`, `x2` and the result that
            defines the vector(s) and cross product(s). Overrides `axisa`,
            `axisb` and `axisc`.

    Note:
        Torch backend does not support two dimensional vectors, or the
        arguments `axisa`, `axisb` and `axisc`. Use `axis` instead.

    Returns:
        Vector cross product(s).
    )r  r  r  r?   )r   r  r7   r   r   r  )rc   rd   r  r  r  r?   s         r   r  r    sc    F RH%uE

-B
	  ==

   r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Cumprodc                 >    t         |           || _        || _        y r   r   r   r?   r'   r   r?   r'   r   s      r   r   zCumprod.__init__F      	
r   c                 n    t         j                  j                  || j                  | j                        S Nr?   r'   )r   r   cumprodr?   r'   rH   s     r   r!   zCumprod.callK  s&    }}$$QTYYdjj$IIr   c                 (   | j                   ;d |j                  v rd}n6t        t        j                  |j                              f}n|j                  }t        j                  | j                  xs |j                        }|dk(  rd}t        ||      S Nr   r   r  	r?   r&   r;   r   r   r   r   r'   r   r   rI   rn   ro   s       r   r.   zCumprod.compute_output_specN  v    99qww& #BGGAGG$4 5777L001FqwwG6!"L<66r   NNr0   r5   s   @r   r  r  E  s    
J7r   r  zkeras.ops.cumprodzkeras.ops.numpy.cumprodc                 (     t        ||      |       S )a;  Return the cumulative product of elements along a given axis.

    Args:
        x: Input tensor.
        axis: Axis along which the cumulative product is computed.
            By default the input is flattened.
        dtype: dtype of returned tensor. Defaults to x.dtype.

    Returns:
        Output tensor.
    r$  )r  rI   r?   r'   s      r   r%  r%  \  s     +7E*1--r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Cumsumc                 >    t         |           || _        || _        y r   r  r   s      r   r   zCumsum.__init__m  r!  r   c                 n    t         j                  j                  || j                  | j                        S r#  )r   r   cumsumr?   r'   rH   s     r   r!   zCumsum.callr  s&    }}##ADIITZZ#HHr   c                 (   | j                   ;d |j                  v rd}n6t        t        j                  |j                              f}n|j                  }t        j                  | j                  xs |j                        }|dk(  rd}t        ||      S r'  r(  r)  s       r   r.   zCumsum.compute_output_specu  r*  r   r+  r0   r5   s   @r   r/  r/  l  s    
I7r   r/  zkeras.ops.cumsumzkeras.ops.numpy.cumsumc                 (     t        ||      |       S )a4  Returns the cumulative sum of elements along a given axis.

    Args:
        x: Input tensor.
        axis: Axis along which the cumulative sum is computed.
            By default the input is flattened.
        dtype: dtype of returned tensor. Defaults to x.dtype.

    Returns:
        Output tensor.
    r$  )r/  r-  s      r   r2  r2    s     *6t5)!,,r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Diagc                 0    t         |           || _        y r   r   r   r   r   r   r   s     r   r   zDiag.__init__      r   c                 X    t         j                  j                  || j                        S Nr   )r   r   diagr   rH   s     r   r!   z	Diag.call       }}!!!tvv!..r   c           	         |j                   }t        |      dk(  rh|d   d d g}n|d   t        t        j                  | j
                              z   |d   t        t        j                  | j
                              z   g}nt        |      dk(  rd |v rd g}nt        j                  |d   |d         }| j
                  dkD  r|d   | j
                  z
  }n|d   | j
                  z   }t        t        j                  dt        j                  ||                  g}nt        d|j                    d      t        ||j                        S )Nr$   r   r#   z+`x` must be 1-D or 2-D, but received shape r   r   )r&   r)   r;   r   r]   r   minimummaximumr*   r   r'   )r   rI   x_shapern   shorter_side	remainings         r   r.   zDiag.compute_output_spec  s'   ''w<1qz! $d| AJRVVDFF^!44AJRVVDFF^!44  \Qw $v!zz'!*gajA66A: '
TVV 3I '
TVV 3I

1bjjL&IJK  =aggYaH  <qww77r   r  r0   r5   s   @r   r6  r6    s    /8r   r6  zkeras.ops.diagzkeras.ops.numpy.diagc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )af  Extract a diagonal or construct a diagonal array.

    Args:
        x: Input tensor. If `x` is 2-D, returns the k-th diagonal of `x`.
            If `x` is 1-D, return a 2-D tensor with `x` on the k-th diagonal.
        k: The diagonal to consider. Defaults to `0`. Use `k > 0` for diagonals
            above the main diagonal, and `k < 0` for diagonals below
            the main diagonal.

    Returns:
        The extracted diagonal or constructed diagonal tensor.

    Examples:
    >>> from keras.src import ops
    >>> x = ops.arange(9).reshape((3, 3))
    >>> x
    array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])

    >>> ops.diag(x)
    array([0, 4, 8])
    >>> ops.diag(x, k=1)
    array([1, 5])
    >>> ops.diag(x, k=-1)
    array([3, 7])

    >>> ops.diag(ops.diag(x)))
    array([[0, 0, 0],
           [0, 4, 0],
           [0, 0, 8]])
    r=  )r   r6  r7   r   r   r>  rI   r   s     r   r>  r>    s>    D QD!ay&&q))==a1%%r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Diagflatc                 0    t         |           || _        y r   r8  r9  s     r   r   zDiagflat.__init__  r:  r   c                 X    t         j                  j                  || j                        S r<  )r   r   diagflatr   rH   s     r   r!   zDiagflat.call  s     }}%%a466%22r   c                    |j                   }t        |      dk(  rd}n4t        |      dk(  r|d   |d   nd }nd }|D ]  }|d } n||}||z  } |d d g}nV|t        t        j                  | j
                              z   |t        t        j                  | j
                              z   g}t        ||j                        S )Nr   r$   r   )r&   r)   r;   r   r]   r   r   r'   )r   rI   rC  	flat_sizesrn   s         r   r.   zDiagflat.compute_output_spec  s    ''w<1I\Q&-aj&<
$II #9 $I& !INI#  $<L Ctvv//Ctvv//L
 <qww77r   r  r0   r5   s   @r   rI  rI    s    38r   rI  zkeras.ops.diagflatzkeras.ops.numpy.diagflatc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Create a two-dimensional array with the flattened input on
       the k-th diagonal.

    Args:
        x: Input tensor to be flattened and placed on the diagonal.
        k: The diagonal to place the flattened input. Defaults to `0`.
           Use `k > 0` for diagonals above the main diagonal,
           and `k < 0` for diagonals below the main diagonal.

    Returns:
        A 2-D tensor with the flattened input on the specified diagonal.
    r=  )r   rI  r7   r   r   rL  rG  s     r   rL  rL  	  s=     QD!!}**1--==!!!q!))r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Diagonalc                 L    t         |           || _        || _        || _        y r   r   r   offsetr,   r-   r   rU  r,   r-   r   s       r   r   zDiagonal.__init__	  #    

r   c                     t         j                  j                  || j                  | j                  | j
                        S NrU  r,   r-   )r   r   diagonalrU  r,   r-   rH   s     r   r!   zDiagonal.call	  s6    }}%%;;****	 & 
 	
r   c           	         t        |j                        }t        |      dk  rt        d|j                   d      || j                     || j
                     g}d|| j                  <   d|| j
                  <   t        t        dj                  |            }d |v rd g}nt        j                  |d   |d         }| j                  dkD  r|d   | j                  z
  }n|d   | j                  z   }t        t        j                  dt        j                  ||                  g}||z   }t        ||j                        S )Nr#   zM`diagonal` requires an array of at least two dimensions, but `x` is of shape r   r9   r   r$   r   )r(   r&   r)   r*   r,   r-   filter__ne__r   rA  rU  r;   rB  r   r'   )r   rI   rC  shape_2drn   
diag_shaperD  rE  s           r   r.   zDiagonal.compute_output_spec&	  s$   qww-w<!##$77)1. 
 DJJ')<= 

 

FB;;898J::hqk8A;?L{{Q$QK$++5	$QK$++5	BJJq"**Y"EFGJ $j0<qww77r   r   r   r$   r0   r5   s   @r   rR  rR  	  s    
8r   rR  zkeras.ops.diagonalzkeras.ops.numpy.diagonalc                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a`  Return specified diagonals.

    If `x` is 2-D, returns the diagonal of `x` with the given offset, i.e., the
    collection of elements of the form `x[i, i+offset]`.

    If `x` has more than two dimensions, the axes specified by `axis1`
    and `axis2` are used to determine the 2-D sub-array whose diagonal
    is returned.

    The shape of the resulting array can be determined by removing `axis1`
    and `axis2` and appending an index to the right equal to the size of
    the resulting diagonals.

    Args:
        x: Input tensor.
        offset: Offset of the diagonal from the main diagonal.
            Can be positive or negative. Defaults to `0`.(main diagonal).
        axis1: Axis to be used as the first axis of the 2-D sub-arrays.
            Defaults to `0`.(first axis).
        axis2: Axis to be used as the second axis of the 2-D sub-arrays.
            Defaults to `1` (second axis).

    Returns:
        Tensor of diagonals.

    Examples:
    >>> from keras.src import ops
    >>> x = ops.arange(4).reshape((2, 2))
    >>> x
    array([[0, 1],
           [2, 3]])
    >>> x.diagonal()
    array([0, 3])
    >>> x.diagonal(1)
    array([1])

    >>> x = ops.arange(8).reshape((2, 2, 2))
    >>> x
    array([[[0, 1],
            [2, 3]],
           [[4, 5],
            [6, 7]]])
    >>> x.diagonal(0, 0, 1)
    array([[0, 6],
           [1, 7]])
    rZ  )r   rR  r7   r   r   r[  rI   rU  r,   r-   s       r   r[  r[  A	  s[    ` QD!
 -
		
 ==!!		 "  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Diffc                 >    t         |           || _        || _        y r   )r   r   nr?   )r   rg  r?   r   s      r   r   zDiff.__init__	  r   r   c                 n    t         j                  j                  || j                  | j                        S )Nrg  r?   )r   r   diffrg  r?   )r   as     r   r!   z	Diff.call	  s&    }}!!!tvvDII!>>r   c                     t        |j                        }|| j                     }|0t        j                  || j
                  z
  d      || j                  <   t        ||j                        S Nr   r   )r(   r&   r?   builtinsmaxrg  r   r'   )r   rk  r&   sizes       r   r.   zDiff.compute_output_spec	  sU    QWWTYY'||D466M1=E$))500r   r$   r9   r0   r5   s   @r   re  re  	  s    
?1r   re  zkeras.ops.diffzkeras.ops.numpy.diffc                 (     t        ||      |       S )a_  Calculate the n-th discrete difference along the given axis.

    The first difference is given by `out[i] = a[i+1] - a[i]` along
    the given axis, higher differences are calculated by using `diff`
    recursively.

    Args:
        a: Input tensor.
        n: The number of times values are differenced. Defaults to `1`.
        axis: Axis to compute discrete difference(s) along.
            Defaults to `-1`.(last axis).

    Returns:
        Tensor of diagonals.

    Examples:
    >>> from keras.src import ops
    >>> x = ops.convert_to_tensor([1, 2, 4, 7, 0])
    >>> ops.diff(x)
    array([ 1,  2,  3, -7])
    >>> ops.diff(x, n=2)
    array([  1,   1, -10])

    >>> x = ops.convert_to_tensor([[1, 3, 6, 10], [0, 5, 6, 8]])
    >>> ops.diff(x)
    array([[2, 3, 4],
           [5, 1, 2]])
    >>> ops.diff(x, axis=0)
    array([[-1,  2,  0, -2]])
    ri  )re  )rk  rg  r?   s      r   rj  rj  	  s    @  4!$""r   c                       e Zd Zd Zd Zy)Digitizec                 B    t         j                  j                  ||      S r   )r   r   digitize)r   rI   binss      r   r!   zDigitize.call	  s    }}%%a..r   c                     |j                   }t        |      dkD  rt        d| d|       t        |dd      }t	        |j                   d|      S )Nr$   z*`bins` must be a 1D array. Received: bins=z with shape bins.shape=rM   Fr  rN   )r&   r)   r*   rP   r   )r   rI   rw  
bins_shaperM   s        r   r.   zDigitize.compute_output_spec	  s^    ZZ
z?Q<TF C))36  He,177'&AAr   NrS   rT   r   r   rt  rt  	  s    /Br   rt  zkeras.ops.digitizezkeras.ops.numpy.digitizec                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Returns the indices of the bins to which each value in `x` belongs.

    Args:
        x: Input array to be binned.
        bins: Array of bins. It has to be one-dimensional and monotonically
            increasing.

    Returns:
        Output array of indices, of same shape as `x`.

    Example:
    >>> x = np.array([0.0, 1.0, 3.0, 1.6])
    >>> bins = np.array([0.0, 3.0, 4.5, 7.0])
    >>> keras.ops.digitize(x, bins)
    array([1, 1, 2, 1])
    )r   rt  r7   r   r   rv  )rI   rw  s     r   rv  rv  	  s<    $ QI&z''400==!!!T**r   c                       e Zd Zd Zd Zy)Dotc                 B    t         j                  j                  ||      S r   )r   r   dotrb   s      r   r!   zDot.call	  re   r   c           
         t        t        |dg             }t        t        |dg             }t        j                  t        |dt	        |            t        |dt	        |                  }|g k(  s|g k(  rt        ||      S t        |      dk(  rt        |      dk(  rt        g |      S t        |      dk(  rA|d   |d   k7  r&t        d|j                   d|j                   d	      t        |d d |      S |d   |d
   |d   |d
   k(  r|d= |d
= t        ||z   |      S t        d|j                   d|j                   d	      )Nr&   r'   r$   r   r9   r   zyShape must match on the last axis of `x1` and `x2` when `x1` is N-d array while `x2` is 1-D, but receive shape `x1.shape=z` and x2.shape=`rB  zShape must match on the last axis of `x1` and second last axis of `x2` when `x1` is N-d array while `x2` is M-D, but received `x1.shape=)
r(   rP   r   ri   rj   multiplyr)   r   r*   r&   )r   rc   rd   rl   rm   r'   s         r   r.   zDot.compute_output_spec	  sk   GR01GR01""Bb*Bb*
 r>X^B##x=A#h-1"4r//x=A|x{* !!#
*:288*BH 
 x}E:: RL |#|x|+x(2%@@""$((+;BHH:RI
 	
r   NrS   rT   r   r   r|  r|  	  s    )!
r   r|  zkeras.ops.dotzkeras.ops.numpy.dotc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a@  Dot product of two tensors.

    - If both `x1` and `x2` are 1-D tensors, it is inner product of vectors
      (without complex conjugation).
    - If both `x1` and `x2` are 2-D tensors, it is matrix multiplication.
    - If either `x1` or `x2` is 0-D (scalar), it is equivalent to `x1 * x2`.
    - If `x1` is an N-D tensor and `x2` is a 1-D tensor, it is a sum product
      over the last axis of `x1` and `x2`.
    - If `x1` is an N-D tensor and `x2` is an M-D tensor (where `M>=2`),
      it is a sum product over the last axis of `x1` and the second-to-last
      axis of `x2`: `dot(x1, x2)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])`.

    Args:
        x1: First argument.
        x2: Second argument.

    Note:
        Torch backend does not accept 0-D tensors as arguments.

    Returns:
        Dot product of `x1` and `x2`.
    )r   r|  r7   r   r   r~  ru   s     r   r~  r~  
  s<    0 RH%u""2r**==R$$r   c                   *     e Zd Z fdZd Zd Z xZS )Einsumc                 0    t         |           || _        y r   )r   r   
subscripts)r   r  r   s     r   r   zEinsum.__init__
  s    $r   c                 V    t        j                  j                  | j                  g| S r   )r   r   einsumr  )r   operandss     r   r!   zEinsum.call#
  s     }}##DOO?h??r   c           
      	   | j                   j                  d      }t        |      dkD  rt        d| j                    d      t        |      dk(  r|d   }|d   }n| j                   }d}|j                  d      }t        |      t        |      k7  r1t        d	t        |       d
t        |       d| j                    d      t	               }t	               }|D ]T  }|j                         s||vr||vr|j                  |       .||v s3|j                  |       |j                  |       V ||j                         }	|j                         }
|D ])  }||vs|	j                  |       |
j                  |       + |D ])  }||v s|
j                  |       |	j                  |       + |	}|
}t        |      }t        |      }|ddj                  |      z   }n|}g }t        ||      D ]  \  }}t        |dg       }|D cg c]  }|dn|
 }}|j                  d      }|}t        |      dk(  rut        |      t        |d         k7  rt        d| d| d      t        ||d         D ]#  \  }}|j                  |t        |      dz         }% |j                  dd      }n	t        t        |d               D ])  }|j                  |d   |   t        ||         dz         }+ t        t        |d               D ]1  }|j                  |d   | dz
     t        || dz
           dz         }3 t        |d         }t        |d         dk(  rt        |      nt        |d          }||| }dj                  |D cg c]  }t        |       c}      dz   }|j                  d|      }t!        j"                  dd|      }|j                         }|D cg c]  }|dk(  rdn
t%        |       }}|j'                  |        |d   }|dd D ]  }t)        ||      } t+        t	        d |D                    }t        |      dk(  r|d   dk(  rd}nt-        j.                  | }t1        ||      S c c}w c c}w c c}w )a)	  Compute the output shape of `einsum`.

        The shape computation follows the steps below:
        1. Find all letters in the input specs (left part of "->"), and
            break them into two categories: letters appearing more than once
            go to `reduced_dims`, otherwise go to `kept_dims`.
        2. Adjust `reduced_dims` and `kept_dims` based on the output spec
            (right part of "->"). The rule is if the letter appears in the
            output spec, then move it to `kept_dims`, otherwise move it to
            `reduced_dims`.
        3. Compute the target output shape. If no output spec is set, then
            the target output shape will be "...{kept_dims}", e.g., "...ijk",
            else it will be the same as output spec. "..." is a wildcard that
            could map shape of arbitrary length.
        4. For each operand in `operands`, map the shape specified in the input
            spec to the output target, e.g, if operand is of shape [2,3,4],
            input spec is "i..." and output target is "i...jk", then 2 will go
            the index 0. For dims not represented by any letter, insert to the
            wildcard part. For each letter in output target not appearing in
            input spec, the dim will be 1 for broadcasting. After 4, each
            operand should have a target shape containing only number and
            `None`.
        5. Broadcast all shapes computed from 4, and the result is the output
            shape.

        Let's take an example to illustrate the steps above. Let's define:
        ```python
        x = KerasTensor([None, 3, 4])
        y = KerasTensor(2, 4, 3)
        z = knp.einsum("...ij, kji->...k", x, y)
        ```

        1. `reduced_dims` is {"i", "j"}, `kept_dims` is {"k"}.
        2. `reduced_dims` is still {"i", "j"}, and `kept_dims` is {"k"}.
        3. Output target is "...k".
        4. For `x`, the input spec is "...ij", and the output target is "...k".
            "i" and "j" do not appear in the output target, so no replacement
            happens, and [None] goes to wildcard. Afterwards, "k" is replaced
            by 1, so we get shape [None, 1]. Applying the same logic to `y`, we
            get shape [2].
        5. Broadcast [None, 1] and [2], and we get [None, 2], which is the
            output shape.
        z->r#   zCAt most one '->' is supported in `einsum` subscripts, but received r   r   r$   N,zNumber of operands (z,) does not match the number of input specs (z#) in `einsum`, received subscripts=z... r&   r9   zrNumber of dimensions in the subscript does not match the number of dimensions in the operand, received subscript `z` and operand of shape  z[a-z]z1 z-1c           
   3   n   K   | ]-  }t        j                  t        |d t        |                   / yw)r'   N)r   r   rP   rj   ).0rI   s     r   	<genexpr>z-Einsum.compute_output_spec.<locals>.<genexpr>
  s0       ))'!Wd1g*FGs   35int8r  r   )r  splitr)   r*   setisalphara   remover  sortedjoinziprP   replacestrr<   resubr;   r   r   r(   r   ri   r   )r   r  split_subscriptsr  output_specinput_specsreduced_dims	kept_dimsrO  kept_dims_copyreduced_dims_copydimtarget_broadcast_specexpanded_operands_shapesrI   specrC  rp  
split_specexpanded_shaperB   wildcard_shape_start_indexwildcard_shape_end_indexwildcard_shapewildcard_shape_strrn   r&   r   r'   s                                r   r.   zEinsum.compute_output_spec&
  s;   X  ??006 1$ OO,A/   A%)!,J*1-KJK &&s+{s8},&s8}o 6**-k*:); <''+&7q: 
 uE	 	$A99;$));a i  #  #	$ " '^^-N , 1 1 3  /k)"))#.%))#./ $ ,+%%,,S1"&&s+, 'I,Ll+9%	$)BGGI,>$>!$/!#% 8[1 5	<GAta"-G@GHT\rt3HGHE*J2N:!# w<3z!}#55$//3f4K")1&   #7JqM: PGD!%3%;%;As4y3%ONP "0!7!7r!B s:a=12 A%3%;%;"1a(#gaj/C*?&N s:a=12 A%3%;%;"1qb1f-s7A26?/Cc/I&N .1A-?* :a=)Q. Ljm,, )
 ")./G" HHNCDc$iCDsJ # "0!7!7-"  VVGT>BN+113N@N8<#d)3N  %++N;k5	<n 02-ab1 	AE+L%@L	A  ! 
  !Q&+<Q+?6+IE&&(9:E<u55E IP Ds   Q=R
 Rr0   r5   s   @r   r  r  
  s    %@h6r   r  zkeras.ops.einsumzkeras.ops.numpy.einsumc                     t        |      r t        |       j                  | S t        j                  j
                  | g| S )a}  Evaluates the Einstein summation convention on the operands.

    Args:
        subscripts: Specifies the subscripts for summation as comma separated
            list of subscript labels. An implicit (classical Einstein
            summation) calculation is performed unless the explicit indicator
            `->` is included as well as subscript labels of the precise
            output form.
        operands: The operands to compute the Einstein sum of.

    Returns:
        The calculation based on the Einstein summation convention.

    Example:
    >>> from keras.src import ops
    >>> a = ops.arange(25).reshape(5, 5)
    >>> b = ops.arange(5)
    >>> c = ops.arange(6).reshape(2, 3)

    Trace of a matrix:

    >>> ops.einsum("ii", a)
    60
    >>> ops.einsum(a, [0, 0])
    60
    >>> ops.trace(a)
    60

    Extract the diagonal:

    >>> ops.einsum("ii -> i", a)
    array([ 0,  6, 12, 18, 24])
    >>> ops.einsum(a, [0, 0], [0])
    array([ 0,  6, 12, 18, 24])
    >>> ops.diag(a)
    array([ 0,  6, 12, 18, 24])

    Sum over an axis:

    >>> ops.einsum("ij -> i", a)
    array([ 10,  35,  60,  85, 110])
    >>> ops.einsum(a, [0, 1], [0])
    array([ 10,  35,  60,  85, 110])
    >>> ops.sum(a, axis=1)
    array([ 10,  35,  60,  85, 110])

    For higher dimensional tensors summing a single axis can be done
    with ellipsis:

    >>> ops.einsum("...j -> ...", a)
    array([ 10,  35,  60,  85, 110])
    >>> np.einsum(a, [..., 1], [...])
    array([ 10,  35,  60,  85, 110])

    Compute a matrix transpose or reorder any number of axes:

    >>> ops.einsum("ji", c)
    array([[0, 3],
           [1, 4],
           [2, 5]])
    >>> ops.einsum("ij -> ji", c)
    array([[0, 3],
           [1, 4],
           [2, 5]])
    >>> ops.einsum(c, [1, 0])
    array([[0, 3],
           [1, 4],
           [2, 5]])
    >>> ops.transpose(c)
    array([[0, 3],
           [1, 4],
           [2, 5]])

    Matrix vector multiplication:

    >>> ops.einsum("ij, j", a, b)
    array([ 30,  80, 130, 180, 230])
    >>> ops.einsum(a, [0, 1], b, [1])
    array([ 30,  80, 130, 180, 230])
    >>> ops.einsum("...j, j", a, b)
    array([ 30,  80, 130, 180, 230])
    )r   r  r7   r   r   r  )r  r  s     r   r  r  
  s?    h H%/vj!//::==
6X66r   c                       e Zd ZddZddZy)EmptyNc                 D    t         j                  j                  ||      S r4  r   r   emptyr   r&   r'   s      r   r!   z
Empty.call+      }}""5"66r   c                 L    |xs t        j                         }t        ||      S r4  r   r   r   r  s      r   r.   zEmpty.compute_output_spec.       ))5..r   r   rS   rT   r   r   r  r  *      7/r   r  zkeras.ops.emptyzkeras.ops.numpy.emptyc                 D    t         j                  j                  | |      S )zReturn a tensor of given shape and type filled with uninitialized data.

    Args:
        shape: Shape of the empty tensor.
        dtype: Desired data type of the empty tensor.

    Returns:
        The empty tensor.
    r   r  r%   s     r   r  r  3       ==uE22r   c                       e Zd Zd Zd Zy)Equalc                 B    t         j                  j                  ||      S r   )r   r   equalrb   s      r   r!   z
Equal.callB      }}""2r**r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S Nr&   r   r   rP   r   r   r   rc   rd   rl   rm   rn   s         r   r.   zEqual.compute_output_specE  7    2w+2w+'(;<v66r   NrS   rT   r   r   r  r  A  s    +7r   r  zkeras.ops.equalzkeras.ops.numpy.equalc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturns `(x1 == x2)` element-wise.

    Args:
        x1: Tensor to compare.
        x2: Tensor to compare.

    Returns:
        Output tensor, element-wise comparison of `x1` and `x2`.
    )r   r  r7   r   r   r  ru   s     r   r  r  L  <     RH%w$$R,,==r2&&r   c                       e Zd Zd Zd Zy)Expc                 @    t         j                  j                  |      S r   )r   r   exprH   s     r   r!   zExp.call]  r  r   c                     t        j                  |j                        }d|v s|dk(  rt        j                         }t	        |j
                  |      S Nr;   r   r   r   r   r'   r   r   r&   r   s      r   r.   zExp.compute_output_spec`  @    ))!''2E>Uf_NN$E177%00r   NrS   rT   r   r   r  r  \  s    $1r   r  zkeras.ops.expzkeras.ops.numpy.expc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zCalculate the exponential of all elements in the input tensor.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise exponential of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  g  r  r   c                       e Zd Zd Zd Zy)Exp2c                 @    t         j                  j                  |      S r   )r   r   exp2rH   s     r   r!   z	Exp2.callw  r  r   c                     t        j                  |j                        }d|v s|dk(  rt        j                         }t	        |j
                  |      S r  r  r   s      r   r.   zExp2.compute_output_specz  r  r   NrS   rT   r   r   r  r  v  s    %1r   r  zkeras.ops.exp2zkeras.ops.numpy.exp2c                     t        | f      rt               j                  |       S t        j                  j                  |       S )zCalculate the base-2 exponential of all elements in the input tensor.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise base-2 exponential of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    r  r   c                   *     e Zd Z fdZd Zd Z xZS )
ExpandDimsc                     t         |           t        |t        t        t
        f      st        d|       || _        y )NzXThe `axis` argument to `expand_dims` should be an integer, tuple or list. Received axis=)r   r   r:   r;   tupler(   r*   r?   r   s     r   r   zExpandDims.__init__  sD    $eT 23004v7  	r   c                 V    t         j                  j                  || j                        S r   )r   r   expand_dimsr?   rH   s     r   r!   zExpandDims.call  s    }}((DII66r   c                     t        j                  |j                  | j                        }t	        |dd      }t        ||j                  |      S rL   )r    compute_expand_dims_output_shaper&   r?   rP   r   r'   r   rI   rn   rM   s       r   r.   zExpandDims.compute_output_spec  sB    &GGGGTYY
 He,<qwwvFFr   r0   r5   s   @r   r  r    s    7Gr   r  zkeras.ops.expand_dimszkeras.ops.numpy.expand_dimsc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a?  Expand the shape of a tensor.

    Insert a new axis at the `axis` position in the expanded tensor shape.

    Args:
        x: Input tensor.
        axis: Position in the expanded axes where the new axis
            (or axes) is placed.

    Returns:
        Output tensor with the number of dimensions increased.
    r   )r   r  r7   r   r   r  r0  s     r   r  r    s;    & QD!t$22155==$$Q--r   c                       e Zd Zd Zd Zy)Expm1c                 @    t         j                  j                  |      S r   )r   r   expm1rH   s     r   r!   z
Expm1.call  r   r   c                     t        j                  |j                        }d|v s|dk(  rt        j                         }t	        |dd      }t        |j                  ||      S )Nr;   r   rM   FrN   )r   r   r'   r   rP   r   r&   r   s       r   r.   zExpm1.compute_output_spec  sP    ))!''2E>Uf_NN$EHe,177%??r   NrS   rT   r   r   r  r    s    &@r   r  zkeras.ops.expm1zkeras.ops.numpy.expm1c                     t        | f      rt               j                  |       S t        j                  j                  |       S )zCalculate `exp(x) - 1` for all elements in the tensor.

    Args:
        x: Input values.

    Returns:
        Output tensor, element-wise exponential minus one.
    )r   r  r7   r   r   r  rW   s    r   r  r    6     QD!w$$Q''==q!!r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Flipc                 0    t         |           || _        y r   r   r   s     r   r   zFlip.__init__  r   r   c                 X    t         j                  j                  || j                        S r   )r   r   flipr?   rH   s     r   r!   z	Flip.call       }}!!!$))!44r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zFlip.compute_output_spec  r{  r   r   r0   r5   s   @r   r  r    s    53r   r  zkeras.ops.flipzkeras.ops.numpy.flipc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Reverse the order of elements in the tensor along the given axis.

    The shape of the tensor is preserved, but the elements are reordered.

    Args:
        x: Input tensor.
        axis: Axis or axes along which to flip the tensor. The default,
            `axis=None`, will flip over all of the axes of the input tensor.

    Returns:
        Output tensor with entries of `axis` reversed.
    r   )r   r  r7   r   r   r  r0  s     r   r  r    s=     QD!,,Q//==ad++r   c                       e Zd Zd Zd Zy)Floorc                 @    t         j                  j                  |      S r   )r   r   floorrH   s     r   r!   z
Floor.call  r   r   c                     t        |dd      }t        j                  |j                        dk(  rt        j                         n#t        j                  |j                  t              }t        |j                  ||      S )NrM   Fr   rN   )
rP   r   r   r'   r   r   ri   r   r   r&   r   rI   rM   r'   s       r   r.   zFloor.compute_output_spec  sc    He, ((1W< NN##AGGU3 	
 177%??r   NrS   rT   r   r   r  r        &@r   r  zkeras.ops.floorzkeras.ops.numpy.floorc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the floor of the input, element-wise.

    The floor of the scalar `x` is the largest integer `i`, such that `i <= x`.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise floor of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    6     QD!w$$Q''==q!!r   c                       e Zd ZddZddZy)FullNc                 F    t         j                  j                  |||      S r4  r   r   fullr   r&   
fill_valuer'   s       r   r!   z	Full.call  s    }}!!%5!AAr   c                 L    |xs t        j                         }t        ||      S r4  r  r  s       r   r.   zFull.compute_output_spec  r  r   r   rS   rT   r   r   r  r    s    B/r   r  zkeras.ops.fullzkeras.ops.numpy.fullc                 F    t         j                  j                  | ||      S )zReturn a new tensor of given shape and type, filled with `fill_value`.

    Args:
        shape: Shape of the new tensor.
        fill_value: Fill value.
        dtype: Desired data type of the tensor.

    Returns:
        Output tensor.
    r   r  )r&   r  r'   s      r   r  r    s      ==eZu==r   c                       e Zd ZddZddZy)FullLikeNc                 F    t         j                  j                  |||      S r4  )r   r   	full_liker   rI   r  r'   s       r   r!   zFullLike.call/  s    }}&&q*E&BBr   c                 P    |xs |j                   }t        |j                  |      S r4  r'   r   r&   r  s       r   r.   zFullLike.compute_output_spec2  s!     177%00r   r   rS   rT   r   r   r  r  .  s    C1r   r  zkeras.ops.full_likezkeras.ops.numpy.full_likec                     t        | f      rt               j                  | ||      S t        j                  j                  | ||      S )a  Return a full tensor with the same shape and type as the given tensor.

    Args:
        x: Input tensor.
        fill_value: Fill value.
        dtype: Overrides data type of the result.

    Returns:
        Tensor of `fill_value` with the same shape and type as `x`.
    r   )r   r  r7   r   r   r  )rI   r  r'   s      r   r  r  7  sD     QD!z'':U'CC==""1j">>r   c                       e Zd Zd Zd Zy)GetItemc                 B    t        |t              rt        |      }||   S r   )r:   r(   r  )r   rI   keys      r   r!   zGetItem.callI  s    c4 *Cvr   c                    t        |j                        }g }t        |t              r|g}nLt        |t              rt        |      }n0t        |t               r|j                         }nt        d| d      |j                  t              }|dkD  rt        d| d      |dk(  r|j                  t               	 |sn`|j                  d      }|t        k(  rGt        |      |j                  t        j                        z
  }t        |      |z
  }	||d |	 z  }||	d  }f|t        j                  k(  r|j                  d       |st        d|j                   d| d      |j                  d      }
t        |t              r4|
|dk\  r|n||
z   }|dk  s||
k\  rt        d|j                   d| d	      t        |t              rF|
2t        t        |j!                  |
             }|j                  |       n!|j                  |
       nt        d| d      dt#        t	        |      |j$                  
      S )Nz1Unsupported key type for array slice. Received: ``r$   z0Slice should only have one ellipsis. Received: `r   zArray has shape z+ but slice has to many indices. Received: `z but out-of-bounds index z was requested.r   )r(   r&   r:   r;   r  r  r*   countEllipsisr   popr)   r   newaxisslicer<   indicesr   r'   )r   rI   r  remaining_shape	new_shaperemaining_keynum_ellipsessubkeyneededconsumedlengthindex
new_lengths                r   r.   zGetItem.compute_output_specN  sO   qww-	c3 EMU# IMT"HHJMCC5J  %**84!B3%qI  Q  * "&&q)F!]+m.A.A"**.MM/&8_Yh77	"1()"<#  #" &qwwi 077:e1>  %((+F&#&%&,kFvEqyEVO(.qwwi 8%%(E:  FE*%!$UFNN6,B%C!DJ$$Z0$$V, GuAN O T 5+177;;r   NrS   rT   r   r   r  r  H  s    
@<r   r  zkeras.ops.get_itemzkeras.ops.numpy.get_itemc                 X    t        | f      rt               j                  | |      S | |   S )zReturn `x[key]`.)r   r  r7   )rI   r  s     r   get_itemr!    s,     QD!y&&q#..S6Mr   c                       e Zd Zd Zd Zy)Greaterc                 B    t         j                  j                  ||      S r   )r   r   greaterrb   s      r   r!   zGreater.call  r  r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zGreater.compute_output_spec  r  r   NrS   rT   r   r   r#  r#    s    -7r   r#  zkeras.ops.greaterzkeras.ops.numpy.greaterc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturn the truth value of `x1 > x2` element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise comparison of `x1` and `x2`.
    )r   r#  r7   r   r   r%  ru   s     r   r%  r%    <     RH%y&&r2..==  R((r   c                       e Zd Zd Zd Zy)GreaterEqualc                 B    t         j                  j                  ||      S r   )r   r   greater_equalrb   s      r   r!   zGreaterEqual.call      }}**2r22r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   z GreaterEqual.compute_output_spec  r  r   NrS   rT   r   r   r*  r*    s    37r   r*  zkeras.ops.greater_equalzkeras.ops.numpy.greater_equalc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturn the truth value of `x1 >= x2` element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise comparison of `x1` and `x2`.
    )r   r*  r7   r   r   r,  ru   s     r   r,  r,    s<      RH%~++B33==&&r2..r   c                       e Zd Zd Zd Zy)Hstackc                 @    t         j                  j                  |      S r   )r   r   hstackr  s     r   r!   zHstack.call      }}##B''r   c           
         |d   j                   }d}g }|D ]  }t        |j                   |dgd      st        d|j                    d| d      ||j                   d   d }n||j                   d   z  }|j                  t	        |dt        |                    t        |      }||d<   t        j                  | }t        ||	      S )
Nr   r$   Tr  r  r  r   r'   r   
r&   rC   r*   r   rP   rj   r(   r   ri   r   )r   r  r  r  r   rI   rn   r'   s           r   r.   zHstack.compute_output_spec  s    ekk 	CAqww1#$O BBC'' K(M,  ")QWWQZ-?%)""aggaj0"$$WQa%AB	C K(,Q""$56<u55r   NrS   rT   r   r   r1  r1    s    (6r   r1  zkeras.ops.hstackzkeras.ops.numpy.hstackc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a1  Stack tensors in sequence horizontally (column wise).

    This is equivalent to concatenation along the first axis for 1-D tensors,
    and along the second axis for all other tensors.

    Args:
        xs: Sequence of tensors.

    Returns:
        The tensor formed by stacking the given tensors.
    )r   r1  r7   r   r   r3  r  s    r   r3  r3    s6     RE"x%%b))==##r   c                       e Zd ZddZddZy)IdentityNc                 D    t         j                  j                  ||      S r4  r   r   identityr   rg  r'   s      r   r!   zIdentity.call  s    }}%%au%55r   c                 P    |xs t        j                         }t        ||g|      S r4  r  r>  s      r   r.   zIdentity.compute_output_spec  s$    ))Aq6//r   r   rS   rT   r   r   r:  r:    s    60r   r:  zkeras.ops.identityzkeras.ops.numpy.identityc                 D    t         j                  j                  | |      S )a/  Return the identity tensor.

    The identity tensor is a square tensor with ones on the main diagonal and
    zeros elsewhere.

    Args:
        n: Number of rows (and columns) in the `n x n` output tensor.
        dtype: Data type of the output tensor.

    Returns:
        The identity tensor.
    r   r<  )rg  r'   s     r   r=  r=  
  s     ==!!!5!11r   c                       e Zd Zd Zd Zy)Imagc                 @    t         j                  j                  |      S r   )r   r   imagrH   s     r   r!   z	Imag.call  r  r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zImag.compute_output_spec  rR   r   NrS   rT   r   r   rB  rB    r  r   rB  zkeras.ops.imagzkeras.ops.numpy.imagc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the imaginary part of the complex argument.

    Args:
        x: Input tensor.

    Returns:
        The imaginary component of the complex argument.
    )r   rB  r7   r   r   rD  rW   s    r   rD  rD  $  r  r   c                       e Zd ZddZ	 ddZy)Isclosec                 H    t         j                  j                  |||||      S r   )r   r   isclose)r   rc   rd   rtolatol	equal_nans         r   r!   zIsclose.call4  s    }}$$RT4CCr   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  )	r   rc   rd   rK  rL  rM  rl   rm   rn   s	            r   r.   zIsclose.compute_output_spec7  s9     2w+2w+'(;<v66r   Ngh㈵>g:0yE>FrS   rT   r   r   rH  rH  3  s    D 7<7r   rH  zkeras.ops.isclosezkeras.ops.numpy.isclosec                     t        | |f      rt               j                  | ||||      S t        j                  j                  | ||||      S )aA  Return whether two tensors are element-wise almost equal.

    Args:
        x1: First input tensor.
        x2: Second input tensor.
        rtol: Relative tolerance.
        atol: Absolute tolerance.
        equal_nan: If `True`, element-wise NaNs are considered equal.

    Returns:
        Output boolean tensor.
    )r   rH  r7   r   r   rJ  )rc   rd   rK  rL  rM  s        r   rJ  rJ  @  sH     RH%y&&r2tT9EE==  RtY??r   c                       e Zd Zd Zd Zy)Isfinitec                 @    t         j                  j                  |      S r   )r   r   isfiniterH   s     r   r!   zIsfinite.callT  rJ   r   c                 0    t        |j                  d      S Nr   r   r6  rH   s     r   r.   zIsfinite.compute_output_specW      177&11r   NrS   rT   r   r   rR  rR  S  s    )2r   rR  zkeras.ops.isfinitezkeras.ops.numpy.isfinitec                     t        | f      rt               j                  |       S t        j                  j                  |       S )aB  Return whether a tensor is finite, element-wise.

    Real values are finite when they are not NaN, not positive infinity, and
    not negative infinity. Complex values are finite when both their real
    and imaginary parts are finite.

    Args:
        x: Input tensor.

    Returns:
        Output boolean tensor.
    )r   rR  r7   r   r   rT  rW   s    r   rT  rT  [  s6     QD!z''**==!!!$$r   c                       e Zd Zd Zd Zy)Isinfc                 @    t         j                  j                  |      S r   )r   r   isinfrH   s     r   r!   z
Isinf.callo  r   r   c                 0    t        |j                  d      S rV  r6  rH   s     r   r.   zIsinf.compute_output_specr  rW  r   NrS   rT   r   r   rZ  rZ  n      &2r   rZ  zkeras.ops.isinfzkeras.ops.numpy.isinfc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zTest element-wise for positive or negative infinity.

    Args:
        x: Input tensor.

    Returns:
        Output boolean tensor.
    )r   rZ  r7   r   r   r\  rW   s    r   r\  r\  v  r  r   c                       e Zd Zd Zd Zy)Isnanc                 @    t         j                  j                  |      S r   )r   r   isnanrH   s     r   r!   z
Isnan.call  r   r   c                 0    t        |j                  d      S rV  r6  rH   s     r   r.   zIsnan.compute_output_spec  rW  r   NrS   rT   r   r   ra  ra    r^  r   ra  zkeras.ops.isnanzkeras.ops.numpy.isnanc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zTest element-wise for NaN and return result as a boolean tensor.

    Args:
        x: Input tensor.

    Returns:
        Output boolean tensor.
    )r   ra  r7   r   r   rc  rW   s    r   rc  rc    r  r   c                       e Zd Zd Zd Zy)Lessc                 B    t         j                  j                  ||      S r   )r   r   lessrb   s      r   r!   z	Less.call      }}!!"b))r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zLess.compute_output_spec  r  r   NrS   rT   r   r   rg  rg    s    *7r   rg  zkeras.ops.lesszkeras.ops.numpy.lessc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturn the truth value of `x1 < x2` element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise comparison of `x1` and `x2`.
    )r   rg  r7   r   r   ri  ru   s     r   ri  ri    s<     RH%v##B++==b"%%r   c                       e Zd Zd Zd Zy)	LessEqualc                 B    t         j                  j                  ||      S r   )r   r   
less_equalrb   s      r   r!   zLessEqual.call      }}''B//r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zLessEqual.compute_output_spec  r  r   NrS   rT   r   r   rn  rn        07r   rn  zkeras.ops.less_equalzkeras.ops.numpy.less_equalc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturn the truth value of `x1 <= x2` element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise comparison of `x1` and `x2`.
    )r   rn  r7   r   r   rp  ru   s     r   rp  rp    s<      RH%{((R00==##B++r   c                   6     e Zd Zdddedf fd	Zd Zd Z xZS )Linspace2   TFr   c                 h    t         |           || _        || _        || _        || _        || _        y r   )r   r   numendpointretstepr'   r?   )r   ry  rz  r{  r'   r?   r   s         r   r   zLinspace.__init__  s3     	 
	r   c           	          t         j                  j                  ||| j                  | j                  | j
                  | j                  | j                        S )Nry  rz  r{  r'   r?   )r   r   linspacery  rz  r{  r'   r?   r   r   r   s      r   r!   zLinspace.call  sG    }}%%]]LL** & 
 	
r   c                 N   t        |dg       }t        |dg       }t        ||      }| j                  dk(  r|| j                  gz   }np| j                  dk\  r.|d | j                   | j                  gz   || j                  d  z   }n3|d | j                  dz    | j                  gz   || j                  dz   d  z   }| j                  | j                  nt        |dt        |            }t        j                  |t              }| j                  rt        ||      d fS t        ||      S Nr&   r9   r   r$   r'   r   )rP   r   r?   ry  r'   rj   r   ri   r   r{  r   r   r   r   start_shape
stop_shapern   r'   s          r   r.   zLinspace.compute_output_spec  s&   eWb1T7B/
'Z@99?'488*4LYY!^[tyy)88*tyy{+,  _tyy1}-88*tyy1}/0  zz% JJe5 	
 ##E51<<E:DAA<u55r   r1   r2   r3   r   r   r!   r.   r4   r5   s   @r   rv  rv    s    tU%a	
6r   rv  zkeras.ops.linspacezkeras.ops.numpy.linspacec           	          t        | |f      r t        |||||      | |      S t        j                  j	                  | ||||||      S )a  Return evenly spaced numbers over a specified interval.

    Returns `num` evenly spaced samples, calculated over the interval
    `[start, stop]`.

    The endpoint of the interval can optionally be excluded.

    Args:
        start: The starting value of the sequence.
        stop: The end value of the sequence, unless `endpoint` is set to
            `False`. In that case, the sequence consists of all but the last
            of `num + 1` evenly spaced samples, so that `stop` is excluded.
            Note that the step size changes when `endpoint` is `False`.
        num: Number of samples to generate. Defaults to `50`. Must be
            non-negative.
        endpoint: If `True`, `stop` is the last sample. Otherwise, it is
            not included. Defaults to `True`.
        retstep: If `True`, return `(samples, step)`, where `step` is the
            spacing between samples.
        dtype: The type of the output tensor.
        axis: The axis in the result to store the samples. Relevant only if
            start or stop are array-like. Defaults to `0`.

    Note:
        Torch backend does not support `axis` argument.

    Returns:
        A tensor of evenly spaced numbers.
        If `retstep` is `True`, returns `(samples, step)`
    r}  )r   rv  r   r   r~  )r   r   ry  rz  r{  r'   r?   s          r   r~  r~    s^    D UDM*<xXwt<UDII==!! "  r   c                       e Zd Zd Zd Zy)Logc                 @    t         j                  j                  |      S r   )r   r   logrH   s     r   r!   zLog.call;  r  r   c                     t        j                  |j                        dk(  rt        j                         n#t	        j
                  |j                  t              }t        |j                  |      S Nr   r   	r   r   r'   r   r   ri   r   r   r&   r   s      r   r.   zLog.compute_output_spec>  S     ((1W< NN##AGGU3 	
 177%00r   NrS   rT   r   r   r  r  :  r  r   r  zkeras.ops.logzkeras.ops.numpy.logc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zNatural logarithm, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise natural logarithm of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  G  r  r   c                       e Zd Zd Zd Zy)Log10c                 @    t         j                  j                  |      S r   )r   r   log10rH   s     r   r!   z
Log10.callW  r   r   c                     t        j                  |j                        dk(  rt        j                         n#t	        j
                  |j                  t              }t        |j                  |      S r  r  r   s      r   r.   zLog10.compute_output_specZ  r  r   NrS   rT   r   r   r  r  V  r   r   r  zkeras.ops.log10zkeras.ops.numpy.log10c                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the base 10 logarithm of the input tensor, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise base 10 logarithm of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  c  r  r   c                       e Zd Zd Zd Zy)Log1pc                 @    t         j                  j                  |      S r   )r   r   log1prH   s     r   r!   z
Log1p.calls  r   r   c                     t        j                  |j                        dk(  rt        j                         n#t	        j
                  |j                  t              }t        |dd      }t        |j                  ||      S r  r  r   s       r   r.   zLog1p.compute_output_specv  c     ((1W< NN##AGGU3 	
 He,177%??r   NrS   rT   r   r   r  r  r  r  r   r  zkeras.ops.log1pzkeras.ops.numpy.log1pc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturns the natural logarithm of one plus the `x`, element-wise.

    Calculates `log(1 + x)`.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise natural logarithm of `1 + x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    r  r   c                       e Zd Zd Zd Zy)Log2c                 @    t         j                  j                  |      S r   )r   r   log2rH   s     r   r!   z	Log2.call  r  r   c                     t        j                  |j                        dk(  rt        j                         n#t	        j
                  |j                  t              }t        |j                  |      S r  r  r   s      r   r.   zLog2.compute_output_spec  r  r   NrS   rT   r   r   r  r    r  r   r  zkeras.ops.log2zkeras.ops.numpy.log2c                     t        | f      rt               j                  |       S t        j                  j                  |       S )zBase-2 logarithm of `x`, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise base-2 logarithm of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    r  r   c                       e Zd Zd Zd Zy)	Logaddexpc                 B    t         j                  j                  ||      S r   )r   r   	logaddexprb   s      r   r!   zLogaddexp.call      }}&&r2..r   c           
          t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |            t
              }t        ||      S r  rP   r   r   ri   rj   r   r   )r   rc   rd   rl   rm   rn   r'   s          r   r.   zLogaddexp.compute_output_spec  sl    2w+2w+'(;""Bb*Bb*

 <u55r   NrS   rT   r   r   r  r    s    /	6r   r  zkeras.ops.logaddexpzkeras.ops.numpy.logaddexpc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Logarithm of the sum of exponentiations of the inputs.

    Calculates `log(exp(x1) + exp(x2))`.

    Args:
        x1: Input tensor.
        x2: Input tensor.

    Returns:
        Output tensor, element-wise logarithm of the sum of exponentiations
        of the inputs.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<     RH%{((R00==""2r**r   c                       e Zd Zd Zd Zy)
LogicalAndc                 B    t         j                  j                  ||      S r   )r   r   logical_andrb   s      r   r!   zLogicalAnd.call      }}((R00r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zLogicalAnd.compute_output_spec  r  r   NrS   rT   r   r   r  r        17r   r  zkeras.ops.logical_andzkeras.ops.numpy.logical_andc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Computes the element-wise logical AND of the given input tensors.

    Zeros are treated as `False` and non-zeros are treated as `True`.

    Args:
        x1: Input tensor.
        x2: Input tensor.

    Returns:
        Output tensor, element-wise logical AND of the inputs.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<    $ RH%|))"b11==$$R,,r   c                       e Zd Zd Zd Zy)
LogicalNotc                 @    t         j                  j                  |      S r   )r   r   logical_notrH   s     r   r!   zLogicalNot.call  r  r   c                 0    t        |j                  d      S rV  r6  rH   s     r   r.   zLogicalNot.compute_output_spec  rW  r   NrS   rT   r   r   r  r    s    ,2r   r  zkeras.ops.logical_notzkeras.ops.numpy.logical_notc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zComputes the element-wise NOT of the given input tensor.

    Zeros are treated as `False` and non-zeros are treated as `True`.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise logical NOT of the input.
    )r   r  r7   r   r   r  rW   s    r   r  r    s6    " QD!|))!,,==$$Q''r   c                       e Zd Zd Zd Zy)	LogicalOrc                 B    t         j                  j                  ||      S r   )r   r   
logical_orrb   s      r   r!   zLogicalOr.call  rq  r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zLogicalOr.compute_output_spec  r  r   NrS   rT   r   r   r  r    rs  r   r  zkeras.ops.logical_orzkeras.ops.numpy.logical_orc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Computes the element-wise logical OR of the given input tensors.

    Zeros are treated as `False` and non-zeros are treated as `True`.

    Args:
        x1: Input tensor.
        x2: Input tensor.

    Returns:
        Output tensor, element-wise logical OR of the inputs.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<    $ RH%{((R00==##B++r   c                   6     e Zd Zdddedf fd	Zd Zd Z xZS )Logspacerw  T
   r   c                 h    t         |           || _        || _        || _        || _        || _        y r   )r   r   ry  rz  baser'   r?   )r   ry  rz  r  r'   r?   r   s         r   r   zLogspace.__init__3  s1     	
	r   c           	          t         j                  j                  ||| j                  | j                  | j
                  | j                  | j                        S )Nry  rz  r  r'   r?   )r   r   logspacery  rz  r  r'   r?   r  s      r   r!   zLogspace.call;  sG    }}%%]]** & 
 	
r   c                    t        |dg       }t        |dg       }t        ||      }| j                  dk(  r|| j                  gz   }np| j                  dk\  r.|d | j                   | j                  gz   || j                  d  z   }n3|d | j                  dz    | j                  gz   || j                  dz   d  z   }| j                  | j                  nt        |dt        |            }t        j                  |t              }t        ||      S r  )
rP   r   r?   ry  r'   rj   r   ri   r   r   r  s          r   r.   zLogspace.compute_output_specF  s   eWb1T7B/
'Z@99?'488*4LYY!^[tyy)88*tyy{+,  _tyy1}-88*tyy1}/0  zz% JJe5 	
 ##E51<u55r   r  r5   s   @r   r  r  2  s    2U 	
6r   r  zkeras.ops.logspacezkeras.ops.numpy.logspacec           	          t        | |f      r t        |||||      | |      S t        j                  j	                  | ||||||      S )a  Returns numbers spaced evenly on a log scale.

    In linear space, the sequence starts at `base ** start` and ends with
    `base ** stop` (see `endpoint` below).

    Args:
        start: The starting value of the sequence.
        stop: The final value of the sequence, unless `endpoint` is `False`.
            In that case, `num + 1` values are spaced over the interval in
            log-space, of which all but the last (a sequence of length `num`)
            are returned.
        num: Number of samples to generate. Defaults to `50`.
        endpoint: If `True`, `stop` is the last sample. Otherwise, it is not
            included. Defaults to `True`.
        base: The base of the log space. Defaults to `10`.
        dtype: The type of the output tensor.
        axis: The axis in the result to store the samples. Relevant only
            if start or stop are array-like.

    Note:
        Torch backend does not support `axis` argument.

    Returns:
        A tensor of evenly spaced samples on a log scale.
    r  )r   r  r   r   r  )r   r   ry  rz  r  r'   r?   s          r   r  r  a  s]    6 UDM*9xXtUD9%FF==!! "  r   c                       e Zd Zd Zd Zy)Matmulc                 B    t         j                  j                  ||      S r   )r   r   matmulrb   s      r   r!   zMatmul.call      }}##B++r   c           	         t        |dg       }t        |dg       }t        j                  ||      }t        |dd      }t        |dd      }|xr |}t        j                  t        |dt        |                  }	t        j                  t        |dt        |                  }
|	dk(  r|
dk(  rd}nt        j                  |	|
      }t        |||      S )Nr&   rM   Tr'   r  r  rN   )	rP   r   compute_matmul_output_shaper   r   rj   r   ri   r   )r   rc   rd   rl   rm   rn   rp   rq   rr   r  r  r'   s               r   r.   zMatmul.compute_output_spec  s    2w+2w+&BBh
 B$/	B$/	!/i,,WR$r(-KL,,WR$r(-KLv(f"4E&&x:E<u]KKr   NrS   rT   r   r   r  r    s    ,Lr   r  zkeras.ops.matmulzkeras.ops.numpy.matmulc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Matrix product of two tensors.

    - If both tensors are 1-dimensional, the dot product (scalar) is returned.
    - If either tensor is N-D, N > 2, it is treated as a stack of matrices
      residing in the last two indexes and broadcast accordingly.
    - If the first tensor is 1-D, it is promoted to a matrix by prepending
      a 1 to its dimensions. After matrix multiplication the prepended
      1 is removed.
    - If the second tensor is 1-D, it is promoted to a matrix by appending a 1
      to its dimensions. After matrix multiplication the appended 1 is removed.

    Args:
        x1: First tensor.
        x2: Second tensor.

    Returns:
        Output tensor, matrix product of the inputs.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<    ( RH%x%%b"--==B''r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Maxc                 ~    t         |           t        |t              r	|g| _        n|| _        || _        || _        y r   r   r   r:   r;   r?   rz   initialr   r?   rz   r  r   s       r   r   zMax.__init__  6    dC DIDI r   c                     t         j                  j                  || j                  | j                  | j
                        S Nr?   rz   r  )r   r   ro  r?   rz   r  rH   s     r   r!   zMax.call  3    }}  DIIt|| ! 
 	
r   c                     t        t        |j                  | j                  | j                        |j
                        S r   r   rH   s     r   r.   zMax.compute_output_spec  r   r   NFNr0   r5   s   @r   r  r        


r   r  zkeras.ops.maxzkeras.ops.numpy.maxc                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a  Return the maximum of a tensor or maximum along an axis.

    Args:
        x: Input tensor.
        axis: Axis or axes along which to operate. By default, flattened input
            is used.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one. Defaults to `False`.
        initial: The minimum value of an output element. Defaults to `None`.

    Returns:
        Maximum of `x`.
    r  )r   r  r7   r   r   ro  rI   r?   rz   r  s       r   ro  ro    M     QD!xAOO
 	
 ==QTHgNNr   c                       e Zd Zd Zd Zy)Maximumc                 B    t         j                  j                  ||      S r   )r   r   rB  rb   s      r   r!   zMaximum.call  r  r   c           
      &   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |                  }t        |dd      }t        |dd      }|xr |}	t        |||	      S rg   rh   rk   s
             r   r.   zMaximum.compute_output_spec  rs   r   NrS   rT   r   r   r  r        -
r   r  zkeras.ops.maximumzkeras.ops.numpy.maximumc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zElement-wise maximum of `x1` and `x2`.

    Args:
        x1: First tensor.
        x2: Second tensor.

    Returns:
        Output tensor, element-wise maximum of `x1` and `x2`.
    )r   r  r7   r   r   rB  ru   s     r   rB  rB    r(  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Medianc                 d    t         |           t        |t              r|g}|| _        || _        y r   ry   r{   s      r   r   zMedian.__init__	  r   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   medianr?   rz   rH   s     r   r!   zMedian.call  r  r   c                 *   t        |j                  | j                  | j                        }t	        j
                  |j                        dk(  rt	        j                         }n$t        j                  |j                  t              }t        ||      S )Nr   r   r   )r   r&   r?   rz   r   r   r'   r   r   ri   r   r   )r   rI   rn   r'   s       r   r.   zMedian.compute_output_spec  sg    #GG$))dmm
 $$QWW-8NN$E&&qww6E<u55r   r   r0   r5   s   @r   r  r    s    !O6r   r  zkeras.ops.medianzkeras.ops.numpy.medianc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Compute the median along the specified axis.

    Args:
        x: Input tensor.
        axis: Axis or axes along which the medians are computed. Defaults to
            `axis=None` which is to compute the median(s) along a flattened
            version of the array.
        keepdims: If this is set to `True`, the axes which are reduce
            are left in the result as dimensions with size one.

    Returns:
        The output tensor.
    r   )r   r  r7   r   r   r  r   s      r   r  r    sB     QD!4(3AA!DD==x@@r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Meshgridc                 N    t         |           |dvrt        d      || _        y )N)xyijzDValid values for `indexing` are 'xy' and 'ij', but received {index}.)r   r   r*   indexing)r   r  r   s     r   r   zMeshgrid.__init__3  s1    <'(  !r   c                 T    t        j                  j                  |d| j                  iS )Nr  )r   r   meshgridr  rH   s     r   r!   zMeshgrid.call<  s     }}%%qA4==AAr   c                    g }|D ]g  }t        |j                        dk(  rd}n9d |j                  v rd }n(t        t        j                  |j                              }|j                  |       i | j                  dk(  r+t        t        |            D cg c]  }t        |       c}S |d   }|d   |d<   ||d<   t        t        |            D cg c]  }t        |j                         c}S c c}w c c}w )Nr   r$   r  r   )
r)   r&   r;   r   r   r   r  r<   r   r'   )r   rI   rn   xirp  _tmps          r   r.   zMeshgrid.compute_output_spec?  s     	&B288}!288#Drwwrxx01D%	& ==D 7<SV}E!K-EE1o&q/QQ?DSV}
:;KBHH5
 	
	 F
s   C2C7)r  r0   r5   s   @r   r  r  2  s    !B
r   r  zkeras.ops.meshgridzkeras.ops.numpy.meshgridr  r  c                     t        |      r t        |       j                  | S t        j                  j
                  |d| iS )a  Creates grids of coordinates from coordinate vectors.

    Given `N` 1-D tensors `T0, T1, ..., TN-1` as inputs with corresponding
    lengths `S0, S1, ..., SN-1`, this creates an `N` N-dimensional tensors
    `G0, G1, ..., GN-1` each with shape `(S0, ..., SN-1)` where the output
    `Gi` is constructed by expanding `Ti` to the result shape.

    Args:
        x: 1-D tensors representing the coordinates of a grid.
        indexing: `"xy"` or `"ij"`. "xy" is cartesian; `"ij"` is matrix
            indexing of output. Defaults to `"xy"`.

    Returns:
        Sequence of N tensors.

    Example:
    >>> from keras.src import ops
    >>> x = ops.array([1, 2, 3])
    >>> y = ops.array([4, 5, 6])

    >>> grid_x, grid_y = ops.meshgrid(x, y, indexing="ij")
    >>> grid_x
    array([[1, 1, 1],
           [2, 2, 2],
           [3, 3, 3]])
    >>> grid_y
    array([[4, 5, 6],
           [4, 5, 6],
           [4, 5, 6]])
    r  r  )r   r  r7   r   r   r  )r  rI   s     r   r  r  T  s?    @ A8x*88!<<==!!18x88r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Minc                 ~    t         |           t        |t              r	|g| _        n|| _        || _        || _        y r   r  r  s       r   r   zMin.__init__z  r  r   c                     t         j                  j                  || j                  | j                  | j
                        S r  )r   r   minr?   rz   r  rH   s     r   r!   zMin.call  r  r   c                     t        t        |j                  | j                  | j                        |j
                        S r   r   rH   s     r   r.   zMin.compute_output_spec  r   r   r  r0   r5   s   @r   r  r  y  r  r   r  zkeras.ops.minzkeras.ops.numpy.minc                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a  Return the minimum of a tensor or minimum along an axis.

    Args:
        x: Input tensor.
        axis: Axis or axes along which to operate. By default, flattened input
            is used.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one. Defaults to `False`.
        initial: The maximum value of an output element. Defaults to `None`.

    Returns:
        Minimum of `x`.
    r  )r   r  r7   r   r   r  r  s       r   r  r    r  r   c                       e Zd Zd Zd Zy)Minimumc                 B    t         j                  j                  ||      S r   )r   r   rA  rb   s      r   r!   zMinimum.call  r  r   c           
      &   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |                  }t        |dd      }t        |dd      }|xr |}	t        |||	      S rg   rh   rk   s
             r   r.   zMinimum.compute_output_spec  rs   r   NrS   rT   r   r   r  r    r  r   r  zkeras.ops.minimumzkeras.ops.numpy.minimumc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zElement-wise minimum of `x1` and `x2`.

    Args:
        x1: First tensor.
        x2: Second tensor.

    Returns:
        Output tensor, element-wise minimum of `x1` and `x2`.
    )r   r  r7   r   r   rA  ru   s     r   rA  rA    r(  r   c                       e Zd Zd Zd Zy)Modc                 B    t         j                  j                  ||      S r   )r   r   modrb   s      r   r!   zMod.call  re   r   c           
          t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |                  }|dk(  rd}t        ||      S )Nr&   r'   r   r  r   rh   r   rc   rd   rl   rm   rn   ro   s          r   r.   zMod.compute_output_spec  sv    2w+2w+'(;))Bb*Bb*
 6!"L<|<<r   NrS   rT   r   r   r
  r
    s    )
=r   r
  zkeras.ops.modzkeras.ops.numpy.modc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturns the element-wise remainder of division.

    Args:
        x1: First tensor.
        x2: Second tensor.

    Returns:
        Output tensor, element-wise remainder of division.
    )r   r
  r7   r   r   r  ru   s     r   r  r    s<     RH%u""2r**==R$$r   c                   *     e Zd Z fdZd Zd Z xZS )Moveaxisc                    t         |           t        |t              r	|g| _        n|| _        t        |t              r	|g| _        n|| _        t        | j                        t        | j
                        k7  rt        d| d| d      y )Nza`source` and `destination` arguments must have the same number of elements, but received `source=z` and `destination=rB  )r   r   r:   r;   sourcedestinationr)   r*   )r   r  r  r   s      r   r   zMoveaxis.__init__  s    fc"!(DK DKk3' +}D*Dt{{s4#3#344<<B8 D  +}B0  5r   c                 l    t         j                  j                  || j                  | j                        S r   )r   r   moveaxisr  r  rH   s     r   r!   zMoveaxis.call  s%    }}%%ad6F6FGGr   c                 r   t        |j                        }t        t        |j                              D cg c]  }d }}t	        | j
                  | j                        D ]  \  }}||   ||<   d||<    d\  }}|t        |      k  r|t        |      k  r$||   dk7  r|dz  }|t        |      k  r	||   dk7  r|t        |      k  r$||   dk(  r|dz  }|t        |      k  r	||   dk(  r|t        |      k(  rn!||   ||<   |dz  }|dz  }|t        |      k  rt        ||j                        S c c}w )Nr9   )r   r   r$   r   )	r(   r&   r<   r)   r  r  r  r   r'   )	r   rI   rC  r  rn   scdstrB   js	            r   r.   zMoveaxis.compute_output_spec   sR   qww-$)#agg,$78q884;;(8(89 	GB 'LGBK	 1#l##c,''LOr,AQ c,''LOr,A c,''GAJ",<Q c,''GAJ",< C%%%ajLOFAFA #l## <qww77# 9s   	D4r0   r5   s   @r   r  r    s    $H8r   r  zkeras.ops.moveaxiszkeras.ops.numpy.moveaxisc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Move axes of a tensor to new positions.

    Other axes remain in their original order.

    Args:
        x: Tensor whose axes should be reordered.
        source: Original positions of the axes to move. These must be unique.
        destination: Destinations positions for each of the original axes.
            These must also be unique.

    Returns:
        Tensor with moved axes.
    )r  r  )r   r  r7   r   r   r  )rI   r  r  s      r   r  r    sB     QD!,::1====!!!F!LLr   c                   ,     e Zd Zd fd	Zd Zd Z xZS )NanToNumc                 L    t         |           || _        || _        || _        y r   )r   r   nanposinfneginf)r   r  r   r!  r   s       r   r   zNanToNum.__init__+  s#    r   c                     t         j                  j                  || j                  | j                  | j
                        S )Nr  r   r!  )r   r   
nan_to_numr  r   r!  rH   s     r   r!   zNanToNum.call1  s3    }}''488DKK ( 
 	
r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zNanToNum.compute_output_spec6  r{  r   g        NNr0   r5   s   @r   r  r  *  s    

3r   r  zkeras.ops.nan_to_numzkeras.ops.numpy.nan_to_numc                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a  Replace NaN with zero and infinity with large finite numbers.

    Args:
        x: Input data.
        nan: Optional float or int. Value to replace `NaN` entries with.
        posinf: Optional float or int.
            Value to replace positive infinity with.
        neginf: Optional float or int.
            Value to replace negative infinity with.

    Returns:
        `x`, with non-finite values replaced.
    r#  )r   r  r7   r   r   r$  )rI   r  r   r!  s       r   r$  r$  :  sF    ( QD!Cv>LLQOO==##A3vf#MMr   c                       e Zd Zd Zd Zy)Ndimc                 @    t         j                  j                  |      S r   )r   r   ndimrH   s     r   r!   z	Ndim.callT  s    }}!!
 	
r   c                 @    t        t        |j                        g      S r   )r   r)   r&   rH   s     r   r.   zNdim.compute_output_specY  s    CL>**r   NrS   rT   r   r   r)  r)  S  s    

+r   r)  zkeras.ops.ndimzkeras.ops.numpy.ndimc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the number of dimensions of a tensor.

    Args:
        x: Input tensor.

    Returns:
        The number of dimensions in `x`.
    )r   r)  r7   r   r   r+  rW   s    r   r+  r+  ]  r  r   c                       e Zd Zd Zd Zy)Nonzeroc                 @    t         j                  j                  |      S r   )r   r   nonzerorH   s     r   r!   zNonzero.callm  r   r   c           	          t        t        t        |j                              D cg c]  }t	        dd       c}      S c c}w )Nr   r  r   )r  r<   r)   r&   r   )r   rI   r  s      r   r.   zNonzero.compute_output_specp  s4    :?AGG:MNQ[0N
 	
Ns   ANrS   rT   r   r   r/  r/  l  s    (
r   r/  zkeras.ops.nonzerozkeras.ops.numpy.nonzeroc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the indices of the elements that are non-zero.

    Args:
        x: Input tensor.

    Returns:
        Indices of elements that are non-zero.
    )r   r/  r7   r   r   r1  rW   s    r   r1  r1  v  r  r   c                       e Zd Zd Zd Zy)NotEqualc                 B    t         j                  j                  ||      S r   )r   r   	not_equalrb   s      r   r!   zNotEqual.call  r  r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zNotEqual.compute_output_spec  r  r   NrS   rT   r   r   r5  r5    s    /7r   r5  zkeras.ops.not_equalzkeras.ops.numpy.not_equalc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturn `(x1 != x2)` element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise comparison of `x1` and `x2`.
    )r   r5  r7   r   r   r7  ru   s     r   r7  r7    s<     RH%z''B//==""2r**r   c                       e Zd ZddZddZy)OnesLikeNc                 D    t         j                  j                  ||      S r4  )r   r   	ones_liker   s      r   r!   zOnesLike.call  s    }}&&q&66r   c                 L    ||j                   }t        |j                  |      S r4  r  r   s      r   r.   zOnesLike.compute_output_spec  !    =GGE177%00r   r   rS   rT   r   r   r;  r;    s    71r   r;  zkeras.ops.ones_likezkeras.ops.numpy.ones_likec                     t        | f      rt               j                  | |      S t        j                  j                  | |      S )zReturn a tensor of ones with the same shape and type of `x`.

    Args:
        x: Input tensor.
        dtype: Overrides the data type of the result.

    Returns:
        A tensor of ones with the same shape and type as `x`.
    r   )r   r;  r7   r   r   r=  r8  s     r   r=  r=    s@     QD!z'''77==""1E"22r   c                       e Zd ZddZddZy)	ZerosLikeNc                 D    t         j                  j                  ||      S r4  )r   r   
zeros_liker   s      r   r!   zZerosLike.call  s    }}'''77r   c                 L    ||j                   }t        |j                  |      S r4  r  r   s      r   r.   zZerosLike.compute_output_spec  r?  r   r   rS   rT   r   r   rB  rB    s    81r   rB  zkeras.ops.zeros_likezkeras.ops.numpy.zeros_likec                     t        | f      rt               j                  | |      S t        j                  j                  | |      S )zReturn a tensor of zeros with the same shape and type as `x`.

    Args:
        x: Input tensor.
        dtype: Overrides the data type of the result.

    Returns:
        A tensor of zeros with the same shape and type as `x`.
    r   )r   rB  r7   r   r   rD  r8  s     r   rD  rD    s@      QD!{((%(88==##AU#33r   c                       e Zd Zd Zd Zy)Outerc                 B    t         j                  j                  ||      S r   )r   r   outerrb   s      r   r!   z
Outer.call  r  r   c           
      l   t        |ddg      }t        |ddg      }d |v rd }nt        t        j                  |            }d |v rd }nt        t        j                  |            }||g}t	        j
                  t        |dt        |            t        |dt        |                  }t        ||      S )Nr&   r$   r'   r   )rP   r;   r   r   r   ri   rj   r   )	r   rc   rd   rl   rm   x1_flatten_shapex2_flatten_shapern   ro   s	            r   r.   zOuter.compute_output_spec  s    2w,2w,8#"2778#458#"2778#45(*:;**Bb*Bb*
 <|<<r   NrS   rT   r   r   rH  rH    s    +=r   rH  zkeras.ops.outerzkeras.ops.numpy.outerc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Compute the outer product of two vectors.

    Given two vectors `x1` and `x2`, the outer product is:

    ```
    out[i, j] = x1[i] * x2[j]
    ```

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Outer product of `x1` and `x2`.
    )r   rH  r7   r   r   rJ  ru   s     r   rJ  rJ    s<    " RH%w$$R,,==r2&&r   c                   6     e Zd Zd fd	Zd ZddZddZ xZS )Padc                 \    t         |           | j                  |      | _        || _        y r   )r   r   _process_pad_width	pad_widthmode)r   rS  rT  r   s      r   r   zPad.__init__  s'    00;	r   c                 :   t        |t              r||ffS t        |t        t        f      rt        |d   t              r|fS t	        |d         }t        |      D ]=  \  }}t	        |      |k7  rt        d|       t	        |      dk(  s1|d   |d   f||<   ? |S )Nr   zM`pad_width` should be a list of tuples of length 1 or 2. Received: pad_width=r$   )r:   r;   r  r(   r)   	enumerater*   )r   rS  	first_lenrB   pws        r   rR  zPad._process_pad_width  s    i%	*,,i%/JaL#5
 <	!%	y) 	.EAr2w)# 33<+?  2w!| "1r!u~	!	. r   c                    t        | j                        dkD  r}t        | j                        t        |j                        k7  rRt        d| j                   dt        | j                         d|j                   dt        |j                         d	      t        j
                  j                  || j                  | j                  |      S )Nr$   H`pad_width` must have the same length as `x.shape`. Received: pad_width= (of length ) and x.shape=))rS  rT  constant_values)r)   rS  r&   r*   r   r   padrT  )r   rI   r^  s      r   r!   zPad.call  s    t~~"s4>>':c!''l'J''+~~&6 7!$..12.	 J!!''l^1.  }}  nn+	 ! 
 	
r   c                 r   t        |j                        }t        | j                        dk(  r/t	        t        |            D cg c]  }| j                  d    }}nt        | j                        t        |      k(  r| j                  }nRt        d| j                   dt        | j                         d|j                   dt        |j                         d	      t	        t        |            D ])  }||   d ||<   ||xx   ||   d   ||   d   z   z  cc<   + t        ||j                        S c c}w )Nr$   r   rZ  r[  r\  r]  r   )r(   r&   r)   rS  r<   r*   r   r'   )r   rI   r^  rn   r  rS  rB   s          r   r.   zPad.compute_output_spec-  s%   AGG}t~~!#49#l:K4LMq*MIM C$55I''+~~&6 7!$..12.	 J!!''l^1.  s<() 	EAA&"&QQ9Q<?Yq\!_#DD		E
 <qww77! Ns   D4)constantr   )r1   r2   r3   r   rR  r!   r.   r4   r5   s   @r   rP  rP    s    
$
8r   rP  zkeras.ops.padzkeras.ops.numpy.padc                 ,     t        ||      | |      S )a  Pad a tensor.

    Args:
        x: Tensor to pad.
        pad_width: Number of values padded to the edges of each axis.
            `((before_1, after_1), ...(before_N, after_N))` unique pad
            widths for each axis.
            `((before, after),)` yields same before and after pad for
            each axis.
            `(pad,)` or `int` is a shortcut for `before = after = pad`
            width for all axes.
        mode: One of `"constant"`, `"edge"`, `"linear_ramp"`,
            `"maximum"`, `"mean"`, `"median"`, `"minimum"`,
            `"reflect"`, `"symmetric"`, `"wrap"`, `"empty"`,
            `"circular"`. Defaults to `"constant"`.
        constant_values: value to pad with if `mode == "constant"`.
            Defaults to `0`. A `ValueError` is raised if not None and
            `mode != "constant"`.

    Note:
        Torch backend only supports modes `"constant"`, `"reflect"`,
        `"symmetric"` and `"circular"`.
        Only Torch backend supports `"circular"` mode.

    Note:
        Tensorflow backend only supports modes `"constant"`, `"reflect"`
        and `"symmetric"`.

    Returns:
        Padded tensor.
    rT  )r^  )rP  )rI   rS  rT  r^  s       r   r_  r_  C  s    B %3yt$QHHr   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Prodc                 ~    t         |           t        |t              r	|g| _        n|| _        || _        || _        y r   )r   r   r:   r;   r?   rz   r'   )r   r?   rz   r'   r   s       r   r   zProd.__init__h  s6    dC DIDI 
r   c                     t         j                  j                  || j                  | j                  | j
                        S )Nr?   rz   r'   )r   r   r   r?   rz   r'   rH   s     r   r!   z	Prod.callq  s6    }}!!]]**	 " 
 	
r   c                 F   | j                   | j                   }n4t        j                  |j                         }|dk(  rd}n|dv rd}n|dv rd}t        j                         dk(  r|dk(  rd}t        t	        |j
                  | j                  | j                        |      S )	Nr   r  )r  int16uint8uint16uint32torchr   r   )r'   r   ri   r   r   r&   r?   rz   r   s      r   r.   zProd.compute_output_specy  s    ::!JJE''0E++-- ??'EX,=Etyy4==I
 	
r   r  r0   r5   s   @r   re  re  g  s    

r   re  zkeras.ops.prodzkeras.ops.numpy.prodc                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a  Return the product of tensor elements over a given axis.

    Args:
        x: Input tensor.
        axis: Axis or axes along which a product is performed. The default,
            `axis=None`, will compute the product of all elements
            in the input tensor.
        keepdims: If this is set to `True`, the axes which are reduce
            are left in the result as dimensions with size one.
        dtype: Data type of the returned tensor.

    Returns:
        Product of elements of `x` over the given axis or axes.
    rh  )r   re  r7   r   r   r   )rI   r?   rz   r'   s       r   r   r     sF      QD!>LLQOO==adXUKKr   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Quantilec                 r    t         |           t        |t              r|g}|| _        || _        || _        y r   )r   r   r:   r;   r?   methodrz   )r   r?   rt  rz   r   s       r   r   zQuantile.__init__  s4    dC 6D	 r   c                 p    t         j                  j                  ||| j                  | j                        S r~   )r   r   quantiler?   rz   )r   rI   qs      r   r!   zQuantile.call  s/    }}%%qtyy4== & 
 	
r   c                    t        |j                  | j                  | j                        }t	        |d      r+t        |j                        dkD  r|j                  d   f|z   }t        j                  |j                        dk(  rt        j                         }n$t        j                  |j                  t              }t        ||      S )Nr   r&   r   r   r   )r   r&   r?   rz   hasattrr)   r   r   r'   r   r   ri   r   r   )r   rI   rw  rn   r'   s        r   r.   zQuantile.compute_output_spec  s    #GG$))dmm
 1g177|a !
}|;$$QWW-8NN$E&&qww6E<u55r   NlinearFr0   r5   s   @r   rr  rr    s    !

6r   rr  zkeras.ops.quantilezkeras.ops.numpy.quantilec                     t        | |f      rt        |||      j                  | |      S t        j                  j                  | ||||      S )a  Compute the q-th quantile(s) of the data along the specified axis.

    Args:
        x: Input tensor.
        q: Probability or sequence of probabilities for the quantiles to
            compute. Values must be between 0 and 1 inclusive.
        axis: Axis or axes along which the quantiles are computed. Defaults to
            `axis=None` which is to compute the quantile(s) along a flattened
            version of the array.
        method: A string specifies the method to use for estimating the
            quantile. Available methods are `"linear"`, `"lower"`, `"higher"`,
            `"midpoint"`, and `"nearest"`. Defaults to `"linear"`.
            If the desired quantile lies between two data points `i < j`:
            - `"linear"`: `i + (j - i) * fraction`, where fraction is the
                fractional part of the index surrounded by `i` and `j`.
            - `"lower"`: `i`.
            - `"higher"`: `j`.
            - `"midpoint"`: `(i + j) / 2`
            - `"nearest"`: `i` or `j`, whichever is nearest.
        keepdims: If this is set to `True`, the axes which are reduce
            are left in the result as dimensions with size one.

    Returns:
        The quantile(s). If `q` is a single probability and `axis=None`, then
        the result is a scalar. If multiple probabilities levels are given,
        first axis of the result corresponds to the quantiles. The other axes
        are the axes that remain after the reduction of `x`.
    )r?   rt  rz   )r   rr  r7   r   r   rv  )rI   rw  r?   rt  rz   s        r   rv  rv    sY    < QF#fx

-1
	 ==!!	14 "  r   c                       e Zd Zd Zd Zy)Ravelc                 @    t         j                  j                  |      S r   )r   r   ravelrH   s     r   r!   z
Ravel.call  r   r   c                     d |j                   v rd g}n)t        t        j                  |j                               g}t	        ||j
                        S r4  )r&   r;   r   r   r   r'   )r   rI   rn   s      r   r.   zRavel.compute_output_spec  sD    177?L   012L<qww77r   NrS   rT   r   r   r~  r~    s    &8r   r~  zkeras.ops.ravelzkeras.ops.numpy.ravelc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn a contiguous flattened tensor.

    A 1-D tensor, containing the elements of the input, is returned.

    Args:
        x: Input tensor.

    Returns:
        Output tensor.
    )r   r~  r7   r   r   r  rW   s    r   r  r    r  r   c                       e Zd Zd Zd Zd Zy)UnravelIndexc                      || _         g | _        y r   )r&   _inbound_nodes)r   r&   s     r   r   zUnravelIndex.__init__  s    
 r   c                 V    t         j                  j                  || j                        S r   )r   r   unravel_indexr&   )r   r  s     r   r!   zUnravelIndex.call	  s    }}**7DJJ??r   c                 f   d | j                   v r| j                   D cg c]  }d g }}nt        |t              r| j                   D cg c]  }dg }}nqt        |d      r-| j                   D cg c]  }t	        |j                          }}n8	 t        j                   |      }| j                   D cg c]  }t	        |       }}|D cg c]  }t        ||j                         c}S c c}w c c}w c c}w c c}w # t        $ r# | j                   D cg c]  }d g nc c}w }}Y dw xY wc c}w )Nr$   r&   r   )	r&   r:   r;   ry  r(   r   	Exceptionr   r'   )r   r  r  output_shapesindices_shaper&   s         r   r.   z UnravelIndex.compute_output_spec  s   4::-1ZZ8dV8M8'3'.2jj 9! 9 9'*>Bjj Igmm!4 I IA$&HHW$5MBF**$MQT-%8$MM$M
 BO
8=KW]]3
 	
 9 !: I %N  A59ZZ$@dV$@$@M$@A
sG   
C+
C0/C5#C? 2C:C? 
D.:C? ?D+
D! D+*D+N)r1   r2   r3   r   r!   r.   rT   r   r   r  r    s    !@
r   r  zkeras.ops.unravel_indexzkeras.ops.numpy.unravel_indexc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Convert flat indices to coordinate arrays in a given array shape.

    Args:
        indices: An integer or array of integers representing flat indices.
        shape: The shape of the array to unravel into.

    Returns:
        Tuple of arrays for each dimension with unraveled indices.

    Example:
        >>> indices = 5
        >>> shape = (3, 3)
        >>> unravel_index(indices, shape)
        (1, 2)  # 5 is at row 1, column 2 in a 3x3 array
    )r   r  r7   r   r   r  )r  r&   s     r   r  r     s;    " WJ'E"0099==&&w66r   c                       e Zd Zd Zd Zy)Realc                 @    t         j                  j                  |      S r   )r   r   realrH   s     r   r!   z	Real.call8  r  r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zReal.compute_output_spec;  rR   r   NrS   rT   r   r   r  r  7  r  r   r  zkeras.ops.realzkeras.ops.numpy.realc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the real part of the complex argument.

    Args:
        x: Input tensor.

    Returns:
        The real component of the complex argument.
    )r   r  r7   r   r   r  rW   s    r   r  r  @  r  r   c                       e Zd Zd Zd Zy)
Reciprocalc                 @    t         j                  j                  |      S r   )r   r   
reciprocalrH   s     r   r!   zReciprocal.callP  s    }}''**r   c                 ,    t        |j                        S r   r6  rH   s     r   r.   zReciprocal.compute_output_specS  s    177##r   NrS   rT   r   r   r  r  O  s    +$r   r  zkeras.ops.reciprocalzkeras.ops.numpy.reciprocalc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the reciprocal of the argument, element-wise.

    Calculates `1/x`.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, element-wise reciprocal of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  W  s6    " QD!|))!,,==##A&&r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Repeatc                 >    t         |           || _        || _        y r   )r   r   r?   repeats)r   r  r?   r   s      r   r   zRepeat.__init__n  s    	r   c                 n    t         j                  j                  || j                  | j                        S r   )r   r   repeatr  r?   rH   s     r   r!   zRepeat.calls  s&    }}##At||$))#DDr   c                    t        |j                        }| j                  }t        |t              r|g}t        |      }|dk(  }| j                  d |v rt        d g|j                        S t	        t        j                  |            }|r
||d   z  g}n5||k7  rt        d| d|       t	        t        j                  |            g}t        ||j                        S || j                     }|t        ||j                        S |}|r||d   z  || j                  <   nN||k7  rt        d| j                   d| d|       t	        t        j                  |            || j                  <   t        ||j                        S )Nr$   r   r   zYSize of `repeats` and dimensions of `x` after flattening should be compatible. Received: r   z*Size of `repeats` and dimensions of `axis z' of x` should be compatible. Received: )r(   r&   r  r:   r;   r)   r?   r   r'   r   r   r*   sum)	r   rI   rC  r  repeats_size	broadcastx_flatten_sizern   
size_on_axs	            r   r.   zRepeat.compute_output_specv  s   qww-,,gs#iG7| A%	99w"D699 !12N . ;</ !!-eN3CE  !$BFF7O 45|177;;TYY'
wagg66&071:&=L#<'''+yyk 2)N%y:  '*"&&/&:L#<qww77r   r   r0   r5   s   @r   r  r  m  s    
E(8r   r  zkeras.ops.repeatzkeras.ops.numpy.repeatc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )aH  Repeat each element of a tensor after themselves.

    Args:
        x: Input tensor.
        repeats: The number of repetitions for each element.
        axis: The axis along which to repeat values. By default, use
            the flattened input array, and return a flat output array.

    Returns:
        Output tensor.
    r   )r   r  r7   r   r   r  )rI   r  r?   s      r   r  r    sB     QD!gD)77::==766r   c                   *     e Zd Z fdZd Zd Z xZS )Reshapec                 0    t         |           || _        y r   )r   r   newshape)r   r  r   s     r   r   zReshape.__init__       r   c                 V    t         j                  j                  || j                        S r   )r   r   reshaper  rH   s     r   r!   zReshape.call  s    }}$$Q66r   c                     t        j                  |j                  | j                  d      }t	        |dd      }t        ||j                  |      S )Nr  rM   FrN   )r   compute_reshape_output_shaper&   r  rP   r   r'   r  s       r   r.   zReshape.compute_output_spec  sD    &CCGGT]]J
 He,<qwwvFFr   r0   r5   s   @r   r  r    s    !7Gr   r  zkeras.ops.reshapezkeras.ops.numpy.reshapec                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )ak  Gives a new shape to a tensor without changing its data.

    Args:
        x: Input tensor.
        newshape: The new shape should be compatible with the original shape.
            One shape dimension can be -1 in which case the value is
            inferred from the length of the array and remaining dimensions.

    Returns:
        The reshaped tensor.
    )r   r  r7   r   r   r  )rI   r  s     r   r  r    s;     QD!x ..q11==  H--r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Rollc                 >    t         |           || _        || _        y r   )r   r   shiftr?   )r   r  r?   r   s      r   r   zRoll.__init__  s    
	r   c                 l    t         j                  j                  || j                  | j                        S r   )r   r   rollr  r?   rH   s     r   r!   z	Roll.call  s#    }}!!!TZZ;;r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zRoll.compute_output_spec  r{  r   r   r0   r5   s   @r   r  r    s    
<3r   r  zkeras.ops.rollzkeras.ops.numpy.rollc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Roll tensor elements along a given axis.

    Elements that roll beyond the last position are re-introduced at the first.

    Args:
        x: Input tensor.
        shift: The number of places by which elements are shifted.
        axis: The axis along which elements are shifted. By default, the
            array is flattened before shifting, after which the original
            shape is restored.

    Returns:
        Output tensor.
    r   )r   r  r7   r   r   r  )rI   r  r?   s      r   r  r    sB      QD!E%33A66==aT22r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Roundc                 0    t         |           || _        y r   )r   r   decimals)r   r  r   s     r   r   zRound.__init__  r  r   c                 V    t         j                  j                  || j                        S r   )r   r   roundr  rH   s     r   r!   z
Round.call  s    }}""1dmm44r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zRound.compute_output_spec  rR   r   r  r0   r5   s   @r   r  r    s    !5Br   r  zkeras.ops.roundzkeras.ops.numpy.roundc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )zEvenly round to the given number of decimals.

    Args:
        x: Input tensor.
        decimals: Number of decimal places to round to. Defaults to `0`.

    Returns:
        Output tensor.
    )r   r  r7   r   r   r  )rI   r  s     r   r  r    s:     QD!X,,Q//==q(++r   c                       e Zd ZddZddZy)SearchSortedc                     t        j                  |      }t        j                  |      }t         j                  j                  |||      S )Nside)r   r]  r   searchsorted)r   sorted_sequencevaluesr  s       r   r!   zSearchSorted.call  s>    !33OD**62}}))/6)MMr   c                     t        |j                        dk7  rt        d      |j                  d   t        j                  t        j
                        j                  k  rdnd}t        |j                  |      S )Nr$   zhsearchsorted only supports 1-D sorted sequences. Usekeras.ops.vectorized_map to extend to N-D sequences.r   r  r   r   )r)   r&   r*   r   iinfor  ro  r   )r   r  r  r  out_types        r   r.   z SearchSorted.compute_output_spec  sp    $$%*G  $$Q'288BHH+=+A+AA  	
 6<<x88r   NleftrS   rT   r   r   r  r    s    N
9r   r  zkeras.ops.searchsortedc                     t        | |f      rt               j                  | ||      S t        j                  |       } t        j                  |      }t        j
                  j                  | ||      S )a  Perform a binary search, returning indices for insertion of `values`
    into `sorted_sequence` that maintain the sorting order.

    Args:
        sorted_sequence: 1-D input tensor, sorted along the innermost
            dimension.
        values: N-D tensor of query insertion values.
        side: 'left' or 'right', specifying the direction in which to insert
            for the equality case (tie-breaker).

    Returns:
        Tensor of insertion indices of same shape as `values`.
    r  )r   r  r7   r   r]  r   r  )r  r  r  s      r   r  r  (  sg     _f56~++OV$+OO//@O&&v.F==%%ovD%IIr   c                       e Zd Zd Zd Zy)Signc                 @    t         j                  j                  |      S r   )r   r   signrH   s     r   r!   z	Sign.call@  r  r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zSign.compute_output_specC  rR   r   NrS   rT   r   r   r  r  ?  r  r   r  zkeras.ops.signzkeras.ops.numpy.signc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturns a tensor with the signs of the elements of `x`.

    Args:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  H  r  r   c                       e Zd Zd Zd Zy)Signbitc                 @    t         j                  j                  |      S r   )r   r   signbitrH   s     r   r!   zSignbit.callX  r   r   c                 L    t        |dd      }t        |j                  d|      S )NrM   Fr   rN   )rP   r   r&   rQ   s      r   r.   zSignbit.compute_output_spec[  s#    He,177&@@r   NrS   rT   r   r   r  r  W  s    (Ar   r  zkeras.ops.signbitzkeras.ops.numpy.signbitc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Return the sign bit of the elements of `x`.

    The output boolean tensor contains `True` where the sign of `x` is negative,
    and `False` otherwise.

    Args:
        x: Input tensor.

    Returns:
        Output boolean tensor of same shape as `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r  `  s6     QD!y&&q))==  ##r   c                       e Zd Zd Zd Zy)Sinc                 @    t         j                  j                  |      S r   )r   r   sinrH   s     r   r!   zSin.calls  r  r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zSin.compute_output_specv  r   r   NrS   rT   r   r   r  r  r      $@r   r  zkeras.ops.sinzkeras.ops.numpy.sinc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zTrigonometric sine, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    r  r   c                       e Zd Zd Zd Zy)Sinhc                 @    t         j                  j                  |      S r   )r   r   sinhrH   s     r   r!   z	Sinh.call  r  r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zSinh.compute_output_spec  r   r   NrS   rT   r   r   r  r        %@r   r  zkeras.ops.sinhzkeras.ops.numpy.sinhc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zHyperbolic sine, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    r  r   c                       e Zd Zd Zd Zy)Sizec                 @    t         j                  j                  |      S r   )r   r   rp  rH   s     r   r!   z	Size.call  r  r   c                     t        g d      S r-  r   rH   s     r   r.   zSize.compute_output_spec  s    2W--r   NrS   rT   r   r   r  r    s    %.r   r  zkeras.ops.sizezkeras.ops.numpy.sizec                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the number of elements in a tensor.

    Args:
        x: Input tensor.

    Returns:
        Number of elements in `x`.
    )r   r  r7   r   r   rp  rW   s    r   rp  rp    r  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Sortc                 0    t         |           || _        y r   r   r   s     r   r   zSort.__init__  r   r   c                 X    t         j                  j                  || j                        S r   )r   r   sortr?   rH   s     r   r!   z	Sort.call  r  r   c                 B    t        |j                  |j                        S r   rz  rH   s     r   r.   zSort.compute_output_spec  s    177AGG,,r   r.  r0   r5   s   @r   r  r    s    5-r   r  zkeras.ops.sortzkeras.ops.numpy.sortc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Sorts the elements of `x` along a given axis in ascending order.

    Args:
        x: Input tensor.
        axis: Axis along which to sort. If `None`, the tensor is flattened
            before sorting. Defaults to `-1`; the last axis.

    Returns:
        Sorted tensor.
    r   )r   r  r7   r   r   r  r0  s     r   r  r    s=     QD!,,Q//==ad++r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Splitc                 t    t         |           t        |t              st	        |      }|| _        || _        y r   )r   r   r:   r;   r  indices_or_sectionsr?   )r   r  r?   r   s      r   r   zSplit.__init__  s4    -s3"'(;"<#6 	r   c                 n    t         j                  j                  || j                  | j                        S r   )r   r   r  r  r?   rH   s     r   r!   z
Split.call  s(    }}""1d&>&>TYY"OOr   c                 n   t        |j                        }|| j                     }t        | j                  t
              r|Gd || j                  <   t        | j                        D cg c]  }t        ||j                         c}S t        j                  || j                        dk7  rt        d| d| j                   d      || j                  z  }||| j                  <   t        | j                        D cg c]  }t        ||j                         c}S dg| j                  |}t        j                  |      }g }t        t        |            D ]N  }	t        |      }
t        ||	         |
| j                  <   |j                  t        |
|j                               P |S c c}w c c}w )Nr   r   zw`x` size on given `axis` must be dividible by `indices_or_sections` when `indices_or_sections` is an int. But received r   r   )r(   r&   r?   r:   r  r;   r<   r   r'   r   r  r*   rj  r)   r   )r   rI   rC  x_size_on_axisr  rp  r  output_sizeoutputsrB   rn   s              r   r.   zSplit.compute_output_spec  s   qww- +d..4%%)		" #4#;#;<  qww7  vvnd&>&>?1D ))7(8//03  "T%=%==D!%GDII t778 G1773 
  !L4#;#;L^Lgg12s;'( 	EA=L&)+a.&9L#NN;|177CD	E 3s   'F-<F2r  r0   r5   s   @r   r  r    s    Pr   r  zkeras.ops.splitzkeras.ops.numpy.splitc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Split a tensor into chunks.

    Args:
        x: Input tensor.
        indices_or_sections: If an integer, N, the tensor will be split into N
            equal sections along `axis`. If a 1-D array of sorted integers,
            the entries indicate indices at which the tensor will be split
            along `axis`.
        axis: Axis along which to split. Defaults to `0`.

    Note:
        A split does not have to result in equal division when using
        Torch backend.

    Returns:
        A list of tensors.
    r   )r   r  r7   r   r   r  )rI   r  r?   s      r   r  r    sD    & QD!(t4BB1EE==q"5DAAr   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Stackc                 0    t         |           || _        y r   r   r   s     r   r   zStack.__init__&  r   r   c                 X    t         j                  j                  || j                        S r   )r   r   stackr?   r  s     r   r!   z
Stack.call*  s     }}""2DII"66r   c           
         |d   j                   }g }|D ]\  }t        |j                   |g d      st        d|j                    d| d      |j                  t	        |dt        |                   ^ t        |      }t        |      }| j                  dk(  r||gz   }nK| j                  dk\  r|j                  | j                  |       n|j                  | j                  d	z   |       t        j                  | }t        ||
      S )Nr   Tr  zIEvery value in `xs` must have the same shape. But found element of shape z5,  which is different from the first element's shape r   r'   r9   r$   r   )r&   rC   r*   r   rP   rj   r)   r(   r?   insertr   ri   r   )r   r  r  r   rI   size_on_axisrn   ro   s           r   r.   zStack.compute_output_spec-  s   ekk 	CAqww"N (()y 1--8M< 
 $$WQa%AB	C 2wK(99?'<.8LYY!^		<8		A|<))+<=<|<<r   r  r0   r5   s   @r   r   r   %  s    7=r   r   zkeras.ops.stackzkeras.ops.numpy.stackc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a%  Join a sequence of tensors along a new axis.

    The `axis` parameter specifies the index of the new axis in the
    dimensions of the result.

    Args:
        x: A sequence of tensors.
        axis: Axis along which to stack. Defaults to `0`.

    Returns:
        The stacked tensor.
    r   )r   r   r7   r   r   r  r0  s     r   r  r  E  s>     QD!$--a00==qt,,r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Stdc                 ~    t         |           t        |t              r|g| _        || _        y || _        || _        y r   ry   r{   s      r   r   zStd.__init__Y  r|   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   stdr?   rz   rH   s     r   r!   zStd.calla  &    }}  T]] KKr   c                     t        j                  |j                        }d|v s|dk(  rt        j                         }t	        t        |j                  | j                  | j                        |      S )Nr;   r   r   r   )	r   r   r'   r   r   r   r&   r?   rz   r   rI   ro   s      r   r.   zStd.compute_output_specd  sY    009L LF$:">>+Ltyy4==I
 	
r   r   r0   r5   s   @r   r	  r	  X  s    !L
r   r	  zkeras.ops.stdzkeras.ops.numpy.stdc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Compute the standard deviation along the specified axis.

    Args:
        x: Input tensor.
        axis: Axis along which to compute standard deviation.
            Default is to compute the standard deviation of the
            flattened tensor.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one.

    Returns:
        Output tensor containing the standard deviation values.
    r   )r   r	  r7   r   r   r  r   s      r   r  r  n  sB     QD!x0>>qAA==QTH==r   c                   *     e Zd Z fdZd Zd Z xZS )Swapaxesc                 >    t         |           || _        || _        y r   )r   r   r,   r-   )r   r,   r-   r   s      r   r   zSwapaxes.__init__  s    

r   c                 l    t         j                  j                  || j                  | j                        S r   )r   r   swapaxesr,   r-   rH   s     r   r!   zSwapaxes.call  s#    }}%%aTZZ@@r   c                     t        |j                        }|| j                     }|| j                     || j                  <   ||| j                  <   t	        ||j
                        S r4  )r(   r&   r,   r-   r   r'   )r   rI   rC  r  s       r   r.   zSwapaxes.compute_output_spec  sS    qww-djj!%djj1

!

7!''22r   r0   r5   s   @r   r  r    s    A3r   r  zkeras.ops.swapaxeszkeras.ops.numpy.swapaxesc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )zInterchange two axes of a tensor.

    Args:
        x: Input tensor.
        axis1: First axis.
        axis2: Second axis.

    Returns:
        A tensor with the axes swapped.
    )r,   r-   )r   r  r7   r   r   r  )rI   r,   r-   s      r   r  r    sB     QD!u%33A66==!!!5!>>r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Takec                 0    t         |           || _        y r   r   r   s     r   r   zTake.__init__  r   r   c                 Z    t         j                  j                  ||| j                        S r   )r   r   taker?   r   rI   r  s      r   r!   z	Take.call  s"    }}!!!W499!==r   c                    t        |j                        }t        |t              r"t        |j                        }|j                  }n+t        t        t        j                  |      dg             }d}| j                  t        ||j                        S | j                  dk  rt        |      | j                  z   n| j                  }|d | |z   ||dz   d  z   }t        ||j                  |      S )Nr&   Fr   r   r$   )r'   ragged)r(   r&   r:   r   r  rP   r   r    r?   r'   r)   )r   rI   r  rC  r  r  r?   rn   s           r   r.   zTake.compute_output_spec  s    qww-g{+ /M^^F '):GR!HIMF99}AGG<< ,099q=s7|dii'diiu~5q
8KK<qwwvFFr   r   r0   r5   s   @r   r  r    s    >Gr   r  zkeras.ops.takezkeras.ops.numpy.takec                     t        | |f      rt        |      j                  | |      S t        j                  j                  | ||      S )a5  Take elements from a tensor along an axis.

    Args:
        x: Source tensor.
        indices: The indices of the values to extract.
        axis: The axis over which to select values. By default, the
            flattened input tensor is used.

    Returns:
        The corresponding tensor of values.
    r   )r   r  r7   r   r   r  rI   r  r?   s      r   r  r    sC     QL),,Q88==at44r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )TakeAlongAxisc                 0    t         |           || _        y r   r   r   s     r   r   zTakeAlongAxis.__init__  r   r   c                 Z    t         j                  j                  ||| j                        S r   )r   r   take_along_axisr?   r  s      r   r!   zTakeAlongAxis.call  s"    }},,Qdii,HHr   c                     t        j                  |j                  |j                  | j                        }t	        ||j
                        S r4  )r   $compute_take_along_axis_output_shaper&   r?   r   r'   )r   rI   r  rn   s       r   r.   z!TakeAlongAxis.compute_output_spec  s8    &KKGGW]]DII
 <qww77r   r   r0   r5   s   @r   r#  r#    s    I8r   r#  zkeras.ops.take_along_axiszkeras.ops.numpy.take_along_axisc                     t        | |f      rt        |      j                  | |      S t        j                  j                  | ||      S )aL  Select values from `x` at the 1-D `indices` along the given axis.

    Args:
        x: Source tensor.
        indices: The indices of the values to extract.
        axis: The axis over which to select values. By default, the flattened
            input tensor is used.

    Returns:
        The corresponding tensor of values.
    r   )r   r#  r7   r   r   r&  r!  s      r   r&  r&    sD    $ QL)$'55aAA==((G$(??r   c                       e Zd Zd Zd Zy)Tanc                 @    t         j                  j                  |      S r   )r   r   tanrH   s     r   r!   zTan.call  r  r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zTan.compute_output_spec  r   r   NrS   rT   r   r   r+  r+    r  r   r+  zkeras.ops.tanzkeras.ops.numpy.tanc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zCompute tangent, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r+  r7   r   r   r-  rW   s    r   r-  r-    r  r   c                       e Zd Zd Zd Zy)Tanhc                 @    t         j                  j                  |      S r   )r   r   tanhrH   s     r   r!   z	Tanh.call  r  r   c                    t        j                  t        |dt        j                                     }|dk(  rt        j                         }nt	        j
                  |t              }t        |dd      }t        |j                  ||      S r   r   r   s       r   r.   zTanh.compute_output_spec  r   r   NrS   rT   r   r   r1  r1    r  r   r1  zkeras.ops.tanhzkeras.ops.numpy.tanhc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zHyperbolic tangent, element-wise.

    Arguments:
        x: Input tensor.

    Returns:
        Output tensor of same shape as `x`.
    )r   r1  r7   r   r   r3  rW   s    r   r3  r3  !  r  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )	Tensordotc                 0    t         |           || _        y r   r   r   r   r   r   r   s     r   r   zTensordot.__init__1  r   r   c                 Z    t         j                  j                  ||| j                        S Nr   )r   r   	tensordotr   rb   s      r   r!   zTensordot.call5  "    }}&&r2DII&>>r   c           
      b   t        t        |dg             }t        t        |dg             }t        j                  t        |dt	        |            t        |dt	        |                  }t        | j                  t              s| j                  d   D cg c]  }||   	 }}| j                  d   D cg c]  }||   	 }}t        ||d      st        d| d| d	      | j                  d   D ]  }d
||<   	 | j                  d   D ]  }d
||<   	 t        t        d
j                  |            }t        t        d
j                  |            }||z   }	t        |	|      S | j                  dk  r||z   }	n |d | j                    || j                  d  z   }	t        |	|      S c c}w c c}w )Nr&   r'   r   r$   TrA  z<Shape mismatch on `x1[axes[0]]` and `x2[axes[1]]`, received r   r   r9   r   )r(   rP   r   ri   rj   r:   r   r;   rC   r*   r]  r^  r   )
r   rc   rd   rl   rm   r'   rA   x1_select_shapex2_select_shapern   s
             r   r.   zTensordot.compute_output_spec8  s   GR01GR01""Bb*Bb*
 $))S)6:iilCx|COC6:iilCx|COCT !  /0o5FaI 
 iil "!"iil "!" FB;;9:HFB;;9:H#h.L|59999>#h.L#Ltyyj1HTYY[4IIL<u555 DCs   F'5F,r#   r0   r5   s   @r   r7  r7  0  s    ?"6r   r7  zkeras.ops.tensordotzkeras.ops.numpy.tensordotc                     t        | |f      rt        |      j                  | |      S t        j                  j                  | ||      S )a!  Compute the tensor dot product along specified axes.

    Args:
        x1: First tensor.
        x2: Second tensor.
        axes: - If an integer, N, sum over the last N axes of `x1` and the
                first N axes of `x2` in order. The sizes of the corresponding
                axes must match.
              - Or, a list of axes to be summed over, first sequence applying
                to `x1`, second to `x2`. Both sequences must be of the
                same length.

    Returns:
        The tensor dot product of the inputs.
    r=  )r   r7  r7   r   r   r>  )rc   rd   r   s      r   r>  r>  ]  D    " RH%d#11"b99==""2r"55r   c                   *     e Zd Z fdZd Zd Z xZS )Tilec                 0    t         |           || _        y r   )r   r   r  )r   r  r   s     r   r   zTile.__init__t  s    r   c                 V    t         j                  j                  || j                        S r   )r   r   tiler  rH   s     r   r!   z	Tile.callx  s    }}!!!T\\22r   c                    t        |j                        }| j                  }t        |t              r|g}t        |      t        |      kD  rdgt        |      t        |      z
  z  |z   }ndgt        |      t        |      z
  z  |z   }g }t        ||      D ]-  \  }}||j                  d        |j                  ||z         / t        ||j                        S )Nr$   r   )
r(   r&   r  r:   r;   r)   r  r   r   r'   )r   rI   rC  r  rn   x_sizer  s          r   r.   zTile.compute_output_spec{  s    qww-,,gs#iGw<#g,&cS\CL89GCGcS\CL89GCG!'73 	5NFF~##D)##FVO4		5
 <qww77r   r0   r5   s   @r   rG  rG  s  s    38r   rG  zkeras.ops.tilezkeras.ops.numpy.tilec                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Repeat `x` the number of times given by `repeats`.

    If `repeats` has length `d`, the result will have dimension of
    `max(d, x.ndim)`.

    If `x.ndim < d`, `x` is promoted to be d-dimensional by prepending
    new axes.

    If `x.ndim > d`, `repeats` is promoted to `x.ndim` by prepending 1's to it.

    Args:
        x: Input tensor.
        repeats: The number of repetitions of `x` along each axis.

    Returns:
        The tiled output tensor.
    )r   rG  r7   r   r   rJ  )rI   r  s     r   rJ  rJ    sA    & QD!

-
	 ==a))r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Tracec                 L    t         |           || _        || _        || _        y r   rT  rV  s       r   r   zTrace.__init__  rW  r   c                     t         j                  j                  || j                  | j                  | j
                        S rY  )r   r   tracerU  r,   r-   rH   s     r   r!   z
Trace.call  s3    }}""dkk4:: # 
 	
r   c                 2   t        |j                        }d|| j                  <   d|| j                  <   t        t	        dj
                  |            }t        j                  |j                        }|dvrt        j                  |d      }t        ||      S )Nr9   )r   rn  uint64r  r   )r(   r&   r,   r-   r]  r^  r   r   r'   r   ri   r   )r   rI   rC  rn   ro   s        r   r.   zTrace.compute_output_spec  s|    qww- 

 

FB;;89009<<!--lGDL<|<<r   ra  r0   r5   s   @r   rO  rO    s    

=r   rO  zkeras.ops.tracezkeras.ops.numpy.tracec                     t        | f      rt        |||      j                  |       S t        j                  j                  | |||      S )a  Return the sum along diagonals of the tensor.

    If `x` is 2-D, the sum along its diagonal with the given offset is
    returned, i.e., the sum of elements `x[i, i+offset]` for all `i`.

    If a has more than two dimensions, then the axes specified by `axis1`
    and `axis2` are used to determine the 2-D sub-arrays whose traces are
    returned.

    The shape of the resulting tensor is the same as that of `x` with `axis1`
    and `axis2` removed.

    Args:
        x: Input tensor.
        offset: Offset of the diagonal from the main diagonal. Can be
            both positive and negative. Defaults to `0`.
        axis1: Axis to be used as the first axis of the 2-D sub-arrays.
            Defaults to `0`.(first axis).
        axis2: Axis to be used as the second axis of the 2-D sub-arrays.
            Defaults to `1` (second axis).

    Returns:
        If `x` is 2-D, the sum of the diagonal is returned. If `x` has
        larger dimensions, then a tensor of sums along diagonals is
        returned.
    rZ  )r   rO  r7   r   r   rR  rc  s       r   rR  rR    sF    8 QD!VUE*88;;==quEJJr   c                   0     e Zd Zd fd	ZddZddZ xZS )Tric                 j    t         |           || _        |xs t        j                         | _        y r   r   r   r   r   r   r'   r   r   r'   r   s      r   r   zTri.__init__  (    .gnn.
r   c                 p    t         j                  j                  ||| j                  | j                        S )NNMr   r'   )r   r   trir   r'   r   r^  r_  s      r   r!   zTri.call  s(    }}  1TVV4:: FFr   c                 <    ||}t        ||f| j                        S r4  r   r'   ra  s      r   r.   zTri.compute_output_spec  !    9AAq644r   r   Nr   r0   r5   s   @r   rW  rW    s    /
G5r   rW  zkeras.ops.trizkeras.ops.numpy.tric                 H    t         j                  j                  | |||      S )aD  Return a tensor with ones at and below a diagonal and zeros elsewhere.

    Args:
        N: Number of rows in the tensor.
        M: Number of columns in the tensor.
        k: The sub-diagonal at and below which the array is filled.
            `k = 0` is the main diagonal, while `k < 0` is below it, and
            `k > 0` is above. The default is 0.
        dtype: Data type of the returned tensor. The default is "float32".

    Returns:
        Tensor with its lower triangle filled with ones and zeros elsewhere.
        `T[i, j] == 1` for `j <= i + k`, 0 otherwise.
    r_  r   r'   )r   r   r`  r]  s       r   r`  r`    s"      ==Q!q66r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Trilc                 0    t         |           || _        y r   r8  r9  s     r   r   zTril.__init__  r:  r   c                 X    t         j                  j                  || j                        S r<  )r   r   trilr   rH   s     r   r!   z	Tril.call  r?  r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zTril.compute_output_spec
  r{  r   r  r0   r5   s   @r   ri  ri        /3r   ri  zkeras.ops.trilzkeras.ops.numpy.trilc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Return lower triangle of a tensor.

    For tensors with `ndim` exceeding 2, `tril` will apply to the
    final two axes.

    Args:
        x: Input tensor.
        k: Diagonal above which to zero elements. Defaults to `0`. the
            main diagonal. `k < 0` is below it, and `k > 0` is above it.

    Returns:
        Lower triangle of `x`, of same shape and data type as `x`.
    r=  )r   ri  r7   r   r   rl  rG  s     r   rl  rl    =     QD!ay&&q))==a1%%r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Triuc                 0    t         |           || _        y r   r8  r9  s     r   r   zTriu.__init__#  r:  r   c                 X    t         j                  j                  || j                        S r<  )r   r   triur   rH   s     r   r!   z	Triu.call'  r?  r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zTriu.compute_output_spec*  r{  r   r  r0   r5   s   @r   rr  rr  "  rn  r   rr  zkeras.ops.triuzkeras.ops.numpy.triuc                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a  Return upper triangle of a tensor.

    For tensors with `ndim` exceeding 2, `triu` will apply to the
    final two axes.

    Args:
        x: Input tensor.
        k: Diagonal below which to zero elements. Defaults to `0`. the
            main diagonal. `k < 0` is below it, and `k > 0` is above it.

    Returns:
        Upper triangle of `x`, of same shape and data type as `x`.
    r=  )r   rr  r7   r   r   ru  rG  s     r   ru  ru  .  rp  r   c                   *     e Zd Z fdZd Zd Z xZS )Truncc                 "    t         |           y r   rd  re  s    r   r   zTrunc.__init__C  rf  r   c                 @    t         j                  j                  |      S r   )r   r   truncrH   s     r   r!   z
Trunc.callF  r   r   c                 D    t        |j                  |j                        S r4  rz  rH   s     r   r.   zTrunc.compute_output_specI  r{  r   r0   r5   s   @r   ry  ry  B  s    &3r   ry  zkeras.ops.trunczkeras.ops.numpy.truncc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Return the truncated value of the input, element-wise.

    The truncated value of the scalar `x` is the nearest integer `i` which is
    closer to zero than `x` is. In short, the fractional part of the signed
    number `x` is discarded.

    Args:
        x: Input tensor.

    Returns:
        The truncated value of each element in `x`.

    Example:
    >>> x = ops.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0])
    >>> ops.trunc(x)
    array([-1.0, -1.0, -0.0, 0.0, 1.0, 1.0, 2.0])
    )r   ry  r7   r   r   r|  rW   s    r   r|  r|  M  s6    & QD!w$$Q''==q!!r   c                       e Zd Zd Zd Zy)Vdotc                 B    t         j                  j                  ||      S r   )r   r   vdotrb   s      r   r!   z	Vdot.callf  rj  r   c           
          t        j                  t        |dt        |            t        |dt        |                  }t	        g |      S Nr'   r   r   ri   rP   rj   r   r   rc   rd   r'   s       r   r.   zVdot.compute_output_speci  A    ""Bb*Bb*
 2U++r   NrS   rT   r   r   r  r  e  s    *,r   r  zkeras.ops.vdotzkeras.ops.numpy.vdotc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Return the dot product of two vectors.

    If the first argument is complex, the complex conjugate of the first
    argument is used for the calculation of the dot product.

    Multidimensional tensors are flattened before the dot product is taken.

    Args:
        x1: First input tensor. If complex, its complex conjugate is taken
            before calculation of the dot product.
        x2: Second input tensor.

    Returns:
        Output tensor.
    )r   r  r7   r   r   r  ru   s     r   r  r  q  s<    " RH%v##B++==b"%%r   c                       e Zd Zd Zd Zy)Innerc                 B    t         j                  j                  ||      S r   )r   r   innerrb   s      r   r!   z
Inner.call  r  r   c           
          t        j                  t        |dt        |            t        |dt        |                  }t	        g |      S r  r  r  s       r   r.   zInner.compute_output_spec  r  r   NrS   rT   r   r   r  r    s    +,r   r  zkeras.ops.innerzkeras.ops.numpy.innerc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )a  Return the inner product of two tensors.

    Ordinary inner product of vectors for 1-D tensors
    (without complex conjugation), in higher dimensions
    a sum product over the last axes.

    Multidimensional arrays are treated as vectors by flattening
    all but their last axes. The resulting dot product is performed
    over their last axes.

    Args:
        x1: First input tensor.
        x2: Second input tensor. The last dimension of `x1` and `x2`
            must match.

    Returns:
        Output tensor. The shape of the output is determined by
        broadcasting the shapes of `x1` and `x2` after removing
        their last axes.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<    , RH%w$$R,,==r2&&r   zkeras.ops.vectorizezkeras.ops.numpy.vectorizeexcluded	signaturec                x    t        |       st        d|        t        j                  j	                  | ||      S )a*  Turn a function into a vectorized function.

    Example:

    ```python
    def myfunc(a, b):
        return a + b

    vfunc = keras.ops.vectorize(myfunc)
    y = vfunc([1, 2, 3, 4], 2)  # Returns Tensor([3, 4, 5, 6])
    ```

    Args:
        pyfunc: Callable of a single tensor argument.
        excluded: Optional set of integers representing
            positional arguments for which the function
            will not be vectorized.
            These will be passed directly to `pyfunc` unmodified.
        signature: Optional generalized universal function signature,
            e.g., `"(m,n),(n)->(m)"` for vectorized
            matrix-vector multiplication. If provided,
            `pyfunc` will be called with (and expected to return)
            arrays with shapes given by the size of corresponding
            core dimensions. By default, `pyfunc` is assumed
            to take scalars tensors as input and output.

    Returns:
        A new function that applies `pyfunc` to every element
        of its input along axis 0 (the batch axis).
    z>Expected argument `pyfunc` to be a callable. Received: pyfunc=r  )callabler*   r   r   	vectorize)pyfuncr  r  s      r   r  r    sN    @ F  &x)
 	
 ==""Y #  r   c                       e Zd Zd Zd Zy)Vstackc                 @    t         j                  j                  |      S r   )r   r   vstackr  s     r   r!   zVstack.call  r4  r   c           
         |d   j                   }d}g }|D ]  }t        |j                   |dgd      st        d|j                    d| d      ||j                   d   d }n||j                   d   z  }|j                  t	        |dt        |                    t        |      }||d<   t        j                  | }t        ||      S )Nr   Tr  r  r  r   r'   r6  )r   r  r  r  r   rI   rn   ro   s           r   r.   zVstack.compute_output_spec  s    ekk 	CAqww1#$O BBC'' K(M,  ")QWWQZ-?%)""aggaj0"$$WQa%AB	C K(,Q))+<=<66r   NrS   rT   r   r   r  r    s    (7r   r  zkeras.ops.vstackzkeras.ops.numpy.vstackc                     t        | f      rt               j                  |       S t        j                  j                  |       S )zStack tensors in sequence vertically (row wise).

    Args:
        xs: Sequence of tensors.

    Returns:
        Tensor formed by stacking the given tensors.
    )r   r  r7   r   r   r  r8  s    r   r  r    s6     RE"x%%b))==##r   c                       e Zd ZddZd Zy)WhereNc                 D    t         j                  j                  |||      S r   )r   r   where)r   	conditionrc   rd   s       r   r!   z
Where.call  s    }}""9b"55r   c           
      &   t        |dg       }t        |dg       }t        |dg       }t        ||      }t        ||      }t        j                  t        |d|t	        |      nd      t        |d|t	        |      nd            }t        ||      S )Nr&   r'   r;   r   rh   )	r   r  rc   rd   condition_shaperl   rm   rn   ro   s	            r   r.   zWhere.compute_output_spec  s    !)Wb92w+2w+'B'h?))BR^bGBR^bG
 <|<<r   r+  rS   rT   r   r   r  r    s    6
=r   r  zkeras.ops.wherezkeras.ops.numpy.wherec                     ||||t        d      t        | ||f      rt               j                  | ||      S t        j
                  j                  | ||      S )a  Return elements chosen from `x1` or `x2` depending on `condition`.

    Args:
        condition: Where `True`, yield `x1`, otherwise yield `x2`.
        x1: Values from which to choose when `condition` is `True`.
        x2: Values from which to choose when `condition` is `False`.

    Returns:
        A tensor with elements from `x1` where `condition` is `True`, and
        elements from `x2` where `condition` is `False`.
    zN`x1` and `x2` either both should be `None` or both should have non-None value.)r*   r   r  r7   r   r   r  )r  rc   rd   s      r   r  r    sh     	
r~2>bj3
 	
 YB/0w$$YB77==y"b11r   c                       e Zd Zd Zd Zy)Subtractc                 B    t         j                  j                  ||      S r   )r   r   subtractrb   s      r   r!   zSubtract.call+      }}%%b"--r   c           
      &   t        |dg       }t        |dg       }t        ||      }t        |dd      }t        |dd      }|xr |}t        j                  t        |dt	        |            t        |dt	        |                  }	t        ||	|      S )Nr&   rM   Fr'   rN   rh   
r   rc   rd   rl   rm   rn   rp   rq   rr   r'   s
             r   r.   zSubtract.compute_output_spec.  s    2w+2w+'(;B%0	B%0	!/i""Bb*Bb*
 <u]KKr   NrS   rT   r   r   r  r  *      .Lr   r  zkeras.ops.subtractzkeras.ops.numpy.subtractc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zSubtract arguments element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise difference of `x1` and `x2`.
    )r   r  r7   r   r   r  ru   s     r   r  r  <  <     RH%z''B//==!!"b))r   c                       e Zd Zd Zd Zy)Multiplyc                 B    t         j                  j                  ||      S r   )r   r   r  rb   s      r   r!   zMultiply.callM  r  r   c           
      &   t        |dg       }t        |dg       }t        ||      }t        |dd      }t        |dd      }|xs |}t        j                  t        |dt	        |            t        |dt	        |                  }	t        ||	|      S )Nr&   rM   Tr'   rN   rh   r  s
             r   r.   zMultiply.compute_output_specP  s    2w+2w+'(;B$/	B$/	!.Y""Bb*Bb*
 <u]KKr   NrS   rT   r   r   r  r  L  r  r   r  zkeras.ops.multiplyzkeras.ops.numpy.multiplyc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zMultiply arguments element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, element-wise product of `x1` and `x2`.
    )r   r  r7   r   r   r  ru   s     r   r  r  ^  r  r   c                       e Zd Zd Zd Zy)Dividec                 B    t         j                  j                  ||      S r   )r   r   dividerb   s      r   r!   zDivide.callo  r  r   c           
      2   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |            t
              }t        |dd      }t        |dd      }|xr | }	t        |||	      S rg   r  rk   s
             r   r.   zDivide.compute_output_specr      2w+2w+'(;))Bb*Bb*

 B%0	B%0	!3)m]
 	
r   NrS   rT   r   r   r  r  n  s    ,
r   r  zkeras.ops.dividezkeras.ops.numpy.dividec                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zDivide arguments element-wise.

    `keras.ops.true_divide` is an alias for this function.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output tensor, the quotient `x1/x2`, element-wise.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<     RH%x%%b"--==B''r   c                       e Zd Zd Zd Zy)DivideNoNanc                 B    t         j                  j                  ||      S r   )r   r   divide_no_nanrb   s      r   r!   zDivideNoNan.call  r-  r   c           
      2   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |            t
              }t        |dd      }t        |dd      }|xr | }	t        |||	      S rg   r  rk   s
             r   r.   zDivideNoNan.compute_output_spec  r  r   NrS   rT   r   r   r  r    s    3
r   r  zkeras.ops.divide_no_nanzkeras.ops.numpy.divide_no_nanc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zSafe element-wise division which returns 0 where the denominator is 0.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        The quotient `x1/x2`, element-wise, with zero where x2 is zero.
    )r   r  r7   r   r   r  ru   s     r   r  r    s<     RH%}**2r22==&&r2..r   c                       e Zd Zd Zd Zy)
TrueDividec                 B    t         j                  j                  ||      S r   )r   r   true_dividerb   s      r   r!   zTrueDivide.call  r  r   c           
      2   t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |            t
              }t        |dd      }t        |dd      }|xr | }	t        |||	      S rg   r  rk   s
             r   r.   zTrueDivide.compute_output_spec  r  r   NrS   rT   r   r   r  r    s    1
r   r  zkeras.ops.true_dividezkeras.ops.numpy.true_dividec                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zAlias for `keras.ops.divide`.)r   r  r7   r   r   r  ru   s     r   r  r    s<     RH%|))"b11==$$R,,r   c                       e Zd Zd Zd Zy)Powerc                 B    t         j                  j                  ||      S r   )r   r   powerrb   s      r   r!   z
Power.call  r  r   c           
          t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |                  }t        ||      S r  rh   r  s          r   r.   zPower.compute_output_spec  sh    2w+2w+'(;))Bb*GBb,J
 <|<<r   NrS   rT   r   r   r  r    s    +=r   r  zkeras.ops.powerzkeras.ops.numpy.powerc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zFirst tensor elements raised to powers from second tensor, element-wise.

    Args:
        x1: The bases.
        x2: The exponents.

    Returns:
        Output tensor, the bases in `x1` raised to the exponents in `x2`.
    )r   r  r7   r   r   r  ru   s     r   r  r    r  r   c                       e Zd Zd Zd Zy)Negativec                 @    t         j                  j                  |      S r   )r   r   negativerH   s     r   r!   zNegative.call  rJ   r   c                 `    t        |dd      }t        |j                  |j                  |      S rL   rO   rQ   s      r   r.   zNegative.compute_output_spec  rR   r   NrS   rT   r   r   r  r    rU   r   r  zkeras.ops.negativezkeras.ops.numpy.negativec                     t        | f      rt               j                  |       S t        j                  j                  |       S )zyNumerical negative, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, `y = -x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    s6     QD!z''**==!!!$$r   c                       e Zd Zd Zd Zy)Squarec                 @    t         j                  j                  |      S r   )r   r   squarerH   s     r   r!   zSquare.call  r   r   c                     t        |dd      }t        j                  |j                        }|dk(  rd}t	        |j
                  ||      S )NrM   Fr   r  rN   )rP   r   r   r'   r   r&   r  s       r   r.   zSquare.compute_output_spec  sC    He,))!''2F?E177%??r   NrS   rT   r   r   r  r    s    '@r   r  zkeras.ops.squarezkeras.ops.numpy.squarec                     t        | f      rt               j                  |       S t        j                  j                  |       S )zReturn the element-wise square of the input.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, the square of `x`.
    )r   r  r7   r   r   r  rW   s    r   r  r    s6     QD!x%%a((==""r   c                       e Zd Zd Zd Zy)Sqrtc                 j    t        j                  |      }t         j                  j                  |      S r   )r   r]  r   sqrtrH   s     r   r!   z	Sqrt.call.  s'    %%a(}}!!!$$r   c                     t        j                  |j                        dk(  rt        j                         n#t	        j
                  |j                  t              }t        |dd      }t        |j                  ||      S r  r  r   s       r   r.   zSqrt.compute_output_spec2  r  r   NrS   rT   r   r   r  r  -  s    %@r   r  zkeras.ops.sqrtzkeras.ops.numpy.sqrtc                     t        | f      rt               j                  |       S t        j                  |       } t        j
                  j                  |       S )zReturn the non-negative square root of a tensor, element-wise.

    Args:
        x: Input tensor.

    Returns:
        Output tensor, the non-negative square root of `x`.
    )r   r  r7   r   r]  r   r  rW   s    r   r  r  <  sF     QD!v##A&&!!!$A==a  r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Squeezec                 0    t         |           || _        y r   r   r   s     r   r   zSqueeze.__init__M  r   r   c                 X    t         j                  j                  || j                        S r   )r   r   squeezer?   rH   s     r   r!   zSqueeze.callQ  r+  r   c           	         t        |j                        }t        |dd      }t        | j                        }|7t        t        dj                  |            }t        ||j                  |      S |D ]  }||   dk7  st        d| d       |D cg c]  }t        |t        |             }}t        |d      D ]  }||=  t        ||j                  |      S c c}w )	NrM   Fr$   rN   zCannot squeeze axis z!, because the dimension is not 1.T)reverse)r(   r&   rP   r
   r?   r]  r^  r   r'   r*   r	   r)   r  )r   rI   input_shaperM   r?   rn   rk  s          r   r.   zSqueeze.compute_output_specT  s    177mHe,		*<zz; ?@L|1776JJ q>Q&$.qc 2$ $  EIIq%a[)9:IDID$/ #N#{!''&II Js   Cr   r0   r5   s   @r   r  r  L  s    8Jr   r  zkeras.ops.squeezezkeras.ops.numpy.squeezec                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a   Remove axes of length one from `x`.

    Args:
        x: Input tensor.
        axis: Select a subset of the entries of length one in the shape.

    Returns:
        The input tensor with all or a subset of the dimensions of
        length 1 removed.
    r   )r   r  r7   r   r   r  r0  s     r   r  r  h  s>     QD!D!//22==   ..r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )	Transposec                 0    t         |           || _        y r   r9  r:  s     r   r   zTranspose.__init__z  r   r   c                 X    t         j                  j                  || j                        S r<  )r   r   	transposer   rH   s     r   r!   zTranspose.call~  s     }}&&qtyy&99r   c                     t        j                  |j                  | j                        }t	        |dd      }t        ||j                  |      S rL   )r   compute_transpose_output_shaper&   r   rP   r   r'   r  s       r   r.   zTranspose.compute_output_spec  sB    &EEGGTYY
 He,<qwwvFFr   r   r0   r5   s   @r   r  r  y  s    :Gr   r  zkeras.ops.transposezkeras.ops.numpy.transposec                     t        | f      rt        |      j                  |       S t        j                  j                  | |      S )a	  Returns a tensor with `axes` transposed.

    Args:
        x: Input tensor.
        axes: Sequence of integers. Permutation of the dimensions of `x`.
            By default, the order of the axes are reversed.

    Returns:
        `x` with its axes permuted.
    r=  )r   r  r7   r   r   r  )rI   r   s     r   r  r    s>     QD!d#11!44==""14"00r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Meanc                 d    t         |           t        |t              r|g}|| _        || _        y r   ry   r{   s      r   r   zMean.__init__  r   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   meanr?   rz   rH   s     r   r!   z	Mean.call  r   r   c                 &   t        j                  |j                        }t        j                  |j                  d      }d|v s|dk(  r|}n|}t        |dd      }t        t        |j                  | j                  | j                        ||      S )Nfloat32r;   r   rM   Fr   rN   )r   r   r'   r   ri   rP   r   r   r&   r?   rz   )r   rI   	ori_dtypecompute_dtyperesult_dtyperM   s         r   r.   zMean.compute_output_spec  s~    --agg6	**177I>If!4(L$LHe,tyy4==I
 	
r   r   r0   r5   s   @r   r  r    s    !M
r   r  zkeras.ops.meanzkeras.ops.numpy.meanc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Compute the arithmetic mean along the specified axes.

    Args:
        x: Input tensor.
        axis: Axis or axes along which the means are computed. The default
            is to compute the mean of the flattened tensor.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one.

    Returns:
        Output tensor containing the mean values.
    r   )r   r  r7   r   r   r  r   s      r   r  r    sB     QD!1??BB==adX>>r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Varc                 d    t         |           t        |t              r|g}|| _        || _        y r   ry   r{   s      r   r   zVar.__init__  r   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   varr?   rz   rH   s     r   r!   zVar.call  r  r   c           	          t        j                  t        |dt        |            t              }t        t        |j                  | j                  | j                        |      S )Nr'   r   r   )
r   ri   rP   rj   r   r   r   r&   r?   rz   r  s      r   r.   zVar.compute_output_spec  sI    **71gtAw+GOtyy4==I
 	
r   r   r0   r5   s   @r   r  r    s    !L
r   r  zkeras.ops.varzkeras.ops.numpy.varc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Compute the variance along the specified axes.

    Args:
        x: Input tensor.
        axis: Axis or axes along which the variance is computed. The default
            is to compute the variance of the flattened tensor.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one.

    Returns:
        Output tensor containing the variance.
    r   )r   r  r7   r   r   r  r   s      r   r  r    B     QD!x0>>qAA==QTH==r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Sumc                 d    t         |           t        |t              r|g}|| _        || _        y r   ry   r{   s      r   r   zSum.__init__  r   r   c                 n    t         j                  j                  || j                  | j                        S r~   )r   r   r  r?   rz   rH   s     r   r!   zSum.call  r  r   c                 F   t        j                  t        |dt        j                                     }|dv rd}n|dv rd}t        j                         dk(  r|dk(  rd}t        |dd      }t        t        |j                  | j                  | j                  	      ||
      S )Nr'   )r   r  rj  r  rk  rn  ro  rM   Fr   rN   )
r   ri   rP   r   r   r   r   r&   r?   rz   r   s       r   r.   zSum.compute_output_spec  s    ""71gw~~7G#HI--E))E??'EX,=EHe,tyy4==I
 	
r   r   r0   r5   s   @r   r  r    s    !L
r   r  zkeras.ops.sumzkeras.ops.numpy.sumc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )a  Sum of a tensor over the given axes.

    Args:
        x: Input tensor.
        axis: Axis or axes along which the sum is computed. The default is to
            compute the sum of the flattened tensor.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one.

    Returns:
        Output tensor containing the sum.
    r   )r   r  r7   r   r   r  r   s      r   r  r  
  r  r   c                       e Zd ZddZddZy)ZerosNc                 D    t         j                  j                  ||      S r4  r   r   zerosr  s      r   r!   z
Zeros.call  r  r   c                 L    |xs t        j                         }t        ||      S r4  r  r  s      r   r.   zZeros.compute_output_spec!  r  r   r   rS   rT   r   r   r	  r	    r  r   r	  zkeras.ops.zeroszkeras.ops.numpy.zerosc                 D    t         j                  j                  | |      S )zReturn a new tensor of given shape and type, filled with zeros.

    Args:
        shape: Shape of the new tensor.
        dtype: Desired data type of the tensor.

    Returns:
        Tensor of zeros with the given shape and dtype.
    r   r  r%   s     r   r  r  &  r  r   c                       e Zd ZddZddZy)OnesNc                 D    t         j                  j                  ||      S r4  r   r   onesr  s      r   r!   z	Ones.call5  s    }}!!%u!55r   c                 L    |xs t        j                         }t        ||      S r4  r  r  s      r   r.   zOnes.compute_output_spec8  r  r   r   rS   rT   r   r   r  r  4  s    6/r   r  zkeras.ops.oneszkeras.ops.numpy.onesc                 D    t         j                  j                  | |      S )zReturn a new tensor of given shape and type, filled with ones.

    Args:
        shape: Shape of the new tensor.
        dtype: Desired data type of the tensor.

    Returns:
        Tensor of ones with the given shape and dtype.
    r   r  r%   s     r   r  r  =  s     ==e511r   c                   0     e Zd Zd fd	ZddZddZ xZS )Eyec                 j    t         |           || _        |xs t        j                         | _        y r   rY  rZ  s      r   r   zEye.__init__L  r[  r   c                 p    t         j                  j                  ||| j                  | j                        S )Nrg  )r   r   eyer   r'   ra  s      r   r!   zEye.callQ  s(    }}  a466 DDr   c                 <    ||}t        ||f| j                        S r4  rc  ra  s      r   r.   zEye.compute_output_specT  rd  r   re  r   r0   r5   s   @r   r  r  K  s    /
E5r   r  zkeras.ops.eyezkeras.ops.numpy.eyec                 H    t         j                  j                  | |||      S )a  Return a 2-D tensor with ones on the diagonal and zeros elsewhere.

    Args:
        N: Number of rows in the output.
        M: Number of columns in the output. If `None`, defaults to `N`.
        k: Index of the diagonal: 0 (the default) refers to the main
            diagonal, a positive value refers to an upper diagonal,
            and a negative value to a lower diagonal.
        dtype: Data type of the returned tensor.

    Returns:
        Tensor with ones on the k-th diagonal and zeros elsewhere.
    rg  )r   r   r  r]  s       r   r  r  Z  s"     ==Q!q66r   c                       e Zd Zd Zd Zy)FloorDividec                 B    t         j                  j                  ||      S r   )r   r   floor_dividerb   s      r   r!   zFloorDivide.callm  s    }}))"b11r   c           
          t        |dg       }t        |dg       }t        ||      }t        j                  t        |dt	        |            t        |dt	        |                  }t        ||      S r  rh   r  s          r   r.   zFloorDivide.compute_output_specp  si    2w+2w+'(;))Bb*Bb*
 <|<<r   NrS   rT   r   r   r  r  l  s    2=r   r  zkeras.ops.floor_dividezkeras.ops.numpy.floor_dividec                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zReturns the largest integer smaller or equal to the division of inputs.

    Args:
        x1: Numerator.
        x2: Denominator.

    Returns:
        Output tensor, `y = floor(x1/x2)`
    )r   r  r7   r   r   r   ru   s     r   r   r   {  s<     RH%}**2r22==%%b"--r   c                       e Zd Zd Zd Zy)
LogicalXorc                 B    t         j                  j                  ||      S r   )r   r   logical_xorrb   s      r   r!   zLogicalXor.call  r  r   c                 h    t        |dg       }t        |dg       }t        ||      }t        |d      S r  r  r  s         r   r.   zLogicalXor.compute_output_spec  r  r   NrS   rT   r   r   r$  r$    r  r   r$  zkeras.ops.logical_xorzkeras.ops.numpy.logical_xorc                     t        | |f      rt               j                  | |      S t        j                  j                  | |      S )zCompute the truth value of `x1 XOR x2`, element-wise.

    Args:
        x1: First input tensor.
        x2: Second input tensor.

    Returns:
        Output boolean tensor.
    )r   r$  r7   r   r   r&  ru   s     r   r&  r&    s<     RH%|))"b11==$$R,,r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )	Correlatec                 0    t         |           || _        y r   )r   r   rT  )r   rT  r   s     r   r   zCorrelate.__init__  r   r   c                 Z    t         j                  j                  ||| j                        S )Nrc  )r   r   	correlaterT  rb   s      r   r!   zCorrelate.call  r?  r   c           
         t        |dg       }t        |dg       }t        |      dk7  rt        dd| z         t        |      dk7  rt        dd| z         |d   |d   }}t        j                  ||      t        j
                  ||      z
  dz   f}| j                  dk(  rt        j                  ||      f}n| j                  dk(  r	||z   dz
  f}| j                  d	vrt        d
| j                         t        j                  t        |dt        |            t        |dt        |                  }|dk(  rd}n|dvrd}t        ||      S )Nr&   r$   z1`x1` must be a 1-dimensional tensor, but receivedzshape z1`x2` must be a 1-dimensional tensor, but receivedr   samer  )validr/  r  z?`mode` must be either `valid`, `same`, or `full`, butreceived: r'   r   float64)bfloat16float16r1  r  r   )rP   r)   r*   r   rB  rA  rT  r   ri   rj   r   )	r   rc   rd   rl   rm   x1_lenx2_lenrn   ro   s	            r   r.   zCorrelate.compute_output_spec  sz   2w+2w+x=AC8*%&  x=AC8*%&  "!hqkJJvv&FF)CCaG
 99JJvv68LYY& "VOa/1L9955!YYK)  ))Bb*Bb*
 7"$L!CC$L<|<<r   r0  r0   r5   s   @r   r*  r*    s    ?"=r   r*  zkeras.ops.correlatezkeras.ops.numpy.correlatec                     t        | |f      rt        |      j                  | |      S t        j                  j                  | ||      S )ad  Compute the cross-correlation of two 1-dimensional tensors.

    Args:
        x1: First 1-dimensional input tensor of length M.
        x2: Second 1-dimensional input tensor of length N.
        mode: Either `valid`, `same` or `full`.
            By default the mode is set to `valid`, which returns
            an output of length max(M, N) - min(M, N) + 1.
            `same` returns an output of length max(M, N).
            `full` mode returns the convolution at each point of
            overlap, with an output length of N+M-1

    Returns:
        Output tensor, cross-correlation of `x1` and `x2`.
    rc  )r   r*  r7   r   r   r-  )rc   rd   rT  s      r   r-  r-    rE  r   c                   .     e Zd Z fdZddZddZ xZS )Selectc                 "    t         |           y r   rd  re  s    r   r   zSelect.__init__  rf  r   c                 D    t         j                  j                  |||      S r   )r   r   select)r   condlist
choicelistdefaults       r   r!   zSelect.call  s    }}##Hj'BBr   c                 N    |d   }t        |j                  |j                        S rm  rz  )r   r=  r>  r?  first_elements        r   r.   zSelect.compute_output_spec  s$    "1=..m6I6IJJr   r  r0   r5   s   @r   r9  r9    s    CKr   r9  zkeras.ops.selectzkeras.ops.numpy.selectc                    t        | t        t        f      rt        |t        t        f      s#t        dt	        |        dt	        |             t        |       } t        |      }| r|st        d|  d|       t        | |z   |gz         rt               j                  | ||      S t        j                  j                  | ||      S )a]  Return elements from `choicelist`, based on conditions in `condlist`.

    Args:
        condlist: List of boolean tensors.
            The list of conditions which determine from which array
            in choicelist the output elements are taken.
            When multiple conditions are satisfied,
            the first one encountered in condlist is used.
        choicelist: List of tensors.
            The list of tensors from which the output elements are taken.
            This list has to be of the same length as `condlist`.
        defaults: Optional scalar value.
            The element inserted in the output
            when all conditions evaluate to `False`.

    Returns:
        Tensor where the output at position `m` is the `m`-th element
        of the tensor in `choicelist` where the `m`-th element of the
        corresponding tensor in `condlist` is `True`.

    Example:

    ```python
    from keras import ops

    x = ops.arange(6)
    condlist = [x<3, x>3]
    choicelist = [x, x**2]
    ops.select(condlist, choicelist, 42)
    # Returns: tensor([0,  1,  2, 42, 16, 25])
    ```
    zBcondlist and choicelist must be lists. Received: type(condlist) = z, type(choicelist) = z@condlist and choicelist must not be empty. Received: condlist = z, choicelist = )r:   r(   r  r*   rj   r   r9  r7   r   r   r<  )r=  r>  r?  s      r   r<  r<    s    D hu.jT5M7   $X/ 0""&z"2!35
 	

 H~Hj!J:" $&<)
 	

 Hz1WI=>x%%h
GDD==*g>>r   c                   *     e Zd Z fdZd Zd Z xZS )Slogdetc                 "    t         |           y r   rd  re  s    r   r   zSlogdet.__init__-  rf  r   c                 @    t         j                  j                  |      S r   )r   r   slogdetrH   s     r   r!   zSlogdet.call0  r   r   c                     t        d|j                        }t        |j                  d d |j                        }||fS )NrT   r   r  )r   r'   r&   )r   rI   r  	logabsdets       r   r.   zSlogdet.compute_output_spec3  s7    2QWW-AGG<	i  r   r0   r5   s   @r   rD  rD  ,  s    (!r   rD  zkeras.ops.slogdetzkeras.ops.numpy.slogdetc                     t        | f      rt               j                  |       S t        j                  j                  |       S )a  Compute the sign and natural logarithm of the determinant of a matrix.

    Args:
        x: Input matrix. It must 2D and square.

    Returns:
        A tuple `(sign, logabsdet)`. `sign` is a number representing
        the sign of the determinant. For a real matrix, this is 1, 0, or -1.
        For a complex matrix, this is a complex number with absolute value 1
        (i.e., it is on the unit circle), or else 0.
        `logabsdet` is the natural log of the absolute value of the determinant.
    )r   rD  r7   r   r   rG  rW   s    r   rG  rG  9  s6     QD!y&&q))==  ##r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Argpartitionc                 z    t         |           t        |t              st	        d|       || _        || _        y )Nz'kth must be an integer. Received:kth = )r   r   r:   r;   r*   kthr?   )r   rN  r?   r   s      r   r   zArgpartition.__init__M  s9    #s#FseLMM	r   c                 n    t         j                  j                  || j                  | j                        S )N)rN  r?   )r   r   argpartitionrN  r?   rH   s     r   r!   zArgpartition.callT  s&    }}))!		)JJr   c                 0    t        |j                  d      S r-  r6  rH   s     r   r.   z Argpartition.compute_output_specW  s    177'22r   r.  r0   r5   s   @r   rL  rL  L  s    K3r   rL  zkeras.ops.argpartitionzkeras.ops.numpy.argpartitionc                     t        | f      rt        ||      j                  |       S t        j                  j                  | ||      S )aE  Performs an indirect partition along the given axis.

    It returns an array
    of indices of the same shape as `x` that index data along the given axis
    in partitioned order.

    Args:
        a: Array to sort.
        kth: Element index to partition by.
            The k-th element will be in its final sorted position and all
            smaller elements will be moved before it and all larger elements
            behind it. The order of all elements in the partitions is undefined.
            If provided with a sequence of k-th it will partition all of them
            into their sorted position at once.
        axis: Axis along which to sort. The default is -1 (the last axis).
            If `None`, the flattened array is used.

    Returns:
        Array of indices that partition `x` along the specified `axis`.
    )r   rL  r7   r   r   rP  )rI   rN  r?   s      r   rP  rP  [  s?    , QD!C&44Q77==%%ad33r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )	Histogramc                    t         |           t        |t              st	        d      |dk  rt        d      |r?t        |      dk  st        |t              st        d      |d   |d   k  rt        d      || _        || _	        y )Nzbins must be of type `int`r   z'`bins` should be a non-negative integerr#   z%range must be a tuple of two elementsr$   z:The second element of range must be greater than the first)
r   r   r:   r;   	TypeErrorr*   r)   r  rw  r<   )r   rw  r<   r   s      r   r   zHistogram.__init__w  s    $$899!8FGG5zA~Zu%= !HIIQx%(" P  	
r   c                     t        j                  |      }t        |j                        dkD  rt	        d      t         j
                  j                  || j                  | j                        S )Nr$   z"Input tensor must be 1-dimensionalrw  r<   )	r   r]  r)   r&   r*   math	histogramrw  r<   rH   s     r   r!   zHistogram.call  sR    %%a(qww<!ABB||%%adiitzz%JJr   c                     t        | j                  f|j                        t        | j                  dz   f|j                        fS )Nr%   r$   )r   rw  r'   rH   s     r   r.   zHistogram.compute_output_spec  s9    tyyl!'':tyy1}.agg>
 	
r   r  Nr0   r5   s   @r   rT  rT  v  s    (K
r   rT  zkeras.ops.histogramzkeras.ops.numpy.histogramc                    t        |t              st        d|       |dk  rt        d|       |rEt	        |      dk  st        |t
              st        d|       |d   |d   k  rt        d|       t        | f      rt        ||      j                  |       S t        j                  |       } t	        | j                        dkD  rt        d	| j                         t        j                  j                  | ||      S )
a+  Computes a histogram of the data tensor `x`.

    Args:
        x: Input tensor.
        bins: An integer representing the number of histogram bins.
            Defaults to 10.
        range: A tuple representing the lower and upper range of the bins.
            If not specified, it will use the min and max of `x`.

    Returns:
        A tuple containing:
        - A tensor representing the counts of elements in each bin.
        - A tensor representing the bin edges.

    Example:

    ```
    >>> input_tensor = np.random.rand(8)
    >>> keras.ops.histogram(input_tensor)
    (array([1, 1, 1, 0, 0, 1, 2, 1, 0, 1], dtype=int32),
    array([0.0189519 , 0.10294958, 0.18694726, 0.27094494, 0.35494262,
        0.43894029, 0.52293797, 0.60693565, 0.69093333, 0.77493101,
        0.85892869]))
    ```
    z6Argument `bins` must be of type `int`. Received: bins=r   zAArgument `bins` should be a non-negative integer. Received: bins=r#   zBArgument `range` must be a tuple of two elements. Received: range=r$   zNThe second element of `range` must be greater than the first. Received: range=rX  z:Input tensor must be 1-dimensional. Received: input.shape=)r:   r;   rV  r*   r)   r  r   rT  r7   r   r]  r&   r   rZ  )rI   rw  r<   s      r   rZ  rZ    s/   6 dC DTFK
 	
 ax"V%
 	

 u:>E5!9##('+ 
 8eAh##('+ 
 QD!d%0>>qAA!!!$A
177|a%%&WWI/
 	
 ==""14u"==r   r/   )NTr   r   r   r.  r+  r_  r  r  ra  rq  rO  )rw  TFNr   )rw  Tr  Nr   r  r&  )ra  Nrz  r  rC  )Nr   Nr6  r\  (c  rn  r  r   r   	keras.srcr   keras.src.api_exportr   keras.src.backendr   r   keras.src.backend.commonr   &keras.src.backend.common.backend_utilsr	   r
   keras.src.opsr   keras.src.ops.operationr   keras.src.ops.operation_utilsr   r   r   r   rC   rE   rG   rY   r]   r_   ra   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r  r  r   r#  r'  r*  r2  r    r:  r?  rG  rI  rP  rR  rV  r[  rb  rh  ru  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r
  r  r  r  r%  r/  r2  r6  r>  rI  rL  rR  r[  re  rj  rt  rv  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r*  r,  r1  r3  r:  r=  rB  rD  rH  rJ  rR  rT  rZ  r\  ra  rc  rg  ri  rn  rp  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ro  r  rB  r  r  r  r  r  r  r  rA  r
  r  r  r  r  r$  r)  r+  r/  r1  r5  r7  r;  r=  rB  rD  rH  rJ  rP  r_  re  r   rr  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rp  r  r  r  r  r   r  r	  r  r  r  r  r  r#  r&  r+  r-  r1  r3  r7  r>  rG  rJ  rO  rR  rW  r`  ri  rl  rr  ru  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r   r$  r&  r*  r-  r9  r<  rD  rG  rL  rP  rT  rZ  rT   r   r   <module>rf     s    	   - ) 2 + D C ) - : 6AI A:  "9:;$6 <$6N7tBy B #%?@A% B%,	( 	  567 8

) 
(  567% 8%>
) 
6  567!> 8!>H
) 
6
1I 
1  "9:;" <"*  567!> 8!>H
9 
, !789!? :!?H
9 
$ !789!? :!?H6Y 6D !#;<= 
&3 >&3R6Y 6& !#;<=-E >-E`
1Y 
1 !#;<=# >#,
1i 
1 "$=>?$ @$&@Y @ !#;<=# >#(@i @ "$=>?$ @$&@Y @ !#;<=# >#(7i 7$ "$=>?() @()V@i @ "$=>?$ @$
Y 
& !#;<=A >A>
Y 
& !#;<=A >A>3i 3 "$=>?"/ @"/J1I 1  "9:;/ </,*i *Z "$=>?6@ @6@r<y < #%?@A% B%(<i < "$=>?$ @$,
y 
> #%?@A+ B+\	1 	1 &(EFG+ H+&3I 3 )+KLM+ N+$3 3 &(EFG( H($	1	 	1 %'CDE* F*&	1 	1 &(EFG+ H+&1y 1 #%IJ22&1	 1 %'CDE* F*&1	 1 $&KL33&1 1 &(EFG+ H+&<y < #%?@A% B%*6) 6  &00.
@9 
@ !789! :!"19 1  !789/ :/&"I) "IJ %44B	 B $&ABC& D&&	9 	 !789 :
B9 B !789! :!
1) 
1  567  8 
19 
1 !789! :!
9 
$ !'556.6I .6b  "9:;- <-`7i 7. "$=>?. @.7Y 7. !#;<=- >-"89 "8J !789#& :#&L"8y "8J #%?@A* B*$'8y '8T #%?@A: B:z19 1" !789# :#DBy B #%?@A+ B+,%
) %
P  567% 8%8p6Y p6f !#;<=U7 >U7p/I /  "9:;
3 <
37I 7  "9:;' <'1) 1  567  8 19 1 !789! :!G G* %..$	@I 	@  "9:;" <"	39 	3 !789, :,$@I @  "9:;" <" /9 / !789> :>1y 1 $&ABC? D? F<i F<R #%?@A B7i 7 "$=>?) @)79 7 !'//6Y 66 !#;<=$ >$"0y 0 #%?@A2 B2 B9 B !789! :!
7i 
7 "$=>?@ @@$2y 2 #%?@A% B%$2I 2  "9:;" <"2I 2  "9:;" <"79 7 !789& :&7	 7 $,,16y 16h #%?@AHI+ B+\
1) 
1  567  8 
1I 
1  "9:;" <"@I @  "9:;" <" 
19 
1 !789! :!6	 6  $&ABC+ D+$7 7 %--"2 2 %(( 7	 7 $,,",6y ,6^ #%?@A$ B$NLY L, !#;<=( >(0
) 
,  567O 8O*
i 
( "$=>?) @)6Y 6, !#;<=A >A&
y 
D #%?@A !9 B!9H
) 
,  567O 8O*
i 
( "$=>?) @)=) ="  567% 8%)8y )8X #%?@AM BM&3y 3  $NN&+9 + !789! :!
i 
 "$=>?$ @$7y 7 $&ABC+ D+1y 1 $&ABC3 D31	 1 $44=I =.  "9:;' <'*:8) :8z  567 I 8 IF#
9 #
L !789L :L(6y 68 #%?@A# B#L8I 8  "9:;" <" 
9 
8 (*IJK7 L7,B9 B !789! :!$ $ $'' 18Y 18h !#;<=7 >7"Gi G  "$=>?. @."
39 
3 !7893 :3(
BI 
B  "9:;, <,99 9( '()J *J,B9 B !789! :!Ai A "$=>?$ @$"@) @  567  8 @9 @ !789! :!.9 . !789! :!	-9 	- !789, :, *I *Z  "9:;B <B.=I =@  "9:;- <-$
) 
,  567> 8>&3y 3$ #%?@A? B? G9 G2 !7895 :5"8I 8 #)@@"@) @  567  8 @9 @ !789! :!*6	 *6Z $&ABC6 D6*89 86 !789* :*2=I =.  "9:;K <K@5) 5  5677 87$	39 	3 !789& :&&	39 	3 !789& :&&3I 3  "9:;" <".	,9 	, !789& :&*	,I 	,  "9:;' <'4 $&ABC"&$ & D&R7Y 76 !#;<=$ >$=I ="  "9:;2 <2,Ly L$ #%?@A* B*Ly L$ #%?@A* B*
Y 
* !#;<=( >("
) 
* (*IJK/ L/
 
* %--=I =  "9:;' <'By B #%?@A% B%	@Y 	@ !#;<=# >#@9 @ !789! :!Ji J8 "$=>?/ @/ G	 G  $&ABC1 D1 
9 
4 !789? :?$
) 
&  567> 8>$
) 
:  567> 8>$/I /  "9:;
3 <
3/9 / !789
2 :
25) 5  5677 87"=) = ')GHI. J.7 7 &(EFG- H-*=	 *=Z $&ABC6 D6*	KY 	K !#;<=3? >3?l
!i 
! "$=>?$ @$$39 3 ')GHI4 J44
	 
D $&ABC:> D:>r   