
    bil                         d Z ddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ ej                  Z G d dej"                        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.
    N)Dqcp2Dcp)	bisection)	base_testc                   t   e Zd Zd/dZd/dZd/dZd/dZd/dZd/dZd/dZ	d/d	Z
d/d
Zd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZd/dZ d/d Z!d/d!Z"d/d"Z#d/d#Z$d/d$Z%d/d%Z&d/d&Z'd/d'Z(d/d(Z)d/d)Z*d/d*Z+d/d+Z,d/d,Z-d/d-Z.d/d.Z/y)0TestDqcpNc                    t        j                         }t        j                  |      }| j                  |j	                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk\  |dk  g      }| j                  |j	                                | j                  |j                                | j                  |j                                t        |      }|j                         }| j                  |j                                | j!                  t#        |j%                               d       t'        j(                  |ddt         j*                        }| j-                  |j.                  dd       |j1                  |       | j!                  |j.                  |j2                         | j-                  |j2                  dd       y )N         )lowhighsolver      (@   placescpVariableceil
assertTrueis_dqcpis_quasiconvexis_quasiconcaveassertFalse	is_convex
is_concaveis_dcpis_dgpProblemMinimizer   reduceassertEquallen
parametersr   bisectSCSassertAlmostEqualopt_valunpackvalueselfxexprproblemredreducedsolns          P/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/tests/test_dqcp.pytest_basic_with_intervalz!TestDqcp.test_basic_with_interval   s   KKMwwqz'++-.,,./)**+''**R[[.b!r'0BC)*)*)*w**,()W//12A6RbHt||T!<tw}}5qwwQ7    c                    t        j                         }t        j                  |      }| j                  |j	                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk\  |dk  g      }| j                  |j	                                | j                  |j                                | j                  |j                                t        |      }|j                         }| j                  |j                                | j!                  t#        |j%                               d       t'        j(                  |t         j*                        }| j-                  |j.                  dd       |j1                  |       | j!                  |j.                  |j2                         | j-                  |j2                  dd       y )Nr	   r
   r   r   r   r   r   r   r,   s          r4   test_basic_without_intervalz$TestDqcp.test_basic_without_interval9   s   KKMwwqz'++-.,,./)**+''**R[[.b!r'0BC)*)*)*w**,()W//12A67t||T!<tw}}5qwwQ7r6   c                    t        j                         }t        j                  |      }| j                  |j	                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk\  |dk  g      }| j                  |j	                                | j                  |j                                | j                  |j                                |j                  t        ddd       | j!                  |j"                  dd       | j!                  |j"                  dd       |j%                          |j                  t        d       | j!                  |j"                  dd       | j!                  |j"                  dd       |j%                          |j                  t        dd	       | j!                  |j"                  dd       | j!                  |j"                  dd       |j%                          |j                  t        dd
       | j!                  |j"                  dd       | j!                  |j"                  dd       |j%                          |j                  t        ddd       | j!                  |j"                  dd       | j!                  |j"                  dd       y )Nr	   r
   Tqcpr   r   r   r   r   r<   )r<   r   )r<   r   r   d   )r   r   r   r   r   r   r   r   r   r   r   r   r    r!   solveSOLVERr(   r+   _clear_solutionr-   r.   r/   r0   s       r4   test_basic_solvezTestDqcp.test_basic_solveU   s   KKMwwqz'++-.,,./)**+''**R[[.b!r'0BC)*)*)*f$BR8w}}d1=qwwQ7!f$'w}}d1=qwwQ7!f$R0w}}d1=qwwQ7!f$B/w}}d1=qwwQ7!f$AC8w}}d1=qwwQ7r6   c                    t        j                         }t        j                  |      }| j                  |j	                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk\  |dk  g      }| j                  |j	                                | j                  |j                                | j                  |j                                |j                  t        d       | j!                  |j"                  dd       y )Nr	   r
   Tr=   g      1@r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r    Maximizer?   r@   r(   r+   rB   s       r4   %test_basic_maximization_with_intervalz.TestDqcp.test_basic_maximization_with_interval}   s4   KKMwwqz'++-.,,./)**+''**R[[.b!r'0BC)*)*)*f$'qwwQ7r6   c                 v   t        j                  d      \  }}t        j                  t        j                  |      t        j                  |            }t        j                  t        j
                  |      |dk\  |dk  |dk\  g      }| j                  |j                                |j                  t        d       | j                  |j                  j                  d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d
       y N   r	   r
   ffffff1@Tr=   g      2@g1@'@L1@)r   r   maximumr   r    r!   r   r   r?   r@   r#   	objectiver+   
