ó
Ħĵ\c           @  sL   d  d l  m Z m Z d  d l m Z d d l m Z d   Z d   Z d S(   i˙˙˙˙(   t   divisiont   print_function(   t   rangei   (   t   SparseMatrixc         C  sß   g  t  |  j     D] } t |  ^ q \ } } } d g | rJ | d n d d } x: t |  D], \ } } | j | g | | | d  qb W| j t |  g |  j t |  d  |  j |  j g } | | | | g S(   sÇ  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.
    i    i   (   t   zipt   row_listt   listt	   enumeratet   extendt   lent   rowst   cols(   t   dokt   it   rowt   JAt   At   IAt   rt   shape(    (    s9   lib/python2.7/site-packages/sympy/matrices/sparsetools.pyt	   _doktocsr   s    4!$+c   
      C  s   i  } |  \ } } } } xq t  t |  d  D]Y } t | | | | d  } x5 t | | | |  D] \ } }	 | | | |	 f <qh Wq/ Wt | | g   S(   s3   Converts a CSR representation to DOK representationi   (   R   R	   t   sliceR   R   (
   t   csrt   smatR   R   R   R   R   t   indicest   lt   m(    (    s9   lib/python2.7/site-packages/sympy/matrices/sparsetools.pyt	   _csrtodok   s    $N(	   t
   __future__R    R   t   sympy.core.compatibilityR   t   sparseR   R   R   (    (    (    s9   lib/python2.7/site-packages/sympy/matrices/sparsetools.pyt   <module>   s   	