
    bi9                         d Z ddlm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 ddlmZ dd	lmZ dd
lmZ ddeeef   defdZd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.
    )UnionN)vec)norm1)norm_inf)normNuc)pnorm)	sigma_max)
Expressionpkeepdimsc                    t        j                  |       } t        | j                  D cg c]  }|dkD  	 c}      }|| j                  dk(  r|dk(  r*t
        j                  j                  t        | d            S |dk(  s
|dk(  r|dk(  rt        t        | d      d      S |dk(  rt        |       S |dk(  rt        |       S |t        j                  d	d
fv r*t
        j                  j                  t        | d            S t        d      |dk(  s| j!                         rt        | ||      S t#        |      j%                         d	k(  rt'        | ||      S t#        |      j%                         dk(  rt        t        | d      d|      S t)        |t"              rt        d| d      t        | |||      S c c}w )a  Wrapper on the different norm atoms.

    Parameters
    ----------
    x : Expression or numeric constant
        The value to take the norm of.  If `x` is 2D and `axis` is None,
        this function constructs a matrix norm.
    p : int or str, optional
        The type of norm. Valid options include any positive integer,
        'fro' (for frobenius), 'nuc' (sum of singular values), np.inf or
        'inf' (infinity norm).
    axis : The axis along which to apply the norm, if any.
    keepdims: If this is set to True, the axes which are reduced are left 
        in the result as dimensions with size one.

    Returns
    -------
    Expression
        An Expression representing the norm.
          r   )axisfroF)ordernucinfInfzUnsupported matrix norm.)r   r   zUnsupported norm option z for non-matrix.)r
   cast_to_constsumshapendimcvxpyatomsmaxr   r   r   r	   r   npr   RuntimeError	is_scalarstrlowerr   
isinstance)xr   r   r   dnum_nontrivial_idxss         K/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/norm.pynormr(      s   * 	  #Aagg6q1u67|!6;;??5#344%ZAF':a'?Qc*A..!VQ<%Z1:2665%((;;??5#3449::6Q[[]99V\\^u$AD8<<V\\^u$Qc*At443!9!<LMNNAD8<<5 7s   F;c                     t        | d|      S )a)  The 2-norm of x.

    Parameters
    ----------
    x : Expression or numeric constant
        The value to take the norm of.  If `x` is 2D and `axis` is None,
        this function constructs a matrix norm.

    Returns
    -------
    Expression
        An Expression representing the norm.
    r   )r   r   )r(   )r$   r   s     r'   norm2r*   S   s     QT""    )r   NF)N)__doc__typingr   numpyr   r   cvxpy.atoms.affine.vecr   cvxpy.atoms.norm1r   cvxpy.atoms.norm_infr   cvxpy.atoms.norm_nucr   cvxpy.atoms.pnormr   cvxpy.atoms.sigma_maxr	   cvxpy.expressions.expressionr
   intr!   boolr(   r*    r+   r'   <module>r9      sK        & # ) ( # + 31=uS#X 1= 1=h#r+   