
    xf                     <    d dl Zd dlZddgZ ed      ZddZd Zy)	    Nsave_npzload_npzF)allow_picklec                 L   i }|j                   dv r(|j                  |j                  |j                         n||j                   dk(  r|j                  |j                         nP|j                   dk(  r(|j                  |j
                  |j                         nt        d|j                    d      |j                  |j                   j                  d	      |j                  |j                  
       |rt        j                  | fi | yt        j                  | fi | y)ac   Save a sparse matrix to a file using ``.npz`` format.

    Parameters
    ----------
    file : str or file-like object
        Either the file name (string) or an open file (file-like object)
        where the data will be saved. If file is a string, the ``.npz``
        extension will be appended to the file name if it is not already
        there.
    matrix: spmatrix (format: ``csc``, ``csr``, ``bsr``, ``dia`` or coo``)
        The sparse matrix to save.
    compressed : bool, optional
        Allow compressing the file. Default: True

    See Also
    --------
    scipy.sparse.load_npz: Load a sparse matrix from a file using ``.npz`` format.
    numpy.savez: Save several arrays into a ``.npz`` archive.
    numpy.savez_compressed : Save several arrays into a compressed ``.npz`` archive.

    Examples
    --------
    Store sparse matrix to disk, and load it again:

    >>> import numpy as np
    >>> import scipy.sparse
    >>> sparse_matrix = scipy.sparse.csc_matrix(np.array([[0, 0, 3], [4, 0, 0]]))
    >>> sparse_matrix
    <2x3 sparse matrix of type '<class 'numpy.int64'>'
       with 2 stored elements in Compressed Sparse Column format>
    >>> sparse_matrix.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)

    >>> scipy.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix)
    >>> sparse_matrix = scipy.sparse.load_npz('/tmp/sparse_matrix.npz')

    >>> sparse_matrix
    <2x3 sparse matrix of type '<class 'numpy.int64'>'
       with 2 stored elements in Compressed Sparse Column format>
    >>> sparse_matrix.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)
    csccsrbsr)indicesindptrdia)offsetscoo)rowcolz4Save is not implemented for sparse matrix of format .ascii)formatshapedataN)r   updater   r   r   r   r   NotImplementedErrorencoder   r   npsavez_compressedsavez)filematrix
compressedarrays_dicts       9/usr/lib/python3/dist-packages/scipy/sparse/_matrix_io.pyr   r      s    Z K}}--6>>&--H	%	6>>2	%	vzzvzz:!$XY_YfYfXggh"ijj}}##G,ll[[  
 
D0K0
%%    c                    t        j                  | fi t        5 }	 |d   }|j                         }t        |t              s|j                  d      }	 t        t        j                  | d      }|d	v r" ||d
   |d   |d   f|d         cddd       S |dk(  r ||d
   |d   f|d         cddd       S |dk(  r# ||d
   |d   |d   ff|d         cddd       S t        dj                  |            # t        $ r}t	        d|  d      |d}~ww xY w# t        $ r}t	        d| d      |d}~ww xY w# 1 sw Y   yxY w)a   Load a sparse matrix from a file using ``.npz`` format.

    Parameters
    ----------
    file : str or file-like object
        Either the file name (string) or an open file (file-like object)
        where the data will be loaded.

    Returns
    -------
    result : csc_matrix, csr_matrix, bsr_matrix, dia_matrix or coo_matrix
        A sparse matrix containing the loaded data.

    Raises
    ------
    OSError
        If the input file does not exist or cannot be read.

    See Also
    --------
    scipy.sparse.save_npz: Save a sparse matrix to a file using ``.npz`` format.
    numpy.load: Load several arrays from a ``.npz`` archive.

    Examples
    --------
    Store sparse matrix to disk, and load it again:

    >>> import numpy as np
    >>> import scipy.sparse
    >>> sparse_matrix = scipy.sparse.csc_matrix(np.array([[0, 0, 3], [4, 0, 0]]))
    >>> sparse_matrix
    <2x3 sparse matrix of type '<class 'numpy.int64'>'
       with 2 stored elements in Compressed Sparse Column format>
    >>> sparse_matrix.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)

    >>> scipy.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix)
    >>> sparse_matrix = scipy.sparse.load_npz('/tmp/sparse_matrix.npz')

    >>> sparse_matrix
    <2x3 sparse matrix of type '<class 'numpy.int64'>'
        with 2 stored elements in Compressed Sparse Column format>
    >>> sparse_matrix.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)
    r   z	The file z" does not contain a sparse matrix.Nr   _matrixzUnknown matrix format ""r   r   r   r   r   )r   r   r   r   r   r   z7Load is not implemented for sparse matrix of format {}.)r   loadPICKLE_KWARGSKeyError
ValueErroritem
isinstancestrdecodegetattrscipysparseAttributeErrorr   r   )r   loadedmatrix_formateclss        r!   r   r   L   s   b 
	'	' [6	Z"8,M &**,-- *009M	P%,,=/(ABC 11vy(96(;KLTZ[bTcd'[ [( e#vy(9:&/R+[ [, e#vu(FGvV]_/[ [2 & 'DDJF=DY[ [-  	Zy.PQRXYY	Z  	P6}oQGHaO	P[ [sc   D>C<1D>D1D>D>:D>"D><	DDDD>	D;&D66D;;D>>E)T)	numpyr   scipy.sparser/   __all__dictr'   r   r    r"   r!   <module>r;      s.     z
" %(>&BK[r"   