
    tKgVH                     2   d dl Z d dlZd dlZd dlmZ d dl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 Zd	 Zd
 Zd Zej0                  j3                  d ee            d        Z G d d      Z G d de      Z G d de      Z G d de      Zy)    N)LinAlgError)assert_allclose)Halton)cKDTree)
_AVAILABLE_SCALE_INVARIANT_NAME_TO_MIN_DEGREE_monomial_powersRBFInterpolator)_rbfinterp_pythranc                 `    t        | j                  d   |      }t        j                  | |      S )N   )r
   shaper   _polynomial_matrix)xdegreepowerss      j/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/scipy/interpolate/tests/test_rbfinterp.py_vandermonder      s+     aggaj&1F00F;;    c                     | d d df   } dt        j                  |        dt        j                  d| z        z  z
  dt        j                  d| z        z  z   z  }|S )Nr   g
ףp=
@      npexp)r   ys     r   _1d_test_functionr       sT     	
!Q$AbffaRj1RVVBqD\>)AbffRTlN:;AHr   c                    | d d df   | d d df   }}dt        j                  d|z  dz
  dz   dz  d|z  dz
  dz  dz  z
        z  }dt        j                  d|z  dz   dz   dz  d|z  dz   dz  z
        z  }d	t        j                  d|z  d
z
  dz   dz  d|z  dz
  dz  dz  z
        z  }dt        j                  d|z  dz
  dz   d|z  d
z
  dz  z
        z  }||z   |z   |z   }|S )Nr   r   g      ?	      r   1   
   g      ?   r   gɿr   )r   x1x2term1term2term3term4r   s           r   _2d_test_functionr-      s    q!tWa1gB266AbDFQ;,q.AbDFQ;q=899E266AbDFQ;,r/QrT!VRK788E"&&1R46A+a1R46A+a-788E266AbDFQ;,!B$q&1455E%AHr   c                 ^   d}d}dD ]  }t        |dt        j                  j                               }t	        |      D ]  }d|j                  |      z  dz
  }t        j                  ||       }t        ||dz
        }	t        j                  j                  |	d	      \  }
}|
d d |	j                  d   d f   }|j                  j                  |      j                  |      }	 t        j                  j                  |         y
# t        j                  j                  $ r Y   yw xY w)Nr%   d   )r   r#   r   r      Fscrambleseedr#   r   complete)modeT)r   r   randomRandomStateranger   _kernel_matrixr   linalgqrr   Tdotcholeskyr   )kernelmnxntestsndimseq_r   APQRQ2Bs                 r   #_is_conditionally_positive_definiterL   *   s    
BF TE		0E0E0GHvA#**R. 1$A"11!V<AQA&A99<<
<3DAq
 1aggajk>"B#A		""1% 	  (  99(( s   %D

D,+D,r?   c                 R    t        j                  | d      dz   }t        | |      sJ y )Nr   )r	   getrL   )r?   r@   s     r   $test_conditionally_positive_definiterP   I   s+    
 	+a/A.vq999r   c                      e Zd Zej                  j                  d ee            d        Zej                  j                  d ee            d        Z	ej                  j                  d ee
            d        Zd Zej                  j                  d        Zd Zd Zej                  j                  d ee
            d	        Zej                  j                  d ee
            d
        Zej                  j                  d ee
            d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!y)_TestRBFInterpolatorr?   c                 F   t        ddt        j                  j                               }d|j                  d      z  }t	        |      }d|j                  d      z  } | j                  ||d|      |      } | j                  ||d|      |      }t        ||d	
       y )Nr   Fr1   r   2         ?epsilonr?          @:0yE>atol)r   r   r6   r7   r    buildr   selfr?   rD   r   r   xitpyitp1yitp2s           r   test_scale_invariance_1dz-_TestRBFInterpolator.test_scale_invariance_1dS   s     QRYY-B-B-DEcjjna B<

1aV
<TB<

1aV
<TBu40r   c                 :   t        ddt        j                  j                               }|j                  d      }t	        |      }|j                  d      } | j                  ||d|      |      } | j                  ||d|      |      }t        ||d	       y )
Nr#   Fr1   r/   rU   rV   rX   rY   rZ   )r   r   r6   r7   r-   r\   r   r]   s           r   test_scale_invariance_2dz-_TestRBFInterpolator.test_scale_invariance_2d_   s     QRYY-B-B-DEJJsOa zz#<

1aV
<TB<

1aV
<TBu40r   c                    t        ddt        j                  j                               }d}d}|j                  d      }t	        |      }|j                  d      }|t
        v rA | j                  |||      |      } | j                  ||z  |z   ||      ||z  |z         }	nE | j                  ||d|	      |      } | j                  ||z  |z   |d|z  |	      ||z  |z         }	t        ||	d
       y )Nr#   Fr1   gd~QJgAjZKr/   r?         @rV   rY   rZ   )r   r   r6   r7   r-   r   r\   r   )
r^   r?   rD   scaleshiftr   r   r_   r`   ra   s
             r   test_extreme_domainsz)_TestRBFInterpolator.test_extreme_domainsk   s    QRYY-B-B-DEJJsOa zz#%%3DJJq!FJ3D9EDJJ%%   u*u$&E
 ADJJq!SJ@FEDJJ%%E	   u*u$	&E 	u40r   c                    t         j                  j                  d      }t        dd|      }d}|j                  d      }|j                  d      }t	        ||      }t	        ||      }|j                  dd|j                  d	         }|j                  |      }	|j                  |      }
 | j                  ||	|
      |      }t        |
