
    &VfG                        d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
  G d de          Z ed	d
g          d             Zd Z G d de          Z eddg          d             Zd Z G d de          Z eddg          d             Zd Z G d de          Z eddg          d             Zd Z G d d e          Z ed!d"g          d#             Zd$ Z G d% d&e          Z ed'd(g          d)             Zd* Z G d+ d,e          Z ed-d.g          dOd1            Z G d2 d3e          Z ed4d5g          dPd7            Z  G d8 d9e          Z! ed:d;g          d<             Z"d= Z# G d> d?e          Z$ ed@dAg          dQdB            Z%dQdCZ& G dD dEe          Z' edFdGg          dRdI            Z(dRdJZ)dK Z*dL Z+dM Z,dN Z-d/S )S    )backend)keras_export)KerasTensor)any_symbolic_tensors)	Operation)reduce_shapec                   *     e Zd Z fdZd Zd Z xZS )Choleskyc                 H    t                                                       d S Nsuper__init__self	__class__s    Q/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/ops/linalg.pyr   zCholesky.__init__
           c                      t          |          S r   )	_choleskyr   xs     r   callzCholesky.call   s    ||r   c                 r    t          |           t          |           t          |j        |j                  S r   
_assert_2d_assert_squarer   shapedtyper   s     r   compute_output_speczCholesky.compute_output_spec   /    1q17AG,,,r   __name__
__module____qualname__r   r   r!   __classcell__r   s   @r   r
   r
   	   sV              - - - - - - -r   r
   zkeras.ops.choleskyzkeras.ops.linalg.choleskyc                     t          | f          r!t                                          |           S t          |           S )a   Computes the Cholesky decomposition of a positive semi-definite matrix.

    Args:
        x: Input tensor of shape `(..., M, M)`.

    Returns:
        A tensor of shape `(..., M, M)` representing the lower triangular
        Cholesky factor of `x`.

    )r   r
   symbolic_callr   r   s    r   choleskyr,      s:     QD!! +zz''***Q<<r   c                     t          j        |           } t          |            t          |            	 t           j                            |           S # t          $ r}t          d|           d }~ww xY w)NzCholesky decomposition failed: )r   convert_to_tensorr   r   linalgr,   	Exception
ValueErrorr   es     r   r   r   '   s    !!$$AqMMM1@~&&q))) @ @ @>1>>???@s   A 
A4A//A4c                   *     e Zd Z fdZd Zd Z xZS )Detc                 H    t                                                       d S r   r   r   s    r   r   zDet.__init__3   r   r   c                      t          |          S r   )_detr   s     r   r   zDet.call6       Awwr   c                     t          |           t          |           t          |j        d d         |j                  S Nr   r   s     r   r!   zDet.compute_output_spec9   s7    1q173B3<111r   r#   r(   s   @r   r5   r5   1   sV              2 2 2 2 2 2 2r   r5   zkeras.ops.detzkeras.ops.linalg.detc                     t          | f          r!t                                          |           S t          |           S )zComputes the determinant of a square tensor.

    Args:
        x: Input tensor of shape `(..., M, M)`.

    Returns:
        A tensor of shape `(...,)` represeting the determinant of `x`.

    )r   r5   r*   r8   r+   s    r   detr>   ?   9     QD!! &uu""1%%%77Nr   c                     t          j        |           } t          |            t          |            t           j                            |           S r   )r   r.   r   r   r/   r>   r+   s    r   r8   r8   O   A    !!$$AqMMM1>a   r   c                   *     e Zd Z fdZd Zd Z xZS )Eigc                 H    t                                                       d S r   r   r   s    r   r   zEig.__init__X   r   r   c                      t          |          S r   )_eigr   s     r   r   zEig.call[   r9   r   c                     t          |           t          |           t          |j        d d         |j                  t          |j        |j                  fS Nr   r   r   r   r    r   s     r   r!   zEig.compute_output_spec^   O    q1ag..))
 	
