
    ^MhH                     D    d dl Zd dlZddgZ ed          Zd	dZd ZdS )
    Nsave_npzload_npzF)allow_pickleTc                 j   i }|j         dv r"|                    |j        |j                   nn|j         dk    r|                    |j                   nG|j         dk    r"|                    |j        |j                   nd|j          d}t          |          |                    |j                             d	          |j	        |j
        
           t          |t          j        j                  r|                    d           |rt          j        | fi | dS t          j        | fi | dS )aj   Save a sparse matrix or array 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 or sparray
        The sparse matrix or array to save.
        Supported formats: ``csc``, ``csr``, ``bsr``, ``dia`` or ``coo``.
    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 as sp
    >>> sparse_matrix = sp.sparse.csc_matrix([[0, 0, 3], [4, 0, 0]])
    >>> sparse_matrix
    <Compressed Sparse Column sparse matrix of dtype 'int64'
        with 2 stored elements and shape (2, 3)>
    >>> sparse_matrix.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)

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

    >>> sparse_matrix
    <Compressed Sparse Column sparse matrix of dtype 'int64'
        with 2 stored elements and shape (2, 3)>
    >>> 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dataT)	_is_arrayN)r   updater   r   r   r   r   NotImplementedErrorencoder   r   
isinstancespsparsesparraynpsavez_compressedsavez)filematrix
compressedarrays_dictmsgs        W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/sparse/_matrix_io.pyr   r      s]   \ K}---6>&-HHHH	%		6>2222	%		vzvz::::UV]UUU!#&&&}##G,,l[    
 &")+,, +T*** &
D00K00000
%%%%%%%    c                 T   t          j        | fi t          5 }|                    d          }|t	          d|  d          |                                }t          |t                    s|                    d          }|                    d          r|dz   }n|dz   }	 t          t          j        |           }n&# t          $ r}t	          d	| d
          |d}~ww xY w|dv r4 ||d         |d         |d         f|d                   cddd           S |dk    r- ||d         |d         f|d                   cddd           S |dk    r5 ||d         |d         |d         ff|d                   cddd           S t          d| d          # 1 swxY w Y   dS )a   Load a sparse array/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_array, csr_array, bsr_array, dia_array or coo_array
        A sparse array/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 array/matrix to a file using ``.npz`` format.
    numpy.load: Load several arrays from a ``.npz`` archive.

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

    >>> import numpy as np
    >>> import scipy as sp
    >>> sparse_array = sp.sparse.csc_array([[0, 0, 3], [4, 0, 0]])
    >>> sparse_array
    <Compressed Sparse Column sparse array of dtype 'int64'
        with 2 stored elements and shape (2, 3)>
    >>> sparse_array.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)

    >>> sp.sparse.save_npz('/tmp/sparse_array.npz', sparse_array)
    >>> sparse_array = sp.sparse.load_npz('/tmp/sparse_array.npz')

    >>> sparse_array
    <Compressed Sparse Column sparse array of dtype 'int64'
        with 2 stored elements and shape (2, 3)>
    >>> sparse_array.toarray()
    array([[0, 0, 3],
           [4, 0, 0]], dtype=int64)

    In this example we force the result to be csr_array from csr_matrix
    >>> sparse_matrix = sp.sparse.csc_matrix([[0, 0, 3], [4, 0, 0]])
    >>> sp.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix)
    >>> tmp = sp.sparse.load_npz('/tmp/sparse_matrix.npz')
    >>> sparse_array = sp.sparse.csr_array(tmp)
    r   Nz	The file z+ does not contain a sparse array or matrix.r   r   _array_matrixzUnknown format ""r   r   r   r   r   )r   r   r   r   r   r   z4Load is not implemented for sparse matrix of format r   )r   loadPICKLE_KWARGSget
ValueErroritemr   strdecodegetattrr   r   AttributeErrorr   )r"   loadedsparse_formatsparse_typeclses         r'   r   r   P   s   l 
	'	'	'	' !S6

8,,  : : : : ; ; ;%**,,--- 	: *0099M::k"" 	4'(2KK')3K	G")%566CC 	G 	G 	G>>>>??QF	G 1113vy(96(;KL#G_. . ./!S !S !S !S !S !S !S !S2 e##3vy(9:#G_. . .5!S !S !S !S !S !S !S !S8 e##3vu(FG#G_. . .;!S !S !S !S !S !S !S !S@ & 'RAN'R 'R 'R S S SA!S !S !S !S !S !S !S !S !S !SsH   B	F"B>=F>
C!CC!!.F&F.F
FF!$F!)T)	numpyr   scipyr   __all__dictr.   r   r    r(   r'   <module>r@      sw           z
" %(((B& B& B& B&JWS WS WS WS WSr(   