
    Vpfj             	      z   d dl mZ d dlmZ d dlZd dlmZ d dlZd dlmZm	Z	m
Z
m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mZmZmZ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'm(Z(m)Z)m*Z*m+Z+m,Z, d dl-m.Z. d dl-m/Z/ d dl-m0Z0 d dl-m1Z1 d dl-m2Z3 d dl-m4Z4 d dl5m6Z6 d dl7m8Z8 d dl7m9Z9 d dl:m;Z< d dl:m=Z= d dl:m>Z> d dl?m@Z@ d d lAmBZBmCZC e4jD        ZE e
d!ed"ef         #          ZFd$d%dd+ZGd$d$d,dd1ZHd$d$d$dd2dd8Z!dd;ZIdd?ZJddAZKd$dBddDZLed$ddEddH            Z$ed$ddEddJ            Z$ed$d$ddKddM            Z$d$d$ddKddNZ$dOdOdOdOdOdPddWZM ee@dXY          ddZ            ZNdd[ZOdd\ZPdd]ZQdd^ZRdd_ZS ejT        ejU                   ejT        ejV                   ejT        ejW                   ejT        ejX                  hZYd` ZZda Z[ e(e*e+z  db          Z\eZej]        e\<   e[ej^        e\<   dc Z_ ej`        e\e_           dd Za ej`        e\eadef           dg Zbdh Zcdi Zd edj          ZedOee_f        eeg                    eb           eeh                     eeji        ee                      ej`        eeecdkf            ej`        ee ejj        eddOl                     dm Zkdn Zldo Zmdp Zndq Zodr Zp eds          Zqd$eq_f        eqh                    ek           eqg                    em            ej`        eqel            ej`        eqendef           eoej^        eq<   epej]        eq<   d$d$dtdduZrdv Zsdw Ztdx Zu edy          Zvd$ev_f        evh                    es           evg                    et            ej`        eveu           dz Zwd{ Zxd| Zyd} Zzd~ Z{d Z| ed          Z}d$e}_f        e}h                    ew           e}g                    ex           e{ej]        e}<   e|ej^        e}<    ej`        e} eeye1j~                  def           e/D ej`        e} eeye/j                  dkf            ej`        e} eeye/j                  df            ej`        e} ejj        ezd$l          df            ee)e,e*e+z  e*e+z  fd          ZdOddZd Zd Zd Z e'eed          Z ej        eed            eej        e<   eej^        e<   d Z ej`        ee           d Z ej`        eedef           d Zd Zd Zd Zd Z ed          ZdOe_f        eh                     eeji        e                     eg                    e           eej^        e<    ej`        e ejj        edOl                      ej`        e eee.j                  dkf            ej`        e eee.j                  df           d ZddZd Zd Zd Zd Zd ZddZd Z ed          Zd$e_f        eh                    e           eg                    e            ej`        e ejj        ed$l                     eej]        e<   eej^        e<    ej`        e eee1j        def          def            ej`        e eee/j        dkf          dkf            ej`        e eee/j        df          df            ej`        eedf            ee@dhd          d d            Z eej        d          d d            Z	 dddZddZd Zd Zd ZddZ ed          Zd$e_f        eh                     eeji        e                     eg                    e           eej^        e<    ej`        ee            ej`        e eee1j        ddef          def            ej`        e eee/j        e/j        dkf          dkf            ej`        e eee/j        e/j        df          df           ddZd Zd Zd ZddZ ed          Zeh                     eeji        e                     eg                    e           eej^        e<    ej`        ee            ej`        e eee1j        def          def            ej`        e eee/j        dkf          dkf            ej`        e eee/j        df          df           d Zd Zd Zd Zd Z ed          Zd$e_f        eh                    e           eg                    e           eej]        e<   eej^        e<    ej`        e ejj        e                     dddZd Z ej        d          d             Zd ZddZdÄ ZdĄ Zdń Z edƦ          Zd$e_f        eǠh                    e           eǠg                    e           eej]        e<   eej^        e<    ej`        e eee1j        def          def            ej`        e eee/j        dkf          dkf            ej`        e eee/j        df          df            ej`        eeŦ           dǄ ZdȄ ZdɄ Z edʦ          ZdOe_f        eΠh                     ej        eji        eΦ                     eΠg                    d˄            eej        e<   eej^        e<    ej`        e eee0j                  dkf            ej`        e eee0j                  df           d̄ Z ej`        e ejj        edOl                     ddЄZd$dOddќddքZdׄ Zd؄ Zdل Zdڄ Zdۄ Zd܄ Z edݦ          Zd$e_f        eڠh                    eԦ           eڠg                    e֦            ej`        eeզ            ej`        eedef           eej^        e<   eej]        e<   ddބZd߄ Z ed          Zeݠh                     eeji        eݦ                     eݠg                    eܦ           d$e_f        d Zeej^        e<   d Z ej`        eedef           d$dddZd Z ed          Zeh                     eeji        e                     eg                    e           d$e_f        d Zeej^        e<   d Z ej`        e eee1j                  def            ej`        e eee/j                  dkf            ej`        e eee/j                  df           ddZd	dZdS (
      )annotations)CallableN)partial)AnyLiteralTypeVaroverload)lax)ad_util)api)dispatch)dtypes)	PrimitiveShapedArrayraise_to_shapedis_constant_dimis_constant_shape)ad)batching)mlir)control_flow)eigh)svd)standard_primitivestandard_unopnaryop_dtype_rule_float_complex_input_dtype)
gpu_linalg)
gpu_solver)
gpu_sparse)lapack)version)
xla_client)ir)chlo)hlo)	lax_numpy)
reductions)ufuncs)	vectorize)Array	ArrayLikeTFun.)boundT)symmetrize_inputxr-   r1   boolreturnc               |    |rt          |           } t          j        t                              |                     S )a  Cholesky decomposition.

  Computes the Cholesky decomposition

  .. math::
    A = L . L^H

  of square matrices, :math:`A`, such that :math:`L`
  is lower triangular. The matrices of :math:`A` must be positive-definite and
  either Hermitian, if complex, or symmetric, if real.

  Args:
    x: A batch of square Hermitian (symmetric if real) positive-definite
      matrices with shape ``[..., n, n]``.
    symmetrize_input: If ``True``, the matrix is symmetrized before Cholesky
      decomposition by computing :math:`\frac{1}{2}(x + x^H)`. If ``False``,
      only the lower triangle of ``x`` is used; the upper triangle is ignored
      and not accessed.

  Returns:
    The Cholesky decomposition as a matrix with the same dtype as ``x`` and
    shape ``[..., n, n]``. If Cholesky decomposition fails, returns a matrix
    full of NaNs. The behavior on failure may change in the future.
  )
symmetrizejnptril
cholesky_pbind)r2   r1   s     S/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/lax/linalg.pycholeskyr<   A   s3    2  1A	*//!$$	%	%%    compute_left_eigenvectorscompute_right_eigenvectorsr.   r?   r@   list[Array]c               <    t                               | ||          S )a=  Eigendecomposition of a general matrix.

  Nonsymmetric eigendecomposition is at present only implemented on CPU.

  Args:
    x: A batch of square matrices with shape ``[..., n, n]``.
    compute_left_eigenvectors: If true, the left eigenvectors will be computed.
    compute_right_eigenvectors: If true, the right eigenvectors will be
      computed.
  Returns:
    The eigendecomposition of ``x``, which is a tuple of the form
    ``(w, vl, vr)`` where ``w`` are the eigenvalues, ``vl`` are the left
    eigenvectors, and ``vr`` are the right eigenvectors. ``vl`` and ``vr`` are
    optional and will only be included if ``compute_left_eigenvectors`` or
    ``compute_right_eigenvectors`` respectively are ``True``.

    If the eigendecomposition fails, then arrays full of NaNs will be returned
    for that batch element.
  r>   )eig_pr:   )r2   r?   r@   s      r;   eigrD   _   s*    * 
A1J/I 
 
K 
K Kr=   )lowerr1   sort_eigenvaluessubset_by_indexrE   rF   rG   tuple[int, int] | Nonetuple[Array, Array]c               n    |rt          |           } t                              | |||          \  }}||fS )ak  Eigendecomposition of a Hermitian matrix.

  Computes the eigenvectors and eigenvalues of a complex Hermitian or real
  symmetric square matrix.

  Args:
    x: A batch of square complex Hermitian or real symmetric matrices with shape
      ``[..., n, n]``.
    lower: If ``symmetrize_input`` is ``False``, describes which triangle of the
      input matrix to use. If ``symmetrize_input`` is ``False``, only the
      triangle given by ``lower`` is accessed; the other triangle is ignored and
      not accessed.
    symmetrize_input: If ``True``, the matrix is symmetrized before the
      eigendecomposition by computing :math:`\frac{1}{2}(x + x^H)`.
    sort_eigenvalues: If ``True``, the eigenvalues will be sorted in ascending
      order. If ``False`` the eigenvalues are returned in an
      implementation-defined order.
     subset_by_index: Optional 2-tuple [start, end] indicating the range of
       indices of eigenvalues to compute. For example, is ``range_select`` =
       [n-2,n], then ``eigh`` computes the two largest eigenvalues and their
       eigenvectors.

  Returns:
    A tuple ``(v, w)``.

    ``v`` is an array with the same dtype as ``x`` such that ``v[..., :, i]`` is
    the normalized eigenvector corresponding to eigenvalue ``w[..., i]``.

    ``w`` is an array with the same dtype as ``x`` (or its real counterpart if
    complex) with shape ``[..., d]`` containing the eigenvalues of ``x`` in
    ascending order(each repeated according to its multiplicity).
    If ``subset_by_index`` is ``None`` then ``d`` is equal to ``n``. Otherwise
    ``d`` is equal to ``subset_by_index[1] - subset_by_index[0]``.
  rE   rF   rG   )r6   eigh_pr:   )r2   rE   r1   rF   rG   vws          r;   r   r   x   sK    T  1A	'%	 
 
 
