
    g;                         d Z  G d de      Zedk(  rd	  e ed            Z e edd            Z eee      Zej                  ddd	       ej                  d
dd        e
ej                                yy)z
sparse this module provides basic pure python sparse matrix implementation
notably this allows the sparse matrix to be output in various formats
c                   2    e Zd ZdZd ZddZd Zd	dZd Zy)
Matrixz.This is a dictionary based sparse matrix classc                     || _         || _        |D ci c]  }|i  c}| _        |D ci c]  }|i  c}| _        yc c}w c c}w )zeinitialises the class by creating a matrix that will have the given
        rows and columns
        N)rowscolsrowdictcoldict)selfr   r   rowcols        H/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/pulp/sparse.py__init__zMatrix.__init__"   sF     		+/0CR0+/0CR0 10s	   
<
Ac                 $   |r|| j                   vsr|r|| j                  vs>t        j                  | ||f|       || j                  |   |<   || j
                  |   |<   y t        | j                         t        d| d      t        d| d      )Nzcol z is not in the matrix columnszrow z is not in the matrix rows)r   r   dict__setitem__r   r   printRuntimeError)r	   r
   r   itemcolcheckrowchecks         r   addz
Matrix.add+   s    S		1DII!5  Sz48)-S!#&)-S!#&dii "T#.K#LMMcU*DEFF    c                     || j                   v r.|j                         D ]  \  }}| j                  |||d        yt        d      )zadds a columnF)r   z col is not in the matrix columnsN)r   itemsr   r   )r	   r   rowitemsr
   r   s        r   addcolzMatrix.addcol7   sJ    $))%^^- 9	Tc4%89 ABBr   c                 0    t         j                  | ||      S )N)r   get)r	   kds      r   r   z
Matrix.get?   s    xxa##r   c                    t        |       }g }g }g }g }t        | j                        D ]  \  }}|j                  t        |             |j	                  t        | j                  |   j                                      |j	                  t        | j                  |   j                                      |j                  t        |      |d   z
          |j                  t        |             |||||fS )N)	len	enumerater   appendextendlistr   valueskeys)r	   numElselemBase
startsBaseindBaselenBaseir   s           r   col_based_arrayszMatrix.col_based_arraysB   s    T
		* 	;FAsc(m,OODc!2!9!9!;<=NN4S 1 6 6 89:NN3x=:b>9:		;
 	#h-(z7GX==r   N)FF)    )	__name__
__module____qualname____doc__r   r   r   r   r/    r   r   r   r      s     81
GC$>r   r   __main__
   2   <      4   r      6   stuffN)r4   r   r   r1   r&   ranger   r   matr   r   r/   r5   r   r   <module>rA      s   2/>T />d zb	?Db"D
t
CGGAr6GGAr7	#


 ! r   