
    bi                     T    d Z ddlmZ ddlmZ ddlmc mZ	 d Z
d Zdeedf   fd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.
    )TupleNc                    |dk(  rt        j                  |      }d|j                  d   z   }g }|df}t        j                  dgdgdgff|      }t        j
                  ||d      }| }| j                  st        j                  | d      }n%t        j                  | d| j                  d   f      }||j                  d   f}|t        j                  |||      gz  }t        |j                        dk(  r%t        j                  ||j                  d   df      }||j                  d   f}|dz
  dgz  }	t        d|      }
t        |dz
        }t        j                  |	|
|ff|      }t        j
                  ||d      }||j                  d   f}|t        j                  |||      gz  }t        j                  t        j                  |            gS )a\  Formats all the row/column cones for the solver.

    Parameters
    ----------
        t: The scalar part of the second-order constraint.
        X: A matrix whose rows/columns are each a cone.
        axis: Slice by column 0 or row 1.

    Returns
    -------
    list
        A list of LinLeqConstr that represent all the elementwise cones.
       r         ?Tsparse)r   r   )lu	transposeshapesp	csc_arraycreate_constreshapemul_exprlenrange
create_geqsum_expr)tXaxis	cone_sizeterms	mat_shapet_matt_vec	mul_shapeval_arrrow_arrcol_arrX_mats                V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/constraints/utilities.pyformat_axisr#      s    qyLLO AGGAJIEAILL3%1#s,i8EOOE9T:EE77

1f% 

1q!''!*o.EKKN+I	bkk%	233E
177|qJJq1771:q/*AGGAJ'I1}se#GAy!GIaK GLL'GW#56	BEOOE9T:EAGGAJ'I	bkk%I.//EMM"++e,-..    c                 F   t        |       }|| d   j                  d   z  | d   j                  d   f}g }t        |       D ]7  \  }}t        |||      }|j	                  t        j                  ||             9 t        j                  t        j                  |            gS )a  Formats all the elementwise cones for the solver.

    Parameters
    ----------
    vars_ : list
        A list of the LinOp expressions in the elementwise cones.

    Returns
    -------
    list
        A list of LinLeqConstr that represent all the elementwise cones.
    r   )	r   r   	enumerateget_spacing_matrixappendr	   r   r   r   )vars_spacingr   r   ivarmats          r"   format_elemwiser.   I   s     %jGq**E!HNN1,=>IEE" ,3 GQ7R[[c*+, MM"++e,-..r$   r   .c                 
   g }g }g }t        | d         D ];  }|j                  d       |j                  ||z  |z          |j                  |       = t        j                  |||ff|       }t	        j
                  || d      S )a~  Returns a sparse matrix LinOp that spaces out an expression.

    Parameters
    ----------
    shape : tuple
        (rows in matrix, columns in matrix)
    spacing : int
        The number of rows between each non-zero.
    offset : int
        The number of zero rows at the beginning of the matrix.

    Returns
    -------
    LinOp
        A sparse matrix constant LinOp.
    r   r   Tr   )r   r(   r   r   r	   r   )r   r*   offsetr   r   r    var_rowr-   s           r"   r'   r'   b   s    " GGGq?  sww/0w  ,,'7!34e
<C??3d33r$   )__doc__typingr   scipy.sparser   r   cvxpy.lin_ops.lin_utilslin_ops	lin_utilsr	   r#   r.   intr'    r$   r"   <module>r:      s7      $ $
-/`/24eCHo 4r$   