$!Q 
A+r=   r_matrixw_vectorc                8    t                               | |          S )aN  Given a Cholesky decomposition A = R.T @ R and a vector w,
  computes the Cholesky decomposition of A + w @ w.T in O(N^2) time.

  Args:
    r_matrix: An upper-triangular matrix (R) such that A = R.T @ R.
    w_vector: A vector (w) for rank-1 update.

  Returns:
    A new R' matrix being the Cholesky decomposition of A + w @ w.T.
  )cholesky_update_pr:   )rO   rP   s     r;   cholesky_updaterS      s     
		(	3	33r=   pivotspermutation_sizeintc                X    t                               | t          |                    }|S )a  Converts the pivots (row swaps) returned by LU to a permutation.

  We build a permutation rather than applying `pivots` directly to the rows
  of a matrix because lax loops aren't differentiable.

  Args:
    pivots: an int32 array of shape (..., k) of row swaps to perform
    permutation_size: the size of the output permutation. Has to be >= k.

  Returns:
    An int32 array of shape (..., permutation_size).
  rU   )lu_pivots_to_permutation_pr:   rV   )rT   rU   permutations      r;   lu_pivots_to_permutationr[      s2     +//s#344 0 6 6+	r=   tuple[Array, Array, Array]c                H    t                               |           \  }}}|||fS )a  LU decomposition with partial pivoting.

  Computes the matrix decomposition:

  .. math::
    P.A = L.U

  where :math:`P` is a permutation of the rows of :math:`A`, :math:`L` is a
  lower-triangular matrix with unit-diagonal elements, and :math:`U` is an
  upper-triangular matrix.

  Args:
    x: A batch of matrices with shape ``[..., m, n]``.

  Returns:
    A tuple ``(lu, pivots, permutation)``.

    ``lu`` is a batch of matrices with the same shape and dtype as ``x``
    containing the :math:`L` matrix in its lower triangle and the :math:`U`
    matrix in its upper triangle. The (unit) diagonal elements of :math:`L` are
    not represented explicitly.

    ``pivots`` is an int32 array with shape ``[..., min(m, n)]`` representing a
    sequence of row swaps that should be performed on :math:`A`.

    ``permutation`` is an alternative representation of the sequence of row
    swaps as a permutation, represented as an int32 array with shape
    ``[..., m]``.
  )lu_pr:   )r2   lurT   rZ   s       r;   r_   r_      s'    < !IIaLL"fk	V[	  r=   full_matricesra   c               H    t                               | |          \  }}||fS )a  QR decomposition.

  Computes the QR decomposition

  .. math::
    A = Q . R

  of matrices :math:`A`, such that :math:`Q` is a unitary (orthogonal) matrix,
  and :math:`R` is an upper-triangular matrix.

  Args:
    x: A batch of matrices with shape ``[..., m, n]``.
    full_matrices: Determines if full or reduced matrices are returned; see
      below.

  Returns:
    A pair of arrays ``(q, r)``.

    Array ``q`` is a unitary (orthogonal) matrix,
    with shape ``[..., m, m]`` if ``full_matrices=True``, or
    ``[..., m, min(m, n)]`` if ``full_matrices=False``.

    Array ``r`` is an upper-triangular matrix with shape ``[..., m, n]`` if
    ``full_matrices=True``, or ``[..., min(m, n), n]`` if
    ``full_matrices=False``.
  r`   )qr_pr:   )r2   ra   qrs       r;   qrrf      s&    6 
1M	2	2$!Q	
A+r=   )ra   rG   
compute_uvLiteral[True]c                   d S N r2   ra   rg   rG   s       r;   r   r     	     #r=   Literal[False]c                   d S rj   rk   rl   s       r;   r   r     rm   r=   ra   rg   rG   "Array | tuple[Array, Array, Array]c                   d S rj   rk   rl   s       r;   r   r   $  rm   r=   c               d    t                               | |||          }|r|\  }}}|||fS |\  }|S )zSingular value decomposition.

  Returns the singular values if compute_uv is False, otherwise returns a triple
  containing the left singular vectors, the singular values and the adjoint of
  the right singular vectors.
  rp   )svd_pr:   )r2   ra   rg   rG   resultsurM   s           r;   r   r   0  sT     ::!%	   &  GAq!a7N	BAHr=   F	left_siderE   transpose_aconjugate_aunit_diagonalabry   rz   r{   r|   c          	     p   |o0t          j        t          j        |           t           j                  }t          j        |          t          j        |           dz
  k    }|rt          j        ||rdnd          }t                              | ||||||          }|r|r|d         n|ddddf         }|S )	a  Triangular solve.

  Solves either the matrix equation

  .. math::
    \mathit{op}(A) . X = B

  if ``left_side`` is ``True`` or

  .. math::
    X . \mathit{op}(A) = B

  if ``left_side`` is ``False``.

  ``A`` must be a lower or upper triangular square matrix, and where
  :math:`\mathit{op}(A)` may either transpose :math:`A` if ``transpose_a``
  is ``True`` and/or take its complex conjugate if ``conjugate_a`` is ``True``.

  Args:
    a: A batch of matrices with shape ``[..., m, m]``.
    b: A batch of matrices with shape ``[..., m, n]`` if ``left_side`` is
      ``True`` or shape ``[..., n, m]`` otherwise.
    left_side: describes which of the two matrix equations to solve; see above.
    lower: describes which triangle of ``a`` should be used. The other triangle
      is ignored.
    transpose_a: if ``True``, the value of ``a`` is transposed.
    conjugate_a: if ``True``, the complex conjugate of ``a`` is used in the
      solve. Has no effect if ``a`` is real.
    unit_diagonal: if ``True``, the diagonal of ``a`` is assumed to be unit
      (all 1s) and not accessed.

  Returns:
    A batch of matrices the same shape and dtype as ``b``.
     rx   .r   .r   N)	r7   
issubdtyper
   dtypecomplexfloatingndimexpand_dimstriangular_solve_pr:   )	r}   r~   ry   rE   rz   r{   r|   	singletonouts	            r;   triangular_solver   K  s    L Qsy||S=P Q Q+hqkkSXa[[1_,) 422233Aiu+] 	  	< 	<#  7"
6#f++CAAAIC	*r=   z(n,m),(m)->(n)	signaturec                N    t          j        | |t           j        j                  S )N	precision)r
   dot	PrecisionHIGHESTr}   r~   s     r;   _matvec_multiplyr   ~  s    	A!6	7	7	77r=   c                    | j         dk    rP|j         | j         | j         dz
  fv r8| j        d         | j        d         cxk    r|j        | j         dz
           k    s!n t          d| j         d|j                   d S )N   r   r   r   z]The arguments to solve must have shapes a=[..., m, m] and b=[..., m, k] or b=[..., m]; got a= and b=)r   shape
ValueErrorr   s     r;   _check_solve_shapesr     s    
&A++!&QVQVaZ$888
'"+
;
;
;
;
(;
;
;
;
;
	H./g	H 	H>?g	H 	HI I I <
;r=   c           	     $    t           |           t          d t           j        d d         dz   |j                  D                       }t	          j        ||          }t          t          j                             \  }t          t          j
         fdfdfd          } j        |j        dz   k    r ||          S  t          j        ||j        dz
  t           j        |j                  dz
            |          S )	Nc              3  0   K   | ]\  }}|d k    r|n|V  dS )r   Nrk   ).0d_ad_bs      r;   	<genexpr>z_solve.<locals>.<genexpr>  sN       G G S !88CC G G G G G Gr=   r   r   c                $    t          |           S rj   )r   )r2   r}   s    r;   <lambda>z_solve.<locals>.<lambda>  s     A&& r=   c                *    t          |d          S )Nr   translu_solve_r2   lu_rZ   s     r;   r   z_solve.<locals>.<lambda>  s    #{AQ??? r=   c                *    t          |d          S )Nr   r   r   r   s     r;   r   z_solve.<locals>.<lambda>  s    8Caq#I#I#I r=   )solvetranspose_solver   )r   tuplezipr   r7   broadcast_tor_   r
   stop_gradientr   custom_linear_solver   r   vmapmax)r}   r~   	out_shaper   custom_solver   rZ   s   `    @@r;   _solver     s;   a  G G$'t(;QW$E$EG G G G G)	q)$$! 3,Q//00#q+	&&&&?????IIIII	K K K,
 Vqvz<?? G38L!&1*c!&!&.A.AA.EFFqIIIr=   c                .    t          j        | dd          S )Nr   r   )r7   swapaxesr2   s    r;   _Tr     s    #,q"b"9"99r=   c                D    t          j        t          |                     S rj   )r+   conjr   r   s    r;   _Hr     s    &+bee"4"44r=   c                ,    | t          |           z   dz  S )Nr   )r   r   s    r;   r6   r6     s    1r!uu9/#9r=   c                $   | \  }|\  }t          j        t                              |                    }d }t	          ||dddd          }t          j        | |t	          ||ddd                    t
          j        j                  }||fS )Nc                    t          j        |           }|t          j        t	          j        | d          t          j        | j        d         | j                  z   t          |j
        dz
                      z  S )Nr   r   r   r   )r7   r8   r
   r   lax_internal_consteyer   r   ranger   )Xls     r;   phiz_cholesky_jvp_rule.<locals>.phi  sg    AsAq!!CGAGBKqw$G$G$GGafqj   r=   FT)ry   rz   r{   rE   ry   rz   rE   r   )	r7   r8   r9   r:   r   r
   batch_matmulr   r   )primalstangentsr2   	sigma_dotLr   tmpL_dots           r;   _cholesky_jvp_ruler     s    "!*)	hzq!!""!   	ID%)	7 	7 	7#

1cc"2%t#= #= #= > >%' ' '% 
E/r=   c                `    | \  }|\  }t          j        ||d          }t          |          dfS Nr   )r   moveaxisr<   batched_args
batch_dimsr2   bds       r;   _cholesky_batching_ruler     s4    "!#"2q!!!	!ar=   r<   c                j    t          j        |t          j                            d                    gS )NTrE   )r(   r<   r&   BoolAttrget)ctxr2   s     r;   _cholesky_loweringr     s(    
,q 5 5
6
6
6	77r=   c                   | j         \  }| j        \  }|j        d d         }t          j        | |j                  }t
          dk     rd}n| f}t          j        g ||j        |R d|d\  }}t          j	        |t          j
        | dt          |t          j        t          j                                      dd          }	t          |d	z   t          j        t          j                            }
t          | t          j        | |	|
t#          t%          |                    
          |
||t'          | |          |          gS )Nr   )r         rk   T)rE   a_shape_valsr   EQSIGNEDr   r   broadcast_dimensions)avals_in	avals_outr   r   eval_dynamic_shape_as_ivalsjaxlib_versionr#   	potrf_hlor   compare_hlofull_like_avalr   npint32bool__broadcasting_select_hlobroadcast_in_dimr   len_nan_like_hlo)r   operandoperand_avalout_avalr   op_shape_valsctx_argru   infookselect_avals              r;   _cholesky_cpu_loweringr    sh   ,-,m)(!#2#&*238JKK-j  GGfG! J7 JL,> J J J(,=J J J,&$ 
DQJ@R@R(S(STT
H " J/"(1C1CDD+
"	
C'16s:1G1GI I I hc844h@ @ 
A Ar=   cpu)platformc                   t          j        | j                  }t          j        |j                  }||k    r|t          j        t          j        fv st          d          | j        dk    rC|j        dk    r8| j        d         | j        d         k    r| j        d         |j        d         k    s-t          d
                    | j        |j                            t          | j        | j                  S )NzCRank-1 Cholesky update is only implemented for float32 and float64.r   r   r   r   zoRank-1 update to Cholesky decomposition takes a square matrix and a vector as inputs. Got shapes {}, {} instead)r   canonicalize_dtyper   r   float32float64NotImplementedErrorr   r   r   formatr   )rO   rP   r_dtypew_dtypes       r;   _cholesky_update_abstract_evalr    s    %hn55'%hn55'
W

RZ,D!D!D
MO O O
-1

!!3!3nR HN2$666nR HN2$666
	<<BFNHN=, =,- - - 
X^X^	4	44r=   c                    | j         \  }}	 | j        j        \  }n# t          $ r t          d          d w xY w|dk    rt	          d          t          j        |||j                  S )Nz4Can only lower cholesky_update on a single platform.cudaz,Can only lower fast cholesky_update on CUDA.)r   module_context	platformsr   r
  r    cuda_cholesky_updater   )r   rO   rP   r_matrix_avalr   r  s         r;   #_cholesky_update_cuda_lowering_ruler    s    \-#-JXX	   
>  
6   
	(--
/ 
/ /s    6c                
   d }dd
}|j         d         }t          |          D ]^} || ||f         ||                   \  }} || |d d f         |||          \  }}| j        |d d f                             |          } _| S )Nc                    d }t          j        d| j                  t          j        d| j                  ft          j                            |dk    fd|| |          S )z:Get coefs for Givens rotation in a numerically stable way.c                2   t           j                            |           }t           j                            |          }t          j        ||k    ||          }| |z  } ||z  }dt           j                            | dz  |dz  z             z  }| |z  | |z  fS )Nr   r   )jaxnumpyabsr7   wheresqrt)r2   yabs_xabs_ydenominatorrhs         r;   _drotg_nonzeroz?_cholesky_update_jax_fn.<locals>._drotg.<locals>._drotg_nonzero  s    immAeimmAeIeemUE::k;a;asy~~a1fqAvo...bVaR"W_r=   g      ?r   g        r   c                    S rj   rk   )r2   r  one_and_zeros     r;   r   z9_cholesky_update_jax_fn.<locals>._drotg.<locals>.<lambda>  s    \ r=   )r7   arrayr   r  r
   cond)r2   r  r#  r%  s      @r;   _drotgz'_cholesky_update_jax_fn.<locals>._drotg  so       		"AG$$$	"AG$$$L 7<<Q 9 9 9 9>1aPPPr=   first_vector	jax.Arraysecond_vectorc_coeffloats_coefr4   tuple[jax.Array, jax.Array]c                .    || z  ||z  z
  ||z  || z  z   fS rj   rk   )r)  r+  r,  r.  s       r;   _drotz&_cholesky_update_jax_fn.<locals>._drot  s2     	 66,!668 8r=   r   )
r)  r*  r+  r*  r,  r-  r.  r-  r4   r/  )r   r   atset)	Rzr(  r1  nkcrv   row_ks	            r;   _cholesky_update_jax_fnr:    s    Q Q Q 8 8 8 8 gaj!88  a6!AqD'1Q4  DAquQq!!!tWaA&&HE1	QT
uAA	
(r=   rS   r  multiple_resultsc               <    t          j        t          | ||          S )Nr>   )r   apply_primitiverC   )r   r?   r@   s      r;   eig_implr?  7  s(    		! 9!;	
 
 
 r=   c                      t          d          )NzNonsymmetric eigendecomposition is only implemented on the CPU backend. If your matrix is symmetric or Hermitian, you should use eigh instead.r
  )argskws     r;   	eig_lowerrD  ?  s    M	N 	N Nr=   c                  t          | t                    r| j        dk     s| j        d         | j        d         k    r't	          d                    | j                            | j        d d         }| j        d         }t          j        | j                  j	        dk    rt          j        nt          j        }t          j        |          }|                     |||fz   |          x}}|                     ||fz   |          }nt          |g}	|r|	                    |           |r|	                    |           t#          |	          S )Nr   r   r   zUArgument to nonsymmetric eigendecomposition must have shape [..., n, n], got shape {}    r   r   )
isinstancer   r   r   r   r  r   finfor   bitsr   	complex64
complex128r  updater
  appendr   )
r   r?   r@   r   r6  r   vlvrrN   outputs
             r;   eig_abstract_evalrR  D  sD   %% |a7=,b0AAA 99?9N9NP P P ss#JbA"L77<BBBLLE%e,,Enn:A#6enDDDBZ1$.e<<AA
3& 
MM" 
MM"	vr=   c               J   | j         \  }| j        d         }|j        d d         }t          j        | |j                  }t          j        |j        ||||          \  }}	}
}t          j        |t          j	        | dt          |t          j        t          j                                      dd          }t          |dz   t          j        t          j                            }t          | t          j        | ||t!          t#          |                              |||t%          | |          |          }|g}|r| j        t#          |                   }t          |dz   t          j        t          j                            }t          | t          j        | ||t!          t#          |                              ||	|t%          | |          |          }	|                    |	           |r| j        t#          |                   }t          |dz   t          j        t          j                            }t          | t          j        | ||t!          t#          |                              ||
|t%          | |          |          }
|                    |
           |S )	Nr   r   )input_shape_valsjobvljobvrr   r   r   r   r   )r   r   r   r   r   r#   geev_hlor   r   r   r   r   r   r   r   r   r   r   r   rN  )r   r   r?   r@   r   r   r   r   rN   rO  rP  r   r  select_w_avalrQ  avalselect_vl_avalselect_vr_avals                     r;   _eig_cpu_loweringr\  \  s   ,-,]1(!#2#&*238JKK-OL$65B*C*DF F F/!RT
 
DQJ@R@R(S(STT
H " j4/"(1C1CDD-	
C]16s:1G1GI I I=h//; ;! 3& 	=V%D f!4bhrx6H6HIIN	!c2~38Z3I3I	K 	K 	K
D-T**D
2 
2B MM" 	=V%D f!4bhrx6H6HIIN	!c2~38Z3I3I	K 	K 	K
D-T**D
2 
2B MM"	-r=   c                   | \  }|\  }t          j        ||d          }t                              |||          dd|z   |z   z  fS )Nr   r>   r   r   )r   r   rC   r:   )r   r   r?   r@   r2   r   s         r;   eig_batching_ruler_    sd    "!#"2q!!!
**Q2K0J  L L
!//2LL
M
O Or=   c          	         |s|rt          d          | \  }|\  }t          |d          \  }}|gt          j        t	          ||                    |j                            t          |          z  d          gfS )NzThe derivatives of eigenvectors are not implemented, only eigenvalues. See https://github.com/google/jax/issues/2748 for discussion.F)r?   r   )r
  rD   r*   sumr   astyper   r   )r   r   r?   r@   r}   dar   rM   s           r;   eig_jvp_rulerd    s     E"< E
	DE E E "!#"	Q%	0	0	0$!Q
z~fQ		!'(:(:;;beeCRHHI	IIr=   rD   rE   rF   c               J    t                               | ||          \  }}||fS )z`Helper Jacobi eigendecomposition implemented by XLA.

  Used as a subroutine of QDWH-eig on TPU.re  )eigh_jacobi_pr:   )r2   rE   rF   rN   rM   s        r;   eigh_jacobirh    s,    
 
		AU=M		N	N$!Q	
