
    bi	                         d Z ddlmZ ddlZddlZddlmZ e	ej                  ej                  g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.
    )TupleN   )base_matrix_interfacec                   z    e Zd ZdZej
                  ZddefdZd Z	de
edf   fdZd Zd	 Zd
e
edf   fdZd Zy)NDArrayInterfacezM
    An interface to convert constant values to the numpy ndarray class.
    convert_scalarsc                    t         j                  j                  |      r|j                         }nut	        |t
        j                        rt        j                  |      }nEt	        |t              r t        j                  |      j                  }nt        j                  |      }|j                  t
        j                  gt        z   v r|S |j                  t
        j                        S )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.
        )scipysparseissparsetoarray
isinstancenumpymatrixasarraylistTdtypefloat64COMPLEX_TYPESastype)selfvaluer   results       l/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/interface/numpy_interface/ndarray_interface.pyconst_to_matrixz NDArrayInterface.const_to_matrix#   s     <<  ']]_Fu||,]]5)Ft$]]5)++F]]5)F<<EMM?]::M==//    c                 ,    t        j                  |      S N)r   eye)r   sizes     r   identityzNDArrayInterface.identity;   s    yyr   return.c                 :    t        d |j                  D              S )Nc              3   2   K   | ]  }t        |        y wr   )int).0ds     r   	<genexpr>z)NDArrayInterface.shape.<locals>.<genexpr>@   s     2SV2s   )tupleshaper   r   s     r   r+   zNDArrayInterface.shape?   s    2V\\222r   c                 J    t        j                  | j                  |            S )z6Returns the number of elements in the matrix.
        )r   prodr+   r,   s     r   r!   zNDArrayInterface.sizeB   s     zz$**V,--r   c                 "    |j                         S r   )itemr,   s     r   scalar_valuezNDArrayInterface.scalar_valueH   s    {{}r   r+   c                 6    t        j                  |d      |z   S )Nr   )r   )r   zeros)r   r   r+   s      r   scalar_matrixzNDArrayInterface.scalar_matrixL   s    {{5	2U::r   c                 2    t        j                  ||d      S )NF)order)r   reshape)r   r   r!   s      r   r8   zNDArrayInterface.reshapeO   s    }}VT55r   N)F)__name__
__module____qualname____doc__r   ndarrayTARGET_MATRIXboolr   r"   r   r&   r+   r!   r1   r4   r8    r   r   r   r      sZ     MMM0d 003uS#X 3.;%S/ ;6r   r   )r<   typingr   r   scipy.sparser
    r   basecomplex	complex64
complex128r   BaseMatrixInterfacer   r@   r   r   <module>rI      sB   "    , %//5+;+;<36t// 36r   