o
    װi                     @   s.   d dl Z d dlZd dlZdd ZdddZdS )    Nc                 C   s<   t | jt jrt| d }n| d }t |S )N   )cupy
issubdtypedtypecomplexfloatingabspowersumsqrt)xsqnorm r   S/home/ubuntu/.local/lib/python3.10/site-packages/cupyx/scipy/sparse/linalg/_norm.py_sparse_frobenius_norm   s   
r   c           	      C   s  t jj| std|du r|dv rt| S |  } |du r"d}n$t|tsFd}zt	|}W n ty:   t|w ||krCt||f}d}t
|dkr|\}}| |  kr]|k rkn n| |  krj|k stn td|| jf || || krtd|dkrt|d	krt|d
krt| j|d S |tjkrt| j|d S |dkrt| j|d S |tj krt| j|d S |dv rt| S tdt
|d
krx|\}| |  kr|k sn td|| jf |tjkrt| j|d  S |tj krt| j|d  S |dkr.| dktjj|d tjS |d
kr=t| j|d S |dv rRtt| dj|d S z|d
  W n tyd   tdw tt| |j|dd
|  S td)a  Norm of a cupy.scipy.spmatrix

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

    Args:
        x (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:
        ndarray : 0-D or 1-D array or norm(s).

    .. seealso:: :func:`scipy.sparse.linalg.norm`
    z)input is not sparse. use cupy.linalg.normN)Nfrof)r      z6'axis' must be None, an integer or a tuple of integersr   z*Invalid axis %r for an array with shape %rzDuplicate axes given.r   )axis)Nr   r   z Invalid norm order for matrices.r   )r   NzInvalid norm order for vectors.z&Improper number of dimensions to norm.)cupyxscipysparseissparse	TypeErrorr   tocsr
isinstancetupleintlen
ValueErrorshapeNotImplementedErrorr   r	   maxnumpyinfmintoarrayravelastypefloat32int_r   r
   r   )	r   ordr   msgint_axisndrow_axiscol_axisar   r   r   norm   s   
2



 &r3   )NN)r$   r   cupyx.scipy.sparser   r   r3   r   r   r   r   <module>   s
    