assertLessassertGreaterr-   r.   yr/   r0   s        r4   test_basic_maximumzTestDqcp.test_basic_maximum   s    {{1~1zz"''!*bggaj1**R[[.b!r'190MN)*f$'**00$7&177D)177D)r6   c                 v   t        j                  d      \  }}t        j                  t        j                  |      t        j                  |            }t        j                  t        j
                  |      |dk\  |dk  |dk\  g      }| j                  |j                                |j                  t        d       | j                  |j                  j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d	       y )
NrI   rK   皙/@rJ   Tr=         0@-@rL   )r   r   minimumr   r    rE   r   r   r?   r@   r#   rN   r+   rO   rP   rQ   s        r4   test_basic_minimumzTestDqcp.test_basic_minimum   s    {{1~1zz"''!*bggaj1**R[[.dAIqDy0QR)*f$'**00$7&177D)177D)r6   c                 P   t        j                  d      \  }}t        j                  t        j                  t        j                  |            t        j                  t        j                  |                  }t        j                  t        j
                  |      |dk\  |dk  |dk\  g      }| j                  |j                                |j                  t        d       | j                  |j                  j                  d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d
       t        j                  t        j                  t        j                  |            t        j                  t        j                  |                  }t        j                  t        j
                  |      |dk\  |dk  |dk\  g      }| j                  |j                                |j                  t        d       | j                  |j                  j                  d       | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d
       y rH   )r   r   rM   r   r    r!   r   r   r?   r@   r#   rN   r+   rO   rP   floorrQ   s        r4   test_basic_compositionzTestDqcp.test_basic_composition   s   {{1~1zz"''"''!*-rwwrwwqz/BC**R[[.b!r'190MN)*f$'**00$7&177D)177D) zz"((2771:.0DE**R[[.b!r'190MN)*f$'**00$7&177D)177D)r6   c                    t        j                         }t        j                  |      }| j                  |j	                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk\  |dk  g      }| j                  |j	                                | j                  |j                                | j                  |j                                |j                  t        d       | j!                  |j"                  j$                  d       | j'                  |j$                  d       y )Ng'@r
   Tr=   g      &@gffffff'@)r   r   r[   r   r   r   r   r   r   r   r   r   r    r!   r?   r@   r#   rN   r+   rP   rB   s       r4   test_basic_floorzTestDqcp.test_basic_floor   sK   KKMxx{'++-.,,./)**+''**R[[.dAG0DE)*)*)*f$'**00$7177D)r6   c                 `   t        j                  dd      \  }}||z  }| j                  |j                                | j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk  |dk  g      }| j                  |j                                | j                  |j                                | j                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd	       | j                  |j                  dd	       | j                  |j                  dd	       y )
