
    bi"                        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
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej8                  eej:                  eej<                  eej>                  eej@                  eejB                  eejD                  eiZ#ej8                  eej:                  eej>                  eiZ$d Z%d Z&y)a+  
Copyright, the CVXPY authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    )atoms)binary_operators)diag_vec)promote)	upper_tri)PSD)	Parameter)Variablec                 n    | j                   d   | j                  | j                  fd}|gS )Nr   c                  "   j                   dkD  ryj                   dz  } d| dz  z
  t        j                        z  t        j                  d| z  z
  z        z
  t        j                        z   | t        j                        z  z
  dk  S )N   F   r   )valuer   sum_squaresmatmul)tsqabtxs    Y/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/reductions/dqcp2dcp/sets.pysublevel_setz$dist_ratio_sub.<locals>.sublevel_set$   s    77Q;ggqj365,,Q//Q#a%[!,-/4/@/@/CDE%%a(()-./ 	/    )argsr   r   )exprr   r   r   r   r   s    ` @@@r   dist_ratio_subr      s1    		!AAA/ >r   c                 *   | j                   \  }}|j                         r,|j                         r||t        j                  |      z  k\  gS |j	                         r.|j	                         r| |t        j                  |       z  k\  gS t        d      NzIncorrect signs.)r   	is_nonnegr   inv_pos	is_nonpos
ValueErrorr   r   r   ys       r   mul_supr%   .   sy    99DAq{{}Qq)))**	
1;;=a%--+++,,+,,r   c                 &   | j                   \  }}|j                         r,|j                         r||t        j                  |      z  k  gS |j                         r,|j                         r||t        j                  |      z  k  gS t        d      r   )r   r   r!   r   r    r"   r#   s       r   mul_subr'   8   su    99DAq{{}Qq)))**	
1;;=Qq)))**+,,r   c                     | j                   \  }}|j                         r	|||z  k\  gS |j                         r	|||z  k  gS t        d      Nz%The denominator's sign must be known.r   r   r!   r"   r#   s       r   	ratio_supr+   B   M    99DAq{{}QU
|	
QU
|@AAr   c                     | j                   \  }}|j                         r	|||z  k  gS |j                         r	|||z  k\  gS t        d      r)   r*   r#   s       r   	ratio_subr.   L   r,   r   c                     | j                   d   t        t              r	fd}|gS t        t	        j
                        j                        d  dk(  gS )Nr   c                      j                   dk  ryj                    j                  k\  ry t        t        j                        j                         d  dk(  S )Nr   FT)r   sizeintr   floor)argr   s   r   r   z length_sub.<locals>.sublevel_setY   sJ    ww{ww#(("s5;;q>//012a77r   )r   
isinstancer	   r2   r   r3   r   )r   r   r   r4   s    ` @r   
length_subr6   V   sR    
))A,C!Y	8 ~CA,,-./1455r   c                 6    | j                   d   fd}|gS )Nr   c                  N     j                   dk  ry j                   dk  rdk\  S y)NTr   r   Fr   r   r   s   r   superlevel_setz sign_sup.<locals>.superlevel_setg   s(    77b=WW\6Mr   r   )r   r   r<   r   s    ` @r   sign_supr>   d   s     		!A r   c                 6    | j                   d   fd}|gS )Nr   c                  N     j                   dk\  ry j                   dk\  rdk  S y)Nr   Tr9   r   Fr:   r;   s   r   r   zsign_sub.<locals>.sublevel_sett   s(    77a<WW]6Mr   r=   )r   r   r   r   s    ` @r   sign_subrA   q   s    		!A >r   c                     | j                   d   | j                   d   j                  k(  | j                   d   dz	  || j                   d   z  | j                   d   z
  dz	  gS )Nr   r   )r   Tr   r   s     r   gen_lambda_max_subrE   ~   sZ    IIaLDIIaLNN*IIaLA1		!,14 4r   c                 H   | j                   d   }|j                  d   }t        d      }t        ||z  |f      }t        ||f      }|t	        |      z
  }t	        |      |z
  }t        |      t        |j                        k(  t        |      t        |      t        |      gS )Nr   T)pos)r   shaper
   r   r   r   rC   r   )	r   r   Anuprom_utprom_u	tmp_expr1	tmp_expr2s	            r   condition_number_subrP      s    		!A	
ATAa!eaT"GQFHV$$I!A%IaLIaccN*F	N	N r   c                 ~    	 t        t        |          | |      S # t        $ r t        dt        |        d      w xY w)zwReturn the t-level sublevel set for `expr`.

    Returned as a constraint phi_t(x) <= 0, where phi_t(x) is convex.
    The d atom is not yet supported in DQCP. Please file an issue here: https://github.com/cvxpy/cvxpy/issues)SUBLEVEL_SETStypeKeyErrorRuntimeErrorrD   s     r   sublevelrX      sU    
MT$Z(q11 MtDzl #L LM 	MM    "<c                 ~    	 t        t        |          | |      S # t        $ r t        dt        |        d      w xY w)zzReturn the t-level superlevel set for `expr`.

    Returned as a constraint phi_t(x) >= 0, where phi_t(x) is concave.
    rR   rS   )SUPERLEVEL_SETSrU   rV   rW   rD   s     r   
superlevelr\      sU    
MtDz*433 MtDzl #L LM 	MMrY   N)'__doc__cvxpyr   cvxpy.atoms.affiner   bin_opcvxpy.atoms.affine.diagr   cvxpy.atoms.affine.promoter   cvxpy.atoms.affine.upper_trir   cvxpy.constraints.psdr   %cvxpy.expressions.constants.parameterr	   cvxpy.expressions.variabler
   r   r%   r'   r+   r.   r6   r>   rA   rE   rP   multiplyDivExpressionlengthsign
dist_ratiogen_lambda_maxcondition_numberrT   r[   rX   r\    r   r   <module>ro      s     9 , . 2 % ; /--BB6

4" 
NNG
)	LL*	JJ	n	,	0 
NNG
)	JJ
M
Mr   