o
    iF                     @   s   d dl 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mZ d dlmZmZmZmZmZ d dlmZ dd	 Zd
d Zdd Zdd Zejdeedd ZG dd dZG dd deZG dd deZG dd deZ dS )    N)LinAlgError)assert_allcloseassert_array_equal)Halton)cKDTree)
_AVAILABLE_SCALE_INVARIANT_NAME_TO_MIN_DEGREE_monomial_powersRBFInterpolator)_rbfinterp_pythranc                 C   s   t | jd |}t| |S )N   )r
   shaper   Z_polynomial_matrix)xdegreeZpowers r   u/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/scipy/interpolate/tests/test_rbfinterp.py_vandermonde   s   r   c                 C   sH   | d d df } dt |  dt d|    dt d|     }|S )Nr   g
ףp=
@      npexp)r   yr   r   r   _1d_test_function   s   4r   c                 C   s   | d d df | d d df }}dt d| d d  d d| d d d   }dt d| d d  d d| d d   }d	t d| d
 d  d d| d d d   }dt d| d d  d| d
 d   }|| | | }|S )Nr   r   g      ?	      r   1   
   g      ?   r   gɿr   )r   x1Zx2Zterm1Zterm2Zterm3Zterm4r   r   r   r   _2d_test_function   s   "404,r#   c              
   C   s   d}d}dD ]_}t |dtj d}t|D ]N}d|| d }t|| }t||d }	tjj	|	dd	\}
}|
d d |	j
d d f }|j||}ztj| W q tjjyd   Y   dS w qd
S )Nr    d   )r   r   r   r      FZscrambleseedr   r   Zcomplete)modeT)r   r   randomRandomStateranger   Z_kernel_matrixr   linalgZqrr   TdotZcholeskyr   )kernelmnxZntestsndimseq_r   APQRZQ2Br   r   r   #_is_conditionally_positive_definite*   s$   
r:   r/   c                 C   s"   t | dd }t| |sJ d S )Nr   )r	   getr:   )r/   r0   r   r   r   $test_conditionally_positive_definiteI   s   r=   c                   @   s8  e Zd Zejdeedd Zejdeedd Z	ejdee
dd Zdd	 Zejjd
d Zdd Zdd Zejdee
dd Zejdee
dd Zejdee
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d&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Z d0S )1_TestRBFInterpolatorr/   c                 C   sv   t ddtj d}d|d }t|}d|d }| j||d|d|}| j||d|d|}t||d	d
 d S )Nr   Fr&   r   2         ?epsilonr/          @:0yE>Zatol)r   r   r)   r*   r   buildr   selfr/   r3   r   r   xitpyitp1yitp2r   r   r   test_scale_invariance_1dS   s   z-_TestRBFInterpolator.test_scale_invariance_1dc                 C   sn   t ddtj d}|d}t|}|d}| j||d|d|}| j||d|d|}t||dd	 d S )
Nr   Fr&   r$   r@   rA   rC   rD   rE   )r   r   r)   r*   r#   rF   r   rG   r   r   r   test_scale_invariance_2d_   s   

z-_TestRBFInterpolator.test_scale_invariance_2dc           
      C   s   t ddtj d}d}d}|d}t|}|d}|tv r=| j|||d|}| j|| | ||d|| | }	n | j||d|d	|}| j|| | |d| |d	|| | }	t||	d
d d S )Nr   Fr&   gd~QJgAjZKr$   r/         @rA   rD   rE   )r   r   r)   r*   r#   r   rF   r   )
rH   r/   r3   scaleshiftr   r   rI   rJ   rK   r   r   r   test_extreme_domainsk   s.   



z)_TestRBFInterpolator.test_extreme_domainsc                 C   s   t jd}tdd|d}d}|d}|d}t||}t||}|dd|jd	 }||}	||}
| j||	|d
|}t	|
|dd d S )Nr   r   Fr&   r   r?           r@   r   r   rD   rE   )
r   r)   r*   r   r   normalr   r.   rF   r   )rH   rngr3   r   r   rI   r6   Pitppoly_coeffsr   rJ   rK   r   r   r   test_polynomial_reproduction   s   





