
    biQ                         d Z ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlmZmZmZmZmZmZmZmZ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)DENSE_CONSTNEGPARAMSCALAR_CONSTSPARSE_CONSTSUM_ENTRIESVARIABLE)	create_const	create_eq
create_leqcreate_param
create_varget_expr_varsneg_exprsum_entriessum_expr)BaseTestc                   X    e Zd 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y)test_lin_opsz$ Unit tests for the lin_ops module. Nc                    t        dd      }| j                  |j                  d       | j                  |j                  d       | j                  t	        |j
                        d       | j                  |j                  t               y)z"Test creating a variable.
                 )var_idr   N)r   assertEqualshapedatalenargstyper	   selfvars     S/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/tests/test_lin_ops.pytest_variablesztest_lin_ops.test_variables.   sd     *F+1%SXX*8,    c                     t        d      }| j                  |j                  d       | j                  t        |j                        d       | j                  |j
                  t               y)z#Test creating a parameter.
        r   r   N)r   r   r   r   r    r!   r   r"   s     r%   
test_paramztest_lin_ops.test_param7   sN     6"F+SXX*5)r'   c                    d}t        d|      }| j                  |j                  |       | j                  t        |j                        d       | j                  |j
                  t               |j                  dk(  sJ d}t        t        j                  |      |      }| j                  |j                  |       | j                  t        |j                        d       | j                  |j
                  t               |j                  t        j                  |      k(  j                         sJ d}t        t        j                  d      |d      }| j                  |j                  |       | j                  t        |j                        d       | j                  |j
                  t               |j                  j                         t        j                   d      k(  j                         sJ y	)
z"Test creating a constant.
        r   r   g      ?r   r   r   r   r   T)sparseN)r
   r   r   r   r    r!   r   r   nponesr   allsp	eye_arrayr   todenseeye)r#   r   mats      r%   test_constantztest_lin_ops.test_constant?   sl    3&E*SXX*<0xx3 2775>51E*SXX*;/BGGEN*//111 2<<?E$?E*SXX*<0  "bffQi/44666r'   c                     d}t        |      }t        |      }t        ||g      }| j                  |j                  |       t	        |j
                        dk(  sJ y)zTest adding lin expr.
        r      N)r   r   r   r   r   r    )r#   r   xyadd_exprs        r%   test_add_exprztest_lin_ops.test_add_exprZ   sV     uuQF#/8==!Q&&&r'   c                     d}t        |      }t        |      }t        t        j                  |      |      }t	        |||g      }t        |      }|j                  |f|j                  |fg}| j                  ||       y)z.Test getting vars from an expression.
        r   N)r   r
   r.   r/   r   r   r   assertCountEqual)r#   r   r9   r:   Ar;   vars_refs           r%   test_get_varsztest_lin_ops.test_get_varse   su     uu/Q1I&h'0eS)r'   c                     d}t        |      }t        |      }t        |j                        dk(  sJ | j	                  |j
                  |       | j	                  |j                  t               y)z%Test negating an expression.
        r   r   N)r   r   r   r    r   r   r!   r   )r#   r   r$   exprs       r%   test_neg_exprztest_lin_ops.test_neg_exprr   sZ     }499~"""U+C(r'   c                 f   d}t        |      }t        |      }t        ||g      }t        j                  |      }t	        ||      }t        ||      }| j                  |j                  |       t        |j                        }|j                  |f|j                  |fg}	| j                  ||	       y)z.Test creating an equality constraint.
        r,   N)r   r   r.   r/   r
   r   r   r   r   rD   r   r>   
r#   r   r9   r:   lh_exprvaluerh_exprconstrr@   rA   s
             r%   test_eq_constrztest_lin_ops.test_eq_constr|   s     uuAq6"ue,7G,u-fkk*0eS)r'   c                 f   d}t        |      }t        |      }t        ||g      }t        j                  |      }t	        ||      }t        ||      }| j                  |j                  |       t        |j                        }|j                  |f|j                  |fg}	| j                  ||	       y)z7Test creating a less than or equal constraint.
        r,   N)r   r   r.   r/   r
   r   r   r   r   rD   r   r>   rG   s
             r%   test_leq_constrztest_lin_ops.test_leq_constr   s     uuAq6"ue,GW-u-fkk*0eS)r'   c                     d}t        |      }t        |d      }| j                  |j                  d       | j                  t	        |j
                        d       | j                  |j                  t               y)zTest sum entries op.
        r,   r+   r   N)r   r   r   r   r   r    r!   r   )r#   r   r9   rD   s       r%   test_sumztest_lin_ops.test_sum   s_     u1f%V,TYY+K0r'   )returnN)__name__
__module____qualname____doc__r&   r)   r6   r<   rB   rE   rL   rN   rP    r'   r%   r   r   +   s2    .-*76	'*)**1r'   r   )rU   numpyr.   scipy.sparser-   r1   cvxpy.lin_ops.lin_opr   r   r   r   r   r   r	   cvxpy.lin_ops.lin_utilsr
   r   r   r   r   r   r   r   r   cvxpy.tests.base_testr   r   rV   r'   r%   <module>r\      sC        
 
 
 +w18 w1r'   