
    bi                     J    d 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 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.
    )reshape)sum)vstack)norm)
Expressionc           
         t        j                  |       } | j                  dk(  rt        d      | j                  dk(  r%t	        | dd | d| j
                  d   dz
   z
  d      S | j                  dk(  r| j
                  \  }}t        t         j                  |      }| gt        |      z   }g }|D ]E  }||d|dz
  d|f   |d|dz
  d|dz
  f   z
  |d|d|dz
  f   |d|dz
  d|dz
  f   z
  gz  }G |d   j
                  d   |d   j
                  d   z  }t        |D cg c]  }t        |d|fd       c}      }	t        t	        |	dd            S t        d	      c c}w )
a  Total variation of a vector, matrix, or list of matrices.

    Uses L1 norm of discrete gradients for vectors and
    L2 norm of discrete gradients for matrices.

    Parameters
    ----------
    value : Expression or numeric constant
        The value to take the total variation of.
    args : Matrix constants/expressions
        Additional matrices extending the third dimension of value.

    Returns
    -------
    Expression
        An Expression representing the total variation.
    r   z!tv cannot take a scalar argument.   N   F)order)paxisz8tv cannot have input arrays with more than 2 dimensions.)r   cast_to_constndim
ValueErrorr   shapemaplistr   r   r   )
valueargsrowscolsvaluesdiffsmatlengthdiffstackeds
             V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/total_variation.pytvr       s   $ $$U+EzzQ<==	qE!"IaAq(8 991==	q[[
d:++T24:% 	CAd1fHaf$%Ad1fHaQh,>(??AdFAd1fH$%Ad1fHaQh,>(?? E	
 q"58>>!#44ERD'$F3?RS411-..STT Ss   %E%N)__doc__cvxpy.atoms.affine.reshaper   cvxpy.atoms.affine.sumr   cvxpy.atoms.affine.vstackr   cvxpy.atoms.normr   cvxpy.expressions.expressionr   r         r   <module>r)      s!     / & , ! 3'Ur(   