§
    fŠtjè  ã                   óf   — d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z
 ddlmZmZ dgZd„ Zd
d	„ZdS )zSparse matrix norms.

é    N)Úissparse)Úsvds)Úconvert_pydata_sparse_to_scipy)ÚsqrtÚabsÚnormc                 ó~   — t           j                             | ¦  «        }t          j                             |¦  «        S )N)ÚspÚ_sputilsÚ_todataÚnpÚlinalgr   )ÚxÚdatas     úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/sparse/linalg/_norm.pyÚ_sparse_frobenius_normr      s+   € ÝŒ;×Ò˜qÑ!Ô!€DÝŒ9�>Š>˜$ÑÔÐó    c                 óÊ	  — t          | d¬¦  «        } t          | ¦  «        st          d¦  «        ‚|€|dv rt          | ¦  «        S |                      ¦   «         } |€"t          t          | j        ¦  «        ¦  «        }nbt          |t
          ¦  «        sMd}	 t          |¦  «        }n"# t          $ r}t          |¦  «        |‚d}~ww xY w||k    rt          |¦  «        ‚|f}| j        }t          |¦  «        dk    �r²|\  }}| |cxk    r|k     rn n| |cxk    r|k     sn d|›d	| j        ›�}	t          |	¦  «        ‚||z  ||z  k    rt          d
¦  «        ‚|dk    rt          | ddd¬¦  «        \  }
}}
|d         S |dk    rt          ‚|dk    r5t          | ¦  «                             |¬¦  «                             ¦   «         S |t$          j        k    r5t          | ¦  «                             |¬¦  «                             ¦   «         S |dk    r5t          | ¦  «                             |¬¦  «                             ¦   «         S |t$          j         k    r5t          | ¦  «                             |¬¦  «                             ¦   «         S |dv rt          | ¦  «        S t          d¦  «        ‚t          |¦  «        dk    �r|\  }| |cxk    r|k     sn d|›d	| j        ›�}	t          |	¦  «        ‚|t$          j        k    r%t          | ¦  «                             |¬¦  «        }�n>|t$          j         k    r%t          | ¦  «                             |¬¦  «        }�n|dk    r| dk                         |¬¦  «        }nç|dk    r$t          | ¦  «                             |¬¦  «        }n½|dv rDt+          t          | ¦  «                             d¦  «                             |¬¦  «        ¦  «        }nu	 |dz    n"# t          $ r}t          d¦  «        |‚d}~ww xY wt%          j        t          | ¦  «                             |¦  «                             |¬¦  «        d|z  ¦  «        }t/          |d¦  «        r&|                     ¦   «                              ¦   «         S t/          |d¦  «        r|j                             ¦   «         S |                     ¦   «         S t          d¦  «        ‚)aº
  
    Norm of a sparse matrix

    This function is able to return one of seven different matrix norms,
    depending on the value of the ``ord`` parameter.

    Parameters
    ----------
    x : a sparse array
        Input sparse array.
    ord : {non-zero int, inf, -inf, 'fro'}, optional
        Order of the norm (see table under ``Notes``). inf means numpy's
        `inf` object.
    axis : {int, 2-tuple of ints, None}, optional
        If `axis` is an integer, it specifies the axis of `x` along which to
        compute the vector norms.  If `axis` is a 2-tuple, it specifies the
        axes that hold 2-D matrices, and the matrix norms of these matrices
        are computed.  If `axis` is None then either a vector norm (when `x`
        is 1-D) or a matrix norm (when `x` is 2-D) is returned.

    Returns
    -------
    n : float or ndarray

    Notes
    -----
    Some of the ord are not implemented because some associated functions like,
    _multi_svd_norm, are not yet available for sparse array.

    This docstring is modified based on numpy.linalg.norm.
    https://github.com/numpy/numpy/blob/main/numpy/linalg/linalg.py

    The following norms can be calculated:

    =====  ============================
    ord    norm for sparse arrays
    =====  ============================
    None   Frobenius norm
    'fro'  Frobenius norm
    inf    max(sum(abs(x), axis=1))
    -inf   min(sum(abs(x), axis=1))
    0      abs(x).sum(axis=axis)
    1      max(sum(abs(x), axis=0))
    -1     min(sum(abs(x), axis=0))
    2      Spectral norm (the largest singular value)
    -2     Not implemented
    other  Not implemented
    =====  ============================

    The Frobenius norm is given by [1]_:

        :math:`||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}`

    References
    ----------
    .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*,
        Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15

    Examples
    --------
    >>> from scipy.sparse import csr_array, diags_array
    >>> import numpy as np
    >>> from scipy.sparse.linalg import norm
    >>> a = np.arange(9) - 4
    >>> a
    array([-4, -3, -2, -1, 0, 1, 2, 3, 4])
    >>> b = a.reshape((3, 3))
    >>> b
    array([[-4, -3, -2],
           [-1, 0, 1],
           [ 2, 3, 4]])

    >>> b = csr_array(b)
    >>> norm(b)
    7.745966692414834
    >>> norm(b, 'fro')
    7.745966692414834
    >>> norm(b, np.inf)
    9
    >>> norm(b, -np.inf)
    2
    >>> norm(b, 1)
    7
    >>> norm(b, -1)
    6

    The matrix 2-norm or the spectral norm is the largest singular
    value, computed approximately and with limitations.

    >>> b = diags_array([-1, 1], offsets=[0, 1], shape=(9, 10))
    >>> norm(b, 2)
    1.9753...
    Úcsr)Útarget_formatz*input is not sparse. use numpy.linalg.normN)NÚfroÚfz6'axis' must be None, an integer or a tuple of integersé   zInvalid axis z for an array with shape zDuplicate axes given.é   Úarpack)ÚkÚsolverÚrngr   éþÿÿÿ)Úaxiséÿÿÿÿ)Nr   r   z Invalid norm order for matrices.)r   NzInvalid norm order for vectors.ÚtoarrayÚAz&Improper number of dimensions to norm.)r   r   Ú	TypeErrorr   ÚtocsrÚtupleÚrangeÚndimÚ
