
    bi                        d Z ddlmZ ddlmZ ddlmZmZ ddlZ	dee
df   dee
df   fd	Zd
eee
df      dee
df   fdZdee
df   dee
df   deee
df   ee
df   ee
df   f   fdZdee
df   dee
df   dee
df   fdZde
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.
    )reduce)mul)ListTupleNshape.returnc                 &    t        d | D              S )Nc              3   ,   K   | ]  }|d k7  s	|  yw)   N ).0dims     P/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/utilities/shape.py	<genexpr>zsqueezed.<locals>.<genexpr>   s     22s   
)tupler   s    r   squeezedr      s    2222    shapesc                 &    t        j                  |  S )a  
    Give the shape resulting from summing a list of shapes.

    Summation semantics are exactly the same as NumPy's, including
    broadcasting.

    Parameters
    ----------
    shapes : list of tuples
        The shapes of the summands

    Returns
    -------
    tuple
        The shape of the sum.

    Raises
    ------
    ValueError
        If the shapes are not compatible.
    )npbroadcast_shapes)r   s    r   
sum_shapesr      s    , ''r   lh_shaperh_shapec                    | r|st        d      t        |       dk(  rd| z   n| } t        |      dk(  r|dz   n|}| d   |d   k7  rt        d| d|      t        |       dkD  st        |      dkD  r+	 t        j                  | d	d |d	d       }|| d   |d   fz   }n
| d   |d   f}| ||fS # t         $ r t        d| d|      w xY w)
a  
    Promotes shapes as necessary and returns promoted shape of product.

    If lh_shape is of length one, prepend a one to it.
    If rh_shape is of length one, append a one to it.
    If either shape is greater than 2, apply broadcasting rules on
    the outer dimensions.
    Parameters
    ----------
    lh_shape : tuple
        The left-hand shape of a multiplication operation.
    rh_shape : tuple
        The right-hand shape of a multiplication operation.

    Returns
    -------
    tuple
        The promoted left-hand shape.
    tuple
        The promoted right-hand shape.
    tuple
        The promoted shape of the product.

    Raises
    ------
    ValueError
        If either of the shapes are scalars, or if the shapes are incompatible.
    z+Multiplication by scalars is not permitted.r   )r   zIncompatible dimensions     N)
ValueErrorlenr   r   )r   r   
outer_dimsr   s       r   mul_shapes_promoter$   4   s    > 8FGG #&h-1"4th(H"%h-1"4x$(H|x|#HhOPP 8}qCMA-	U,,Xcr]HSbMJJ hrlHRL99"x|,h&&  	U(STT	Us   3B, ,Cc                 d    | |}}t        | |      \  } }}| |k7  r|dd |d   fz   }||k7  r|dd }|S )a?  
    Give the shape resulting from multiplying two shapes.

    Adheres the semantics of np.matmul and additionally permits multiplication
    by scalars. The broadcasting rules are the same as NumPy's.

    Parameters
    ----------
    lh_shape : tuple
        The left-hand shape of a multiplication operation.
    rh_shape :  tuple
        The right-hand shape of a multiplication operation.

    Returns
    -------
    tuple
        The shape of the product as per matmul semantics.

    Raises
    ------
    ValueError
        If either of the shapes are scalar.
    Nr   r   )r$   )r   r   lh_oldrh_oldr   s        r   
mul_shapesr(   i   sV    0 xFF 28X FHh6cr
eBi\)6cr
Lr   c                 $    t        t        | d      S )a  
    Compute the size of a given shape by multiplying the sizes of each axis.

    This is a replacement for np.prod(shape, dtype=int) which is much slower for
    small arrays than the implementation below.

    Parameters
    ----------
    shape : tuple
        a tuple of integers describing the shape of an object

    Returns
    -------
    int
        The size of an object corresponding to shape.
    r   )r   r   r   s    r   size_from_shaper*      s    " #ua  r   )__doc__	functoolsr   operatorr   typingr   r   numpyr   intr   r   r$   r(   r*   r   r   r   <module>r1      s       3E#s(O 3c3h 3(tE#s(O, (sCx (22'CHo2').sCx2'
5c?E#s(OU38_<=2'jsCx E#s(O cSVh B!c !r   