A+r=   c               J    t          j        t          | ||          \  }}||fS )Nre  )r   r>  rg  )r   rE   rF   rN   rM   s        r;   _eigh_jacobi_implrj    s2    		!-3C
E 
E 
E$!Q	
A+r=   c                  t          | t                    r| j        dk     s| j        d         | j        d         k    r't	          d                    | j                            | j        d d         }| j        d         }|                     ||fz   t          j        | j	                            }|                     |||fz             }n| | }}||fS )Nr   r   r   QArgument to symmetric eigendecomposition must have shape [..., n, n],got shape {}rG  r   
rH  r   r   r   r   r  rM  r   _complex_basetyper   )r   rE   rF   r   r6  rN   rM   s          r;   _eigh_jacobi_abstract_evalrp    s    %% |a7=,b0AAA	vgm,,. . . ss#JbAZ1$.);GMJJ 	 	L 	LAZ1a&011AAGqA	
A+r=   c                     j         \  }|j        d         dk    rM|                    |j        d d                   }t          j        t          j         ||                    |gS t          j         j        d                   }t          j         j        d                   }||g}t          |           dt          |           d}	t          d  j        D                       r. fdt          t           j                            D             }
nd }
t          j        d	||g|	d|

          }|j        d         |j        d         fS )Nr   r   rm  r   ,z	,100,1e-6c              3  @   K   | ]}t          |j                   V  d S rj   r   r   r   aval_outs     r;   r   z-_eigh_jacobi_lowering_rule.<locals>.<genexpr>  C       	( 	( x~..	. 	( 	( 	( 	( 	( 	(r=   c                D    g | ]}t          j        |j                  S rk   r   eval_dynamic_shape_as_tensorr   r   rv  r   s     r;   
<listcomp>z._eigh_jacobi_lowering_rule.<locals>.<listcomp>  s:         	)#x~>>  r=   Eigh)result_typesoperandsbackend_configapi_versionresult_shapes)r   r   rM  r(   realr   reshapeaval_to_ir_typer   rV   anylistreversedcustom_callresults)r   r   rE   rF   r   reshape_avaleigvals_typeeigvecs_typer~  r  r  ops   `           r;   _eigh_jacobi_lowering_ruler    s   ,-,q  &&\-?-D&EELc7L99:: 
 %cmA&677,%cmA&677,-,%jjCC3'7#8#8CCC. 	( 	(	( 	( 	( ( (     Xcm4455  MM My#!  " 
A
1	%%r=   rh  c               L    t          j        t          | |||          \  }}||fS )NrK   )r   r>  rL   )r   rE   rF   rG   rM   rN   s         r;   
_eigh_implr    s7    		!'%
 
 
$!Q 
A+r=   c                  t          | t                    r| j        dk     s| j        d         | j        d         k    r't	          d                    | j                            | j        d d         }| j        d         }||n|d         |d         z
  }|                     |||fz             }|                     ||fz   t          j        | j	                            }n| | }}||fS )	Nr   r   r   rl  r   r   rm  rG  rn  )	r   rE   rF   rG   r   r6  drM   rN   s	            r;   _eigh_abstract_evalr    s	   %% |a7=,b0AAA	vgm,,. . . ss#JbA " 	
Q/!"44 
 	Z1a&011AA4,W];; 	 	 	AA
 GqA	
A+r=   c                  ~|j         \  }|j        \  }}|j        d         }	|j        d d         }
t          |j        dd                    st	          d|j                   ||d|	fk    st	          d          t          j        ||j                  } | |j        |||          \  }}}t          j        |dt          |
t          j        t          j                                      }t          j        ||dd          }t          |
d	z   t          j        t          j                            }t          |t          j        |||t!          t#          |
                    
          |||t%          ||          |          }t          |
dz   t          j        t          j                            }t          |t          j        |||t!          t#          |
                    
          |||t%          ||          |          }||gS )Nr   r   ^Shape polymorphism for native lowering for eigh is implemented only for the batch dimensions: r   /subset_by_index not implemented for CPU and GPU)r   rE   r   r   r   r   r   )r   r   r   r   r
  r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
syevd_implr   r   rE   rF   rG   r   v_avalw_avalr6  r   r   rM   rN   r   zerosr  select_v_avalrX  s                      r;   _eigh_cpu_gpu_loweringr    s$    ,-,=.&&!!#2#&*
 
<-bcc2	3	3 @
	?*6*<	? 	?@ @ @ 
!_A%>%>
O
P
PP238JKK-z,,g'4EC C C*!Q 
c1k*bhrx>P>P&Q&Q
R
R%eT844"j6128BH3E3EFF-	
C]16s:1G1GI I IsF++V5 5! j4/"(1C1CDD-	
C]16s:1G1GI I IsF++V5 5! Q-r=   c               "  	
 | j         ^ }}	|	k    sJ |	f            d
t          |          st          d| j                    |
k    r#d	fk    rt          |           \  }}||fS 	
fd |           \  }}||fS )N   r  r   re  c           	        t          | j                  dk    rt          j        |           S rt	          j        dt                    }n.t          j        t	          j        dt                              }t          j
        | j        t          j                  rt          j        |t          j        |           t!          t          j        |                               }rt	          j        dt                    }n.t          j        t	          j        dt                              }t          j        |t          j        |           t	          j        t          j        |                               }t          j        ||t!          |                     }t          j        ||          } n#t          j        || t!          |                     } t)          j        | 
	          S )Nr   r   )r7  r   r   )rF   termination_sizerG   )r   r   r   mapr7   trir3   r+   logical_notr   r   r   r   r
   selectr  r   imag
zeros_likecomplexlax_eighr   )r2   maskreim_maskim	eigh_qdwhrE   r6  rF   rG   r  s        r;   r  z!_eigh_tpu_impl.<locals>.eigh_qdwhW  s   
17||ai+++  >WQ!4(((ddRt < < <==d#"566 
%:dCHQKKCHQKK99b	 B'!r...$SWQ!4%@%@%@AA:gsx{{CN38A;;,G,GHHb:dBB((b
+b"

aa
*T1bee
$
$a=	))'	   r=   )r   r   r
  rh  )r2   rE   rF   rG   r   meig_valseig_vecsr  r6  r  s    ```    @@@r;   _eigh_tpu_implr  F  s	   W(1a	
a!Q			 5
	4*+'	4 	45 5 5 
QF!:!:$Qe6FH H HHhX         : !y||(H	8	r=   c                  | \  }|j         d         }||d|fk    st          d          |\  }t                              t	          |          |||          \  }}	|	                    |j                  }
t          j        ||j                  }t          j
        ||
dt          j        d d f         z   |
dt          j        f         z
            |z
  }t          |j        dk    rt          j        nt          j        t          j        j                  } | |t'          |          |          |          } ||t          j        ||                    }t          j        t          j        |d	d
                    }||	f||ffS )Nr   r   z8Derivatives not defined for partial eigen decomposition.rK   r   .r   r   r   )axis1axis2)r   r
  rL   r:   r6   rb  r   r7   r   r+   
reciprocalnewaxisr   r   r
   r   r   r   r   r   multiplyr  diagonal)r   r   rE   rF   rG   r}   r6  a_dotrM   w_realrN   eye_nFmatr   vdag_adot_vdvdws                    r;   _eigh_jvp_ruler  x  s    
$1gbk!

!_A%>%>
B   &%kkmm'%	   )!V mmAG!
'!17
#
#
#%		51S#+qqq%8#99Ac3;>N<OO	P	PSX	X$16Q;;C,<-/	1 	1 	1#CC1u%%q))+
s1fodK0011"{3<2R@@@AA"
Vr2h	r=   c               ~    | \  }|\  }t          j        ||d          }t                              ||||          dfS )Nr   rK   r   r   )r   r   rL   r:   )r   r   rE   rF   rG   r2   r   s          r;   _eigh_batching_ruler    sW     "!#"2q!!!	'%	 
 
 

 
 r=   r   rocmtpur   )ry   c                  | j         dk     r)d}t          |                    | j                             |j         dk     r)d}t          |                    |j                             | j        d         | j        d         k    r)d}t          |                    | j                            | j        d d         |j        d d         k    r/d}t          |                    | j        |j                            |rdnd}| j        d         |j        |         k    r/d}t          |                    | j        |j                            |j        S )	Nr   z:triangular_solve requires a.ndim to be at least 2, got {}.z:triangular_solve requires b.ndim to be at least 2, got {}.r   r   z^triangular_solve requires the last two dimensions of a to be equal in size, got a.shape of {}.zytriangular_solve requires both arguments to have the same number of dimensions and equal batch dimensions, got {} and {}.zAIncompatible shapes for arguments to triangular_solve: {} and {}.)r   	TypeErrorr  r   )r}   r~   ry   unused_kwargsmsg
common_dims         r;   _triangular_solve_shape_ruler    s-   VaZZ
FC
CJJqv&&
'
''VaZZ
FC
CJJqv&&
'
''WR[AGBK)C
CJJqw''
(
((WSbS\QWSbS\!!FC
CJJqw00
1
11&rrB*WR[AGJ'''
MC
CJJqw00
1
11	
.r=   c                  |j         dd          \  }	}
rdnd}rt          j        | |           nt          j        | |          } t	          j        |           } rt          j        | dd          n| } rt          j        |           n| } t          | j
        dk    rt          j        nt          j        t          j        j                  }fd}rs| j         dd          j         dd          cxk    r|	|	fk    rn n|j         dd          |	|
fk    sJ |	|
k    r | || |                    S  | ||           |          S | j         dd          j         dd          cxk    r|
|
fk    rn n|j         dd          |	|
fk    sJ |	|
k     r | |||                     S  || ||                     S )	Nr   r   r   )r7  r   r   r   c           	     0    t          |           S Nrx   r   )rhsr}   r{   ry   rE   rz   r|   s    r;   	a_inversez/_triangular_solve_jvp_rule_a.<locals>.a_inverse  s*    Asiu(3*79 9 9 9r=   )r   r7   r8   triur
   negr   r+   r   r   r   r   r   r   r   )g_aansr}   r~   ry   rE   rz   r{   r|   r  r6  r7  r   r  s     ` `````     r;   _triangular_solve_jvp_rule_ar    s4    
$!Qaaa!$<#(3!*<*<*<##%09S"b!!!c#'0CS#38q==c.>-/	1 	1 	1#9 9 9 9 9 9 9 9 9 9  &9RSS>QWRSS\3333aV33333	"##1a&8P8P8P8P1uuYss3}}%%%S3%%%9RSS>QWRSS\3333aV33333	"##1a&8P8P8P8P1uuYss3}}%%%Siinn%%%r=   c          	         t          j        |          st          j        |          sJ t          |           t          j        u rt          j        |j                  }nt          || ||| ||          }d |gS r  )r   is_undefined_primaltyper   ZerorY  r   )		cotangentr}   r~   ry   rE   rz   r{   r|   cotangent_bs	            r;    _triangular_solve_transpose_ruler     s    
 #A&&D2+A!+D+DDDD	)__$$,qv&&KK"1i9).O/:1>@ @ @K 	r=   c          	        | \  }}|\  }	}
|	t           j        u r|r`t          j        ||
d          }|                    |j        d d         |j        d         |j        d         z  fz             }|j        dz
  }nkt          j        ||