z1_TestRBFInterpolator.test_polynomial_reproductionc                    s   t jd}tdd|d}d}d}|d}||}t||}t||}	|dd	|jd
 }
||
}|	|
}| j|||d}|j	  fdd}|
|d| ||}t||dd d S )Nr   r   Fr&   r   i	  r?   rS   r@   r   rT   c                     s   |j dd  | i |S )Nr$   )Zmemory_budget)update)argskwargsZce_realr   r   _chunk_evaluator   s   z<_TestRBFInterpolator.test_chunking.<locals>._chunk_evaluatorr^   rD   rE   )r   r)   r*   r   r   rU   r   r.   rF   r^   setattrr   )rH   ZmonkeypatchrV   r3   r   ZlargeNr   rI   r6   rW   rX   r   rJ   interpr^   rK   r   r]   r   test_chunking   s"   





z"_TestRBFInterpolator.test_chunkingc              	   C   s   t ddtj d}|d}|d}tt|t|d d d d df gj}| |||}| ||d d df |}| ||d d df |}t|d d df | t|d d df | d S )Nr   Fr&   r$   r;   r   r   )	r   r   r)   r*   arrayr#   r-   rF   r   rH   r3   r   rI   r   rJ   rK   Zyitp3r   r   r   test_vector_data   s   


z%_TestRBFInterpolator.test_vector_datac                 C   s   t ddtj d}|d}|d}t|dt|d d d d df   }| |||}| ||j|}| ||j|}t|j| t|j| d S )Nr   Fr&   r$   y              ?r;   )	r   r   r)   r*   r#   rF   realimagr   rc   r   r   r   test_complex_data   s   

&z&_TestRBFInterpolator.test_complex_datac           	      C   sx   t ddtj d}d|d }d|d }t|}t|}| j||d|d|}t|| d }|d	k s:J d S )
Nr   Fr&   r   r?   rO   rA   r   -C6?)r   r   r)   r*   r   rF   mean	rH   r/   r3   r   rI   r   ytrueyitpZmser   r   r   test_interpolation_misfit_1d   s   z1_TestRBFInterpolator.test_interpolation_misfit_1dc           	      C   sp   t ddtj d}|d}|d}t|}t|}| j||d|d|}t|| d }|dk s6J d S )Nr   Fr&   r$   rO   rA   g-C6*?)r   r   r)   r*   r#   rF   ri   rj   r   r   r   test_interpolation_misfit_2d   s   

z1_TestRBFInterpolator.test_interpolation_misfit_2dc                 C   s   t jd}tdd|d}d}d}dt ddd	 }d
|d }t||d|d }t|}	d}
|D ]"}| j||d||d|}t t 	||	 d }||k rVd}
 nq4|
s[J d S )Nr   r   Fr&   g?g?r       r   r$   rS   )r$   r@   )rB   	smoothingr/   r   T)
r   r)   r*   r   linspacer   rU   rF   sqrtri   )rH   r/   rV   r3   noiseZrmse_tolZsmoothing_ranger   r   rk   Zrmse_within_tolrq   ZysmoothZrmser   r   r   test_smoothing_misfit   s0   z*_TestRBFInterpolator.test_smoothing_misfitc                 C   s   t jd}tdd|d}d}|d}t||}|dd|jd }||}t |}|d	  d7  < t 	d
}	d|	d	< | j
|||	d|}
t|
|dd d S )Nr   r   Fr&   r   r?   rS   r@   r    )r?   g     @@rq   rh   rE   )r   r)   r*   r   r   rU   r   r.   copyzerosrF   r   )rH   rV   r3   r   r   r6   rX   r   Zy_with_outlierrq   rl   r   r   r   test_array_smoothing  s   