r   r#   r(   s   @r   rC   rC   V   sV              
 
 
 
 
 
 
r   rC   zkeras.ops.eigzkeras.ops.linalg.eigc                     t          | f          r!t                                          |           S t          |           S )a$  Computes the eigenvalues and eigenvectors of a square matrix.

    Args:
        x: Input tensor of shape `(..., M, M)`.

    Returns:
        A tuple of two tensors: a tensor of shape `(..., M)` containing
        eigenvalues and a tensor of shape `(..., M, M)` containing eigenvectors.
    )r   rC   r*   rF   r+   s    r   eigrM   g   r?   r   c                     t          j        |           } t          |            t          |            t           j                            |           S r   )r   r.   r   r   r/   rM   r+   s    r   rF   rF   w   sA    !!$$A1qMMM>a   r   c                   *     e Zd Z fdZd Zd Z xZS )Eighc                 H    t                                                       d S r   r   r   s    r   r   zEigh.__init__   r   r   c                      t          |          S r   )_eighr   s     r   r   z	Eigh.call   s    Qxxr   c                     t          |           t          |           t          |j        d d         |j                  t          |j        |j                  fS rH   rJ   r   s     r   r!   zEigh.compute_output_spec   rK   r   r#   r(   s   @r   rP   rP   ~   sV              
 
 
 
 
 
 
r   rP   zkeras.ops.eighzkeras.ops.linalg.eighc                     t          | f          r!t                                          |           S t          |           S )a)  Computes the eigenvalues and eigenvectors of a complex Hermitian.

    Args:
        x: Input tensor of shape `(..., M, M)`.

    Returns:
        A tuple of two tensors: a tensor of shape `(..., M)` containing
        eigenvalues and a tensor of shape `(..., M, M)` containing eigenvectors.

    )r   rP   r*   rS   r+   s    r   eighrV      s9     QD!! 'vv##A&&&88Or   c                     t          j        |           } t          |            t          |            t           j                            |           S r   )r   r.   r   r   r/   rV   r+   s    r   rS   rS      sA    !!$$A1qMMM>q!!!r   c                   *     e Zd Z fdZd Zd Z xZS )Invc                 H    t                                                       d S r   r   r   s    r   r   zInv.__init__   r   r   c                      t          |          S r   )_invr   s     r   r   zInv.call   r9   r   c                 r    t          |           t          |           t          |j        |j                  S r   r   r   s     r   r!   zInv.compute_output_spec   r"   r   r#   r(   s   @r   rY   rY      sV              - - - - - - -r   rY   zkeras.ops.invzkeras.ops.linalg.invc                     t          | f          r!t                                          |           S t          |           S )zComputes the inverse of a square tensor.

    Args:
        x: Input tensor of shape `(..., M, M)`.

    Returns:
        A tensor of shape `(..., M, M)` representing the inverse of `x`.

    )r   rY   r*   r\   r+   s    r   invr_      r?   r   c                     t          j        |           } t          |            t          |            t           j                            |           S r   )r   r.   r   r   r/   r_   r+   s    r   r\   r\      rA   r   c                   *     e Zd Z fdZd Zd Z xZS )LuFactorc                 H    t                                                       d S r   r   r   s    r   r   zLuFactor.__init__   r   r   c                      t          |          S r   )
_lu_factorr   s     r   r   zLuFactor.call   s    !}}r   c                     t          |           |j        d d         }|j        dd          \  }}t          ||          }t          |||fz   |j                  t          ||fz   |j                  fS r;   )r   r   minr   r    )r   r   batch_shapemnks         r   r!   zLuFactor.compute_output_spec   st    1gcrclwrss|11IIq!f,ag66qd*AG44
 	
r   r#   r(   s   @r   rb   rb      sV              
 
 
 
 
 
 
r   rb   zkeras.ops.lu_factorzkeras.ops.linalg.lu_factorc                     t          | f          r!t                                          |           S t          |           S )a@  Computes the lower-upper decomposition of a square matrix.

    Args:
        x: A tensor of shape `(..., M, M)`.

    Returns:
        A tuple of two tensors: a tensor of shape `(..., M, M)` containing the
        lower and upper triangular matrices and a tensor of shape `(..., M)`
        containing the pivots.

    )r   rb   r*   re   r+   s    r   	lu_factorrm      s:     QD!! +zz''***a==r   c                     t          j        |           } t          |            t          j                     dk    r6	 t          |            n%# t          $ r}t	          d| d          d }~ww xY wt           j                            |           S )N
tensorflowzLU decomposition failed: zG. LU decomposition is only supported for square matrices in Tensorflow.)r   r.   r   r   r1   r/   rm   r2   s     r   re   re      s    !!$$AqMMML((	1 	 	 	?A ? ? ?  	
 >##A&&&s   A 
A.A))A.c                   ,     e Zd Zd fd	Zd Zd Z xZS )NormNFc                     t                                                       t          |t                    r|dvrt	          d|           t          |t
                    r|g}|| _        || _        || _        d S )N)fronuczXInvalid `ord` argument. Expected one of {'fro', 'nuc'} when using string. Received: ord=)	r   r   
