#NEWLINE# def _doktocsr( dok ) : #NEWLINE# #INDENT# 'Converts a sparse matrix to Compressed Sparse Row (CSR) format.\n\n    Parameters\n    ==========\n\n    A : contains non-zero elements sorted by key (row, column)\n    JA : JA[i] is the column corresponding to A[i]\n    IA : IA[i] contains the index in A for the first non-zero element\n        of row[i]. Thus IA[i+1] - IA[i] gives number of non-zero\n        elements row[i]. The length of IA is always 1 more than the\n        number of rows in the matrix.\n    ' #NEWLINE# ( row , JA , A ) = [ list ( i ) for i in zip ( * dok . row_list ( ) ) ] #NEWLINE# IA = ( [ 0 ] * ( ( row [ 0 ] if row else 0 ) + 1 ) ) #NEWLINE# for ( i , r ) in enumerate ( row ) : #NEWLINE# #INDENT# IA . extend ( ( [ i ] * ( r - row [ ( i - 1 ) ] ) ) ) #NEWLINE# #UNINDENT# IA . extend ( ( [ len ( A ) ] * ( ( dok . rows - len ( IA ) ) + 1 ) ) ) #NEWLINE# shape = [ dok . rows , dok . cols ] #NEWLINE# return [ A , JA , IA , shape ]