Ë
    0Ò^j£  ã                   ój   — 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
„ Zy)zSparse matrix norms.

é    N)Úissparse)Úsvds)Úconvert_pydata_sparse_to_scipy)ÚsqrtÚabsÚnormc                 ó~   — t         j                  j                  | «      }t        j                  j                  |«      S )N)ÚspÚ_sputilsÚ_todataÚnpÚlinalgr   )ÚxÚdatas     úd/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_norm.pyÚ_sparse_frobenius_normr      s)   € Ü�;‰;×Ñ˜qÓ!€DÜ�9‰9�>‰>˜$ÓÐó    c                 ó¸  — t        | d¬«      } t        | «      st        d«      ‚|€|dv rt        | «      S | j                  dk(  r| j                  «       } |€t        t        | j                  «      «      }n1t        |t        «      s!d}	 t        |«      }||k7  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v rt        | «      S t!        j"                  | j$                  t&        «      r| j)                  t&        d¬«      } |dk(  r)t+        | «      j-                  |¬«      j/                  «       S |t         j0                  k(  r)t+        | «      j-                  |¬«      j/                  «       S |dk(  r)t+        | «      j-                  |¬«      j3                  «       S |t         j0                   k(  r)t+        | «      j-                  |¬«      j3                  «       S t        d«      ‚t        |«      dk(  �r |\  }| |cxk  r|k  sn d	|›d
| j                  ›�}	t        |	«      ‚|dk(  r| j5                  |¬«      S t!        j"                  | j$                  t&        «      r| j)                  t&        d¬«      } |t         j0                  k(  r$t7        t+        | «      j/                  |¬«      «      S |t         j0                   k(  r$t7        t+        | «      j3                  |¬«      «      S |dk(  r$t7        t+        | «      j-                  |¬«      «      S |dv r<t7        t9        t+        | «      j;                  d«      j-                  |¬«      «      «      S 	 |dz    t!        j:                  t+        | «      j;                  |«      j-                  |¬«      d|z  «      S t        d«      ‚# t        $ r}t        |«      |‚d}~ww xY w# t        $ r}t        d«      |‚d}~ww xY w)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
        The selected norm of `x`.

    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ÚfÚdiaz6'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   éþÿÿÿ)Nr   r   F)Úcopy)Úaxiséÿÿÿÿz Invalid norm order for matrices.)r   NzInvalid norm order for vectors.z&Improper number of dimensions to norm.)r   r   Ú	TypeErrorr   ÚformatÚtocsrÚtupleÚrangeÚndimÚ
isinstanceÚintÚlenÚshapeÚ
ValueErrorr   ÚNotImplementedErrorr   Úcan_castÚdtypeÚfloatÚastyper   ÚsumÚmaxÚinfÚminÚcount_nonzeroÚ_ravelr   Úpower)r   Úordr"   ÚmsgÚint_axisÚeÚndÚrow_axisÚcol_axisÚmessageÚ_ÚsÚas                r   r   r      sÜ  € ô~ 	' q¸Ô>€AÜ�AŒ;ÜÐDÓEÐEð €|˜Ð1Ñ1Ü% aÓ(Ð(ð 	‡x�x�5ÒØ�G‰G‹Iˆà€|Ü”U˜1Ÿ6™6“]Ó#‰Ü˜œeÔ$ØFˆð	(Ü˜4“yˆHð �8ÒÜ˜C“.Ð Øˆ{ˆà	
�‰€BÜ
ˆ4ƒy�Aƒ~Ø!Ñˆ�(Ø��xÔ$ "Õ$¨"¨°Ô)=¸2Ô)=Ø% d XÐ-FÀqÇwÁwÀkÐRˆGÜ˜WÓ%Ð%Ø�b‰=˜H r™MÒ)ÜÐ4Ó5Ð5Ø�!Š8Ü˜1 ¨(¸Ô=‰GˆAˆq�!Ø�Q‘4ˆKØ�"Š9Ü%Ð%àÐ$Ñ$ä)¨!Ó,Ð,Ü�;‰;�q—w‘w¤Ô&Ø—‘œ U�Ó+ˆAØ�!Š8Ü�q“6—:‘: 8�:Ó,×0Ñ0Ó2Ð2Ø”B—F‘FŠ]Ü�q“6—:‘: 8�:Ó,×0Ñ0Ó2Ð2Ø�BŠYÜ�q“6—:‘: 8�:Ó,×0Ñ0Ó2Ð2Ø”R—V‘V�GŠ^Ü�q“6—:‘: 8�:Ó,×0Ñ0Ó2Ð2äÐ?Ó@Ð@Ü	ˆT‹�a‹Ø‰ˆØ��q”˜2”Ø% d XÐ-FÀqÇwÁwÀkÐRˆGÜ˜WÓ%Ð%Ø�!Š8Ø—?‘?¨�?Ó*Ð*Ü�;‰;�q—w‘w¤Ô&Ø—‘œ U�Ó+ˆAØ”"—&‘&Š=Üœ#˜a›&Ÿ*™*¨!˜*Ó,Ó-Ð-Ø”2—6‘6�'Š>Üœ#˜a›&Ÿ*™*¨!˜*Ó,Ó-Ð-Ø�!Š8äœ#˜a›&Ÿ*™*¨!˜*Ó,Ó-Ð-Ø�)ÑÜœ$œs 1›vŸ|™|¨A›×2Ñ2¸Ð2Ó:Ó;Ó<Ð<ð	GØ�!ŠGô �x‰xœ˜A›Ÿ™ SÓ)×-Ñ-°1Ð-Ó5°q¸3±wÓ?Ð?äÐAÓBÐBøôw ò 	(Ü˜C“. aÐ'ûð	(ûôn ò 	GÜÐ>Ó?ÀQÐFûð	Gús0   ÂP" ÏP? Ð"	P<Ð+P7Ð7P<Ð?	QÑQÑQc                 óÂ   — t        | d«      r| j                  «       j                  «       S t        | d«      r| j                  j                  «       S | j                  «       S )NÚtoarrayÚA)ÚhasattrrG   ÚravelrH   )ÚMs    r   r9   r9   Ã   sF   € Üˆq�)ÔØ�y‰y‹{× Ñ Ó"Ð"Ü	��CŒØ�s‰s�y‰y‹{Ðà�w‰w‹yÐr   )NN)Ú__doc__Únumpyr   Úscipy.sparser   Úscipy.sparse.linalgr   Úscipy.sparse._sputilsr   Úsparser
   r   r   Ú__all__r   r   r9   © r   r   ú<module>rT      s7   ðñó Ý !Ý $Ý @Ý ç àˆ(€ò ó
lCó^r   