�
��g�# � �X � d dl mZ d dlmZ d dlmZ d dlmZmZ ddl m
Z d� Zd� Z
d � Zd
S )� )�Dict)�Dummy)�is_sequence)�as_int�
filldedent� )�MutableSparseMatrixc � � d� t | � � � � D � � \ }}}dg|r|d nddz z }t |� � D ]*\ }}|� |g|||dz
z
z � � �+|� t |� � g| j t |� � z
dz z � � | j | j g}||||gS )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.
Examples
========
>>> from sympy.matrices.sparsetools import _doktocsr
>>> from sympy import SparseMatrix, diag
>>> m = SparseMatrix(diag(1, 2, 3))
>>> m[2, 0] = -1
>>> _doktocsr(m)
[[1, 2, -1, 3], [0, 1, 0, 2], [0, 1, 2, 4], [3, 3]]
c �, � g | ]}t |� � ��S � )�list)�.0�is �j/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/matrices/sparsetools.py�
<listcomp>z_doktocsr.<locals>.<listcomp>! s � �8�8�8�a�$�q�'�'�8�8�8� r r )�zip�row_list� enumerate�extend�len�rows�cols)�dok�row�JA�A�IAr �r�shapes r � _doktocsrr! s� � �0 9�8�3������#7�8�8�8�J�C��Q�
���#�s�1�v�v�!�q�(� )�B��#��� (� (���1�
� � �1�#�q�3�q�1�u�:�~�&�'�'�'�'��I�I�s�1�v�v�h���3�r�7�7�*�Q�.�/�0�0�0�
�X�s�x� �E�
�r�2�u��r c � � i }| \ }}}}t t |� � dz
� � D ]J}t || ||dz � � }t || || � � D ]\ }} |||| f<