d          }|                    |j        d d         |j        d         |j        d         z  |j        d         fz             }|j        dz
  }t          |||||||          }|                    |j                  |fS t          d t          | |          D                       }t          j	        ||	|          }t          j	        ||
|          }t          |||||||          dfS )	Nr   r   r   r   rx   c              3  :   K   | ]\  }}||j         |         V  d S rj   rm  r   tis      r;   r   z2_triangular_solve_batching_rule.<locals>.<genexpr>$  9       " "tq!= 
 ===" "r=   r   )
r   
not_mappedr   r  r   r   r   nextr   bdim_at_front)r   r   ry   rE   rz   r{   r|   r2   r  bxbyy_flatbdim_outout_flatsizes                  r;   _triangular_solve_batching_ruler    s    
$!Q&"b8 

Ar2
&
&ayy"qwr{)B(DDEEf!hh

Ar2
&
&ayy"!'"+*CQWR[)QQRRf!h	6Ye[#% % %H AG$$h.. " "s<'D'D " " " " "Dq"d++Aq"d++AAqIU(3*79 9 9:;< <r=   c                    t          || fi |S rj   r  )g_br   r}   r~   kwss        r;   r   r   1  s    '73'F'F#'F'F r=   c          
     z   | j         \  }|r|st          j        |          }d}|sd}	n|rdnd}	t          j        ||t
          j                            |          t
          j                            |          t
          j                            |          t          j                            |	                    gS )NFNO_TRANSPOSEADJOINT	TRANSPOSE)	r   r'   ConjOpr(   r   r&   r   r   TransposeAttr)
r   r}   r~   ry   rE   rz   r{   r|   r   	transposes
             r;   _triangular_solve_loweringr  6  s    m)(  AAK	 :II(9		kI

BKOOI&&kooebkoom<<	I&&( ( 
) )r=   c                  | j         \  }}	|r|st          j        |          }d}t          |j                  dk    rt          j        |j                  t          v rjt          j	        t          j
        d|j                            }
t          j        | |	j                  }t          j        |j        |
||||||||
  
        S |r|rdnd}nd}t          j        ||t           j                            |          t           j                            |          t           j                            |          t          j                            |                    gS )	NFr   r   r   )b_shape_valsr  r  r  )r   r'   r   r   r   r   r   _cpu_lapack_typesr   ir_constantr&  r   r#   trsm_hlor(   r   r&   r   r   r  )r   r}   r~   ry   rE   rz   r{   r|   a_avalb_avalalphar  r  s                r;   _triangular_solve_cpu_lowerr  G  sJ    <.&&  	!AK! 6 6:K K KRXav|<<<==E3CFFL?lEIuk;! ! ! !  !*;))ii i Ar{y'A'A!#!7!7!#!?!?!$!2!6!6y!A!AC C D Dr=   c                *   |\  }}|j         d d         }|d| f         }t          j        d |D              }|d| f         }|||fz            }|j        d| f                             |          }|j        ||fz                                |          |fS )Nr   .c              3  T   K   | ]#}t          j        t          j        |          V  $d S rj   r
   iotar7   r   r   r~   s     r;   r   z%_lu_pivots_body_fn.<locals>.<genexpr>n  s0      ??qCHSY**??????r=   )r   r7   ix_r2  r3  )	r  permutation_and_swapsrZ   swapsr   jiotasr2   r  s	            r;   _lu_pivots_body_fnr  j  s    ,+u{3B3*CFm!
'??J???
@%#q&!%1$,!sAv&**1--+		%	)	)!	,	,e	33r=   c                   t          | j                  dk    sJ | j        dd         }| j        d         }|}t          j        t          j        ||fz   t          |                    }|dk    r|S t          j        t          j        dt          j                  t          j        |t          j                  t          || f          \  }}|S )a  Converts the pivots (row swaps) returned by LU to a permutation.

  We build a permutation rather than applying `swaps` directly to the rows
  of a matrix because lax loops aren't differentiable.

  Args:
    swaps: an array of shape (..., k) of row swaps to perform
    permutation_size: the size of the output permutation. Should be >= k.
  Returns:
    An int32 array of shape (..., m).
  r   Nr   r   )
r   r   r
   broadcasted_iotar7   r   	fori_loopr   r&  r  )r  rU   r   r7  r  rZ   ru   r   s           r;   !_generic_lu_pivots_to_permutationr  u  s     
U[		Q				{3B3*k"o!!$SY
aT0A%(__6 6+!VVmBHQ1128Arx3H3H.e0DF F)&!	-r=   c                  t          |           } t          | t                    r| j        dk     s'| j        t          j        t
          j                  k    r-t          d                    | j	        | j                            || j	        d         k     r(t          d                    || j	                            | j	        d d         }| 
                    ||fz             }n| }|S )Nr   zcArgument to lu_pivots_to_permutation must have rank >= 1 and dtype int32. Got shape={} and dtype={}r   z[Output permutation size {} has to exceed the trailing dimension of the pivots. Got shape {}rm  )r   rH  r   r   r   r   r   r   r  r   rM  )rT   rU   r   permutationss       r;   '_lu_pivots_to_permutation_abstract_evalr    s    6""&$$ {Q&,"(28*<*<<<--3VFL&,-O-OQ Q Q &,r***%%+V,<fl%K%KM M M crc"J==z5E4G'G=HHLLL	r=   c               z    | \  }|\  }t          j        ||d          }t                              ||          dfS )Nr   rX   )r   r   rY   r:   )r   r   rU   r2   r   s        r;   '_lu_pivots_to_permutation_batching_ruler    sO    "!#"2q!!!	#	(	(* 
) 
, 
,-.
/ /r=   c                    | ||          S )NrX   rk   )loweringr   rT   rU   s       r;   &_lu_pivots_to_permutation_gpu_loweringr    s    	&+;	<	<	<<r=   r[   c                6   | j         \  fd}t          j        t                    ft          j                  }t          j        t          j                  }dk    rdk    r||| fS t          j        dt                    |||| f          S )z-Unblocked LU decomposition, as a rolled loop.c                   |\  }}}t          j                  }t          j                  }t          j        |j        t           j                  rZ|d d | f         }t          j        t          j        |                    t          j        t          j        |                    z   }nt          j        |d d | f                   }t          j	        t          j
        || k    |t           j                             }	|j        |                              |	                    |j                            }|j        | |	gf                             ||	| gf                   }|j        |	| gf                             || |	gf                   }|| | f         }
|j        d d | f                             t          j
        || k    |
dk    z  |d d | f         |
z  |d d | f                             }|t          j
        |d d d f         | k    |d d d f         | k    z  t          j        |d d | f         || d d f                   t          j        d|j                            z
  }|||fS )Nr   r   )r7   aranger   r   r   r+   r  r  r  argmaxr  infr2  r3  rb  outerr&  )r7  statepivotpermr}   m_idxn_idxr  	magnituder  r2   r  r6  s              r;   bodyz_lu_unblocked.<locals>.body  s+   NE4JqMMEJqMME
~ags233 &
AAAqD'a*V[^^,,vz&+a../I/IIii*Qqqq!tW%%i
39UaZSWH==>>AHQKOOAHHU[1122E	aVW!QFG*%%A7Aq67aVW..D 	
!Q$A	QQQT
sy%!)Q!7111a41a1gNNOOA 	
CIuQQQW~)eD!!!Gnq.@AYqAw!QQQ$00#)AQW2M2M2MO O 	OA$>r=   r   r   )r   r7   r  minr   r  r
   r  )r}   r'  r"  r#  r  r6  s       @@r;   _lu_unblockedr)    s    	
$!Q     0 )SAYYL	
2
2
2%	ASY	'	'	'$!VVQ 4	q#a))TE4+;	<	<<r=      c           
     v   | j         \  }}t          ||          }t          j        |ft          j                  }t          j        |t          j                  }t          d||          D ]}t          ||z
  |          }t          | |d|||z   f                   \  }	}
}|j        |||z            	                    |	|z             }|j        |d         	                    ||
|z                      }| j        |dddf         	                    | |
|z   ddf                   } | j        |d|||z   f         	                    |          } ||z   |k     r| j        |||z   ||z   df         	                    t          | |||z   |||z   f         | |||z   ||z   df         ddd                    } | j        ||z   d||z   df                             t          j        | ||z   d|||z   f         | |||z   ||z   df         t          j        j                             } | ||fS )z.Blocked LU decomposition, as an unrolled loop.r   r   NTry   rE   r|   r   )r   r(  r7   r  r   r  r   r)  r2  r3  r   addr
   r   r   r   )r}   
block_sizer  r6  re   r"  r#  r7  r~   block_pivot
block_permlu_blocks               r;   _lu_blockedr2    sj   	
$!Q	!Qii!
)QD	
*
*
*%	ASY	'	'	'$Az"" J JaAE:A(5aAacE	l(C(C%KXHQqsUOa00E7122;??4
Q/00D	QRRU*q.!!!+,--A	QRR1Q3YH%%A1uqyy
$q1uacdd{


1QqS5!AaC%<!AacE1Q344K.D#4	9 	9 	9: :a $qsttQqSTTz


!A#$$!A#+!AaC%1+25-2G!I !I !I  I J Ja	
E4r=   c                    | j         dd         }t          }t          t          |                    D ]}t	          j        |          } ||           S )zCDefault LU decomposition in Python, where no better version exists.Nr   )r   r2  r   r   r   r   )r2   r   fnr   s       r;   
_lu_pythonr5    sO    wss|*"Z!!  a	"BB	A,r=   c                H    t          j        t          |           \  }}}|||fS rj   )r   r>  r^   )r   r_   r"  r#  s       r;   _lu_implr7    s&    ,T7;;/"eT	UDr=   c                   t          |           } t          | t                    r| j        dk     rt	          d          | j        d d         }| j        d         }| j        d         }|                     |t          ||          fz   t          j	                  }|                     ||fz   t          j	                  }n| }| }| ||fS )Nr   z1Argument to LU decomposition must have ndims >= 2r   r   rG  )
r   rH  r   r   r   r   rM  r(  r7   r   )r   r   r  r6  r"  r#  s         r;   _lu_abstract_evalr9    s    G$$'%% |aJKKKss#JbAbANNs1ayyl!:#)NLLE>>
aT 1>CCDDED	%	r=   c           	        | \  }|\  }t                               |          \  }}}t          j        |          }|dd          \  }}	t	          j        |          }
t          ||	          }|d d         }t          j        d |dz   D              }||d d         |t          d           fz            }t          |          }dg|z  }d||z
  df|d<   t          j        |d          }t	          j        t          j        |dd d d |f         d          ||          }|t	          j        t          j        |||
          t!          |j        d	z
                      z   }t	          j        t          j        |	|z
  |	|z
  |
          ||ddf|ddff          }dg|z  }d|	|z
  df|d<   t	          j        t          j        |dd |d d f                   ||          t	          j        |t!          |j        d	z
                      z   }t'          ||d