NrI   Tnonnegr	      r=   H   r   r   r   r   r   r   r   r   r   r   r    rE   r   r?   r'   r(   rN   r+   rQ   s        r4   test_basic_multiply_nonnegz#TestDqcp.test_basic_multiply_nonneg   s;   {{1T*11u',,./,,./'**R[[.b!q&0AB)*)*)*bff$'w00661Eqww15qww!4r6   c                 `   t        j                  dd      \  }}||z  }| j                  |j                                | j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk\  |dk\  g      }| j                  |j                                | j                  |j                                | j                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd	       | j                  |j                  dd	       | j                  |j                  dd	       y )
NrI   Tnonposir=   rc   r   r   rd   rQ   s        r4   test_basic_multiply_nonposz#TestDqcp.test_basic_multiply_nonpos   s;   {{1T*11u',,./,,./'**R[[.c170CD)*)*)*bff$'w00661EqwwA6qww15r6   c                    t        j                  d      }t        j                  d      }||z  }| j                  |j                                | j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk  |dk\  g      }| j                  |j                                | j                  |j                                | j                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd	       | j                  |j                  dd	       | j                  |j                  dd	       t        j                  d      }t        j                  d      }||z  }| j                  |j                                | j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk  |dk\  g      }| j                  |j                                | j                  |j                                | j                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd	       | j                  |j                  dd	       | j                  |j                  dd	       y )
NTr`   rg      ri   r=   ir   r   )r   r   r   r   r   r   r   r   r    r!   r   r?   r'   r(   rN   r+   rQ   s        r4   test_basic_multiply_qcvxz!TestDqcp.test_basic_multiply_qcvx   s   KKt$KKt$1u'++-.--/0'**R[[.ab0AB)*)*)*bff$'w0066AFqww!4qww15KKt$KKt$1u'++-.--/0'**R[[.ab0AB)*)*)*bff$'w0066AFqww!4qww15r6   c                 p   t        j                  dd      \  }}t        j                  |      t        j                  |      z  }| j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk  |dk  g      }|j                  t         j                  d       | j                  |j                  j                  dd	       | j                  |j                  dd	       | j                  |j                  dd	       t        j                  dd      \  }}t        j                  |      d
z   t        j                  |      dz   z  }| j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |dk  |dk  g      }|j                  t         j                  d       | j                  |j                  j                  dd	       | j                  |j                  dd	       | j                  |j                  dd	       y )NrI   Tr`      	   r=   rb   r   r          @      @   )r   r   sqrtr   r   r   r   r   r    rE   r?   r'   r(   rN   r+   rQ   s        r4   test_concave_multiplyzTestDqcp.test_concave_multiply!  s   {{1T*1wwqzBGGAJ&',,./,,./**R[[.aa0@Abff$'w0066!Dqww!4qww!4{{1T*1
S RWWQZ#%56',,./,,./**R[[.aa0@Abff$'w00661Eqww!4qww!4r6   c                    t        j                         }t        j                  d      }||z  }| j                  |j                                | j                  |j	                                | j                  |j                                t        j                  t        j                  |      |dk(  |dk  g      }| j                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd       | j                  |j                  dd       | j                  |j                  dd       t        j                         }t        j                  d	      }||z  }| j                  |j                                | j                  |j	                                | j                  |j                                t        j                  t        j                  |      |dk(  |d
k\  g      }| j                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd       | j                  |j                  dd       | j                  |j                  d
d       y )NTr`   r	   rb   r=   rq   r   r   rg   ri   g       )r   r   r   r   r   r   r    r!   r?   r'   r(   rN   r+   rE   rQ   s        r4   test_basic_ratiozTestDqcp.test_basic_ratio;  s   KKMKKt$1u',,./++-.**R[[.b!q&0AB)*bff$'w0066AFqww15qww!4KKMKKt$1u',,./++-.**R[[.b!r'0BC)*bff$'w0066QGqww15qww15r6   c                    t        j                  dd      }t        j                  ddgddgg      }t        j                  d      }d|z  }t        j                  d      }t        j
                  ||      |z   t        j
                  ||      |z   z  }| j                  |j                                | j                  |j                                | j                  |j                                t        j                  t        j                  t        j                  |            |d	k\  |d
