
    bi^                     H    d Z ddlZddlmZmZmZ d Zd Zd Z	d Z
d 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.

THIS FILE IS DEPRECATED AND MAY BE REMOVED WITHOUT WARNING!
DO NOT CALL THESE FUNCTIONS IN YOUR CODE!
    N)mul	sum_dictstmulc                 @     ddt         f fd}ddt         f fd}||fS )Nis_absc                     |j                   d   }t        | j                  j                        }|t	        j
                  |||      z  }y )Nr   )shapevec_to_dictvar_offsets	var_sizes
constr_mulconstraints)xyr   rowsvar_dictsym_datas        S/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/problems/iterative.pyaccAmulzget_mul_funcs.<locals>.accAmul   sH    wwqzq("6"6'113	Z,,hfEE    c                     t        j                  |       }t        j                  ||      }|t        |j                  j
                  j                        z  }y )N)constr_unpackr   constr_tmuldict_to_vecr   r   x_length)r   r   r   termsval_dictr   s        r   accATmulzget_mul_funcs.<locals>.accATmul%   sW    h22A6x33UFC	[8#7#7!++X->->@ 	@r   )F)bool)r   r   r   s   `  r   get_mul_funcsr       s,    Fd F@t @ Xr   c                     g }d}| D ]]  }|j                   \  }}t        j                  ||f      }t        |      D ]  }||||z    |dd|f<   ||z  } |j	                  |       _ |S )z<Unpacks a vector into a list of values for constraints.
    r   N)sizenpzerosrangeappend)	r   vectorvaluesoffsetconstrr   colsvalcols	            r   r   r   /   s     FF [[
dhhd|$; 	C t4C3KdNF	 	c Mr   c                     i }|j                         D ]V  \  }}||   }t        j                  |      }||   }t        |d         D ]  }| ||d   |z    |dd|f<   ||d   z  } |||<   X |S )ar  Converts a vector to a map of variable id to value.

    Parameters
    ----------
    vector : NumPy matrix
        The vector of values.
    var_offsets : dict
        A map of variable id to offset in the vector.
    var_sizes : dict
        A map of variable id to variable size.

    Returns
    -------
    dict
        A map of variable id to variable value.
       r   N)itemsr#   r$   r%   )	r'   r   r   r   id_r)   r"   valuer-   s	            r   r
   r
   >   s    " H"((* V~S!a> 	C"6$q'&.9E!S&Md1gF	  Or   c                 6   t        j                  |      }| j                         D ]p  \  }}||   }||   }t        |d         D ]P  }	t        j                  |      r||||d   |z    n%t        j
                  |dd|	f         |||d   |z    ||d   z  }R r |S )ah  Converts a map of variable id to value to a vector.

    Parameters
    ----------
    val_dict : dict
        A map of variable id to value.
    var_offsets : dict
        A map of variable id to offset in the vector.
    var_sizes : dict
        A map of variable id to variable size.
    vector : NumPy matrix
        The vector to store the values in.
    r/   r   N)r#   r$   r0   r%   isscalarsqueeze)
r   r   r   vec_lenr'   r1   r2   r"   r)   r-   s
             r   r   r   [   s     XXgFnn& 	
U~S!a> 	C{{5!05vd1gfn-02

5C=0Ivd1gfn-d1gF		 Mr   c                 8   t        j                  |      }d}| D ]}  }t        |j                  ||      }|j                  \  }}	t        |	      D ]G  }
t        j                  |      r	|||||z    n"t        j                  |dd|
f         ||||z    ||z  }I  |S )aj  Multiplies a vector by the matrix implied by the constraints.

    Parameters
    ----------
    constraints : list
        A list of linear constraints.
    var_dict : dict
        A dictionary mapping variable id to value.
    vec_size : int
        The length of the product vector.
    is_abs : bool
        Multiply by the absolute value of the matrix?
    r   N)r#   r$   r   exprr"   r%   r4   r5   )r   r   vec_sizer   productr)   r*   resultr   r+   r-   s              r   r   r   x   s     hhx GF 	V[[(F3[[
d; 	C{{6".4vd{+.0jj3.Hvd{+dNF		 Nr   c                     g }t        | |      D ]+  \  }}|j                  t        |j                  ||             - t	        |      S )ai  Multiplies a vector by the transpose of the constraints matrix.

    Parameters
    ----------
    constraints : list
        A list of linear constraints.
    values : list
        A list of NumPy matrices.
    is_abs : bool
        Multiply by the absolute value of the matrix?

    Returns
    -------
    dict
        A mapping of variable id to value.
    )zipr&   r   r8   r   )r   r(   r   productsr*   r,   s         r   r   r      sG    " H;/ 8V[[#v678Xr   )__doc__numpyr#   cvxpy.lin_ops.tree_matr   r   r   r    r   r
   r   r   r    r   r   <module>rC      s3   ,  7 7&::<r   