dd
d
          }t'          ||ddd          }t          j        |t          j        |d          t          j        j                  }t          j        t          j        |          |t          j        j                  }||z   }|||f|t.          j                            |          t.          j                            |          ffS )Nr   c              3  T   K   | ]#}t          j        t          j        |          V  $d S rj   r  r  s     r;   r   z_lu_jvp_rule.<locals>.<genexpr>0  s0      FFqCHSY**FFFFFFr=   r   r   r   r   r   r   .r   r   TF)ry   rz   rE   r|   r   r   )r^   r:   r7   r   r
   r   r(  r	  slicer   r   r   padr8   r   r   r   r   r  r   matmulr   r   r   r  
from_value)r   r   r}   r  r_   rT   rZ   a_shaper  r6  r   r7  r   r  r2   ndims	l_paddingzeror   u_eye	u_paddingrw   lalaul_dotu_dotlu_dots                              r;   _lu_jvp_rulerL  %  s   "!&% IIaLL"fkIaLL'	$!Q
)A,,%	!Qii!ss|*
'FFJ4EFFF
G%E#2#J+uT{{334! g,,%kE!)a!eQ-)B-		R	#	#$	gchr#qqq"1"*~r**D)<<!#/#'!Qe444eAFQJ6G6G
H
HH!
'#'!a%Qe444dq!9q!Qi(* *%kE!)a!eQ-)B-
wsx3AAA:''y99
ueBGaK00112! 1%t&*, , ,"B%U$	& 	& 	&# *Qb))S]5J
K
K
K%
*SXc]]A1F
G
G
G%5=&
fk	"VW\-D-DV-L-L%,\%<%<[%I%I%K 
K Kr=   c                v    | \  }|\  }t          j        ||d          }t                              |          dfS )Nr   r<  )r   r   r^   r:   r   s       r;   _lu_batching_rulerN  V  s9    "!#"2q!!!	1y	  r=   r  strc               B   |j         \  }t          |j        dd                    st          d|j                   |j        \  }}}|j        d d         }|j        d         |dv rAt          |j                  st          d|j                    | |j        |          \  }	}
}n1t          j        ||j                  } | |j        ||          \  }	}
}t          j	        |
t          j
        |d|                    }
t          j        |t          j
        |dt          |t          j        t          j                                      dd	          }t          |d
z   t          j        t          j                            }t!          |t          j        |||t%          t'          |                              ||	|t)          ||          |          }	|                    d |g|g          }t          j        fdd          } |||
          \  }|	|
|gS )Nr   zkShape polymorphism for native lowering for lu on CPU and GPU is implemented only for the batch dimensions: r  r  z[Shape polymorphism for native serialization for lu on GPU is not implemented; b/261671778; r   r   r   GEr   r   r   )	primitiver   r   c                $    t          |           S rj   )r[   )r2   r  s    r;   r   z&_lu_cpu_gpu_lowering.<locals>.<lambda>  s    %=a%C%C r=   Fr;  )r   r   r   r
  r   r   r   r   r(   subtractr   r   r   r   r   r   r   r   r   r   r   replace	lower_fun)
getrf_implr   r   r  r   r   
pivot_aval	perm_avalr   r_   r"  r   r   r  select_lu_avalsub_ctxperm_fnr#  r  s                     @r;   _lu_cpu_gpu_loweringr_  \  sf   ,-, 
<-bcc2	3	3 J
I4@4FI IJ J J %(M!(J	!#2#&*!!!!\/00 =<'3'9< <= = = !j!3W==OBtt4S,:LMMM jG-A A AOBt ,ud1#q*EE
F
F%
DQJ@R@R(S(STT
H " zF2BHRX4F4FGG.	
C^16s:1G1GI I I(M#x00(< <" KK$*)KUU'NCCCC,13 3 3'
''5
!
!%$
eT	r=   c                d    t          j         j        d                   t          j         j        d                   t          j         j        d                   g}t          d  j        D                       r fd j        D             }nd }t          j        d||g|          }|j        S )Nr   r   r   c              3  @   K   | ]}t          |j                   V  d S rj   rt  )r   r}   s     r;   r   z(_lu_tpu_lowering_rule.<locals>.<genexpr>  s0      ??Aqw''	'??????r=   c                D    g | ]}t          j        |j                  S rk   ry  )r   r}   r   s     r;   r|  z)_lu_tpu_lowering_rule.<locals>.<listcomp>  s8       
 'QW55  r=   LuDecomposition)r~  r  r  r   r  r   r  r  r  )r   r   r~  r  r  s   `    r;   _lu_tpu_lowering_rulere    s    q)**q)**q)**,, 	???????    }  MM MY	! ! !"
 
r=   r_      z(n,n),(n),(n,k)->(n,k))excludedr   rZ   r   c           	        | j         d         }t          j        ||t          j        |j         dd                    f          }|dk    r4||d d f         }t          | |ddd          }t          | |dd          }nn|dk    s|dk    rP|dk    }t          | |ddd|          }t          | |dddd|	          }|t          j        |          d d f         }nt          d
|           t          j        ||j                   S )Nr   r   Tr,  F)ry   rE   r   )ry   rE   rz   r{   )ry   rE   r|   rz   r{   z&'trans' value must be 0, 1, or 2, got )	r   r7   r  mathprodr   argsortr   r
   )r_   rZ   r~   r   r  r2   r   s          r;   _lu_solve_corerl    s*   hqk!	k!a17122;//011!
aZZ	+qqq.AQ$d$OOOAQ$e<<<AAzzUaZZA:DQ$e%)	+ 	+ 	+AQ$d$%)t	= 	= 	=A	#+k
"
"AAA
%&AA
EeEE
F
FF	Q	 	  r=   )rf  )static_argnumsc                   t          | j                  dk     s| j        d         | j        d         k    r't          d                    | j                            t          |j                  dk     r't          d                    |j                            | j        |j        dz   k    }|r^|j        d         | j        d         k    r-t          d                    | j        |j                            |dt
          j        f         }nI|j        d         | j        d         k    r-t          d	                    | j        |j                            t          | |||          }|r|d
         n|S )Nr   r   r   zClast two dimensions of LU decomposition must be equal, got shape {}r   z*b matrix must have rank >= 1, got shape {}zWhen LU decomposition matrix and b have the same number of dimensions, last axis of LU decomposition matrix (shape {}) and b array (shape {}) must match.zWhen LU decomposition matrix and b different numbers of dimensions, last axis of LU decomposition matrix (shape {}) and second to last axis of b array (shape {}) must matchr   )r   r   r   r  r   r7   r  rl  )r_   rZ   r~   r   
rhs_vectorr2   s         r;   	_lu_solverp    sf   ]]Q"(2,"(2,66
 $$*F28$4$46 6 6\\A
AfQWoo' ' '
 w!&1*$* 3wr{bhrl"" M rx113 3 3 	
#s{
AAwr{bhrl"" / rx11	3 3 3
 Ra//! 	'6a'r=   c                &    t          | |||          S )zLU solve with broadcasting.)rp  )r_   rZ   r~   r   s       r;   r   r     s     
2{Au	-	--r=   c                D    t                               |           \  }}||fS )aN  Computes the QR decomposition of a matrix.

  Args:
    a: an ``[..., m, n]`` batch of matrices, with floating-point or complex type.
  Returns:
    An ``(a, taus)`` pair where ``r`` is in the upper triangle of ``a``,
    ``q`` is represented in the lower triangle of ``a`` and in ``taus`` as
    elementary Householder reflectors.
  )geqrf_pr:   )r}   a_outtauss      r;   geqrfrv    s!     Q+%	r=   c                    t          | t                    st          d| j                   | j        dk     rt          d          | j        ^ }}}|                     g |t          ||          R           }| |fS )Nz)Unsupported aval in geqrf_abstract_eval: r   1Argument to QR decomposition must have ndims >= 2rm  )	rH  r   r
  rY  r   r   r   rM  r(  )r   r   r  r6  ru  s        r;   _geqrf_abstract_evalry    s    	G[	)	) 1
 0!(0 0 1 1 1\A
H
I
IIm:q!	6
6C1II66	7	7$	$r=   c                \    | \  }|\  }t          t          j        ||d                    dfS )Nr   r  )rv  r   r   r   s       r;   _geqrf_batching_ruler{  	  s2    "!#"	x B**	+	+V	33r=   c                2    t          j         j        d                   }t          j         j        d                   }||g}t          d  j        D                       r fd j        D             }nd }t          j        d||gd|          }|j        S )Nr   r   c              3  @   K   | ]}t          |j                   V  d S rj   rt  ru  s     r;   r   z'_geqrf_lowering_rule.<locals>.<genexpr>  rw  r=   c                D    g | ]}t          j        |j                  S rk   ry  r{  s     r;   r|  z(_geqrf_lowering_rule.<locals>.<listcomp>  s8        	)#x~>>  r=   Qrr~  r  r  r  rd  )r   r   ts_typer_typer~  r  r  s   `      r;   _geqrf_lowering_ruler    s     q!122'a 011&6", 	( 	(	( 	( 	( ( (      MM
 M
y!  " 
r=   c               @   |j         \  }}|j        ^ }}}	t          ||	g          st          d|j                   t	          j        |          }
|
dk    s|dk    s|	dk    r,t          j        |d|          t          j        |d|          fS t          |j                  s|dv rt          d|j                   |.|
dk    r(||
z  dk    r|	|
z  dk    r ||j        |          \  }}n|dv r | |j        |          \  }}}n1t          j	        ||j                  } | |j        ||          \  }}}t          j        |dt          |t          j        t          j                                      }t          j        ||dd	          }t          |ddgz   t          j        t          j                            }t          j        |||t!          t#          |                    
          }t%          |||||t'          ||          |          }t          |dgz   t          j        t          j                            }t          j        |||t!          t#          |                    
          }t%          |||||t'          ||          |          }||fS )NzpShape polymorphism for native serialization for qr on CPU and GPU is implemented only for the batch dimensions: r   rQ  zkShape polymorphism for native serialization for QR is not implemented, try to upgrade jaxlib; b/261671778; r   r*  rR  r   r   r   )r   r   r   r
  ri  rj  r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
geqrf_implbatched_geqrf_implr   r}   r  r   	taus_avalr   r  r6  batchrt  ru  
info_geqrfr   r  r  select_ok_a_avalok_aselect_ok_taus_avalok_tauss                        r;   _geqrf_cpu_gpu_loweringr  #  s   m&)l:q! 
Aq6	"	" D
C4:LC CD D D )J

%
aZZ166Q!VVsAv..0CCI0V0VVV	6<	(	( N###M>DlM MN N N $qEzS7H7H5jC$$V\155KE44### *
6< ; ;eT::5c6<HHl *
6<8D!F !F !FeT:QJ@R@R(S(STTE		*eT8	<	<B":A#68J8JKK b*:6;C
OO6L6LN N ND$S$0@%Q^_bdjQkQkmsttE%jA3&68J8JKK#C-@9>s:9O9OQ Q QG#C2EtYXefiktXuXu  xA  B  BD	r=   rv  ru  c                8    t                               | |          S )a  Product of elementary Householder reflectors.

  Args:
    a: A matrix with shape ``[..., m, n]``, whose lower triangle contains
      elementary Householder reflectors.
    taus: A vector with shape ``[..., k]``, where ``k < min(m, n)``, containing
      the scalar factors of the elementary Householder reflectors.

  Returns:
    A batch of orthogonal (unitary) matrices with the same shape as ``a``,
    containing the products of the elementary Householder reflectors.
  )householder_product_pr:   )r}   ru  s     r;   householder_productr  k  s     
	#	#At	,	,,r=   c                   t          | t                    rt          |t                    st          d| j         d|j                   | j        dk     rt          d          | j        ^ }}}|j        ^ }}| j        |j        k    s||k    s|t          ||          k    rt          d| d|          ||k     rt          d| j                   | S )Nz7Unsupported aval in householder_product_abstract_eval:  r   z4Argument to Householder product must have ndims >= 2z)Type mismatch for Householder product: a=z taus=zQHouseholder product inputs must have at least as many rows as columns, got shape )	rH  r   r
  rY  r   r   r   r   r(  )r}   ru  r   r  r6  taus_batch_dimsr7  s          r;   "_householder_product_abstract_evalr  {  s
   	A{	#	# 7:dK+H+H 7
 6!"6 6*.)6 6 7 7 7VaZZ
K
L
LLg:q!
?AW
jO;;q3q!99}}
KqKKDKK
L
LLUU
 =347= = > > >	
