
    bi	                     >    d Z ddlmZ ddl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.
    )TupleN   )Elementwisec                        e Zd ZdZdZd fdZej                  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 xZS )absz Elementwise absolute value Treturnc                 ,    t         t        |   |       y )N)superr   __init__)selfx	__class__s     V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/elementwise/abs.pyr   zabs.__init__   s    c4!!$    c                 2    t        j                  |d         S )Nr   )npabsolute)r   valuess     r   numericzabs.numeric    s    {{6!9%%r   c                      y)zCReturns sign (is positive, is negative) of the expression.
        )TF r   s    r   sign_from_argszabs.sign_from_args$   s     r   c                      y)zIs the atom convex?
        Tr   r   s    r   is_atom_convexzabs.is_atom_convex*   s     r   c                      y)zIs the atom concave?
        Fr   r   s    r   is_atom_concavezabs.is_atom_concave/   s     r   c                 <    | j                   |   j                         S )z;Is the composition non-decreasing in argument idx?
        )args	is_nonnegr   idxs     r   is_incrzabs.is_incr4        yy~''))r   c                 <    | j                   |   j                         S )z;Is the composition non-increasing in argument idx?
        )r   	is_nonposr!   s     r   is_decrzabs.is_decr9   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
abs.is_pwl>   sL     yy|""$ ?YYq\!!#=tyy|';';'=	?r   c                     | j                   j                  }| j                  }t        j                  | j                   j                        }||d   dkD  z  }||d   dk  z  }t
        j                  |||      g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.
        r   )exprsizer   zerosshaper   elemwise_grad_to_diag)r   r   rowscolsDs        r   _gradz	abs._gradD   sl     yy~~yyHHTYY__%	fQi!m	fQi!m))!T4899r   )r   N)__name__
__module____qualname____doc___allow_complexr   r   numpy_numericr   r   boolr   r   r   r#   r'   r)   r5   __classcell__)r   s   @r   r   r      s    &N% & &dDj 1  
 
*d *
*d *
? ?:r   r   )r9   typingr   numpyr   elementwiser   r   r   r   r   <module>rA      s!       $=:+ =:r   