|d       y )Nr   r#   Fr1   r   rT           rU   r   r   rY   rZ   )
r   r6   r7   r   r   normalr   r=   r\   r   )r^   rngrD   r   r   r_   rG   Pitppoly_coeffsr   r`   ra   s               r   test_polynomial_reproductionz1_TestRBFInterpolator.test_polynomial_reproduction   s     ii##A&QS1JJrNzz"~F#D&)jjc1771:6EE+%/

1a
/5u40r   c                    t         j                  j                  d      }t        dd|      }d}d}|j                  d      }|j                  |      }t	        ||      }t	        ||      }	|j                  dd	|j                  d
         }
|j                  |
      }|	j                  |
      }| j                  |||      }|j                  fd}|j                  |d|        ||      }t        ||d       y )Nr   r#   Fr1   r   i	  rT   rl   rU   r   rm   c                  8    |j                  d        | i |S )Nr/   )memory_budget)update)argskwargsce_reals     r   _chunk_evaluatorz<_TestRBFInterpolator.test_chunking.<locals>._chunk_evaluator   s!    MMM,D+F++r   rz   rY   rZ   )r   r6   r7   r   r   rn   r   r=   r\   rz   setattrr   )r^   monkeypatchro   rD   r   largeNr   r_   rG   rp   rq   r   r`   interprz   ra   ry   s                   @r   test_chunkingz"_TestRBFInterpolator.test_chunking   s    
 ii##A&QS1JJrNzz&!F#D&)jjc1771:6EE+%Aq0))	, 	F$68HItu40r   c           
         t        ddt        j                  j                               }|j                  d      }|j                  d      }t        j                  t        |      t        |d d d d df         g      j                  } | j                  ||      |      } | j                  ||d d df         |      } | j                  ||d d df         |      }t        |d d df   |       t        |d d df   |       y )Nr#   Fr1   r/   rN   r   r   )	r   r   r6   r7   arrayr-   r<   r\   r   r^   rD   r   r_   r   r`   ra   yitp3s           r   test_vector_dataz%_TestRBFInterpolator.test_vector_data   s     QRYY-B-B-DEJJsOzz#HH'*'!TrT'
35 667a 	
 !

1a &&

1a1g&t,&

1a1g&t,adU+adU+r   c           	         t        ddt        j                  j                               }|j                  d      }|j                  d      }t	        |      dt	        |d d d d df         z  z   } | j                  ||      |      } | j                  ||j                        |      } | j                  ||j                        |      }t        |j                  |       t        |j                  |       y )Nr#   Fr1   r/   y              ?rN   )	r   r   r6   r7   r-   r\   realimagr   r   s           r   test_complex_dataz&_TestRBFInterpolator.test_complex_data   s     QRYY-B-B-DEJJsOzz#a 2&7!TrT'
&C#CC 

1a &%

1aff%d+%

1aff%d+

E*

E*r   c                 N   t        ddt        j                  j                               }d|j                  d      z  }d|j                  d      z  }t	        |      }t	        |      } | j                  ||d|      |      }t        j                  ||z
  dz        }|d	k  sJ y )
