
    bi                     Z    d Z ddlmZm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.
    )ListTupleN)AxisAtom)
Constraintc                       e Zd ZdZd Zdeeef   fdZdefdZdefdZ	defdZ
defdZdefd	Zd
 ZdefdZdee   fdZd Zd Zy)norm1Tc                    | j                   't        j                  |d         j                         }nt        j                  |d         }t        j                  j                  |d| j                   | j                        S )z#Returns the one norm of x.
        r      )axiskeepdims)r   nparrayflattenlinalgnormr   selfvaluess     L/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/norm1.pynumericznorm1.numeric   s^     99XXfQi(002FXXfQi(Fyy~~fadii$--~PP    returnc                      y)zCReturns sign (is positive, is negative) of the expression.
        )TF r   s    r   sign_from_argsznorm1.sign_from_args%   s     r   c                      y)zIs the atom convex?
        Tr   r   s    r   is_atom_convexznorm1.is_atom_convex+   s     r   c                      y)zIs the atom concave?
        Fr   r   s    r   is_atom_concaveznorm1.is_atom_concave0   s     r   c                 <    | j                   d   j                         S )z;Is the composition non-decreasing in argument idx?
        r   )args	is_nonnegr   idxs     r   is_incrznorm1.is_incr5        yy|%%''r   c                 <    | j                   d   j                         S )z;Is the composition non-increasing in argument idx?
        r   )r"   	is_nonposr$   s     r   is_decrznorm1.is_decr:   r'   r   c                     | j                   d   j                         xr< | j                   d   j                         xs | j                   d   j                         S )z&Is the atom piecewise linear?
        r   )r"   is_pwlis_realis_imagr   s    r   r,   znorm1.is_pwl?   sL     yy|""$ ?YYq\!!#=tyy|';';'=	?r   c                     | j                   gS )N)r   r   s    r   get_dataznorm1.get_dataE   s    		{r   c                 p    | j                   j                  d| j                  d   j                         dS )N(r   ))	__class____name__r"   namer   s    r   r6   z
norm1.nameH   s-    >>2299Q<,,.0 	0r   c                     g S )z?Returns constraints describing the domain of the node.
        r   r   s    r   _domainznorm1._domainL   s	     	r   c                 $    | j                  |      S )a+  Gives the (sub/super)gradient of the atom w.r.t. each argument.

        Matrix expressions are vectorized, so the gradient is a matrix.

        Args:
            values: A list of numeric values for the arguments.

        Returns:
            A list of SciPy CSC sparse matrices or None.
        )
_axis_gradr   s     r   _gradznorm1._gradQ   s     v&&r   c                     |j                   }t        j                  |dfd      }|j                  |df      }||dkD  z  }||dk  z  }|S )a  Gives the (sub/super)gradient of the atom w.r.t. a column argument.

        Matrix expressions are vectorized, so the gradient is a matrix.

        Args:
            value: A numeric value for a column.

        Returns:
            A NumPy ndarray matrix or None.
        r
   float64)dtyper   )sizesp	csc_arrayreshape)r   valuerowsD_nulls       r   _column_gradznorm1._column_grad^   sT     zztQiy9tQi(519519r   N)r5   
__module____qualname___allow_complexr   r   boolr   r   r    r&   r*   r,   r0   strr6   r   r   r8   r;   rF   r   r   r   r   r      s    NQdDj 1  
 
(d (
(d (
? ?0c 0j) 
'r   r   )__doc__typingr   r   numpyr   scipy.sparsesparser@   cvxpy.atoms.axis_atomr   cvxpy.constraints.constraintr   r   r   r   r   <module>rS      s)       * 3UH Ur   