
    bi                     J    d Z ddlZddlmZ ddlmZ ddl	m
Z
  G d de
      Zy)a,  
Copyright 2013 Steven Diamond

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)BaseTestc                   8    e Zd ZdZddZddZddZddZddZy)	TestInterfacesz# Unit tests for matrix interfaces. Nc                      y )N )selfs    V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/tests/test_interfaces.pysetUpzTestInterfaces.setUp   s        c                    |j                  g dg dg      }| j                  t        j                  |      d       | j                  t        j                  |       d       | j                  t        j                  d|z        d       |j                  g dg dg      }| j                  t        j                  |      d       y	)
z)Test sign for a given interface.
                    r   r         )TF)FTr   )TT)r   r   r   )FFN)const_to_matrixassertEqualintfsign)r   	interfacemats      r	   sign_for_intfzTestInterfaces.sign_for_intf   s     ''|(DE37C4-81S5)<8''(EF38r   c           	         t        j                  t        j                        }|j	                  g d      }| j                  |j                  |      d       |j	                  ddg      }| j                  |j                  |      d       |j                  dd      }| j                  |j                  |      d       | j                  |j                  |d      d       |j	                  g dg dg      }|j                  |d	      }| j                  |j                  |d
      d       |j	                  dd      }| j                  t        |j                  |d            t        |             |j	                  g dg dg      }| j                  |j                  |d      d       |j                  |t        ddd      t        ddd       f      }| j                  t        |j                  d            g d       |j	                  d      }|j	                  g d      }| j                  ||z  |j	                  g d      k(  j                                | j                  ||z
  |j	                  g d      k(  j                                | j!                  |       | j                  |j                  t        j"                  g d            d       y )Nr   r   r   )r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   T)convert_scalarsr   r   r   r   r   r   r   r   C)r   r   r   r   )r   r   r   )r   r   r   )r   get_matrix_interfacenpndarrayr   r   shapescalar_matrixindexreshapetypeslicelistflatten
assertTrueallr   array)r   r   r   scalars       r	   test_ndarrayzTestInterfaces.test_ndarray)   sI   --bjj9	''	2-t4''A/-t4%%a0-v6f5q9''I(>?V,f5q9''4'@i//V<=tCyI''|(DEf5q9oocE!QNE!Q4E#FGckk#./>**1-''	2s
i77	BBCCE	K	 9 9* EEssu	N 	9%))<=tDr   c           	         t        j                  t        j                        }|j	                  g d      }| j                  |j                  |      d       |j                  d      }|j	                  t        j                  d            }| j                  |j                  |      |j                  |             | j                  ||z
  j                  d       |j                  dd      }| j                  |j                  |      d       | j                  |j                  |d      d       |j	                  g dg dg      }|j                  |d	      }| j                  |j                  |d
      d       |j                  dd      }| j                  t        |      t        j                         |j                  dd      }| j                  |j                  d       |j	                  g dg dg      }| j                  |j                  |d      d       |j                  |t!        ddd      t!        ddd      f      }| j#                  |t        j$                  ddgddgg      z
  j'                                t        j(                  d      }| j                  t        j*                  |      d       | j-                  |       t        j$                  ddg      }t        j$                  ddg      }t        j$                  ddg      }t        j.                  |||ffd      }|j	                  |      }| j                  |d   d       | j                  |d   d       y)z&Test cvxopt sparse interface.
        r   )r   r   r   r   r   r   r    r!   r"   r#   r   r%   )r   r   r   r   r&   r   Nr   g      ?y              ?y             )r   r   )r+   )r   r   )r   r(   sp	csc_arrayr   r   r+   identityr)   eyennzr,   r-   r.   r/   r*   r0   assertFalser5   any	eye_arrayscalar_valuer   	csr_array)	r   r   r   cmp_matr6   rowcoldataAs	            r	   test_scipy_sparsez TestInterfaces.test_scipy_sparseJ   s    --bll;	''	2-v6
   #++BFF1I6-yw/GH#-,,a0%%a0-v6f5q9''I(>?V,f5q9((F3frzz2((F3v.''|(DEf5q9oocE!QNE!Q4E#FG#1a&1a&)9 ::??ABll1o**3/59% hh1vhh1vxxS	"LL$c
+6:''*TB'TC(r   c                 \   t        j                  t        j                        t        j                  t        j
                        g}g dg dg dg}t        t        |            D ]C  }t        |dz   t        |            D ]$  }||   }|j                  |      }||   }|j                  |      }t        t        |            D ]  }	t        t        |d               D ]  }
t        |
|
dz   d      t        |	|	dz   d      f}| j                  |j                  ||      |j                  ||             | j                  ||	   |
   |j                  |j                  |      |             | j                  |j                  |j                  |      |      ||	   |
            ' F y)z:Test conversion between every pair of interfaces.
        r   r   )r   r   r   r   r   r   N)r   r(   r)   r*   r9   r:   rangelenr   r0   r   r-   )r   
interfacesrC   ijintf1mat1intf2mat2rE   rD   keys               r	   test_conversion_between_intfz+TestInterfaces.test_conversion_between_intfz   s    //

;//=?
}=s:' 	<A1Q3J0 <"1,,W5"1,,W5 W. 
<C$S_5 	<$S#a%6$S#a%68((T3)?).T3)?A ((c):).U5J5J45PRU)VX((U5J5J45PRU)V)0c):<	<
<<	<r   )returnN)	__name__
__module____qualname____doc__r
   r   r7   rH   rT   r   r   r	   r   r      s!    -9EB.)`<r   r   )rY   numpyr)   scipy.sparsesparser9   cvxpy.interfacer   r   cvxpy.tests.base_testr   r   r   r   r	   <module>r_      s&        *x<X x<r   