(r=   c                    | \  }}|\  }}t          t          j        ||d          t          j        ||d                    dfS )Nr   r^  )r  r   r   )r   r   r}   ru  b_ab_tauss         r;   "_householder_product_batching_ruler    sQ    '!T,#v	X.q#q99 vq11
3 
348
9 9r=   c                    | j         \  }t          |j                  st          j        | |j                  g}nd }t          j        dt          j        |          g||gd|          }|j        gS )N(ProductOfElementaryHouseholderReflectorsr   r  )r   r   r   r   rz  r  r  ru   )r   r}   ru  rv  r  r  s         r;   "_householder_product_lowering_ruler    s    m)(	8>	*	* )#x~>>@MM M0(2234y!# # #" )r=   c                  |j         \  }}|j        ^ }}}	t          ||	g          st          d|j                   |dk    s|	dk    rt	          j        |d|          gS |dv rAt          |j                  st          d|j                    | |j        ||          \  }}
nLt	          j        ||j                  }t	          j        ||j                  } | |j        ||||          \  }}
t	          j        |dt          |t          j        t          j
                                      }t	          j        |
|dd          }t          |ddgz   t          j        t          j                            }t	          j        |||t          t          |                    	          }t!          |||||t#          ||          |          }|gS )
NzShape polymorphism for native serialization for householder_product on CPU and GPU is implemented only for the batch dimensions: r   )r  r  zlShape polymorphism for native serialization for householder_product on GPU is not implemented; b/261671778; )r   tau_shape_valsr   r   r   r   )r   r   r   r
  r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
orgqr_implr   r}   ru  r  r   r  r   r  r6  
info_orgqrr   r  r  r  select_a_avals                   r;   %_householder_product_cpu_gpu_loweringr    s   l&)l:q!	Aq6	"	" S
RCI<R RS S S !VVqAvvQ//00!!!V\** ED5;\D DE E E Jv|Q55MAzz3CFFL5c9?KKNJv|Q,8.<> > >MAz 
c1k*bhrx>P>P&Q&Q
R
R%
E4::"jAq6128BH3E3EFF-S"m27J2H2HJ J J"sBq&-PSU[B\B\^dee!
*r=   r  c               H    t          j        t          | |          \  }}||fS )Nr`   )r   r>  rc   )r   ra   rd   re   s       r;   _qr_implr    s&    		!$}	M	M	M$!Q	
A+r=   c               $   t          | t                    rt| j        dk     rt          d          | j        ^ }}}|r|nt          ||          }|                     g |||R           }|                     g |||R           }n| }| }||fS )Nr   rx  rm  )rH  r   r   r   r   r(  rM  )r   ra   r   r  r6  r7  rd   re   s           r;   _qr_abstract_evalr    s    %% 	|aJKKKZA)Aq		A0z010a0011A0z010a0011AAAA	
A+r=   c                  | \  }|\  }t                               |d          \  }}|j        ^ }}}	||	k     s|r||	k    rt          d          t	          ||          }
t          j        t          |          |
          }t          j        |d          }|t          |          z
  }t          j
        t          j        |	|j                  t          |j        dz
                      }||||j                            |j                  z
  z  z   }t          j        |||z
            |
z   }t          j        ||z
  |          }||f||ffS )NFr`   z1Unimplemented case of QR decomposition derivativer   r   r   )rc   r:   r   r
  r   r7   r?  r   r8   r
   r   r   r   r   r   r  rb  )r   r   ra   r2   dxrd   re   r   r  r6  dx_rinv
qt_dx_rinvqt_dx_rinv_lowerdoIdqdrs                    r;   qr_jvp_ruler    sE   "!#"	1E	*	*$!QW(1aUU}Ua
9; ; ;Q##'z"Q%%))*Xj"--"-..."	ocgarx000%
!8K2L2LMM!	Ajo44Z5EFFFGG"
z!R*_%%/"
z*r/1%%"
Q"b	r=   c               z    | \  }|\  }t          j        ||d          }t                              ||          dfS )Nr   r`   r  )r   r   rc   r:   )r   r   ra   r2   r   s        r;   _qr_batching_ruler    s?    "!#"2q!!!	1M	2	2F	::r=   c                  | j         ^ }}}|dk    s|dk    rp|r|nt          ||          }t          j        t          j        ||| j                  g |||R           }t          j        g |||R | j                  }||fS t          |           \  }}||k     rt          |dd |d |f         |          }nz|rYdgt          |          dz   z  d||z
  dfgz   }	t          j        |t          j        |          |	          }t          ||          }nt          ||          }|dd |d |f         }t          j        |          }||fS )Nr   r   .r<  r   )r   r(  r7   r   r   r   emptyrv  r  r   r
   r>  r   _zeror  )
r}   ra   r   r  r6  r7  rd   re   ru  padss
             r;   _qr_loweringr    sw   g:q!!VVqAvv)Aq		AAQW5557J7JQ7J7J7JKKA	%J%%1%%QW555Aa4K!HH'!TUUAc2A2rrkND11AA ;#j//A-.1a!eQ-@D<%a(($//AAt$$AAAt$$A	#rr2A2+A	hqkk!	
A+r=   rf   )rG   c               >    t          j        t          | |||          S )Nrp   )r   r>  rt   )r   ra   rg   rG   s       r;   	_svd_implr  %  s+    		!!%
 
 
 r=   c                  t          | t                    r| j        d d         }| j        d         }| j        d         }t          ||          }|8|r|d|fk    rt	          d          t          ||d         |d         z
            }|                     ||fz   t          j        | j                            }|rC|                     |||r|n|fz             }	|                     ||r|n||fz             }
||	|
fS |fS t          )Nr   r   r   z4full_matrices and subset_by_index cannot both be setr   rG  rm  )
rH  r   r   r(  r   rM  r   ro  r   r
  )r   ra   rg   rG   r   r  r6  rankrv   rw   vts              r;   _svd_abstract_evalr  /  s3   %% ss#JbAbAq!99D"	 Q?q$i77OPPPq)OA,>>??dD7",W];; 	 	 	A  
..zQ]0L,MM.
N
Na>>
=.JaadA-N N>OOb2XoRi
r=   r  c                  | \  }|\  }t                               |dd|          \  }}}	|r|rt          d          t          |          t          |	          }}
|dd d d f         }|
|z  |z  }t	          j        t          j        |ddd                    }|s|f|ffS |t          |          z   |t          |          z
  z  }t          j	        |j
        d         |j        	          }t          j        |t          |j        d
z
                      }d||z   z  |z
  }|                    |j                  |z  }t          |                    |j                            |z  }|dk                        |j                  }d||z   z  |z
  } t          j        t          j        d          |          }d|t          |          z
  z  |                    |j                  z  }||                    |j                  |t          |          z   z  |z   z  }||                    |j                  |t          |          z   z  z  }|j
        dd          \  }}||k    r.||z  }||||
|z  z  z
  |                    |j                  z  z   }||k    r;t          |          |z  }||||	|z  z  z
  |                    |j                  z  z   }|||	f||t          |          ffS )NFTrp   zBSingular value decomposition JVP not implemented for full matrices.r   r   r   r   r   r   z
(k)->(k,k)r   g      ?)rt   r:   r
  r   r+   r  r7   r  r   r   r   r   r
   r   r   r   rb  r,   diag)r   r   ra   rg   rG   AdArv   UVtUtVs_dimdSdss_diffss_diffs_zerosFdSSSdSs_zeross_inv	s_inv_mat	dUdV_diagdUdVr  r6  dAVdAHUs                                 r;   _svd_jvp_ruler  H  s    "!#"ZZu   (!Q  LM L
JL L L Q%%Ba"
CqqqL/%	Bw{"{3<Ar2..//"	 4";RYY52e99#45''!'"+QW555-/-w|a7G1H1HII-7]"#m3!QW"#
5<<  !!B&#!VOOAG$$'
q7{
g
%%=cmCH===eDD)BBK 9#3#3AG#<#<<)AHHQWr#ww/);<"AHHQWr#ww/0"	
$!QUU
q&C	sQ"s(^#u||AG'<'<<	<BUUb66A:D	ta29o%ag)>)>>	>B
Qb"bff%	%%r=   c                  | j         d d         }| j         dd          \  }}t          j        |dz   t          j        | j                            }|s|fS |rDt          ||          }t          j        t          j        || j                  |||fz             }n t          j        |||fz   | j                  }t          j        |dz   | j                  }	||k     r|	|}	}|||	fS )Nr   r^  r   r  )	r   r7   r  r   ro  r   r   r   r   )
r}   ra   rg   batch_shaper  r6  rv   r  rw   rM   s
             r;   
_empty_svdr  x  s    +	
$!Q	id",*H*Q*QRRR!	 4K 7q!99DQW555{dD\7QRRAA	+A&ag666A	if$AG444!UUaqA	
Aq.r=   c               l   |j         \  }|j        d         }|j        dd          \  }	}
t          |	|
g          st	          d|j                   |j        d d         }|%|dt          |	|
          fk    st	          d          |	dk    s|
dk    r( t          j        t          d          ||||          S |dv rEt          |j                  st	          d	|j                    | |j	        |||          \  }}}}n4t          j
        ||j                  } | |j	        ||||
          \  }}}}t          j        |dt          |t          j	        t          j                                      }t          j        ||dd          }t          |dz   t          j	        t          j                            }t#          |t          j        |||t'          t)          |                              |||t+          ||          |          }|g}|r|j        dd          \  }}t          |dz   t          j	        t          j                            }t#          |t          j        |||t'          t)          |                              |||t+          ||          |          }t          |dz   t          j	        t          j                            }t#          |t          j        |||t'          t)          |                              |||t+          ||          |          }|||gz  }|S )Nr   r   zqShape polymorphism for native serialization for svd on CPU and GPU is implemented only for the batch dimensions: r  Tr;  ra   rg   rQ  zlShape polymorphism for native serialization for SVD is not implemented, try to upgrade jaxlib; b/261671778; )ra   rg   r   r   r   r   r   r   r   )r   r   r   r   r
  r(  r   rX  r  r   r   r   r   r   r   r   r   r   r   r   r   r   )
gesvd_implr   r   ra   rg   rG   r  r   s_avalr  r6  r   rv   rw   r  r   r   r  r  select_s_avalru   u_avalvt_avalselect_u_avalr  s                            r;   _svd_cpu_gpu_loweringr    s    ,-,=&		BCC	 $!Q 
Aq6	"	" J
I4@4FI IJ J J !#2#&*

!_C1II%F%F
O
P
PP!VVqAvv<4>*t<<<#	    !!!\/00 TS>J>PS ST T T  Z 2G.;+57 7 7NAq"dd 3C9KLLLZ 2G.;+5-9; ; ;NAq"d 
c1k*bhrx>P>P&Q&Q
R
R%eT844"j4/"(1C1CDD-	
C]16s:1G1GI I IsF++V5 5! 3& mABB'OFG
V 3RXbh5G5GHHM c2}38Z3I3I	K 	K 	K	6=f--v	7 	7A  
V 3RXbh5G5GHHM	!c2}38Z3I3I	K 	K 	K
G]300'
; 
;B q"gF	-r=   c                  | j         d d         }t          t          j        |||          }t	          t          |                    D ]}t          j        |          }|r ||           \  }}}	|||	gS  ||           }|gS )Nr   rp   )r   r   lax_svdr   r   r   r   r   )
r}   ra   rg   rG   r   r4  r   rw   rv   vhs
             r;   _svd_tpur    s    wss|*k!%	  " Z!!  a	"BB r!uuHAq"q":
1A3Jr=   c                   | j         \  }|j        dd          \  }}|dk    s|dk    r( t          j        t          d          | |||          S  t          j        t
          d          | ||||          S )Nr   r   Tr;  r  rp   )r   r   r   rX  r  r  )r   r   ra   rg   rG   r   r  r6  s           r;   _svd_tpu_lowering_ruler    s     ,-,		BCC	 $!Q!VVqAvv<4>*t<<<#	    