z)_TestRBFInterpolator.test_array_smoothingc                 C   s   t ddtj dd}t|}t ddtj dd}d}tjt|d | ||| W d    d S 1 s;w   Y  d S )Nr   Fr&   r    r   zExpected the second axis of `x`match)	r   r   r)   r*   r#   pytestraises
ValueErrorrF   )rH   r   dr   r{   r   r   r   $test_inconsistent_x_dimensions_error/  s   "z9_TestRBFInterpolator.test_inconsistent_x_dimensions_errorc                 C   sh   t dddd d d f }t d}d}tjt|d | || W d    d S 1 s-w   Y  d S )Nr   r   r%   zExpected the first axis of `d`rz   r   rr   rx   r|   r}   r~   rF   rH   r   r   r{   r   r   r    test_inconsistent_d_length_error9  s   
"z5_TestRBFInterpolator.test_inconsistent_d_length_errorc                 C   s\   t ddd}t d}d}tjt|d | || W d    d S 1 s'w   Y  d S )Nr   r   r%   z"`y` must be a 2-dimensional array.rz   r   r   r   r   r   test_y_not_2d_error@  s   
"z(_TestRBFInterpolator.test_y_not_2d_errorc                 C   sv   t dddd d d f }t d}t d}d}tjt|d | j|||d W d    d S 1 s4w   Y  d S )Nr   r   r%   zExpected `smoothing` to berz   rv   )r   rr   rx   onesr|   r}   r~   rF   )rH   r   r   rq   r{   r   r   r   (test_inconsistent_smoothing_length_errorG  s   

"z=_TestRBFInterpolator.test_inconsistent_smoothing_length_errorc                 C   sl   t dddd d d f }t d}d}tjt|d | j||dd W d    d S 1 s/w   Y  d S )Nr   r   r%   z`kernel` must be one ofrz   testrN   r   r   r   r   r   test_invalid_kernel_name_errorO     
"z3_TestRBFInterpolator.test_invalid_kernel_name_errorc              	   C   s~   t dddd d d f }t d}tD ](}|tv rqd}tjt|d | j|||d W d    n1 s7w   Y  qd S )Nr   r   r%   z`epsilon` must be specifiedrz   rN   )	r   rr   rx   r   r   r|   r}   r~   rF   )rH   r   r   r/   r{   r   r   r    test_epsilon_not_specified_errorV  s   
z5_TestRBFInterpolator.test_epsilon_not_specified_errorc                 C   sz   t dddd d d f }t ddd}t d}d}tjt|d | ||| W d    d S 1 s6w   Y  d S )Nr   r   r%   z"`x` must be a 2-dimensional array.rz   r   )rH   r   r   r   r{   r   r   r   test_x_not_2d_errora  s   
"z(_TestRBFInterpolator.test_x_not_2d_errorc                 C   sl   t dddd d d f }t d}d}tjt|d | j||dd W d    d S 1 s/w   Y  d S )Nr   r   z#At least 2 data points are requiredrz   thin_plate_splinerN   r   r   r   r   r   "test_not_enough_observations_errori  r   z7_TestRBFInterpolator.test_not_enough_observations_errorc              	   C   s   t dddd d d f }t d}t D ],\}}d| }tjt|d | j||d||d d W d    n1 s=w   Y  qd S )Nr   r   r%   z`degree` should not be below rz   r@   )rB   r/   r   )	r   rr   rx   r	   itemsr|   ZwarnsWarningrF   )rH   r   r   r/   degr{   r   r   r   test_degree_warningp  s   

z(_TestRBFInterpolator.test_degree_warningc                 C   sv   t ddgddgddgg}t g d}d}tjt|d | j||dd| W d    d S 1 s4w   Y  d S )	NrC   rS   r@   )rS   rS   rS   zdoes not have full column rankrz   r   rN   )r   rb   r|   r}   r   rF   r   r   r   r   test_rank_errorx  s   "z$_TestRBFInterpolator.test_rank_errorc                 C   sD   dD ]}t d|f}t d}| j||dd|}t|| qd S )N)r   r   r   r   )r   ZlinearrN   )r   rx   r   rF   r   )rH   dimr   r   fr   r   r   test_single_point  s   
z&_TestRBFInterpolator.test_single_pointc                 C   sp   t ddtjdd}d|d }d|d }t|}| ||}||}tt||}t	|| d S )Nr   Fl   e r&   r   r?   )
r   r   r)   r*   r   rF   pickleloadsdumpsr   )rH   r3   r   rI   r   r`   rJ   rK   r   r   r   test_pickleable  s   z$_TestRBFInterpolator.test_pickleableN)!__name__
__module____qualname__r|   markparametrizesortedr   rL   rM   r   rR   rY   Zslowra   rd   rg   rm   rn   ru   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   R   s>    







		r>   c                   @   s$   e Zd Zdd Zdd Zdd ZdS ) TestRBFInterpolatorNeighborsNonec                 O   s   t |i |S )Nr   rH   r[   r\   r   r   r   rF     s   z&TestRBFInterpolatorNeighborsNone.buildc                 C   s   t ddtj d}d}d}d|d }d|d }t|}| j||||d|}t||}t||}	|	tjj	||d dd	 }
t
||
d
d d S )Nr   Fr&   r       חAr?   r   rq   Zrcondr   rD   rE   )r   r   r)   r*   r   rF   r   r.   r,   lstsqr   rH   r3   r   rq   r   rI   r   rJ   r6   rW   rK   r   r   r   test_smoothing_limit_1d  s"   

z8TestRBFInterpolatorNeighborsNone.test_smoothing_limit_1dc                 C   s   t ddtj d}d}d}|d}|d}t|}| j||||d|}t||}t||}	|	tjj	||d dd	 }
t
||
d
d d S )Nr   Fr&   r   r   r$   r   r   r   rD   rE   )r   r   r)   r*   r#   rF   r   r.   r,   r   r   r   r   r   r   test_smoothing_limit_2d  s"   



z8TestRBFInterpolatorNeighborsNone.test_smoothing_limit_2dN)r   r   r   rF   r   r   r   r   r   r   r     s    r   c                   @      e Zd Zdd Zdd ZdS )TestRBFInterpolatorNeighbors20c                 O   s   t |i |ddiS )N	neighborsrp   r   r   r   r   r   rF     s   z$TestRBFInterpolatorNeighbors20.buildc                 C   s   t ddtj d}|d}|d}t|}| |||}g }t|}|D ]}||d\}	}
|t	||
 ||
 |d  d  q(t
||dd d S )	Nr   Fr&   r$   rp   r   rD   rE   )r   r   r)   r*   r#   rF   r   queryappendr   r   )rH   r3   r   rI   r   rJ   rK   treexir4   Znbrr   r   r   #test_equivalent_to_rbf_interpolator  s   

&zBTestRBFInterpolatorNeighbors20.test_equivalent_to_rbf_interpolatorNr   r   r   rF   r   r   r   r   r   r     s    r   c                   @   r   )TestRBFInterpolatorNeighborsInfc                 O   s   t |i |dtjiS )Nr   )r   r   infr   r   r   r   rF     s   z%TestRBFInterpolatorNeighborsInf.buildc                 C   sh   t ddtj d}d|d }d|d }t|}| |||}t|||}t||dd d S )Nr   Fr&   r   r?   rD   rE   )r   r   r)   r*   r   rF   r   r   )rH   r3   r   rI   r   rJ   rK   r   r   r   r     s   zCTestRBFInterpolatorNeighborsInf.test_equivalent_to_rbf_interpolatorNr   r   r   r   r   r     s    r   )!r   r|   numpyr   Znumpy.linalgr   Znumpy.testingr   r   Zscipy.stats.qmcr   Zscipy.spatialr   Zscipy.interpolate._rbfinterpr   r   r	   r
   r   Zscipy.interpolater   r   r   r#   r:   r   r   r   r=   r>   r   r   r   r   r   r   r   <module>   s*    
  L7