o
    5ήcK                     @   sp   d Z ddlZddlmZ ddlmZmZ ddl	m
Z ddlZddlmZ dd ZG dd	 d	ZG d
d dZdS )z1Test functions for the sparse.linalg.norm module
    N)norm)assert_allcloseassert_equal)raisesc                  C   s   t g d} t g d}t g d}tjj|| |ffdd}tjj|| |ffdd}tt|dddt g d tt|dddt g d tt|dddt d	d
g tt|dddt d	d
g d S )N)r   r      r   )r   r         )         	   )r   r	   )shaper   r   ordaxisr      )nparrayscipysparse	coo_array
coo_matrixr   spnorm)rowcoldatatest_arrtest_mat r   J/tmp/pip-target-vg8gfxp4/lib/python/scipy/sparse/linalg/tests/test_norm.pytest_sparray_norm   s   "r    c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestNormc                 C   s*   t dd }|d}tj|| _d S )Nr   r	   r   r   )r   arangereshaper   r   
csr_matrixb)selfar&   r   r   r   setup_method   s   
zTestNorm.setup_methodc                 C   s   t t| jd t t| jdd t t| jtjd t t| jtj d t t| jdd t t| jdd ttt| jd ttt| jd	 d S )
NNO@fror   r   r   r      )r   r   r&   r   infassert_raisesNotImplementedError)r'   r   r   r   test_matrix_norm    s   zTestNorm.test_matrix_normc                 C   s   | j d f| j df| j jdffD ]B\}}tt||dd tt|d|dd tt|tj|dd tt|tj |dd tt|d|dd	 tt|d
|dd qd S )Nr   r   r   r   r   r*   r+   r   r   r   r   r,   r-   r&   Tr   r   r   r/   )r'   mr   r   r   r   test_matrix_norm_axis/   s   &zTestNorm.test_matrix_norm_axisc                 C   s   g d}| j df| j jdffD ]I\}}||f|d |d ffD ]8}tt|d|dg d tt|tj|dg d tt||d| tt|d|d| tt|d |d| qqd S )	N)T@glv@r:   r   r   r   r5   )r   r-   r   )r	   r   r	   r   r6   )r'   vr8   r(   r   r   r   r   test_vector_norm8   s   zTestNorm.test_vector_normc                 C   s   | j }ttt|d d ttt|d dg ttt|d d ttt|d d ttt|d d ttt|d d ttt|d d ttt|d d ttt|d d ttt|d	d
 ttt|d	d d S )Ng      ?r   r   )r   r   r   )r   r   )r   r   )r   r=   plate_of_shrimpr   r3   )r&   r0   	TypeErrorr   
ValueError)r'   r8   r   r   r   test_norm_exceptionsB   s   zTestNorm.test_norm_exceptionsN)__name__
__module____qualname__r)   r2   r9   r<   rA   r   r   r   r   r!      s    	
r!   c                   @   s   e Zd Zejjejjejjejjejj	ejj
ejjfZedd dg dg dgg dg dgfZdd	 Zd
d Zdd ZdS )TestVsNumpyNormr   r	   r"   )r   r   r   )r,   r   r	   )r   r   r   )r,   r   y              @c                 C   s   | j D ]R}| jD ]L}||}tt|t| tt|dt|d tt|tjt|tj tt|tj t|tj  tt|dt|d tt|dt|d qqd S )Nr+   r   r,   _sparse_types_test_matricesr   r   npnormr   r/   )r'   sparse_typeMSr   r   r   test_sparse_matrix_normse   s   

z(TestVsNumpyNorm.test_sparse_matrix_normsc                 C   s   | j D ]j}| jD ]d}||}dD ]+}tt||dt||d dtjtj ddfD ]}tt|||dt|||d q)qdD ]-}tt||dt||d tt|d|dt|d|d tt|d|dt|d|d q>qqd S )N)Nr3   r4   r5   r+   r   r,   ))r.   r,   )r,   r.   )r   r.   frF   r'   rJ   rK   rL   r   r   r   r   r   "test_sparse_matrix_norms_with_axisp   s*   

z2TestVsNumpyNorm.test_sparse_matrix_norms_with_axisc                 C   s   | j D ]<}| jD ]6}||}dD ]-}tt||dt||d d dtjtj dddfD ]}tt|||dt|||d q+qqqd S )N)r   r   r,   r.   )r   )r   )r,   )r.   r5   r   r   g      ?gzG?rF   rO   r   r   r   test_sparse_vector_norms   s   

z(TestVsNumpyNorm.test_sparse_vector_normsN)rB   rC   rD   r   r   
bsr_matrixr   
csc_matrixr%   
dia_matrix
dok_matrix
lil_matrixrG   r   r#   r$   rH   rM   rP   rQ   r   r   r   r   rE   Q   s(    

rE   )__doc__numpyr   numpy.linalgr   rI   numpy.testingr   r   pytestr   r0   scipy.sparser   scipy.sparse.linalgr   r    r!   rE   r   r   r   r   <module>   s    7