o
    h<                     @   sx   d Z ddl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   sB  t g d} t g d}t g d}tjj|| |ffdd}tjj|| |ffdd}dt jd fD ]*}dD ]%}||fD ]}t| ||d}t	|||d}	t
|	d	sVJ t|	| q=q7q3tjj||ffd
d}
tjj||g dffdd}dt jd fD ]!}dD ]}|
|fD ]}t| ||d}tt	|||d| qqq}d S )N)r   r      r   )r   r         )         	   )r   r	   )shaper   )r   r   Nr   r   r   r   ordaxisdtype)r	   )r   r   r   r   )r	   r   )r   N)nparrayscipysparse	coo_array
coo_matrixinfnpnormtoarrayspnormhasattrr   )rowcoldatatest_arrtest_matr   axAexpectedactualtest_arr_1dtest_mat_col r*   W/var/www/vscode/kcb/lib/python3.10/site-packages/scipy/sparse/linalg/tests/test_norm.pytest_sparray_norm   s0   r,   c                   @   s<   e Zd Zdd Zejj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_arrayb)selfar2   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jtd	d
 t t| jtj	dd W d    n1 sWw   Y  t
tt| jd d S )NNO@fror   r   r   r      zThe problem size)matchgűd@)r   r   r2   r   r   pytestwarnsUserWarningastypefloat64assert_raisesNotImplementedError)r3   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 )Nr   r   r   r6   r7   r   r   r   r   r8   r9   r2   Tr   r   r   r   )r3   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@rI   r   r   r   rD   )r   r9   r   )r	   r   r	   r   rE   )r3   vrG   r4   r   r*   r*   r+   test_vector_normI   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   rL   plate_of_shrimpr   r   )r2   rA   	TypeErrorr   
ValueError)r3   rG   r*   r*   r+   test_norm_exceptionsS   s   zTestNorm.test_norm_exceptionsN)__name__
__module____qualname__r5   r<   markthread_unsaferC   rH   rK   rP   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   )r8   r   r	   )r   r   r   )r8   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 )Nr7   r   r8   _sparse_types_test_matricesr   r   r   r   r   )r3   sparse_typeMSr*   r*   r+   test_sparse_matrix_normsv   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)Nr   r   rD   r7   r   r8   ))r;   r8   )r8   r;   )r   r;   frW   r3   rZ   r[   r\   r   r   r*   r*   r+   "test_sparse_matrix_norms_with_axis   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   r8   r;   )r   )r   )r8   )r;   rD   r   r   g      ?gzG?rW   r_   r*   r*   r+   test_sparse_vector_norms   s   

z(TestVsNumpyNorm.test_sparse_vector_normsN)rQ   rR   rS   r   r   	bsr_arrayr   	csc_arrayr1   	dia_array	dok_array	lil_arrayrX   r   r/   r0   rY   r]   r`   ra   r*   r*   r*   r+   rV   b   s(    

rV   )__doc__r<   numpyr   numpy.linalgr   r   numpy.testingr   r   r   rA   scipy.sparser   scipy.sparse.linalgr   r,   r-   rV   r*   r*   r*   r+   <module>   s    ;