k  g      }| j                  |j                                |j                  t        d       | j                  |j                   j"                  d	d
       t        j$                  j'                  |j"                  d	d       y )N)rI   Tr`         ?rq         @rr   rI   r   r   r=   r      decimal)r   r   nparrayarangematmulr   r   r   r   r    r!   sumr?   r@   r(   rN   r+   testingassert_almost_equal)r-   r.   AbCdlin_fracr0   s           r4   test_lin_fraczTestDqcp.test_lin_fracZ  sF   KKT*HHsCj3*-.IIaLEIIaLIIaOa'BIIaOa,?@((*+//120023**R[[3a1fh!m5LM)*f$'w0066!D


&&qww1&=r6   c                    t        j                  d      }t        j                  |      t        j                  |      z  }| j	                  |j                                | j	                  |j                                | j                  |j                                t        j                  t        j                  |            }| j	                  |j                                |j                  t         j                  d       | j                  |j                  j                  dd       | j                  |j                  dd       y )NTr`   r=   g1Zd?r   r         ?)r   r   rt   expr   r   r   r   r   r    rE   r?   r'   r(   rN   r+   )r-   r.   concave_fracr0   s       r4   test_concave_fraczTestDqcp.test_concave_frack  s    KKt$wwqzBFF1I-,,./44674467**R[[67)*bff$'w0066aHqwwA6r6   c                 x   t        j                  d      }t        j                  |      }| j                  |j	                                | j                  |j                                | j                  |j                                t        j                  t        j                  |      |d   dk(  |d   dk(  g      }|j                  t        d       | j                  |j                  j                  d       t        j                   j#                  |j                  t        j$                  g d	             y )
Nr{   r   rq   r   ry   Tr=   rI   )rI   r   r   r   r   )r   r   lengthr   r   r   r   r   r    r!   r?   r@   r#   rN   r+   r~   r   r   r   rB   s       r4   test_lengthzTestDqcp.test_lengthx  s    KKNyy|'++-.--/0**R[[.1adck0JKf$'**00!4


&&qww0IJr6   c                 D   d}t         j                  j                  d       t         j                  j                  ||      }t         j                  j                  |      }||z  }d}t	        j
                  |      }t	        j                  ||z  |z
        |z  }t	        j                  t	        j                  t	        j                  |            ||k  g      }|j                         sJ |j                  d       t        j                  |j                  d      sJ y)z
Fix #1760.
   r   g{Gz?Tr=      N)r~   randomseedrandnr   r   sum_squaresr    r!   r   r   r?   iscloser+   )	r-   nr   x_starr   epsilonr.   mser0   s	            r4   test_length_examplezTestDqcp.test_length_example  s    
		qIIOOAq!#JKKNnnQUQY')**R[[168HI   $zz'--+++r6   c                    d}t        j                  |      }| j                  t        j                  t        j                  |            j                  d             | j                  t        j                  t        j                  |      dz
        j                  d             | j                  t        j                  t        j                  |            j                                | j                  t        j                  t        j                  |      dz
        j                                | j                  t        j                  t        j                  |             j                  d             | j                  t        j                  t        j                  |       dz         j                  d             y )Nr{   r   r   )	r   r   r   r   absis_incrr   r   is_decr)r-   r   r.   s      r4   test_length_monototicityz!TestDqcp.test_length_monototicity  s   KKN		"&&),44Q78266!9Q;/77:;		"&&),4467266!9Q;/779:		266!9*-55a89BFF1I:a<088;<r6   c                 ~   t        j                  d      }t        j                  t        j                  t        j                  |            |dk(  t        j
                  |      dk\  g      }|j                  t        d       | j                  |j                  t        j                  t        j                  f       y )NrI   r   Tr=   )r   r   r    r!   r   r   r?   r@   assertInstatuss
INFEASIBLEINFEASIBLE_INACCURATEr-   r.   r0   s      r4   test_infeasiblezTestDqcp.test_infeasible  sz    KKN**KK		!%Rq'ACf$'gnnq||Q5L5L&MNr6   c                    t        j                         }t        j                  t        j                  t        j                  |            d|k  |dk  g      }|j                  t        d       | j                  |j                  j                  d       | j                  |j                  d       t        j                  t        j                  t        j                  |            d|k  |dk  g      }|j                  t        d       | j                  |j                  j                  d	       | j                  |j                  d       t        j                  g d
      }t        j                  t        |            }t        j                  t        j                  ||z        t        j                   |      d	k  g      }|j                  t         j"                         |j                  j%                         }t        j                  |      j                   | j'                  ||j                         t        j                  d      }t        j(                  t        j*                  d      |z
        }t        j,                  t        j                  |            dk  g}t        j                  t        j                  |      |      }|j/                         rJ y )N      Tr=   r   r   r   rI   ry   )g?g333333ӿr   r8   )r   r   r    r!   signr?   r@   r#   rN   r+   assertLessEqualrE   rP   r~   r   r$   norm2r'   copyassertItemsAlmostEqualr   onesr   r   )	r-   r.   r0   vectorvariabler+   objconstrprobs	            r4   	test_signzTestDqcp.test_sign  s   KKM**R[[4rQwT	6JKf$'**00"5QWWa(**R[[4qAvqAv6FGf$'**00#6177A& -(;;s6{+**R[[():; hhx0B679RVV$##%
##E8>>: KKNnnRWWQZ!^,&&$)*zz"++c*F3<<>!!>r6   c           	      6   t        j                  d      }t        j                  d      }t        j                  d      }t        j
                  t        j                  t        j                  |||            |dk  g      }|j                  t         j                  d       t        j                  j                  |j                  j                  dd       t        j                  j                  |j                  t        j                  ddg      d       y )NrI   皙?Tr=   g      ?r   r|   )r   r   r~   r   zerosr    r!   
dist_ratior?   r'   r   r   rN   r+   r   )r-   r.   ar   r0   s        r4   test_dist_ratiozTestDqcp.test_dist_ratio  s    KKNGGAJHHQK**R[[q!Q)?@18*Mbff$'


&&w'8'8'>'>a&P


&&qww#s0Da&Pr6   c                 X   t        j                         }t        j                  t        j                  |            dk  g}t        j                  t        j
                  d      |      }|j                  t        d       | j                  |j                  t        j                         y Nr   Tr=   )r   r   r   r   r    r!   r?   r@   r#   r   r   r   r-   r.   r   r0   s       r4   test_infeasible_exp_constrz#TestDqcp.test_infeasible_exp_constr  sk    KKM&&$*+**R[[^V4f$'6r6   c                 \   t        j                  d      }t        j                  t        j                  |            dk  g}t        j                  t        j
                  d      |      }|j                  t        d       | j                  |j                  t        j                         y NTr`   r   r   r=   )r   r   inv_posr   r    r!   r?   r@   r#   r   r   r   r   s       r4   test_infeasible_inv_pos_constrz'TestDqcp.test_infeasible_inv_pos_constr  sn    KKt$**RWWQZ(B./**R[[^V4f$'6r6   c                 \   t        j                  d      }t        j                  t        j                  |            dk  g}t        j                  t        j
                  d      |      }|j                  t        d       | j                  |j                  t        j                         y r   )r   r   logisticr   r    r!   r?   r@   r#   r   r   r   r   s       r4   test_infeasible_logistic_constrz(TestDqcp.test_infeasible_logistic_constr  sn    KKt$++bggaj)R/0**R[[^V4f$'6r6   c                 X   t        j                         }t        j                  t        j                  |            dk\  g}t        j                  t        j
                  d      |      }|j                  t        d       | j                  |j                  t        j                         y r   )r   r   r   r   r    r!   r?   r@   r#   r   r   OPTIMALr   s       r4   test_noop_exp_constrzTestDqcp.test_noop_exp_constr  sk    KKM&&$*+**R[[^V4f$'3r6   c                 X   t        j                         }t        j                  t        j                  |            dk\  g}t        j                  t        j
                  d      |      }|j                  t        d       | j                  |j                  t        j                         y r   )r   r   r   r   r    r!   r?   r@   r#   r   r   r   r   s       r4   test_noop_inv_pos_constrz!TestDqcp.test_noop_inv_pos_constr  sk    KKM**RWWQZ(B./**R[[^V4f$'3r6   c                 \   t        j                  d      }t        j                  t        j                  |            dk\  g}t        j                  t        j
                  d      |      }|j                  t        d       | j                  |j                  t        j                         y r   )r   r   r   r   r    r!   r?   r@   r#   r   r   r   r   s       r4   test_noop_logistic_constrz"TestDqcp.test_noop_logistic_constr  sn    KKt$++bggaj)R/0**R[[^V4f$'3r6   c                    t        j                  d      }t        j                  dd      }t        j                  ||      }t        t	        ddgddgddgg       }||   g dk(  ||   g dk(  g}t        j
                  t        j                  |      |      }| j                  |j                                |j                  t         j                  d	       y )
