#NEWLINE# def write_sparse_matrix( matrix , filename , compressed = False ) : #NEWLINE# #INDENT# '\n    Write a ``scipy.sparse.csr_matrix`` or ``scipy.sparse.csc_matrix`` to disk\n    at ``filename``, optionally compressed.\n\n    Args:\n        matrix (``scipy.sparse.csr_matrix`` or ``scipy.sparse.csr_matrix``)\n        filename (str): /path/to/file on disk to which matrix objects will be written;\n            if ``filename`` does not end in ``.npz``, that extension is\n            automatically appended to the name\n\n    .. See also: http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.savez.html\n    ' #NEWLINE# if ( not isinstance ( matrix , ( csc_matrix , csr_matrix ) ) ) : #NEWLINE# #INDENT# raise TypeError ( 'input matrix must be a scipy sparse csr or csc matrix' ) #NEWLINE# #UNINDENT# _make_dirs ( filename ) #NEWLINE# if ( compressed is False ) : #NEWLINE# #INDENT# savez ( compressed , data = matrix . data , indices = matrix . indices , indptr = matrix . indptr , shape = matrix . shape ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# savez_compressed ( filename , data = matrix . data , indices = matrix . indices , indptr = matrix . indptr , shape = matrix . shape )