ó
    Eñiè  ã                   óf   • S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJrJr  S/rS rS
S	 jrg)zSparse matrix norms.

é    N)Úissparse)Úsvds)Úconvert_pydata_sparse_to_scipy)ÚsqrtÚabsÚnormc                 ó~   • [         R                  R                  U 5      n[        R                  R                  U5      $ )N)ÚspÚ_sputilsÚ_todataÚnpÚlinalgr   )ÚxÚdatas     ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/sparse/linalg/_norm.pyÚ_sparse_frobenius_normr      s)   € Ü�;‰;×Ñ˜qÓ!€DÜ�9‰9�>‰>˜$ÓÐó    c                 óR  • [        U SS9n [        U 5      (       d  [        S5      eUc  US;   a  [        U 5      $ U R	                  5       n Uc  [        [        U R                  5      5      nO6[        U[
        5      (       d!  Sn [        U5      nX$:w  a  [        U5      eU4nU R                  n[        U5      S:X  Gah  Uu  pxU* Us=::  a  U:  a  O  OU* Us=::  a  U:  d!  O  SU< S	U R                  < 3n	[        U	5      eXv-  X†-  :X  a  [        S
5      eUS:X  a  [        U SSSS9u  p«n
US   $ US:X  a  [        eUS:X  a&  [        U 5      R!                  US9R#                  5       $ U[$        R&                  :X  a&  [        U 5      R!                  US9R#                  5       $ US:X  a&  [        U 5      R!                  US9R)                  5       $ U[$        R&                  * :X  a&  [        U 5      R!                  US9R)                  5       $ US;   a  [        U 5      $ [        S5      e[        U5      S:X  Ga¬  Uu  nU* Us=::  a  U:  d!  O  SU< S	U R                  < 3n	[        U	5      eU[$        R&                  :X  a  [        U 5      R#                  US9nOâU[$        R&                  * :X  a  [        U 5      R)                  US9nO´US:X  a  U S:g  R!                  US9nO›US:X  a  [        U 5      R!                  US9nO|US;   a1  [+        [        U 5      R-                  S5      R!                  US95      nOE US-     [$        R,                  " [        U 5      R-                  U5      R!                  US9SU-  5      n[/        US5      (       a  UR1                  5       R3                  5       $ [/        US5      (       a  UR4                  R3                  5       $ UR3                  5       $ [        S5      e! [         a  n[        U5      UeSnAff = f! [         a  n[        S5      UeSnAff = f)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�;‰;ÜÐDÓEÐEð �|˜Ð1Ó1Ü% aÓ(Ð(ð 	
�‰‹	€Aà�|Ü”U˜1Ÿ6™6“]Ó#‰Ü˜œe×$Ñ$ØFˆð	(Ü˜4“yˆHð ÓÜ˜C“.Ð Øˆ{ˆà	
�‰€BÜ
ˆ4ƒy�A„~Ø!ÑˆØ��xÕ$ "Ö$¨"¨°Õ)=¸2Õ)=Ø% d¡XÐ-FÀqÇwÁwÁkÐRˆGÜ˜WÓ%Ð%Ø‰=˜H™MÓ)ÜÐ4Ó5Ð5Ø�!‹8Ü˜1 ¨(¸Ñ=‰GˆA�!Ø�Q‘4ˆKØ�B‹YÜ%Ð%à�A‹XÜ�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Ó%Ð%Ø”"—&‘&‹=Ü�A“—
‘
 �
Ð"‰AØ”R—V‘V�G‹^Ü�A“—
‘
 �
Ð"‰AØ�A‹Xà�a‘—‘ !�Ð$‰AØ�A‹Xä�A“—
‘
 �
Ð"‰AØ�IÓÜ”S˜“V—\‘\ !“_×(Ñ(¨aÐ(Ð0Ó1‰AðKØ�a’ô —’œ˜Q›Ÿ™ cÓ*×.Ñ.°AÐ.Ð6¸¸C¹Ó@ˆAÜ�1�i× Ñ Ø—9‘9“;×$Ñ$Ó&Ð&Ü�Q˜�_‰_Ø—3‘3—9‘9“;Ðà—7‘7“9ÐäÐAÓBÐBøô ó 	(Ü˜C“. aÐ'ûð	(ûôj ó KÜ Ð!BÓCÈÐJûðKús0   ÂO- Ì4P Ï-
PÏ7PÐPÐ
P&ÐP!Ð!P&)NN)Ú__doc__Únumpyr   Úscipy.sparser   Úscipy.sparse.linalgr   Úscipy.sparse._sputilsr   Úsparser
   r   r   Ú__all__r   r   © r   r   Ú<module>rJ      s1   ðñó Ý !Ý $Ý @Ý ç àˆ(€ò õ
nCr   