
    bi*                     X    d Z ddlZddlmZ ddlZddlZ G d dej                        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.
    N)Tuplec                   v   e Zd ZdZej
                  ddefd       Zed        Z	ej
                  d        Z
d Zej
                  d        Zej
                  d        Zd	eed
f   fdZd	eed
f   fdZej
                  d	eed
f   fd       Zd Zej
                  d	eed
f   fd       Z	 ddededdfdZd Zy)BaseMatrixInterfacezd
    An interface between constants' internal values
    and the target matrix used internally.
    convert_scalarsc                     t               )a  Convert an arbitrary value into a matrix of type self.target_matrix.

        Args:
            value: The constant to be converted.
            convert_scalars: Should scalars be converted?

        Returns:
            A matrix of type self.target_matrix or a scalar.
        NotImplementedError)selfvaluer   s      `/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/interface/base_matrix_interface.pyconst_to_matrixz#BaseMatrixInterface.const_to_matrix   s     "##    c                 "     ddt         f fd}|S )Nr   c                     |sRt         j                  j                  j                  |      r)t         j                  j                  j	                  |      S  | |      S N)cvxpy	interfacematrix_utilities	is_scalarscalar_value)r
   r   r   	converters      r   new_converterz7BaseMatrixInterface.scalar_const.<locals>.new_converter.   sF    "u'G'G'Q'QRW'X77DDUKK u--r   F)bool)r   r   s   ` r   scalar_constz BaseMatrixInterface.scalar_const,   s    	. 	.
 r   c                     t               r   r   )r
   sizes     r   identityzBaseMatrixInterface.identity6       !##r   c                 V    t        j                  | j                  |      t              S )N)dtype)npprodshapeintr
   matrixs     r   r   zBaseMatrixInterface.size;   s    wwtzz&)55r   c                     t               r   r   r&   s     r   r$   zBaseMatrixInterface.shape?   r   r   c                     t               r   r   r&   s     r   r   z BaseMatrixInterface.scalar_valueD   r   r   r$   .c                 &    | j                  d|      S )Nr   scalar_matrixr
   r$   s     r   zeroszBaseMatrixInterface.zerosI       !!!U++r   c                 &    | j                  d|      S )N   r+   r-   s     r   oneszBaseMatrixInterface.onesM   r/   r   c                     t               r   r   )r
   r   r$   s      r   r,   z!BaseMatrixInterface.scalar_matrixQ   r   r   c                     ||   }t         j                  j                  j                  |      dk(  r)t         j                  j                  j	                  |      S |S )Nr1   r1   )r   r   r   r$   r   )r
   r'   keyr   s       r   indexzBaseMatrixInterface.indexV   sH    s??++11%8FB??33@@GGLr   c                     t               r   r   )r
   r'   r$   s      r   reshapezBaseMatrixInterface.reshape_   r   r   	vert_step
horiz_stepreturnNc	                 b    | j                  ||||      }||||z   ||||z   |fxx   |z  cc<   y)a  Add the block to a slice of the matrix.

        Args:
            matrix: The matrix the block will be added to.
            block: The matrix/scalar to be added.
            vert_offset: The starting row for the matrix slice.
            horiz_offset: The starting column for the matrix slice.
            rows: The height of the block.
            cols: The width of the block.
            vert_step: The row step size for the matrix slice.
            horiz_step: The column step size for the matrix slice.
        N)_format_block)	r
   r'   blockvert_offsethoriz_offsetrowscolsr:   r;   s	            r   	block_addzBaseMatrixInterface.block_addc   sR     ""65$={D,i7\$.
:; 	<?D	E 	<r   c                 0   t         j                  j                  j                  |      r<| j	                  t         j                  j                  j                  |      ||      }|S t         j                  j                  j                  |      r|dkD  r| j                  |||f      }|S t         j                  j                  j                  |      s|dk(  r| j                  |||f      }|S t        |      t        |      k7  r| j                  |      }|S )zFormats the block for block_add.

        Args:
            matrix: The matrix the block will be added to.
            block: The matrix/scalar to be added.
            rows: The height of the block.
            cols: The width of the block.
        r1   )
r   r   r   r   r,   r   	is_vectorr9   typer   )r
   r'   r?   rB   rC   s        r   r>   z!BaseMatrixInterface._format_blocku   s     ??++55e<&&00==eDdDRE  __--77>4!8LLt5E  11;;EBtqyLLt5E  %[DL(((/Er   r   r5   )__name__
__module____qualname____doc__abcabstractmethodr   r   staticmethodr   r   r   r$   r   r   r%   r.   r2   r,   r7   r9   rD   r>    r   r   r   r      s9   
 	
$d 
$ 
$   	$ $6 	$ $ 	$ $,5c? ,,%S/ , 	$%S/ $ $ 	$U38_ $ $ 9:E E25E>BE$r   r   )	metaclass)
rK   rL   typingr   numpyr"    cvxpy.interface.matrix_utilitiesr   ABCMetar   rO   r   r   <module>rU      s*       'sCKK sr   