94	8	8	8	!%
 
 
 r=   c                   | \  }|\  }t          j        ||d          }t                              ||||          }|r|dfS |dfS )Nr   rp   r<  r^  )r   r   rt   r:   )r   r   ra   rg   rG   r2   r   outss           r;   _svd_batching_ruler    sh     "!#"2q!!!	!%	 
 
 
$  ?:r=   r   c                   |j         \  }
}
}
}t          j        ||j                  } | |||||||t	          j        |	          |	  	        gS )N)r  r6  ldbr  r  )r   r   r   r   r   r  )r  r   dlr  dur~   r  r6  r  r  r   r  r  s                r;   _tridiagonal_solve_gpu_loweringr  -  sb    L/!Q61#v|DD,
(!Ra1#)B1)E)E! ! ! 
" "r=   c               H   ~~~~t          j        |          s<t          j        |          s(t          j        |          st          j        |          sJ t          |           t          j        u rt          j        |j                  }	nt          ||||           }	d d d |	gS rj   )r   r  r  r   r  rY  tridiagonal_solve)
r  r  r  r  r~   r  r6  r  r  r  s
             r;   !_tridiagonal_solve_transpose_ruler  5  s    C $R(( HB,B1,E,E H$R((H.0.DQ.G.GH H H	)__$$,qv&&KK#B2y99K
dK	((r=   c                  ~~~~| \  }}}}	|\  }
}}}|
t           j        u r|t           j        u r|t           j        u rt          j        |	|d          }	|	                    |	j        d d         |	j        d         |	j        d         |	j        d         z  fz             }|	j        dz
  }t          ||||          }|                    |	j                  |fS t          d t          | |          D                       }t          j	        ||
|          }t          j	        |||          }t          j	        |||          }t          j	        |	||          }	t          ||||	          dfS )Nr   r  r   r   c              3  :   K   | ]\  }}||j         |         V  d S rj   rm  r  s      r;   r   z3_tridiagonal_solve_batching_rule.<locals>.<genexpr>Q  r  r=   r   )
r   r  r   r  r   r   r  r  r   r  )r   r   r  r6  r  r  r  r  r  r~   bdlr   bdubbb_flatr  r  r  s                     r;    _tridiagonal_solve_batching_ruler  B  sv   C,"aQ#r3	X   H	X   !R$$AYYqwss|QWR[172;5N'OOPPFvzH QF33HAG$$h.. " "s<'D'D " " " " "D		C	.	.Bq"d++A		C	.	.Bq"d++ARB**A--r=   r  c                   |S rj   rk   )r  r  r  r~   r  r6  r  r  s           r;   r   r   ^  s    A r=   c           	        d }d d d d t          j        | dd          } t          j        |dd          }t          j        |dd          }t          j        |dd          }t          j        |dd          }t          j        fd|d         |d         z  ||| fd	
          \  }}t          j        fd|d         |dd         z  || ||          | fd	
          \  }}t          j        fd|d         |ddd         |ddd         fd	
          \  }}	|	ddd         }
t          j        |
dd          }
t          j        |
dd          }
|
S )z/Pure JAX implementation of `tridiagonal_solve`.c                    t          j        t          j        d| j        dd          z   | j                  | d d         d          S )Nr   r   r   r   r   )axis)r7   rN  r  r   r   r   s    r;   prepend_zeroz,_tridiagonal_solve_jax.<locals>.prepend_zerop  sK    :	$$AG444	#2#Q   r=   c                <    |d         |d         |d         | z  z
  z  S )Nr   r   r   rk   )tu_r2   s     r;   r   z(_tridiagonal_solve_jax.<locals>.<lambda>t  s     !!qtcz 12 r=   c                    |d         |d         t           j        df         | z  z
  |d         |d         |d         z  z
  t           j        df         z  S )Nr   rf  .r   r   r7   r  )b_r2   s     r;   fwd2z$_tridiagonal_solve_jax.<locals>.fwd2v  sS    aD1Q4S()B..	!qtad{CK,3. . .r=   c                N    |d         |d         t           j        df         | z  z
  S )Nr   r   .r  )x_r2   s     r;   r   z(_tridiagonal_solve_jax.<locals>.<lambda>z  s$    qtad3;#34r99 r=   c                     | |  | | fS rj   rk   )frB  s     r;   r   z(_tridiagonal_solve_jax.<locals>.<lambda>{  s    AAtHaah/ r=   r   r   c                      | |f          S rj   rk   )r  r2   doublefwd1s     r;   r   z(_tridiagonal_solve_jax.<locals>.<lambda>  s    66$a#9#9 r=   rF  )unrollc                      | |f          S rj   rk   )r  r2   r  r  s     r;   r   z(_tridiagonal_solve_jax.<locals>.<lambda>      r1g!6!6 r=   r   c                      | |f          S rj   rk   )r  r2   bwd1r  s     r;   r   z(_tridiagonal_solve_jax.<locals>.<lambda>  r  r=   N)r7   r   r
   scan)r  r  r  r~   rC  r  r   r  r  r  ru   r  r  r  r  s              @@@@r;   _tridiagonal_solve_jaxr  n  s      
3	2$. . . 
:	9$//& |BA"	l1b!!
|BA"	l1b!!	l1b!! 899999qEAaDLBK  &!S
 (66666Q4!AaC&=q,,s++R0  %!R (66666b6tttHc$$B$i(  %!R
 ddd8&<2&&&<2&&&	-r=   r  r  r  c                   | j         |j         k    s|j         |j         k    r(t          d| j          d|j          d|j          d          | j         d         }|dk     rt          d| d          |j         d	         }|j         d         }|t          d
|          k     rt          d| d| d          | j        |j        k    s |j        |j        k    s|j        |j        k    r0t          d| j         d|j         d|j         d|j         d	          | j        }|t          j        t          j        fvrt          d|           t                              | |||||||          S )a  Computes the solution of a tridiagonal linear system.

  This function computes the solution of a tridiagonal linear system:

  .. math::
    A . X = B

  Args:

    dl: A batch of vectors with shape ``[..., m]``.
      The lower diagonal of A: ``dl[i] := A[i, i-1]`` for i in ``[0,m)``.
      Note that ``dl[0] = 0``.
    d: A batch of vectors with shape ``[..., m]``.
      The middle diagonal of A: ``d[i]  := A[i, i]`` for i in ``[0,m)``.
    du: A batch of vectors with shape ``[..., m]``.
      The upper diagonal of A: ``du[i] := A[i, i+1]`` for i in ``[0,m)``.
      Note that ``dl[m - 1] = 0``.
    b: Right hand side matrix.

  Returns:
    Solution ``X`` of tridiagonal system.
  zdl=z, d=z and du=z must all be `[m]`r   rf  zm (z) must be >= 3r   r   zLeading dimension of b=u    must be ≥ max(1, )z, du=r   z must be the same dtype,z Only f32/f64 are supported, got )r  r6  r  r  )	r   r   r   r   r   r  r	  tridiagonal_solve_pr:   )r  r  r  r~   r  r  r6  r  s           r;   r  r    s   . XAGrx//
IbhIIAGIIRXIIIK K K 	hrl!UU
,1,,,
-
--	#gbk!3q!99__
LsLLLLL
M
MMXAGrx//28qw3F3F
 <28 < < < <rx < <'< < < = = = 	h!rz2:&&&
;;;
<
<<		!	!"aQ!qcQ	!	G	GGr=   compute_schur_vectorssort_eig_valsselect_callabler  r  r  Callable[..., Any] | Nonec               >    t                               | |||          S Nr  )schur_pr:   )r2   r  r  r  s       r;   schurr    s+     
1!%	 
 
' 
' 'r=   c               >    t          j        t          | |||          S r  )r   r>  r  )r   r  r  r  s       r;   _schur_implr!    s+    		!1!%
' 
' 
' 'r=   c                     t          d          )Nz;Schur decomposition is only implemented on the CPU backend.rA  )r   rB  kwargss      r;   _schur_loweringr$    s    C	E 	E Er=   c                  | j         dk     s| j        d         | j        d         k    r't          d                    | j                            | j        d d         }| j        d         }| j        }t          j        |          }|                     |||fz   |          }|                     |||fz   |          }|r||fn|fS )Nr   r   r   zIArgument to Schur decomposition must have shape [..., n, n], got shape {}rG  )r   r   r   r  r   r   r  rM  )	r   r  r  r  r   r6  r   Tvss	            r;   _schur_abstract_evalr(    s     \Ar*gmB.???
 77=vgm7L7LN N N }SbS!*mB!
-%

#E
*
*%nn:A.en<<!~~J!Q/u~==")	3!Rt3r=   c                   | j         \  }|j        d d         }t          j        | |j                  }t	          j        |j        |||||          }|^}	}
}}t          j        |t          j        | dt          |t          j        t          j                                      dd          }t          |dz   t          j        t          j                            }t          | t          j        | ||t          t!          |                              ||	| j        d         t%          | | j        d                   | j        d                   }	|	g}|rt          |dz   t          j        t          j                            }t          | t          j        | ||t          t!          |                              ||
| j        d         t%          | | j        d                   | j        d                   }
|                    |
           |S )	Nr   )jobvssortr  r   r   r   r   r   r   r   )r   r   r   r   r#   gees_hlor   r   r   r   r   r   r   r   r   r   r   r   r   rN  )r   r   r  r  r  r   r   r   gees_resultr&  r'  r   r   r  select_T_avalrQ  select_vs_avals                    r;   _schur_cpu_loweringr0    s   ,-,!#2#&*1#|7IJJ, 2G&;%2'6-9	; ; ;+  /!R!T
DQJ@R@R(S(STT
H " j6128BH3E3EFF-	
C]16s:1G1GI I Iq	-S]1-=>>a@PR R! 3& 	 f!4bhrx6H6HIIN	!c2~38Z3I3I	K 	K 	K
CM!mCq1ABBCMRSDT
V 
VB MM"	-r=   c                   | \  }|\  }t          j        ||d          }t                              ||||          dd|z   z  fS )Nr   r  r^  r   )r   r   r  r:   )r   r   r  r  r  r2   r   s          r;   _schur_batching_ruler2  "	  sb    "!#"2q!!!	1!%	 
 
' 
' )-4I0I(J	
K Kr=   c                     t          d          )NzPThe differentiation rules for the Schur factorization have not been implemented.rA  )r   r   kwdss      r;   _schur_jvp_ruler5  /	  s    X	 	 r=   r  c                6    t                               |           S )a  Reduces a square matrix to upper Hessenberg form.

  Currently implemented on CPU only.

  Args:
    a: A floating point or complex square matrix or batch of matrices.

  Returns:
  A ``(a, taus)`` pair, where the upper triangle and first subdiagonal of ``a``
  contain the upper Hessenberg matrix, and the elements below the first
  subdiagonal contain the Householder reflectors. For each Householder
  reflector ``taus`` contains the scalar factors of the elementary Householder
  reflectors.
  )hessenberg_pr:   r}   s    r;   
hessenbergr9  A	  s     
		1		r=   c                   | j         t          j        t          j        t          j        t          j        fvrt          d| j          d          | j        dk     rt          d| j         d          | j        d         | j        d         k    rt          d| j         d          | t          | j        d d         | j        d         dz
  fz   | j                   gS )	NzRhessenberg requires a.dtype to be float32, float64, complex64, or complex128, got .r   z1hessenberg requires a.ndim to be at least 2, got r   r   zUhessenberg requires the last two dimensions of a to be equal in size, got a.shape of r   )
r   r7   r  r	  rK  rL  r  r   r   r   r8  s    r;   _hessenberg_abstract_evalr<  R	  s   WS[#+s}cnMMM
 @56W@ @ @ A A AVaZZ
 !v! ! ! " " "WR[AGBK
 @56W@ @ @ A A A
["q(::AGDD	EEr=   r9  c                `    | \  }|\  }t          j        ||d          }t          |          dfS r   )r   r   r9  r   s       r;   _hessenberg_batching_ruler>  c	  s5    "!#"2q!!!	A	r=   c                   | j         \  }|j        d d         }t          j        |j        |          \  }}}t          j        |t          j        | dt          |t          j        t          j
                                      dd          }t          |dz   t          j        t          j                            }t          |dz   t          j        t          j                            }t          | t          j        | ||t          t          |                              ||| j        d         t#          | | j        d                   | j        d                   t          | t          j        | ||t          t          |                              ||| j        d         t#          | | j        d                   | j        d                   gS )	Nr   r   r   r   r   r   r   r   )r   r   r#   	gehrd_hlor   r   r   r   r   r   r   r   r   r   r   r   r   r   )	r   r}   r   r   ru  r   r  r  select_taus_avals	            r;   _hessenberg_cpu_hlorB  k	  s   L'&|CRC *"6<33-!T4
