
    4[g                     X    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	m
Z
 dgZd Zd	dZy)
zSparse matrix norms.

    N)issparse)svds)sqrtabsnormc                 ~    t         j                  j                  |       }t        j                  j                  |      S )N)sp_sputils_todatanplinalgr   )xdatas     T/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_norm.py_sparse_frobenius_normr      s)    ;;q!D99>>$    c                    t        |       st        d      ||dv rt        |       S | j                         } |d}n1t	        |t
              s!d}	 t        |      }||k7  rt        |      |f}d}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   S |dk(  rt        |d
k(  r.t        |       j                  |      j                  |      d   S |t        j                   k(  r.t        |       j                  |      j                  |      d   S |dk(  r.t        |       j                  |      j#                  |      d   S |t        j                    k(  r.t        |       j                  |      j#                  |      d   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        |       j                  |      }n|t        j                    k(  rt        |       j#                  |      }n|dk(  r| dk7  j                  |      }n|d
k(  rt        |       j                  |      }n|dv r4t%        t        |       j'                  d      j                  |            }nG	 |d
z    t        j&                  t        |       j'                  |      j                  |      d
|z        }t)        |d      r|j+                         j-                         S t)        |d      r|j.                  j-                         S |j-                         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 matrix
        Input sparse matrix.
    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 matrix.

    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 matrices
    =====  ============================
    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 *
    >>> 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_matrix(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([-1, 1], [0, 1], shape=(9, 10))
    >>> norm(b, 2)
    1.9753...
    z*input is not sparse. use numpy.linalg.normN)Nfrof)r      z6'axis' must be None, an integer or a tuple of integers   zInvalid axis z for an array with shape zDuplicate axes given.r   lobpcg)ksolverr   )axis)r   r   )Nr   r   z Invalid norm order for matrices.)r   NzInvalid norm order for vectors.toarrayAz&Improper number of dimensions to norm.)r   	TypeErrorr   tocsr
isinstancetuple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   | A;DEE |11%a(( 	
	A|e$F	(4yH 8C. {	
B
4yA~!(x$"$")=2)=%dX-FqwwkRGW%%b=HrM)455!81(3GAq!Q4KBY%%AXq6::8:,00h0?DDBFF]q6::8:,00h0?DDBYq6::8:,00h0?DDRVVG^q6::8:,00h0?DD&&)!,,?@@	Taq2%dX-FqwwkRGW%%"&&=A


"ARVVG^A


"AAXa!$AAXA


"AISV\\!_((a(01AKa Qc*..A.6C@A1i 99;$$&&Q_3399;779ABBA  	(C.a'	(l  K !BCJKs0   O O 	O
OO	O8'O33O8)NN)__doc__numpyr   scipy.sparser   scipy.sparse.linalgr   sparser	   r   r   __all__r   r    r   r   <module>rC      s.     ! $  ( 
nCr   