isinstanceÚintÚlenÚshapeÚ
ValueErrorr   ÚNotImplementedErrorr   ÚsumÚmaxr   ÚinfÚminr   ÚpowerÚhasattrr"   Úravelr#   )r   Úordr    ÚmsgÚint_axisÚeÚndÚrow_axisÚcol_axisÚmessageÚ_ÚsÚaÚMs                 r   r   r      sÐ  € õ| 	' q¸Ð>Ñ>Ô>€AÝ�A‰;Œ;ð FÝÐDÑEÔEÐEð €|˜Ð1Ð1Ð1Ý% aÑ(Ô(Ð(ð 	
�Š‰	Œ	€Aà€|Ý•U˜1œ6‘]”]Ñ#Ô#ˆˆÝ˜�eÑ$Ô$ð ØFˆð	(Ý˜4‘y”yˆHˆHøÝð 	(ð 	(ð 	(Ý˜C‘.”. aÐ'øøøøð	(øøøà�8ÒÐÝ˜C‘.”.Ð Øˆ{ˆà	
Œ€BÝ
ˆ4�y„y�A‚~�~Ø!Ñˆ�(Ø��xÐ$Ð$Ò$Ð$ "Ò$Ð$Ð$Ð$Ð$¨"¨°Ð)=Ð)=Ò)=Ð)=¸2Ò)=Ð)=Ð)=Ð)=ØR dÐRÐRÀqÄwÐRÐRˆGÝ˜WÑ%Ô%Ð%Ø�b‰=˜H r™MÒ)Ð)ÝÐ4Ñ5Ô5Ð5Ø�!Š8ˆ8Ý˜1 ¨(¸Ð=Ñ=Ô=‰GˆAˆq�!Ø�Q”4ˆKØ�BŠYˆYÝ%Ð%à�AŠXˆXÝ�q‘6”6—:’: 8�:Ñ,Ô,×0Ò0Ñ2Ô2Ð2Ø•B”FŠ]ˆ]Ý�q‘6”6—:’: 8�:Ñ,Ô,×0Ò0Ñ2Ô2Ð2Ø�BŠYˆYÝ�q‘6”6—:’: 8�:Ñ,Ô,×0Ò0Ñ2Ô2Ð2Ø•R”V�GŠ^ˆ^Ý�q‘6”6—:’: 8�:Ñ,Ô,×0Ò0Ñ2Ô2Ð2ØÐ&Ð&Ð&å)¨!Ñ,Ô,Ð,åÐ?Ñ@Ô@Ð@Ý	ˆT‰Œ�aŠ‰Ø‰ˆØ��q��’�˜2’���ØR dÐRÐRÀqÄwÐRÐRˆGÝ˜WÑ%Ô%Ð%Ø•"”&Š=ˆ=Ý�A‘”—
’
 �
Ñ"Ô"ˆA‰AØ•R”V�GŠ^ˆ^Ý�A‘”—
’
 �
Ñ"Ô"ˆA‰AØ�AŠXˆXà�a’—’ !�Ñ$Ô$ˆAˆAØ�AŠXˆXå�A‘”—
’
 �
Ñ"Ô"ˆAˆAØ�IÐÐÝ•S˜‘V”V—\’\ !‘_”_×(Ò(¨aÐ(Ñ0Ô0Ñ1Ô1ˆAˆAðKØ�a‘��øÝð Kð Kð KÝ Ð!BÑCÔCÈÐJøøøøðKøøøå”�˜Q™œŸš cÑ*Ô*×.Ò.°AÐ.Ñ6Ô6¸¸C¹Ñ@Ô@ˆAÝ�1�iÑ Ô ð 	Ø—9’9‘;”;×$Ò$Ñ&Ô&Ð&Ý�Q˜‰_Œ_ð 	Ø”3—9’9‘;”;Ðà—7’7‘9”9ÐåÐAÑBÔBÐBs0   ÂB% Â%
CÂ/B?Â?CÏ/O5 Ï5
PÏ?PÐP)NN)Ú__doc__Únumpyr   Úscipy.sparser   Úscipy.sparse.linalgr   Úscipy.sparse._sputilsr   Úsparser
   r   r   Ú__all__r   r   © r   r   ú<module>rJ      s½   ððð ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø $Ð $Ð $Ð $Ð $Ð $Ø @Ð @Ð @Ð @Ð @Ð @Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ð Ð àˆ(€ð ð  ð  ð
nCð nCð nCð nCð nCð nCr   