Nr   Fr1   r   rT   rg   rV   r#   -C6?)r   r   r6   r7   r    r\   mean	r^   r?   rD   r   r_   r   ytrueyitpmses	            r   test_interpolation_misfit_1dz1_TestRBFInterpolator.test_interpolation_misfit_1d   s     QRYY-B-B-DEcjjnBa !$';tzz!QFz;DAggte|a'(V||r   c                 B   t        ddt        j                  j                               }|j                  d      }|j                  d      }t	        |      }t	        |      } | j                  ||d|      |      }t        j                  ||z
  dz        }|dk  sJ y )Nr#   Fr1   r/   rg   rV   g-C6*?)r   r   r6   r7   r-   r\   r   r   s	            r   test_interpolation_misfit_2dz1_TestRBFInterpolator.test_interpolation_misfit_2d   s     QRYY-B-B-DEJJsOzz#a !$';tzz!QFz;DAggte|a'(V||r   c           	         t         j                  j                  d      }t        dd|      }d}d}dt        j                  ddd	      z  }d
|j                  d      z  }t        |      |j                  d|d      z   }t        |      }	d}
|D ]U  } | j                  ||d||      |      }t        j                  t        j                  ||	z
  dz              }||k  sSd}
 n |
sJ y )Nr   r   Fr1   g?g?r%      r   r/   rl   )r/   rU   )rW   	smoothingr?   r#   T)
r   r6   r7   r   linspacer    rn   r\   sqrtr   )r^   r?   ro   rD   noisermse_tolsmoothing_ranger   r   r   rmse_within_tolr   ysmoothrmses                 r   test_smoothing_misfitz*_TestRBFInterpolator.test_smoothing_misfit   s     ii##A&QS1bkk"a44cjjoa 3::c5&#AA!!$(Idjj1#	 !   !	"G
 77277GeOa#789Dh"& ) r   c                    t         j                  j                  d      }t        dd|      }d}|j                  d      }t	        ||      }|j                  dd|j                  d         }|j                  |      }t        j                  |      }|d	xx   dz  cc<   t        j                  d
      }	d|	d	<    | j                  |||	      |      }
t        |
|d       y )Nr   r   Fr1   r#   rT   rl   rU   r%   )rT   g     @@r   r   rZ   )r   r6   r7   r   r   rn   r   r=   copyzerosr\   r   )r^   ro   rD   r   r   rG   rq   r   y_with_outlierr   r   s              r   test_array_smoothingz)_TestRBFInterpolator.test_array_smoothing  s     ii##A&QS1JJrNF#jjc1771:6EE+rc!HHUO		"Atzz!^yzA!Dad+r   c                    t        ddt        j                  j                               j                  d      }t	        |      }t        ddt        j                  j                               j                  d      }d}t        j                  t        |      5   | j                  ||      |       d d d        y # 1 sw Y   y xY w)Nr#   Fr1   r%   r   zExpected the second axis of `x`match)	r   r   r6   r7   r-   pytestraises
ValueErrorr\   )r^   r   dr   r   s        r   $test_inconsistent_x_dimensions_errorz9_TestRBFInterpolator.test_inconsistent_x_dimensions_error/  s     1u299+@+@+BCJJ2Na 1u299+@+@+BCJJ2N1]]:U3DJJq!Q 433s   B==Cc                     t        j                  ddd      d d d f   }t        j                  d      }d}t        j                  t
        |      5  | j                  ||       d d d        y # 1 sw Y   y xY w)Nr   r   r0   zExpected the first axis of `d`r   r   r   r   r   r   r   r\   r^   r   r   r   s       r    test_inconsistent_d_length_errorz5_TestRBFInterpolator.test_inconsistent_d_length_error9  sW    KK1a D)HHQK0]]:U3JJq! 433s   A--A6c                     t        j                  ddd      }t        j                  d      }d}t        j                  t
        |      5  | j                  ||       d d d        y # 1 sw Y   y xY w)Nr   r   r0   z"`y` must be a 2-dimensional array.r   r   r   s       r   test_y_not_2d_errorz(_TestRBFInterpolator.test_y_not_2d_error@  sN    KK1a HHQK4]]:U3JJq! 433s   