isinstancestrr1   intordaxiskeepdims)r   rx   ry   rz   r   s       r   r   zNorm.__init__   s    c3 	.(( +%(+ +  
 dC   	6D	 r   c           
      f   t          j        |j                  }d|v s|dk    rt          j                    }| j        /t          t          t          |j                                      }n| j        }t          |          }|dk    r1t          | j
        t                    rt          d| j
                   |dk    rC| j
        d ddt          d          t          d	          dd
ddf	vrt          d| j
                   t          t          |j        | j        | j                  |          S )Nrw   bool   z6Invalid `ord` argument for vector norm. Received: ord=   rs   rt   infz-infrI   r<   z6Invalid `ord` argument for matrix norm. Received: ord=)ry   rz   )r    )r   standardize_dtyper    floatxry   tuplerangelenr   ru   rx   rv   r1   floatr   r   rz   )r   r   output_dtypery   num_axess        r   r!   zNorm.compute_output_spec  sO   099L  LF$:$:">++L9s17||,,--DD9Dt99q==Z#66=,!%, ,   ]]tx%LL&MM
0
 
 
 
 
 ,!%, ,   ty4=III
 
 
 	
r   c                     t          j        |          }t           j                            || j        | j        | j                  S )Nrx   ry   rz   )r   r.   r/   normrx   ry   rz   r   s     r   r   z	Norm.call1  s@    %a((~""48$)dm # 
 
 	
r   NNFr$   r%   r&   r   r!   r   r'   r(   s   @r   rq   rq      s\        ! ! ! ! ! ! 
  
  
D
 
 
 
 
 
 
r   rq   zkeras.ops.normzkeras.ops.linalg.normNFc                     t          | f          r%t          |||                              |           S t          j        |           } t          j                            | |||          S )aM  Matrix or vector norm.

    This function is able to return one of eight different matrix norms, or one
    of an infinite number of vector norms (described below), depending on the
    value of the `ord` parameter.

    Args:
        x: Input tensor.
        ord: Order of the norm (see table under Notes). The default is `None`.
        axis: If `axis` is an integer, it specifies the axis of `x` along which
            to compute the vector norms. If `axis` is a 2-tuple, it specifies
            the axes that hold 2-D matrices, and the matrix norms of these
            matrices are computed.
        keepdims: If this is set to `True`, the axes which are reduced are left
            in the result as dimensions with size one.

    Note:
        For values of `ord < 1`, the result is, strictly speaking, not a
        mathematical 'norm', but it may still be useful for various numerical
        purposes. The following norms can be calculated:
        - For matrices:
            - `ord=None`: Frobenius norm
            - `ord="fro"`: Frobenius norm
            - `ord="nuc"`: nuclear norm
            - `ord=np.inf`: `max(sum(abs(x), axis=1))`
            - `ord=-np.inf`: `min(sum(abs(x), axis=1))`
            - `ord=0`: not supported
            - `ord=1`: `max(sum(abs(x), axis=0))`
            - `ord=-1`: `min(sum(abs(x), axis=0))`
            - `ord=2`: 2-norm (largest sing. value)
            - `ord=-2`: smallest singular value
            - other: not supported
        - For vectors:
            - `ord=None`: 2-norm
            - `ord="fro"`: not supported
            - `ord="nuc"`: not supported
            - `ord=np.inf`: `max(abs(x))`
            - `ord=-np.inf`: `min(abs(x))`
            - `ord=0`: `sum(x != 0)`
            - `ord=1`: as below
            - `ord=-1`: as below
            - `ord=2`: as below
            - `ord=-2`: as below
            - other: `sum(abs(x)**ord)**(1./ord)`

    Returns:
        Norm of the matrix or vector(s).

    Example:

    >>> x = keras.ops.reshape(keras.ops.arange(9, dtype="float32") - 4, (3, 3))
    >>> keras.ops.linalg.norm(x)
    7.7459664
    r   )r   rq   r*   r   r.   r/   r   )r   rx   ry   rz   s       r   r   r   8  sj    p QD!! L$:::HHKKK!!$$A>qcxHHHr   c                   ,     e Zd Zd fd	Zd Zd Z xZS )Qrreducedc                     t                                                       |dvrt          d|           || _        d S )N>   r   completez]`mode` argument value not supported. Expected one of {'reduced', 'complete'}. Received: mode=)r   r   r1   mode)r   r   r   s     r   r   zQr.__init__w  sV    ...)"&) )  
 			r   c                    t          |j                  dk     rt          d|j                   |j        d         }|j        d         }||t          d|j                   t          ||          }t	          |j        d d                   }| j        dk    r6t          |||fz   |j                  t          |||fz   |j                  fS t          |||fz   |j                  t          |||fz   |j                  fS )Nr~   z5Input should have rank >= 2. Received: input.shape = r<   rI   zOInput should have its last 2 dimensions fully-defined. Received: input.shape = r   )r   r    )r   r   r1   rg   r   r   r   r    )r   r   ri   rj   rk   bases         r   r!   zQr.compute_output_spec  s3   qw<<!+!"+ +   GBKGBK9	+!"+ +  
 1IIQWSbS\""9	!!$!Q-qw???$!Q-qw???  daVm17;;;daVm17;;;
 	
