o
    Ö­j�!  ã                   @   sà   d dl m  mZ d dlZd dlmZmZm	Z	 d dl
mZ d dl mZ d dlmZmZmZmZ d dlZd dlmZ e ¡ dd„ ƒZe ¡ d	d
„ ƒZejejejgd�dd„ ƒZe ¡ dd„ ƒZe ¡ dd„ ƒZG dd„ dƒZdS )é    N)ÚhilbertÚsvdvalsÚnorm©Úaslinearoperator)Úinterp_decomp)Úassert_Úassert_allcloseÚassert_equalÚassert_array_equal)Úraisesc                   c   s   � dV  d S )Nçê-�™—q=© r   r   r   úb/var/www/html/CropPilot/venv/lib/python3.10/site-packages/scipy/linalg/tests/test_interpolative.pyÚeps)   s   €
r   c                  c   s   � t j d¡} | V  d S )Nl   ,b„30k0 )ÚnpÚrandomÚdefault_rng©Úrngr   r   r   r   .   s   €
r   )Úparamsc                 c   s   � d}t |ƒ | j¡V  d S )Ni,  )r   ÚastypeÚparam)ÚrequestÚnr   r   r   ÚA4   s   €r   c                 c   s   � t | ƒV  d S )Nr   )r   r   r   r   ÚL<   s   €r   c                 C   sL   t jj| dd�}zt  ||k ¡d d }W |S  ty%   | jd }Y |S w )NF)Ú
compute_uvr   )r   ÚlinalgÚsvdÚnonzeroÚ
IndexErrorÚshape)r   r   ÚSÚrankr   r   r   r$   A   s   þþr$   c                   @   s  e Zd Zej dg d¢¡dd„ ƒZej dg d¢¡dd„ ƒZej ddg¡dd	„ ƒZej dg d¢¡d
d„ ƒZ	ej dg d¢¡dd„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zej dejejg¡ej dd d!g¡ej d"d#d$g¡d%d&„ ƒƒƒZd'd(„ Zd)S )*ÚTestInterpolativeDecompositionzrand,lin_op)©FF)TF)TTc                 C   sZ   |s|n|}t j||||d�\}}	}
t  |d d …|	d |… f |	|
¡}t|||dd� d S ©N)Úrandr   ç:Œ0âŽyE>©ÚrtolÚatol©Ú
pymatrixidr   Úreconstruct_matrix_from_idr	   )Úselfr   r   r   r(   Úlin_opr   ÚA_or_LÚkÚidxÚprojÚBr   r   r   Útest_real_id_fixed_precisionM   s   "z;TestInterpolativeDecomposition.test_real_id_fixed_precisionc                 C   s\   |}|s|n|}	t j|	|||d�\}
}t  |d d …|
d |… f |
|¡}t|||dd� d S r'   r-   )r0   r   r   r   r$   r(   r1   r   r3   r2   r4   r5   r6   r   r   r   Útest_real_id_fixed_rankX   s
   "z6TestInterpolativeDecomposition.test_real_id_fixed_rankr&   c                 C   s|   |}|s|n|}	t j|	|||d�\}
}t  |
|¡}t  |||
¡}t||d d …|
d |… f |dd� t|| ||dd� d S r'   )r.   r   Úreconstruct_interp_matrixÚreconstruct_skel_matrixr	   )r0   r   r   r   r$   r(   r1   r   r3   r2   r4   r5   ÚPr6   r   r   r   Ú%test_real_id_skel_and_interp_matricesc   s   $zDTestInterpolativeDecomposition.test_real_id_skel_and_interp_matricesc                 C   sJ   |s|n|}t j||||d�\}}	}
||	 |
j ¡  }t|||dd� d S r'   ©r.   r   ÚTÚconjr	   )r0   r   r   r   r(   r1   r   r2   ÚUr#   ÚVr6   r   r   r   Útest_svd_fixed_precisiono   s   z7TestInterpolativeDecomposition.test_svd_fixed_precisionc                 C   sN   |}|s|n|}	t j|	|||d�\}
}}|
| |j ¡  }t|||dd� d S r'   r=   )r0   r   r   r   r$   r(   r1   r   r3   r2   r@   r#   rA   r6   r   r   r   Útest_svd_fixed_ranky   s
   z2TestInterpolativeDecomposition.test_svd_fixed_rankc                 C   sf   |}t j||dd�\}}t  |d d …|d |… f ||¡\}}}	|| |	j ¡  }
t||
|dd� d S )NF©r(   r)   r*   )r.   r   Ú	id_to_svdr>   r?   r	   )r0   r   r   r$   r3   r4   r5   r@   r#   rA   r6   r   r   r   Útest_id_to_svd„   s
   (z-TestInterpolativeDecomposition.test_id_to_svdc                 C   s.   t |ƒ}tj||d�}t||d ddd� d S )Nr   r   ç�íµ ÷Æ°>r)   r*   )r   r.   Úestimate_spectral_normr	   )r0   r   r   ÚsÚ
