B
    ˜‘[Þ  ã               @   s<   d dl mZmZ d dlmZ d dlmZ dd„ Zdd„ ZdS )	é    )Úprint_functionÚdivision)Úrange)ÚSparseMatrixc             C   s¢   dd„ t |  ¡ Ž D ƒ\}}}dg|r,|d ndd  }x0t|ƒD ]$\}}| |g|||d    ¡ q@W | t|ƒg| jt|ƒ d  ¡ | j| jg}||||gS )aÇ  Converts a sparse matrix to Compressed Sparse Row (CSR) format.

    Parameters
    ==========

    A : contains non-zero elements sorted by key (row, column)
    JA : JA[i] is the column corresponding to A[i]
    IA : IA[i] contains the index in A for the first non-zero element
        of row[i]. Thus IA[i+1] - IA[i] gives number of non-zero
        elements row[i]. The length of IA is always 1 more than the
        number of rows in the matrix.
    c             S   s   g | ]}t |ƒ‘qS © )Úlist)Ú.0Úir   r   ú9lib/python3.7/site-packages/sympy/matrices/sparsetools.pyú
<listcomp>   s    z_doktocsr.<locals>.<listcomp>r   é   )ÚzipZrow_listÚ	enumerateÚextendÚlenZrowsZcols)ZdokÚrowÚJAÚAÚIAr	   ÚrÚshaper   r   r
   Ú	_doktocsr   s     "r   c       
      C   sz   i }| \}}}}xZt t|ƒd ƒD ]F}t|| ||d  ƒ}x*t|| || ƒD ]\}}	||||	f< qPW q"W t||g Ž S )z3Converts a CSR representation to DOK representationr   )r   r   Úslicer   r   )
ZcsrZsmatr   r   r   r   r	   ÚindicesÚlÚmr   r   r
   Ú	_csrtodok   s    r   N)	Z
__future__r   r   Zsympy.core.compatibilityr   Zsympyr   r   r   r   r   r   r
   Ú<module>   s   