DQJ@R@R(S(STT
H " j6128BH3E3EFF- d!2BHRX4F4FGG	
C]16s:1G1GI I Iq	=cmA.>??qAQS S 	
C%516s:1G1GI I I
CM!mCq1ABBCMRSDTV V
 r=   r   !tuple[Array, Array, Array, Array]c                  t                               t          j        |           |          \  }}}}}|j                            t          j                  }t          j        |j        t          j	                  r*||j                            t          j        dz            z   }t          j
        |dk    d         ||          }t          j        |j                  j        j        }t          j
        |dk    d         | |t          j                            }t          j
        |dk    d         | |t          j                            }t          j
        |dk    d         ||          }||||fS )a+  Reduces a symmetric/Hermitian matrix to tridiagonal form.

  Currently implemented on CPU and GPU only.

  Args:
    a: A floating point or complex matrix or batch of matrices.
    lower: Describes which triangle of the input matrices to use.
      The other triangle is ignored and not accessed.

  Returns:
  A ``(a, d, e, taus)`` pair. If ``lower=True``, the diagonal and first subdiagonal of
  matrix (or batch of matrices) ``a`` contain the tridiagonal representation,
  and elements below the first subdiagonal contain the elementary Householder
  reflectors, where additionally ``d`` contains the diagonal of the matrix and ``e`` contains
  the first subdiagonal.If ``lower=False`` the diagonal and first superdiagonal of the
  matrix contains the tridiagonal representation, and elements above the first
  superdiagonal contain the elementary Householder reflectors, where
  additionally ``d`` contains the diagonal of the matrix and ``e`` contains the
  first superdiagonal. ``taus`` contains the scalar factors of the elementary
  Householder reflectors.
  r                 ?r   ).NN).N)tridiagonal_pr:   r7   asarrayr   r  nanr   r   r   r  rI  )	r}   rE   arrr  eru  r   rH  	real_types	            r;   tridiagonalrL  	  s(   . (,,S[^^5,II#q!T4	sw#^CIr122 -
	sw|,,
,C	419o.S99#i	""(-)	iI&99SW+=+=>>!	iI&99SW+=+=>>!	DAIy)4	5	5$	aDr=   c          	     B   | j         t          j        t          j        t          j        t          j        fvrt          d| j          d          | j        dk     rt          d| j         d          | j        d         | j        d         k    rt          d| j         d          | j        d         dk    rt          d	| j         d          t          j	        | j                   j         }| t          | j        d d         | j        d         fz   |          t          | j        d d         | j        d         d
z
  fz   |          t          | j        d d         | j        d         d
z
  fz   | j                   t          | j        d d         t          j                  gS )NzStridiagonal requires a.dtype to be float32, float64, complex64, or complex128, got r;  r   z2tridiagonal requires a.ndim to be at least 2, got r   r   zVtridiagonal requires the last two dimensions of a to be equal in size, got a.shape of r   zQtridiagonal requires the last two dimensions of a to be non-zero, got a.shape of r   )r   r7   r  r	  rK  rL  r  r   r   rI  r   r   r   )r}   rE   
real_dtypes      r;   _tridiagonal_abstract_evalrO  	  s   WS[#+s}cnMMM
 @56W@ @ @ A A AVaZZ
 !v! ! ! " " "WR[AGBK
 @56W@ @ @ A A AWR[A
 ;01; ; ; < < <y!!'*!'#2#,!'"+/<<!'#2#,!'"+/!33Z@@!'#2#,!'"+/!33QW==!'#2#,))
 r=   rL  c               `    | \  }|\  }t          j        ||d          }t          |          dfS r   )r   r   rL  )r   r   rE   r2   r   s        r;   _tridiagonal_batching_rulerQ  	  s5    "!#"2q!!!	Q	r=   c               T    |j         \  } | |j        ||          \  }}}}}|||||fS )Nr   )r   r   )	
sytrd_implr   r}   rE   r   r  rJ  ru  r   s	            r;   _tridiagonal_cpu_gpu_hlorT  	  s?    L'&"
6<%@@@!Q4	
Aq$	r=   r   mlir.LoweringRuleContextir.Valuec                    t          j        |j        t          j                  r0t          j        | t          j        t          j        dz  z   |          S t          j        | t          j        |          S )NrE  )r7   r   r   r   r   r   r   rH  )r   rY  s     r;   r   r   	  sT    ^DJ 233 2sBFRVb[$8$???sBFD111r=   c           	     "   t          t          j        t          |j                  t          |j                  t          |j                                      }t          j        | |||f|||f|          \  }}}t          j        |||          S )z:Wrapper around XLA `Select` that broadcasts its arguments.)	r  r   broadcast_shapesr   r   r   multi_broadcast_in_dimr(   r  )r   which
which_avalr2   x_avalr  y_aval
out_shapess           r;   r   r   	  s    L1JuV\22E&,4G4GI I J J*+C%A-7,H,68 8+%A 
E1a	 	  r=   )r2   r-   r1   r3   r4   r-   )r2   r.   r?   r3   r@   r3   r4   rA   )r2   r-   rE   r3   r1   r3   rF   r3   rG   rH   r4   rI   )rO   r.   rP   r.   r4   r-   )rT   r.   rU   rV   r4   r-   )r2   r.   r4   r\   )r2   r.   ra   r3   r4   rI   )
r2   r.   ra   r3   rg   rh   rG   rH   r4   r\   )
r2   r.   ra   r3   rg   rn   rG   rH   r4   r-   )
r2   r.   ra   r3   rg   r3   rG   rH   r4   rq   )r}   r.   r~   r.   ry   r3   rE   r3   rz   r3   r{   r3   r|   r3   r4   r-   )r}   r-   r~   r-   r4   r-   )r}   r-   r~   r-   )r2   r-   r4   r-   )r2   r.   rE   r3   rF   r3   r4   rI   )r*  )r  rO  )
r_   r-   rZ   r-   r~   r-   r   rV   r4   r-   r^  )
r_   r.   rZ   r.   r~   r.   r   rV   r4   r-   )r}   r.   r4   rI   )r}   r.   ru  r.   r4   r-   )
r  r-   r  r-   r  r-   r~   r-   r4   r-   )
r2   r.   r  r3   r  r3   r  r  r4   rI   )r}   r.   r4   rC  )r   rU  r4   rV  )r4   rV  )
__future__r   collections.abcr   	functoolsr   ri  typingr   r   r   r	   r  r   r  r
   jax._srcr   r   r   r   jax._src.corer   r   r   r   r   jax._src.interpretersr   r   r   jax._src.laxr   r   r  r   r   r  jax._src.lax.laxr   r   r   r   r   r   jax._src.libr    r!   r"   r#   r$   r   r%   jax._src.lib.mlirr&   jax._src.lib.mlir.dialectsr'   r(   jax._src.numpyr)   r7   r*   r+   jax._src.numpy.vectorizer,   jax._src.typingr-   r.   opsxopsr/   r<   rD   rS   r[   r_   rf   r   r   r   r   r   r   r6   r   r  r	  rK  rL  r  r   r   r9   primitive_jvpsprimitive_batchersr   register_loweringr  r  r  r:  rR   r<  def_abstract_evaldef_implr>  rX  r?  rD  rR  r\  r_  rd  rC   rh  rj  rp  r  rg  r  r  r  r  r  r  rL   	syevd_hlo
cuda_syevd
rocm_syevd_triangular_solve_dtype_ruler  r  r  r  r   defjvp2primitive_transposesr  r  r  r  r  r  r  rY   cuda_lu_pivots_to_permutationhip_lu_pivots_to_permutationr)  r2  r5  r7  r9  rL  rN  r_  re  r^   	getrf_hlo
cuda_getrf
rocm_getrfrl  jitrp  r   rv  ry  r{  r  r  rs  	geqrf_hlo
cuda_geqrfcuda_geqrf_batched
rocm_geqrfrocm_geqrf_batchedr  r  r  r  r  r  	orgqr_hlo
cuda_orgqr
rocm_orgqrr  r  r  r  r  rc   r  r  default_matmul_precisionr  r  r  r  r  r  rt   	gesdd_hlo
cuda_gesvd
rocm_gesvdr  r  r  r  
cuda_gtsv2
rocm_gtsv2r  r  r  r!  r$  r(  r0  r2  r5  r  r9  r<  r7  r>  rB  rL  rO  rF  rQ  rT  	sytrd_hlo
cuda_sytrd
rocm_sytrdr   r   rk   r=   r;   <module>r     sd   # " " " " " $ $ $ $ $ $            2 2 2 2 2 2 2 2 2 2 2 2     



                              Q Q Q Q Q Q Q Q Q Q Q Q Q Q $ $ $ $ $ $ * * * * * * & & & & & & % % % % % % ) ) ) ) ) ) , , , , , , ' ' ' ' ' '                $ # # # # # # # # # # # # # # # # #       2 2 2 2 2 2 # # # # # #             + + + + + + * * * * * * + + + + + + % % % % % % ! ! ! ! ! ! . . . . . . , , , , , , , ,~wvXc3h/000 48 & & & & & &< <@+/K K K K K K8 !!.22 2 2 2 2 2j4 4 4 4   $! ! ! !D /3      > 
 .2     
 
 .2     
 
 .2     
 .2     8 (-E).E+0/ / / / / /f 	.///8 8 8 0/8I I I IJ J J J0 : 9 9 9 4 4 4 4 9 9 9 9 RXbj))828BJ+?+?RXbl++XRXbm-D-DF 
  &   ]6H,j99
 2 * *A J '8 8 8  z#5 6 6 6A A A2  &8 8 8 8
5 5 5/ / /   < I/00 %*  "  # #$B C C C   778#;=NOO P P P  :VM M M M  DN*UCCCE E E  N N N
  0- - -`O O OJ J J 		%  x      ) * * *  ui ( ( (  u/% @ @ @ @%6 E "' %  04)-       
  " &  &  &D 	-((!%    ( ) ) )    : ; ; ;  }&@ A A A    0( ( (V/ / /d% % %P   
6		  
      , - - -* & &9 F #  
GG*F,<==    $
GG*J,ABB    $
GG*J,ABB     
NDN>DAAA   
  'w|fx&7(9J%K     5:     *& & &B   < < <8 (' ">   
'FFH H H /O * +2Q . /) ) )  )+E F F FD D D6  )+F %' ' ' '4 4 4  4  */ / /= = =
 'Y'ABB .3  +  # #GH$&@AAC C C  , ,+- - - , 	 6 7  DN4uMMMO O O  G246 6	   
  G235 5	   != != !=H   .       .K .K .Kb! ! !) ) ) )X  & y  h      ( ) ) )  t^T^JNNN O O O& $ $5 D !  t 4f6F).0 0 0!&( ( ( (
  ''&
(=!# # #     ''&
(=!# # #   
  t2U C C C C 	aS,DEEE! ! ! FE!& 	&&&( ( ( '&(< . . . . .     4 4 4
  *+ + + +Z )G

    17;; < < <   . / / /'; G $  w 4 5 5 5  WW,f.>#% % %     G#Z%:)        G#Z%:)      - - - -   9 9 9     D "	"788    wwx'?AVWW X X X  ' '(J K K K5W 1 2  ,.P Q Q Q  G163C  	   
  G1:3H  	   
  G1:3H  	         (; ; ;  , y  h      ( ) ) )% $ $5 D !  t^T^L99 : : : FJ       2 i((,& ,& )(,&^  "L L L L^  (  .  & 		%  y      * + + +( % %7 E "  	77(&*:!# # #     &
(= 
" 
" 
"     &
(= 
" 
" 
"   
  u4 5 5 5" " "
) 
) 
). . .0  i 344 ',  $   Ih.0CDDF F F  % %&M&M N N N/P + ,3S / 0  G+Z-BCC     G+Z-BCC   * * *Z  *NDNU-4 -4 -4 5 5 5,H ,H ,H ,Hf )- %7;' ' ' ' ' '' ' 'E E E4 4 4 & & &R
K 
K 
K   )G

          . / / /  w 0 0 0  w 3e D D D D'; G $, ' 
   "
F 
F 
F y&&   ggh6EE F F F   8 9 9 9 $    -F L )  0  |%85 I I I I
 (,            D  , 	-((   wwx7GG H H H    : ; ; ;!%    .H M *  
  773V5EFF     773Z5JKK     773Z5JKK   2 2 2 2! ! ! ! ! !r=   