norm_2_estr   r   r   Útest_estimate_spectral_normŒ   s   z:TestInterpolativeDecomposition.test_estimate_spectral_normc                 C   sT   |  ¡ }|d d …df  d9  < t|| ƒ}tj|||d�}t||d ddd� d S )Nr   g333333ó?r   rG   r)   r*   )Úcopyr   r.   Úestimate_spectral_norm_diffr	   )r0   r   r   r6   rI   rJ   r   r   r   Ú test_estimate_spectral_norm_diff‘   s
   z?TestInterpolativeDecomposition.test_estimate_spectral_norm_diffc                 C   s|   t jg d¢g d¢g d¢g|jd�}||fD ]&}d}t j |t|dƒ| ¡}tj|||d�}t||kƒ t||d kƒ qd S )N©é   rP   r   ©r   r   rP   ©Údtypeç•Ö&è.>é   r   é
   )	r   ÚarrayrS   r   Úmatrix_rankr   r.   Úestimate_rankr   )r0   r   r   r6   ÚMÚrank_tolÚrank_npÚrank_estr   r   r   Útest_rank_estimates_array˜   s   "ûz8TestInterpolativeDecomposition.test_rank_estimates_arrayc           	      C   sˆ   t jg d¢g d¢g d¢g|jd�}||fD ],}t|ƒ}d}t j |t|dƒ| ¡}tj|||d�}t	||d kƒ t	||d kƒ qd S )NrO   rQ   rR   rT   rU   r   é   )
r   rW   rS   r   r   rX   r   r.   rY   r   )	r0   r   r   r6   rZ   ÚMLr[   r\   r]   r   r   r   Útest_rank_estimates_lin_op¢   s   "úz9TestInterpolativeDecomposition.test_rank_estimates_lin_opc                 C   sN   t dƒ tj¡}ttƒ� tj|ddd� W d   ƒ d S 1 s w   Y  d S )Né   rG   FrD   )r   r   r   Úfloat32Úassert_raisesÚ
ValueErrorr.   r   )r0   r   r   r   r   Útest_badcall­   s   
"ÿz+TestInterpolativeDecomposition.test_badcallc                 C   sD   t  d¡}ttƒ� t |d¡ W d   ƒ d S 1 sw   Y  d S )N)r_   é   r_   )r   Úonesrd   re   r.   r   )r0   Úar   r   r   Útest_rank_too_large²   s   

"ÿz2TestInterpolativeDecomposition.test_rank_too_largec                 C   s˜   d}t j dd¡}t ||¡\}}}t||jd ƒ t ||¡}t |||¡}t	||| ƒ t ||¡\}}t ||¡}t |||¡}t	||| ƒ d S )Nr   é   é   rP   )
r   r   r(   r.   r   r
   r"   r9   r:   r	   )r0   r   r   r3   r4   r5   r;   r6   r   r   r   Útest_full_rank¸   s   z-TestInterpolativeDecomposition.test_full_rankrS   r(   TFr   rP   gš™™™™™¹?c                 C   sT   t jg d¢g d¢g d¢g d¢g d¢g|dd�}| ¡ }t|j||d� t||ƒ d S )	N)éÿÿÿÿrn   rn   r   r   r   )r   r   r   rP   rP   rP   )rP   r   r   rP   r   r   )r   rP   r   r   rP   r   )r   r   rP   r   r   rP   ÚC)rS   ÚorderrD   )r   rW   rL   r   r>   r   )r0   rS   r(   r   r   r6   r   r   r   Útest_bug_9793Ë   s   
üûz,TestInterpolativeDecomposition.test_bug_9793c                 C   s¬   t j d¡}|jddgd�}t|ƒ}t |d¡\}}}t|jdƒ t|jdƒ t|jdƒ |jd	d
gd�}t|ƒ}t |d¡\}}}t|jdƒ t|jdƒ t|jdƒ d S )Nl   Ca£N¿J1 é   rb   )Úsizerg   )rr   rg   )rg   )rb   rg   r_   é	   rU   )r_   rU   )rU   )rt   rU   )	r   r   r   Úuniformr   r.   r   r
   r"   )r0   r   ÚxÚxlÚurI   Úvr   r   r   Ú%test_svd_aslinearoperator_shape_checkÙ   s   zDTestInterpolativeDecomposition.test_svd_aslinearoperator_shape_checkN)Ú__name__Ú
__module__Ú__qualname__ÚpytestÚmarkÚparametrizer7   r8   r<   rB   rC   rF   rK   rN   r^   ra   rf   rj   rm   r   Úfloat64Ú
complex128rq   rz   r   r   r   r   r%   K   sH    þ
þ

þ
þ

r%   )Úscipy.linalg.interpolativer   Úinterpolativer.   Únumpyr   Úscipy.linalgr   r   r   Úscipy.sparse.linalgr   r   Únumpy.testingr   r	   r
   r   r~   r   rd   Úfixturer   r   r�   r‚   r   r   r$   r%   r   r   r   r   Ú<module>   s&   




	