A&&A/c                     t        j                  ddd      d d d f   }t        j                  d      }t        j                  d      }d}t	        j
                  t        |      5  | j                  |||       d d d        y # 1 sw Y   y xY w)Nr   r   r0   zExpected `smoothing` to ber   r   )r   r   r   onesr   r   r   r\   )r^   r   r   r   r   s        r   (test_inconsistent_smoothing_length_errorz=_TestRBFInterpolator.test_inconsistent_smoothing_length_errorG  sh    KK1a D)HHQKGGAJ	,]]:U3JJq!yJ1 433s   &BBc                     t        j                  ddd      d d d f   }t        j                  d      }d}t        j                  t
        |      5  | j                  ||d       d d d        y # 1 sw Y   y xY w)Nr   r   r0   z`kernel` must be one ofr   testrf   r   r   s       r   test_invalid_kernel_name_errorz3_TestRBFInterpolator.test_invalid_kernel_name_errorO  s[    KK1a D)HHQK)]]:U3JJq!FJ+ 433   A//A8c                    t        j                  ddd      d d d f   }t        j                  d      }t        D ]E  }|t        v rd}t        j                  t        |      5  | j                  |||       d d d        G y # 1 sw Y   RxY w)Nr   r   r0   z`epsilon` must be specifiedr   rf   )	r   r   r   r   r   r   r   r   r\   )r^   r   r   r?   r   s        r    test_epsilon_not_specified_errorz5_TestRBFInterpolator.test_epsilon_not_specified_errorV  sv    KK1a D)HHQK F))1Ez7

1a
/ 87 !
 87s   #BB	c                 ,   t        j                  ddd      d d d f   }t        j                  ddd      }t        j                  d      }d}t        j                  t
        |      5   | j                  ||      |       d d d        y # 1 sw Y   y xY w)Nr   r   r0   z"`x` must be a 2-dimensional array.r   r   )r^   r   r   r   r   s        r   test_x_not_2d_errorz(_TestRBFInterpolator.test_x_not_2d_errora  sp    KK1a D)KK1a HHQK4]]:U3DJJq!Q 433s   (B

Bc                     t        j                  ddd      d d d f   }t        j                  d      }d}t        j                  t
        |      5  | j                  ||d       d d d        y # 1 sw Y   y xY w)Nr   r   z#At least 2 data points are requiredr   thin_plate_splinerf   r   r   s       r   "test_not_enough_observations_errorz7_TestRBFInterpolator.test_not_enough_observations_errori  s\    KK1a D)HHQK5]]:U3JJq!$7J8 433r   c           
      J   t        j                  ddd      d d d f   }t        j                  d      }t        j                         D ]M  \  }}|dk\  sd| }t        j                  t        |      5  | j                  ||d||dz
         d d d        O y # 1 sw Y   ZxY w)Nr   r   r0   z`degree` should not be below r   rU   rW   r?   r   )	r   r   r   r	   itemsr   warnsWarningr\   )r^   r   r   r?   degr   s         r   test_degree_warningz(_TestRBFInterpolator.test_degree_warningp  s    KK1a D)HHQK.446KFCax7u=\\'7JJq!SAJN 87	 7 87s   4BB"	c                     t        j                  ddd      d d d f   }t        j                  d      }t        j                         D ]  \  }}| j                  ||d|d        y )Nr   r   r0   rU   rN   r   )r   r   r   r	   r   r\   )r^   r   r   r?   rE   s        r   test_minus_one_degreez*_TestRBFInterpolator.test_minus_one_degreez  sW    KK1a D)HHQK,224IFAJJq!SJC 5r   c                    t        j                  ddgddgddgg      }t        j                  g d      }d}t        j                  t        |      5   | j                  ||d      |       d d d        y # 1 sw Y   y xY w)	NrX   rl   rU   )rl   rl   rl   zdoes not have full column rankr   r   rf   )r   r   r   r   r   r\   r   s       r   test_rank_errorz$_TestRBFInterpolator.test_rank_error  sl     HHsCj3*sCj9:HH_%0]];e48DJJq!$7J8; 544s   A77B c                     dD ]T  }t        j                  d|f      }t        j                  d      } | j                  ||d      |      }t	        ||       V y )N)r   r#   r   r   )r   linearrf   )r   r   r   r\   r   )r^   dimr   r   fs        r   test_single_pointz&_TestRBFInterpolator.test_single_point  sR     C!S"AA1

