o
    i e#                     @   sl  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ eejdd Zeejdd Zee
jdd Zeejdd Zeejdd Zeejdd Zeejdd Zeejdd Z ee	j!dd  Z"eej#d!d" Z$d#S )$z)Registrations for LinearOperator.inverse.    )math_ops)linear_operator)linear_operator_addition)linear_operator_algebra)linear_operator_block_diag)&linear_operator_block_lower_triangular)linear_operator_circulant)linear_operator_diag)linear_operator_full_matrix)linear_operator_householder)linear_operator_identity)linear_operator_inversion)linear_operator_kroneckerc                 C   s   t j| | j| j| j| jdS )Nis_non_singularis_self_adjointis_positive_definite	is_square)r   LinearOperatorInversionr   r   r   r   )linop r   a/var/www/myenv/lib/python3.10/site-packages/tensorflow/python/ops/linalg/inverse_registrations.py_inverse_linear_operator"   s   r   c                 C   s   | j S N)operator)linop_inversionr   r   r    _inverse_inverse_linear_operator,   s   r   c                 C   s    t jd| j | j| j| jddS )N      ?Tr   )r	   LinearOperatorDiagdiagr   r   r   )diag_operatorr   r   r   _inverse_diag2   s   r!   c                 C      | S r   r   identity_operatorr   r   r   _inverse_identity=      r%   c                 C   s"   t j| jd| j | jd| jddS )Nr   T)num_rows
multiplierr   r   r   r   )r   LinearOperatorScaledIdentity	_num_rowsr(   r   r   r#   r   r   r   _inverse_scaled_identityC   s   r+   c                 C   &   t jdd | jD | j| j| jddS )Nc                 S      g | ]}|  qS r   inverse.0r   r   r   r   
<listcomp>T       z'_inverse_block_diag.<locals>.<listcomp>T	operatorsr   r   r   r   )r   LinearOperatorBlockDiagr5   r   r   r   )block_diag_operatorr   r   r   _inverse_block_diagO   s   r8   c                    sn  t | jdkrtj| jd d  gg| j| j| jddS t | j}t| jdd  }| jd }|d  }g }t|d D ]_}g }t||d D ]&}|| 	|j| |  t
 fddtjD smt   |  qLt|}	t |	dksJ |	d }
|	|
}
tj| tjd|
jd	d
	|
}
||
 qA|| tj|j|g | j| j| jddS )a  Inverse of LinearOperatorBlockLowerTriangular.

  We recursively apply the identity:

  ```none
  |A 0|'  =  |    A'  0|
  |B C|      |-C'BA' C'|
  ```

  where `A` is n-by-n, `B` is m-by-n, `C` is m-by-m, and `'` denotes inverse.

  This identity can be verified through multiplication:

  ```none
  |A 0||    A'  0|
  |B C||-C'BA' C'|

    = |       AA'   0|
      |BA'-CC'BA' CC'|

    = |I 0|
      |0 I|
  ```

  Args:
    block_lower_triangular_operator: Instance of
      `LinearOperatorBlockLowerTriangular`.

  Returns:
    block_lower_triangular_operator_inverse: Instance of
      `LinearOperatorBlockLowerTriangular`, the inverse of
      `block_lower_triangular_operator`.
     r   Tr   Nc                 3   s    | ]}t  |V  qd S r   )
isinstance)r1   op_typeresultr   r   	<genexpr>   s    z2_inverse_block_lower_triangular.<locals>.<genexpr>)dtype)r'   r(   )lenr5   r   "LinearOperatorBlockLowerTriangularr/   r   r   r   rangematmulanyr   SUPPORTED_OPERATORSr
   LinearOperatorFullMatrixto_denseappendadd_operatorsr   r)   domain_dimension_tensorr   castr@   )block_lower_triangular_operatorblockwise_dimupper_left_inverse
bottom_rowbottom_right_inverseinverse_bottom_rowiblocksjsummed_blocksblockr   r=   r   _inverse_block_lower_triangular\   sf   $
	




rX   c                 C   r,   )Nc                 S   r-   r   r.   r0   r   r   r   r2      r3   z&_inverse_kronecker.<locals>.<listcomp>Tr4   )r   LinearOperatorKroneckerr5   r   r   r   )kronecker_operatorr   r   r   _inverse_kronecker   s   r[   c                 C   s$   | j d| j | j| j| jd| jdS )Nr   T)spectrumr   r   r   r   input_output_dtype)	__class__r\   r   r   r   r@   )circulant_operatorr   r   r   _inverse_circulant   s   r`   c                 C   r"   r   r   )householder_operatorr   r   r   _inverse_householder   r&   rb   N)%__doc__tensorflow.python.opsr   tensorflow.python.ops.linalgr   r   r   r   r   r   r	   r
   r   r   r   r   RegisterInverseLinearOperatorr   r   r   r   r!   LinearOperatorIdentityr%   r)   r+   r6   r8   rB   rX   rY   r[   _BaseLinearOperatorCirculantr`   LinearOperatorHouseholderrb   r   r   r   r   <module>   sh   

	

	




a