N)r   r   TPSDr   rI   r   )ry   gffffff?r   )rz   gffffff?g?r=   )r   r   gen_lambda_maxtuplezipr    r!   r   r   r?   r'   )r-   r   Br   known_indicesr   r0   s          r4   %test_gen_lambda_max_matrix_completionz.TestDqcp.test_gen_lambda_max_matrix_completion  s    KKKKD)**1a0cQFQFQF#;<=
M
o
-
M
o
-
 **R[[8&A)*bff$'r6   c                    t        j                  dd      }t        j                  |      }|d   d   dk(  |d   d   dk(  |d   d   dk  |d   d   dk\  |d   d   dk  |d   d   dk\  g}t        j                  t        j                  |      |      }| j                  |j                                |j                  t         j                  d	       t        j                  dd
gd
dgg      }| j                  |j                  |d       y )NrI   rI   Tr   r   rq   r   rz   rI   r=   ry   r   )r   r   condition_numberr    r!   r   r   r?   r'   r~   asarrayr   r+   )r-   r   con_numr   r   anss         r4   test_condition_numberzTestDqcp.test_condition_number  s    KKD)%%a(aDGsNaDGsNaDGqL!A$q'Q,aDGqL!A$q'Q,	
 zz"++g.7'

266t
$jj3**& '##AGGS#;r6   c                 .   d}t         j                  j                  d       t         j                  j                  ||      }t         j                  j                  |      }t	        j
                  ||      }d}t	        j                  |      }t	        j                  |      }t	        j                  t	        j
                  ||      |z
        |z  }t	        j                  t	        j                  |      ||k  g      }	|	j                  t        d       y )Nr   r   gMbP?Tr=   )r~   r   r   r   r   r   r   r   r   r    r!   r?   r@   )