1a
1!4AAq!	 r   c                 l   t        ddt        j                  j                  d            }d|j                  d      z  }d|j                  d      z  }t	        |      }| j                  ||      } ||      } t        j                  t        j                  |            |      }t        ||d       y )	Nr   Fl   e r1   r   rT   gؗҜ<rZ   )
r   r   r6   r7   r    r\   pickleloadsdumpsr   )r^   rD   r   r_   r   r~   r`   ra   s           r   test_pickleablez$_TestRBFInterpolator.test_pickleable  s     QRYY-B-B:-NOcjjnBa Aq!t2V\\&1248u51r   N)"__name__
__module____qualname__r   markparametrizesortedr   rb   rd   r   rj   rr   slowr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   rR   rR   R   su   [[Xv.>'?@	1 A	1 [[Xv.>'?@	1 A	1 [[Xvj'9:1 ;161, [[1 1>,$+" [[Xvj'9: ; [[Xvj'9: ; [[Xvj'9: ;6,& 2,	0 9OD<"2r   rR   c                       e Zd Zd Zd Zd Zy) TestRBFInterpolatorNeighborsNonec                     t        |i |S )Nr   r^   rw   rx   s      r   r\   z&TestRBFInterpolatorNeighborsNone.build  s    ///r   c                    t        ddt        j                  j                               }d}d}d|j                  d      z  }d|j                  d      z  }t	        |      } | j                  ||||      |      }t        ||      }t        ||      }	|	j                  t        j                  j                  ||d       d	         }
t        ||
d
       y )Nr   Fr1   r       חArT   r   r   rcondr   rY   rZ   )r   r   r6   r7   r    r\   r   r=   r:   lstsqr   r^   rD   r   r   r   r_   r   r`   rG   rp   ra   s              r   test_smoothing_limit_1dz8TestRBFInterpolatorNeighborsNone.test_smoothing_limit_1d  s     QRYY-B-B-DE	cjjnBa 

q   	 F#D&)AT:1=>u40r   c                    t        ddt        j                  j                               }d}d}|j                  d      }|j                  d      }t	        |      } | j                  ||||      |      }t        ||      }t        ||      }	|	j                  t        j                  j                  ||d       d	         }
t        ||
d
       y )Nr#   Fr1   r   r   r/   r   r   r   rY   rZ   )r   r   r6   r7   r-   r\   r   r=   r:   r   r   r   s              r   test_smoothing_limit_2dz8TestRBFInterpolatorNeighborsNone.test_smoothing_limit_2d  s     QRYY-B-B-DE	JJsOzz#a 

q   	 F#D&)AT:1=>u40r   N)r   r   r   r\   r   r   r   r   r   r   r     s    0121r   r   c                       e Zd Zd Zd Zy)TestRBFInterpolatorNeighbors20c                      t        |i |ddiS )N	neighborsr   r   r   s      r   r\   z$TestRBFInterpolatorNeighbors20.build  s    =="==r   c           	         t        ddt        j                  j                               }|j                  d      }|j                  d      }t	        |      } | j                  ||      |      }g }t        |      }|D ]D  }|j                  |d      \  }	}
|j                   t        ||
   ||
         |d          d          F t        ||d       y )	Nr#   Fr1   r/   r   r   rY   rZ   )r   r   r6   r7   r-   r\   r   queryappendr   r   )r^   rD   r   r_   r   r`   ra   treexirE   nbrs              r   #test_equivalent_to_rbf_interpolatorzBTestRBFInterpolatorNeighbors20.test_equivalent_to_rbf_interpolator  s    QRYY-B-B-DEJJsOzz#a  

1a &qzBZZB'FAsLL8338DB1EF  	u40r   Nr   r   r   r\   r   r   r   r   r   r     s    >1r   r   c                       e Zd Zd Zd Zy)TestRBFInterpolatorNeighborsInfc                 <    t        |i |dt        j                  iS )Nr   )r   r   infr   s      r   r\   z%TestRBFInterpolatorNeighborsInf.build  s    AA"&&AAr   c                 .   t        ddt        j                  j                               }d|j                  d      z  }d|j                  d      z  }t	        |      } | j                  ||      |      } t        ||      |      }t        ||d       y )Nr   Fr1   r   rT   rY   rZ   )r   r   r6   r7   r    r\   r   r   )r^   rD   r   r_   r   r`   ra   s          r   r   zCTestRBFInterpolatorNeighborsInf.test_equivalent_to_rbf_interpolator  s    QRYY-B-B-DEcjjnBa  

1a &%1%d+u40r   Nr   r   r   r   r   r     s    B
1r   r   ) r   r   numpyr   numpy.linalgr   numpy.testingr   scipy.stats.qmcr   scipy.spatialr   scipy.interpolate._rbfinterpr   r   r	   r
   r   scipy.interpolater   r   r    r-   rL   r   r   r   rP   rR   r   r   r   r   r   r   <module>r     s       $ ) " !  1<	> 6*#56: 7:P2 P2f
41'; 41n1%9 101&F 1r   