
    bik
                     2    d dl mZ d dlmZ  G d de      Zy)    )settings)	Reductionc                   ^     e Zd ZdZdd fdZd ZdefdZd Zde	fdZ
dde	fd	Zd
 Z xZS )ChainzA logical grouping of multiple reductions into a single reduction.

    Attributes
    ----------
    reductions : list[Reduction]
        A list of reductions.
    returnc                 P    t         t        |   |       |g | _        y || _        y )N)problem)superr   __init__
reductions)selfr	   r   	__class__s      Q/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/reductions/chain.pyr   zChain.__init__   s'    eT#G#4 * 2"
    c                 ,    t        | j                        S N)strr   r   s    r   __str__zChain.__str__   s    4??##r   c                 2    dt        | j                        z  S )NzChain(reductions=%s))reprr   r   s    r   __repr__zChain.__repr__   s    %T__(===r   c                 P    | j                   D ]  }t        ||      s|c S  t        r   )r   
isinstanceKeyError)r   reduction_type	reductions      r   getz	Chain.get   s,     	!I)^4  	! r   c                 t    | j                   D ])  }|j                  |      s y|j                  |      \  }}+ y)a  A problem is accepted if the sequence of reductions is valid.

        In particular, the i-th reduction must accept the output of the i-1th
        reduction, with the first reduction (self.reductions[0])
        in the sequence taking as input the supplied problem.

        Parameters
        ----------
        problem : Problem
            The problem to check.

        Returns
        -------
        bool
            True if the chain can be applied, False otherwise.
        FT)r   acceptsapply)r   r	   r_s       r   r    zChain.accepts   s=    $  	*A99W%)JGQ	* r   verbosec                     g }| j                   D ]\  }|r3t        j                  j                  dt	        |      j
                         |j                  |      \  }}|j                  |       ^ ||fS )a  Applies the chain to a problem and returns an equivalent problem.

        Parameters
        ----------
        problem : Problem
            The problem to which the chain will be applied.
        verbose : bool, optional
            Whehter to print verbose output.

        Returns
        -------
        Problem or dict
            The problem yielded by applying the reductions in sequence,
            starting at self.reductions[0].
        list
            The inverse data yielded by each of the reductions.
        zApplying reduction %s)r   sLOGGERinfotype__name__r!   append)r   r	   r$   inverse_datar"   invs         r   r!   zChain.apply6   si    $  	%A5tAw7G7GH777+LGS$		%
 $$r   c                     t        t        t        | j                  |                  D ]  \  }}|j	                  ||      } |S )zKReturns a solution to the original problem given the inverse_data.
        )reversedlistzipr   invert)r   solutionr,   r"   r-   s        r   r2   zChain.invertP   sA     tC$FGH 	/FAsxx#.H	/r   )NN)r   N)F)r*   
__module____qualname____doc__r   r   r   r   r   boolr    r!   r2   __classcell__)r   s   @r   r   r      sA    C$># >$ 0%d %4r   r   N)cvxpyr   r&   cvxpy.reductions.reductionr   r    r   r   <module>r<      s     0PI Pr   