r-   r   r   r   r   r   r.   objective_fnr   r0   s
             r4   test_card_lszTestDqcp.test_card_ls  s    
		qIIOOAq!#IIa KKNyy|nnRYYq!_q01!3**R[[68HIf$'r6   c                 d   t        j                         }t        j                  dt        j                  |      z        }t        j                  ||dk\  g      }|j                  t        d       | j                  |j                  dd       | j                  |j                  dd       t        j                         }t        j                  t        j                  |      dz        }t        j                  ||dk\  g      }|j                  t        d       | j                  |j                  dd       | j                  |j                  dd       t        j                         }t        j                  dt        j                  |      z        }t        j                  ||dk\  g      }|j                  t        d       | j                  |j                  dd       | j                  |j                  d	d       t        j                         }t        j                  t        j                  |      dz        }t        j                  ||dk\  g      }|j                  t        d       | j                  |j                  dd       | j                  |j                  d	d       y )
Nr   r   Tr=   r   r   r{   r   r   
r   r   r!   r   r    r?   r@   r(   r+   rE   r-   r.   r   r0   s       r4   test_multiply_constzTestDqcp.test_multiply_const%  s   KKMkk#
*+**S17),f$'qww15w}}a:KKMkk"''!*s*+**S17),f$'qww15w}}a:KKMkk$+,**S17),f$'qww15w}}b;KKMkk"''!*t+,**S17),f$'qww15w}}b;r6   c                    t        j                         }t        j                  t        j                  |      dz        }t        j                  ||dk\  g      }|j                  t        d       | j                  |j                  dd       | j                  |j                  dd       t        j                         }t        j                  t        j                  |      dz        }t        j                  ||dk\  g      }|j                  t        d       | j                  |j                  dd       | j                  |j                  d	d       y )
Nr   r   Tr=   r   r      r   ir   r   s       r4   test_div_constzTestDqcp.test_div_constB  s    KKMkk"''!*s*+**S17),f$'qww15w}}b;KKMkk"''!*t+,**S17),f$'qww15w}}c!<r6   c                     t        j                  d      }t        j                  t        j                  d|z              }|j	                  t
        d       | j                  |j                  dd       y NTposr   r=   r   r   r   )r   r   r    r!   r?   r@   r(   r+   r   s      r4   test_reciprocalzTestDqcp.test_reciprocalQ  sT    KKD!**R[[1-.f$'w}}a:r6   c                 (   t        j                  d      }t        j                  t        j                  t        j                  d|z                    }|j                  t        d       | j                  |j                  dd       t        j                  d      }t        j                  t        j                  t        j                  d|z                    }|j                  t        d       | j                  |j                  dd       y )	NTr   r   r=   r   r   r   )neg)	r   r   r    r!   r   r?   r@   r(   r+   r   s      r4   test_abszTestDqcp.test_absW  s    KKD!**R[[!56f$'w}}a:KKD!**R[[!56f$'w}}a:r6   c                 L   t        j                         }t        j                  d      }t        j                  |       |z  }t        j                  t        j                  |      t        j
                  |      |k  g      }|j                  t         j                  d       y )NTr   r=   )r   r   rt   r    r!   r   r?   r'   )r-   r.   rR   r   r0   s        r4   test_tutorial_examplezTestDqcp.test_tutorial_exampleb  sj    KKMKKD!
{Q**R[[6a8HIbff$'r6   c                    t        j                  d      }t        j                  |      }| j                  |j                  t
        j                         t        j                  |       }| j                  |j                  t
        j                         t        j                  |      }| j                  |j                  t
        j                         | j                  |j                                y )Nr   )r   r   r   r#   	curvaturer   QUASICONVEXQUASICONCAVEr   QUASILINEARr   is_quasilinear)r-   r.   r/   s      r4   test_curvaturezTestDqcp.test_curvaturej  s    KKNyy|7		!}8wwqz7++-.r6   c                    t        j                  d      }|t        j                  |      z  }t        j                  |      dk  g}t        j                  t        j
                  |      |      }| j                  |j                                | j                  |d   j                                | j                  |j                                t        j                         }|t        j                  |      z  }t        j                  t        j
                  |            }| j                  |j                                | j                  |j                                y )NTr`   r   r   )
r   r   rt   r   r    rE   r   r   r   r   )r-   r.   r   
constraintr0   wfns          r4   test_tutorial_dqcpzTestDqcp.test_tutorial_dqcpt  s    KKt$2771:~ggajB&'
**R[[6
C4467
1--/0)*KKM^**R[[_-&*+r6   c                    t        j                         }t        j                  t        j                  t        j                  |      dz         |dk\  g      }|j                  t        d       t        j                  j                  |j                  d       t        j                  j                  |j                  j                  d       y )Nr{   rI   Tr=   rl   )r   r   r    r!   r   r?   r@   r~   r   r   r+   rN   r   s      r4   test_add_constantzTestDqcp.test_add_constant  s    KKM**R[[a816(Cf$'


&&qww2


&&w'8'8'>'>Br6   c                    t        j                  dd      }t        j                  ddt        j                  |      z  z
  |z   |z        }t        j                  t        j
                  |      |d   dk  |d   dk  g      }| j                  |j                                |j                  t         j                  d       | j                  |j                  j                  d	d
       y )NrI   Tr   r   r   r   g?r=   gʡE?r   )r   r   maxrt   r    r!   r   r   r?   r'   r(   rN   r+   r   s       r4   test_maxzTestDqcp.test_max  s    KKt$ffa!BGGAJ,&*a/0**R[[-!QqTS[/IJ)*bff$'w0066qIr6   c                 l   t        j                  d      }t        j                  t        j                  |            }t        j                  t        j
                  |      |d   dk\  |d   dk  |d   dk\  g      }| j                  |j                                |j                  t        d       | j                  |j                  j                  d	       | j                  |d   j                  d	       | j                  |d   j                  d
       | j                  |d   j                  d       y )NrI   r   rK   rU   r   rJ   Tr=   rV   rW   rL   )r   r   minr   r    rE   r   r   r?   r@   r(   rN   r+   rO   rP   rB   s       r4   test_minzTestDqcp.test_min  s    KKNvvbggaj!**R[[.ddlAaDDL!A$$,GI)*f$'w0066=!

D)1Q4::t,1Q4::t,r6   c                     t        j                  dd      }t        j                  t        j                  |      |z        }| j	                  |j                                y )Nr{   Tr   )r   r   r   squarer   r   )r-   tr/   s      r4   test_sum_of_qccv_not_dqcpz"TestDqcp.test_sum_of_qccv_not_dqcp  sA    KKt$vvbiilQ&'(r6   c                    t        j                  d      }t        j                  t        j                  t        j                  |            |dk  g      }|j                  t        ddd       | j                  |j                  d       | j                  |j                  d       |j                  t        ddd        | j                  |j                  d       | j                  |j                  d       |j                  t        dd d       | j                  |j                  d       | j                  |j                  d       y )NTr   r   r   r   r;   )
r   r   r    rE   r   r?   r@   rP   r+   r   r   s      r4   test_flip_boundszTestDqcp.test_flip_bounds  s    KKD!**R[[4qAvh?f$AC8177A&QWWa(f$AD9177A&QWWa(f$Ds;177A&QWWa(r6   c                    t        j                  d      }t        j                  t        j                  t        j                  d|z                    }|j                  t        d       | j                  |j                  dd       t        j                  t        j                  t        j                  d|z                    }|j                  t        d       | j                  |j                  dd       y r   )
r   r   r    r!   r   r?   r@   r(   r+   cumsumr   s      r4   test_scalar_sumzTestDqcp.test_scalar_sum  s    KKD!**R[[!56f$'w}}a:**R[[1Q389f$'w}}a:r6   c                    t        j                         }t        j                  t        j                  |            }|dk  |dk\  g}t        j                  ||      }|j                  dt         j                         | j                  |j                  |j                  d       | j                  |j                  dd       y)zTest bug with parameters arising from interaction of
        DQCP and DPP.

        https://github.com/cvxpy/cvxpy/issues/2386
        rI   r   T)r<   r   r   r   N)	r   r   r!   rt   r    r?   r'   r(   r+   )r-   r.   rN   constraintsr0   s        r4   test_parameter_bugzTestDqcp.test_parameter_bug  s     KKMKK
+	AvqAv&**Y4$rvv.qww	Bqww!4r6   c                 V   t        j                  dd      }|d   }|d   }t         j                  j                  j                  j                  |      }t         j                  j                  j                  j                  |      }|dz	  g}||z  }t        j                  t        j                  |      |      }|j                         sJ t        j                  t         j                  d      5  |j                  dt         j                  d	
       ddd       y# 1 sw Y   yxY w)zlTest bug with DQCP and PSD constraints.
        
        https://github.com/cvxpy/cvxpy/issues/2373
        r   T)	symmetric)r   r   )r   r   r   zMax iters hit during bisection.)matchr   )r<   r   	max_itersN)r   r   atomsaffinewrapsnonneg_wrapr    rE   r   pytestraisesSolverErrorr?   r'   )r-   r   r.   rR   r  fr0   s          r4   test_psd_constraint_bugz TestDqcp.test_psd_constraint_bug  s    
 KK-cFcF HHOO!!--a0HHOO!!--a0Avh aC **R[[^[9    ]]2>>!BD 	@MMd266QM?	@ 	@ 	@s   3#DD()returnN)0__name__
__module____qualname__r5   r9   rC   rF   rS   rY   r\   r^   re   rj   rm   ru   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r&   r6   r4   r   r      s    8888&8P8(
*
**,**5&6&%6N546>>"7
K, =O">Q777444(<"(<:=;	;(/, CJ
-)
);5&@r6   r   )__doc__numpyr~   r"  cvxpyr   cvxpy.settingssettingsr   "cvxpy.reductions.dqcp2dcp.dqcp2dcpr   cvxpy.reductions.solversr   cvxpy.testsr   CLARABELr@   BaseTestr   r+  r6   r4   <module>r6     s@        7 . !	N@y!! N@r6   