r   c                 v    t          j        |          }t           j                            || j                  S )Nr   )r   r.   r/   qrr   r   s     r   r   zQr.call  s/    %a((~   333r   r   r   r(   s   @r   r   r   v  s[             
 
 
64 4 4 4 4 4 4r   r   zkeras.ops.qrzkeras.ops.linalg.qrr   c                     t          | f          r#t          |                              |           S t          j        |           } t          j                            | |          S )a4  Computes the QR decomposition of a tensor.

    Args:
        x: Input tensor of shape `(..., M, N)`.
        mode: A string specifying the mode of the QR decomposition.
            - 'reduced': Returns the reduced QR decomposition. (default)
            - 'complete': Returns the complete QR decomposition.

    Returns:
        A tuple containing two tensors. The first tensor of shape `(..., M, K)`
        is the orthogonal matrix `q` and the second tensor of shape
        `(..., K, N)` is the upper triangular matrix `r`, where `K = min(M, N)`.

    Example:

    >>> x = keras.ops.convert_to_tensor([[1., 2.], [3., 4.], [5., 6.]])
    >>> q, r = qr(x)
    >>> print(q)
    array([[-0.16903079  0.897085]
           [-0.5070925   0.2760267 ]
           [-0.8451542  -0.34503305]], shape=(3, 2), dtype=float32)
    r   )r   r   r*   r   r.   r/   r   )r   r   s     r   r   r     s]    0 QD!! .t}}}**1---!!$$A>QT***r   c                   *     e Zd Z fdZd Zd Z xZS )Solvec                 H    t                                                       d S r   r   r   s    r   r   zSolve.__init__  r   r   c                 "    t          ||          S r   )_solver   abs      r   r   z
Solve.call  s    a||r   c                     t          |           t          |           t          |           t          ||           t	          |j        |j                  S r   r   r   
_assert_1d_assert_a_b_compatr   r   r    r   s      r   r!   zSolve.compute_output_spec  J    1q11a   17AG,,,r   r#   r(   s   @r   r   r     sV              - - - - - - -r   r   zkeras.ops.solvezkeras.ops.linalg.solvec                     t          | |f          r"t                                          | |          S t          | |          S a  Solves a linear system of equations given by `a x = b`.

    Args:
        a: A tensor of shape `(..., M, M)` representing the coefficients matrix.
        b: A tensor of shape `(..., M)` or `(..., M, N)` represeting the
        right-hand side or "dependent variable" matrix.

    Returns:
        A tensor of shape `(..., M)` or `(..., M, N)` representing the solution
        of the linear system. Returned shape is identical to `b`.

    )r   r   r*   r   r   r   s     r   solver     s@     QF## +ww$$Q***!Q<<r   c                    t          j        |           } t          j        |          }t          |            t          |            t	          |           t          | |           t           j                            | |          S r   )r   r.   r   r   r   r   r/   r   r   s     r   r   r     sn    !!$$A!!$$AqMMM1qMMMq!>1%%%r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )SolveTriangularFc                 V    t                                                       || _        d S r   )r   r   lower)r   r   r   s     r   r   zSolveTriangular.__init__  s$    


r   c                 .    t          ||| j                  S r   )_solve_triangularr   r   s      r   r   zSolveTriangular.call  s     Atz222r   c                     t          |           t          |           t          |           t          ||           t	          |j        |j                  S r   r   r   s      r   r!   z#SolveTriangular.compute_output_spec  r   r   Fr#   r(   s   @r   r   r     s[             3 3 3- - - - - - -r   r   zkeras.ops.solve_triangularz!keras.ops.linalg.solve_triangularc                     t          | |f          r#t          |                              | |          S t          | ||          S r   )r   r   r*   r   r   r   r   s      r   solve_triangularr     sH      QF## :u%%33Aq999Q5)))r   c                    t          j        |           } t          j        |          }t          |            t          |            t	          |           t          | |           t           j                            | ||          S r   )r   r.   r   r   r   r   r/   r   r   s      r   r   r     sp    !!$$A!!$$AqMMM1qMMMq!>**1a777r   c                   ,     e Zd Zd fd	Zd Zd Z xZS )SVDTc                 d    t                                                       || _        || _        d S r   )r   r   full_matrices
compute_uv)r   r   r   r   s      r   r   zSVD.__init__  s,    *$r   c                 8    t          || j        | j                  S r   )_svdr   r   r   s     r   r   zSVD.call#  s    At)4?;;;r   c                    t          |           |j        dd          \  }}|j        d d         }|t          ||          fz   }| j        r|||fz   }|||fz   }n*||t          ||          fz   }|t          ||          |fz   }| j        r>t          ||j                  t          ||j                  t          ||j                  fS t          ||j                  S r;   )r   r   rg   r   r   r   r    )r   r   rowscolumnsbatchess_shapeu_shapev_shapes           r   r!   zSVD.compute_output_spec&  s    1g'#2#,Sw//11 	>t,G' 22GGs4'9'9 ::GT7!3!3W ==G? 	GQW--GQW--GQW-- 
 7AG,,,r   TTr#   r(   s   @r   r   r     s[        % % % % % %
< < <- - - - - - -r   r   zkeras.ops.svdzkeras.ops.linalg.svdTc                     t          | f          r#t          ||                              |           S t          | ||          S )a  Computes the singular value decomposition of a matrix.

    Args:
        x: Input tensor of shape `(..., M, N)`.

    Returns:
        A tuple of three tensors: a tensor of shape `(..., M, M)` containing the
        left singular vectors, a tensor of shape `(..., M, N)` containing the
        singular values and a tensor of shape `(..., N, N)` containing the
        right singular vectors.

    )r   r   r*   r   r   r   r   s      r   svdr   ;  sF     QD!! ?=*--;;A>>>=*---r   c                     t          j        |           } t          |            t           j                            | ||          S r   )r   r.   r   r/   r   r   s      r   r   r   N  s7    !!$$AqMMM>a
;;;r   c                  D    | D ]}|j         dk     rt          d          d S )Nr}   z<Expected input to have rank >= 1. Received scalar input {a}.ndimr1   arraysr   s     r   r   r   T  sB      6A::-    r   c                  D    | D ]}|j         dk     rt          d          d S )Nr~   zFExpected input to have rank >= 2. Received input with shape {a.shape}.r   r   s     r   r   r   ]  sB      6A::7    r   c                  n    | D ]1}|j         dd          \  }}||k    rt          d|j                    2d S )Nr<   z?Expected a square matrix. Received non-square input with shape )r   r1   )r   r   ri   rj   s       r   r   r   f  se      wrss|166B89B B    r   c                 @   | j         |j         k    r=| j        d         |j        d         k    rt          d| j         d|j                   d S | j         |j         dz
  k    r;| j        d         |j        d         k    r!t          d| j         d|j                   d S d S )Nr<   zbIncompatible shapes between `a` and `b`. Expected `a.shape[-2] == b.shape[-2]`. Received: a.shape=z
, b.shape=r}   rI   zbIncompatible shapes between `a` and `b`. Expected `a.shape[-1] == b.shape[-1]`. Received: a.shape=)r   r   r1   r   s     r   r   r   p  s    v72;!'"+%%B%&WB B89B B   &% 
16A:		72;!'"+%%B%&WB B89B B   
	%%r   r   r   r   r   ).	keras.srcr   keras.src.api_exportr   keras.src.backendr   r   keras.src.ops.operationr   keras.src.ops.operation_utilsr   r
   r,   r   r5   r>   r8   rC   rM   rF   rP   rV   rS   rY   r_   r\   rb   rm   re   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   <module>r      s&         - - - - - - ) ) ) ) ) ) 2 2 2 2 2 2 - - - - - - 6 6 6 6 6 6
- 
- 
- 
- 
-y 
- 
- 
- #%@ABB  CB @ @ @2 2 2 2 2) 2 2 2  6788  98! ! !
 
 
 
 
) 
 
 
"  6788  98! ! !
 
 
 
 
9 
 
 
" !89::  ;: " " "- - - - -) - - -  6788  98! ! !
 
 
 
 
y 
 
 
& $&BCDD  ED"' ' '6
 6
 6
 6
 6
9 6
 6
 6
r !89:::I :I :I ;::Iz(4 (4 (4 (4 (4 (4 (4 (4V ~4566+ + + 76+:- - - - -I - - -   ":;<<  =<$& & &- - - - -i - - -" !#FG * * * *$8 8 8 8- - - - -) - - ->  6788. . . 98.$< < < <          r   