a
    h                     @   s   d dl Z d dlZd dlZd dlmZmZmZmZ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lmZ ejdejZG dd	 d	ZG d
d dZG dd dZdS )    N)assert_allcloseassert_equalassert_warnsassert_array_almost_equalassert_array_equal)raises)RegularGridInterpolatorinterpnRectBivariateSplineNearestNDInterpolatorLinearNDInterpolator)matrix)ComplexWarningmethodc                   @   s  e Zd Zdd Zdd Zdd Zdd Zed	d
 Ze	j
dg ddd Ze	j
deeg dg dg dgfeeg dfgdd Zdd Zedd Zdd Zdd Zdd Ze	j
d eg d!d"feg d#d$feg d%d$feg d&d'feg d(d)fgd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Ze	j
dd<d=gd>d? Zd@dA ZdBdC Z dDdE Z!e	j
dFdGej"ej#ge	j
dd=d<gdHdI Z$e	j
dd<d=gdJdK Z%e	j
dd<d=gdLdM Z&ee	j
dNdOdPdQ fdRdSdQ fdTdUdQ fdVdWdQ fgdXdY Z'dZd[ Z(ed\d] Z)ed^d_ Z*ee	j
d`dadbgdcdd Z+dedf Z,e	j
dgej-ej.ej/ej0ge	j
dhej-ej.gdidj Z1dkdl Z2dGS )mTestRegularGridInterpolatorc                 C   s   dgd }t g d}|d d t jt jt jf }|t jd d t jt jf }|t jt jd d t jf }|t jt jt jd d f }||d  |d  |d  }||fS )N              ?      ?   
   d     npasarraynewaxisselfpointsvaluesvalues0values1Zvalues2Zvalues3 r#   \/var/www/html/assistant/venv/lib/python3.9/site-packages/scipy/interpolate/tests/test_rgi.py_get_sample_4d   s    
z*TestRegularGridInterpolator._get_sample_4dc                 C   s   dgd dgd  }t g d}|d d t jt jt jf }|t jd d t jt jf }|t jt jd d t jf }|t jt jt jd d f }||d  |d  |d  }||fS Nr      )r         @      $@r   r   r   r   r   r#   r#   r$   _get_sample_4d_2"   s    z,TestRegularGridInterpolator._get_sample_4d_2c                 C   s   dgd }t g d}|d d t jt jt jf }|t jd d t jt jf }|t jt jd d t jf }|t jt jt jd d f }||d  |d  |d  }||fS )Nr   r   r         ?       @      @      @r   r   r   r   r   r   r#   r#   r$   _get_sample_4d_3-   s    
z,TestRegularGridInterpolator._get_sample_4d_3c                 C   s   dgd }t ddg}|d d t jt jt jf }|t jd d t jt jf }|t jt jd d t jf }|t jt jt jd d f }||d  |d  |d  }||fS )N)r   r   r   r   r   r   r   r   r   r   r#   r#   r$   _get_sample_4d_48   s    
z,TestRegularGridInterpolator._get_sample_4d_4c                 C   sj   |   \}}tg dg dg dg}t|| |d}|| }t|||d}||}t|| d S )N皙?r3   r   ?皙?r3   g?g?r   r   r   r   r   )r0   r   r   r   tolistr   )r   r   r   r    sampleinterpv1v2r#   r#   r$   test_list_inputC   s    z+TestRegularGridInterpolator.test_list_inputr   )cubicquinticpchipc                 C   s   |   \}}d}tjt|d t|||d W d    n1 sB0    Y  t||}tg dg dg dg}tjt|d |||d W d    n1 s0    Y  d S )Nzpoints in dimensionmatchr8   r2   r5   r7   )r1   pytestr   
ValueErrorr   r   r   )r   r   r   r    rC   r;   r:   r#   r#   r$   test_spline_dim_errorT   s    ,
z1TestRegularGridInterpolator.test_spline_dim_errorzpoints_values, sampler2   r5   r7   r3   r3   r)         "@c                 C   sF   || \}}t ||dd}||}t ||dd}||}t|| d S )Nlinearr8   slinear)r   r   )r   Zpoints_valuesr:   r   r    r;   r<   r=   r#   r#   r$   test_linear_and_slinear_closed   s    z9TestRegularGridInterpolator.test_linear_and_slinear_closec                 C   s   |   \}}tg dg dg dg}t||dd}tt ||dd W d    n1 s`0    Y  t||ddg d	d
d t||ddg dd
d t||ddg ddd d S )Nr2   r5   r7   rJ   r8      )nu)rL   r   r   r   )rL   rL   rL   V瞯<atol)r   rL   r   r   )r   r   r   )r   rL   rL   r   )r   r   r   g-=)r%   r   arrayr   assert_raisesrE   r   )r   r   r    r:   r;   r#   r#   r$   test_derivativesz   s"    

*z,TestRegularGridInterpolator.test_derivativesc           
      C   s   |dkrt d |  \}}|d|  }tg dg dg dg}t|||d}t||j|d}t||j|d}||}||d||  }	t||	 d S )	NrA   *pchip does not make sense for complex data               @r2   r5   r7   r8                 ?)	rD   skipr0   r   r   r   realimagr   )
r   r   r   r    r:   r;   ZrinterpZiinterpr<   r=   r#   r#   r$   test_complex   s    
z(TestRegularGridInterpolator.test_complexc           
      C   s   g dg d }}t j||dd\}}dd ||}t||f|dd}t||f|dd}|d	d
g}|d	d
g}	t j||	dddrJ d S )N)rL   r'      r   ij)indexingc                 S   s   | d |d  S )Nr   r#   xyr#   r#   r$   <lambda>       zATestRegularGridInterpolator.test_cubic_vs_pchip.<locals>.<lambda>r?   r8   rA   r,   r'   +=r   rP   Zrtol)r   meshgridr   Zallclose)
r   r_   r`   xgygr    r?   rA   Z
vals_cubicZ
vals_pchipr#   r#   r$   test_cubic_vs_pchip   s    z/TestRegularGridInterpolator.test_cubic_vs_pchipc                 C   s:   |   \}}t||}tg d}d}t||| d S )NrG   H@r*   r   r   r   r   r   r   r    r;   r:   wantedr#   r#   r$   test_linear_xi1d   s
    
z,TestRegularGridInterpolator.test_linear_xi1dc                 C   sR   |   \}}t||}tg dg dg dg}tg d}t||| d S )Nr2   r5   r7   ri   gq@g     \@r%   r   r   r   r   rk   r#   r#   r$   test_linear_xi3d   s    
z,TestRegularGridInterpolator.test_linear_xi3dzsample, wanted)r3   r3   r4   r4   g     0@)r3   r3   r3   r3   r   r   r   r   r   r   r   r   r        \@)r3   皙?g333333?r4   g     |@c                 C   s,   |   \}}t||dd}t||| d S )Nnearestr8   )r%   r   r   )r   r:   rl   r   r    r;   r#   r#   r$   test_nearest   s    z(TestRegularGridInterpolator.test_nearestc                 C   sL   |   \}}t||}tg dg dg}tddg}t||| d S )Nrq   rr   r   rs   ro   rk   r#   r#   r$   test_linear_edges   s
    
z-TestRegularGridInterpolator.test_linear_edgesc                 C   s   ddg}t g d}|d d t jf }|t jd d f }||d  }ttt|| ddg}ttt|| ddg}ttt|| g d}ttt|| ddg}ttt||dd d S )	Nr   )r   r   r   r   )r   )r   r   g      ?r   )r   r   r   undefmethodr8   )r   r   r   rR   rE   r   )r   r   r    r!   r"   r#   r#   r$   test_valid_create   s     
z-TestRegularGridInterpolator.test_valid_createc                 C   s   |   \}}t||}tg dg dg}tt||d tg dg dg}tt|| tg dg dg}tt|| d S )Nrq   rr   rx   )r   r   r   )r   r   r   )r   r   r   皙?)r%   r   r   r   rR   rE   )r   r   r    r;   r:   r#   r#   r$   test_valid_call   s    
z+TestRegularGridInterpolator.test_valid_callc                 C   s   |   \}}t||dd d}tg dg dg dg dg}tg d}t||dd	| tg d
}t||dd	| d S )NFbounds_error
fill_value皙r   r   r   rz   rz   rz   rz       @皙ir   r   r   r   )r   rs         &@r   ru   r8   )gfffff[gfffff@g     grI   ro   rk   r#   r#   r$   test_out_of_bounds_extrap   s    z5TestRegularGridInterpolator.test_out_of_bounds_extrapc                 C   s   |   \}}t||dd d}tg dg dg dg dg}tg d}t||dd	| tg d
}t||dd	| d S )NFr|   r   r   r   r   )r   r   r   r   ru   r8   )g333333(g33333`@g     gyXrI   rj   rk   r#   r#   r$   test_out_of_bounds_extrap2   s    z6TestRegularGridInterpolator.test_out_of_bounds_extrap2c                 C   s   |   \}}t||dtjd}tg dg dg dg}ttjtjtjg}t||dd| t||dd| tg d	g d
g dg}tg d}t||| d S )NFr|   r   r   r   ru   r8   rI   r2   r5   r7   rn   )r%   r   r   nanr   r   rk   r#   r#   r$   test_out_of_bounds_fill  s    z3TestRegularGridInterpolator.test_out_of_bounds_fillc                 C   s   |   \}}t||dd}tj| }dd |D }t|}|d}t||}tg dg dg dg}t|||| d S )	Nru   r8   c                 S   s   g | ]}|qS r#   r#   .0pr#   r#   r$   
<listcomp>  rb   zJTestRegularGridInterpolator.test_nearest_compare_qhull.<locals>.<listcomp>r2   r5   r7   )	r%   r   	itertoolsproductr   r   reshaper   r   r   r   r    r;   Zpoints_qhullZvalues_qhullZinterp_qhullr:   r#   r#   r$   test_nearest_compare_qhull  s    



z6TestRegularGridInterpolator.test_nearest_compare_qhullc                 C   s~   |   \}}t||}tj| }dd |D }t|}|d}t||}tg dg dg dg}t|||| d S )Nc                 S   s   g | ]}|qS r#   r#   r   r#   r#   r$   r      rb   zITestRegularGridInterpolator.test_linear_compare_qhull.<locals>.<listcomp>r   r2   r5   r7   )	r%   r   r   r   r   r   r   r   r   r   r#   r#   r$   test_linear_compare_qhull  s    




z5TestRegularGridInterpolator.test_linear_compare_qhullru   rI   c                 C   sp   t ddd}t ddd}td}t||f||d}|dd	g}t||f|j|d}|dd	g}t|| d S )
Nr   r'      rL      r   r   r8   rt   ffffff?)r   linspaceMyValuer   _vr   )r   r   r_   r`   r    r;   r<   r=   r#   r#   r$   test_duck_typed_values(  s    z2TestRegularGridInterpolator.test_duck_typed_valuesc                 C   sb   t jd t ddd}t ddd}t jdd}t||f|dd ttt||f|dd d S )	N  r   r'   r   rL   r   r~   y      ?       @)r   randomseedr   randr   rR   rE   )r   r_   r`   r    r#   r#   r$   test_invalid_fill_value6  s    
z3TestRegularGridInterpolator.test_invalid_fill_valuec                 C   s:   t jddd}dd |jD }t|| t||dd d S )Nr         z>f4dtypec                 S   s   g | ]}t |qS r#   )r   arange)r   nr#   r#   r$   r   F  rb   zCTestRegularGridInterpolator.test_fillvalue_type.<locals>.<listcomp>r   r   )r   onesshaper   )r   r    r   r#   r#   r$   test_fillvalue_typeC  s    
z/TestRegularGridInterpolator.test_fillvalue_typec                 C   sP  dd }t ddd}t ddd}|t j||ddd }t||f|dd	d
d}t|t ddgddgddggg ddd t|t ddgddgddggg ddd t|t ddg|jdd d |_t|ddgddggddgdd t|ddgddggddgdd t||f|dd	d d}t|ddgddggd d!gdd d S )"Nc                 S   s   | | S Nr#   r^   r#   r#   r$   fO  s    z;TestRegularGridInterpolator.test_length_one_axis.<locals>.frL   r   r\   Tr]   sparserI   Fe   r   r}   r~   r   )r'         rc   rO   gffffff?333333@)333333@333333@r   rz   r   333333?g      '@g?g      )@rN   r,   gffffff?ru   g?gffffff@r[   r   )r   r   re   r   r   rQ   r~   )r   r   r_   r`   datar;   r#   r#   r$   test_length_one_axisK  sB      z0TestRegularGridInterpolator.test_length_one_axisr~   Nc                 C   s   |d|d}t ddt j d}t |}t|f|d d  fi |}t|dgf|d d d f fi |}t ddt j d d}||}	t d}
|t ||
gj}t||	 t 	d}
|t ||
gj}|d u rt||	 n
t|| d S )	NFr~   r}   r   r   r'   r   r   rL   r   )
r   r   pisinr   ZzerosvstackTr   r   )r   r~   r   optionsr_   zfaZfbZx1aZzaZy1bZzbr#   r#   r$   test_length_one_axis2v  s"    
$


z1TestRegularGridInterpolator.test_length_one_axis2c           	      C   s,  t g dfg ddd|d}t|tjgs2J tjd}|jddd	 }|jddd
k}tj||< tjdd ||}W d    n1 s0    Y  t|| tj t||  |||   g d}dg}td}t ||f|dd|d}t|tjdgsJ t|dtjgs(J d S )N)rL   r'   r[   r   rL   Fr      lJ r   sizer   r   ignoreinvalid)r[   rL   )	r   r   isnanr   r   default_rngerrstater   r   )	r   r   r   rngr_   iresr`   r   r#   r#   r$   test_nan_x_1d  s(    
&
z)TestRegularGridInterpolator.test_nan_x_1dc                 C   s  t g dt g d }}dd }t j||ddd\}}|||}t||f||dd	}t jd
d& |dt jgddgg}	W d    n1 s0    Y  t|	d ddd t |	d sJ t j	d}
|
jddd d }|
jddd }|
jdddk}|
jdddk}||B }t j||< t j||< t ||gj
}t jd
d ||}	W d    n1 sh0    Y  t|	| t j t|	|  |||   d S )N)r   rL   r'   )rL   r[   r   c                 S   s   | d |d  S Nr'   r#   r^   r#   r#   r$   r     s    z4TestRegularGridInterpolator.test_nan_x_2d.<locals>.fr\   Tr   Fr   r}   r   r   r,   rL   r'   rc   rO   r   r   r   r   r      r   )r   rQ   re   r   r   r   r   r   r   r   r   r   )r   r   r_   r`   r   rf   rg   r   r;   r   r   i1i2r   r   r#   r#   r$   test_nan_x_2d  s0    

4

(z)TestRegularGridInterpolator.test_nan_x_2d)ndimsfuncr'   c                 C   s   d| d  d|d   S Nr'   r[   r#   r^   r#   r#   r$   ra     rb   z$TestRegularGridInterpolator.<lambda>r[   c                 C   s   d| d  d|d   | S r   r#   )r_   r`   r   r#   r#   r$   ra     rb   r   c                 C   s    d| d  d|d   | | S r   r#   r_   r`   r   ar#   r#   r$   ra     rb   r   c                 C   s$   d| d  d|d   | ||  S r   r#   )r_   r`   r   r   br#   r#   r$   ra     rb   c                    s   |dkr|dv rt d tjd}dd |j d|fd} fdd	t|D }|tj|d
dd }t|||d}||}	dd	 |D }
|tj|
d
dd }t|
||d}||}t	|	| d S )Nr   >   r@   r?   z-too slow; OOM (quintic); or nearly so (cubic)*   rL   r'   r   c                    s   g | ]}t  d qS )   )r   r   )r   _Zsample_highZ
sample_lowr#   r$   r     s   zITestRegularGridInterpolator.test_descending_points_nd.<locals>.<listcomp>r\   Tr   r8   c                 S   s   g | ]}|d d d qS )Nr   r#   )r   xir#   r#   r$   r     rb   )
rD   rW   r   r   r   uniformrangere   r   r   )r   r   r   r   r   Ztest_pointsZascending_pointsZascending_valuesZascending_interpZascending_resultZdescending_pointsZdescending_valuesZdescending_interpZdescending_resultr#   r   r$   test_descending_points_nd  s:    	


z5TestRegularGridInterpolator.test_descending_points_ndc                 C   s   dd }t g d}t g d}||f}|t j|ddd }d}tjt|d	 t|| W d    n1 st0    Y  d S )
Nc                 S   s   d| d  d|d   S r   r#   r^   r#   r#   r$   val_func_2d  s    zJTestRegularGridInterpolator.test_invalid_points_order.<locals>.val_func_2dr   r-   r         @      @r   r-   r/   r   r   r\   Tr   (must be strictly ascending or descendingrB   )r   rQ   re   rD   r   rE   r   )r   r   r_   r`   r   r    rC   r#   r#   r$   test_invalid_points_order  s    

z5TestRegularGridInterpolator.test_invalid_points_orderc                 C   s6   t tdgtd|dd}t|dgs2J d S )Nr   Fr   r   )r   r   r   r   r   )r   r   r;   r#   r#   r$   test_fill_value  s    z+TestRegularGridInterpolator.test_fill_valuec                 C   s   |dkrt d dgd dgd  }tjd}|d}|d}t|||d	d
}||}t|jd|d g }tdD ]*}	t||d|	f |d	d
}|	|| qzt
|ddd}
t||
d|d d S )Nr@   Way too slow.r   r   r   r,   r-   r.   r'   r   r(   r)         .@r         9@r   r   r   r   r   r   r   r[   r   Fr   r   r[   r   err_msgr   .rL   r   rc   rP   r   )rD   rW   r   r   r   r   r   r   r   appendrQ   	transposer   )r   r   r   r   r    r:   r;   vvsjr=   r#   r#   r$   test_nonscalar_values  s0    


z1TestRegularGridInterpolator.test_nonscalar_valuesflip_pointsFTc                 C   s  |dv rt d g d}|r,dd |D }tjd}d}|dd	d
dg|R }|d}t|||dd}||}	|	jdg|R ksJ t|jdd  }
t|jd D ]F}t|jd D ]2}t||d||f |dd}||	 |
||f< qqtj
|
dd}t|	|d|d d S )N>   r@   r?   r   r   r+   )r   r(   r)   r   r   r        A@      B@)	r   r(   r)   r   r   r   r  r  /   c                 S   s   g | ]}t t|qS r#   )tuplereversedr   r#   r#   r$   r   ?  rb   zGTestRegularGridInterpolator.test_nonscalar_values_2.<locals>.<listcomp>r   r[   r'   r   r   r   	   r   Fr   rL   r   .r   Zaxisrc   r   )rD   rW   r   r   r   r   r   emptyr   itemexpand_dimsr   )r   r   r  r   r   trailing_pointsr    r:   r;   r   r   r   r   r=   r#   r#   r$   test_nonscalar_values_2/  s0    

z3TestRegularGridInterpolator.test_nonscalar_values_2c                 C   s   d}ddg}t jd}d}|ddg|R }|d}t|||d	d
}||}|jdg|R kshJ t |jdd  }	t|jd D ]F}
t|jd D ]2}t||d|
|f |d	d
}|| |	|
|f< qqt j|	dd}t	||d|d d S )NrI   r   r+   r   )r[   r   r   r   r'   Fr   rL   r
  r   .r   r  rc   r   )
r   r   r   r   r   r  r   r  r  r   )r   r   r   r   r  r    r:   r;   r   r   r   r   r=   r#   r#   r$   test_nonscalar_values_linear_2DZ  s.    
z;TestRegularGridInterpolator.test_nonscalar_values_linear_2Dr   xi_dtypec                 C   s   dd }t ddd}t ddd}t j||dd	d
\}}|||}||}t||f|}	t jddgddgg|d}
t|	|
ddgdd d S )Nc                 S   s   d| d  d|d   S r   r#   r^   r#   r#   r$   r     s    z:TestRegularGridInterpolator.test_float32_values.<locals>.frL   r   r   r      r\   Tr   r   g@ffffff
@g@r   g Y`@g{,c@gHz>rO   )r   r   re   Zastyper   rQ   r   )r   r   r  r   r_   r`   rf   rg   r   r;   ptsr#   r#   r$   test_float32_valuesy  s    


z/TestRegularGridInterpolator.test_float32_valuesc                 C   s@  t ddd}t ddd}t j||ddd\}}|| }tt& t||f|dd d	 W d    n1 sn0    Y  tt( t||f|d
dd d W d    n1 s0    Y  tt* t||f|d
dd dd W d    n1 s0    Y  tt( t||f|d
ddid W d    n1 s20    Y  d S )Nr   r[   r   r\   Tr   c                 S   s   | S r   r#   r_   r#   r#   r$   ra     rb   z=TestRegularGridInterpolator.test_bad_solver.<locals>.<lambda>)solverrJ   c                 S   s   | S r   r#   r  r#   r#   r$   ra     rb   )r   r  c                 S   s   | S r   r#   r  r#   r#   r$   ra     rb   woof)r   r  r  r   )r   Zsolver_args)r   r   re   rR   rE   r   	TypeError)r   r_   r`   rf   rg   r   r#   r#   r$   test_bad_solver  s$    
4
$
$
z+TestRegularGridInterpolator.test_bad_solver)3__name__
__module____qualname__r%   r*   r0   r1   parametrize_rgi_interp_methodsr>   rD   markparametrizerF   r   r   rK   rS   rZ   rh   rm   rp   rv   rw   ry   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  Zfloat32Zfloat64Z	complex64Z
complex128r  r  r#   r#   r#   r$   r      s   







+

$



!

)r   c                   @   s2   e Zd ZdZdd Zdd Zdd Zdd	d
ZdS )r   z"
    Minimal indexable object
    c                 C   s(   d| _ || _tt||| _d S r   )ndimr   r   r   prodr   r   )r   r   r#   r#   r$   __init__  s    zMyValue.__init__c                 C   s
   | j | S r   )r   )r   idxr#   r#   r$   __getitem__  s    zMyValue.__getitem__c                 C   s   d S r   r#   )r   r#   r#   r$   __array_interface__  s    zMyValue.__array_interface__Nc                 C   s   t dd S )NzNo array representation)RuntimeError)r   r   copyr#   r#   r$   	__array__  s    zMyValue.__array__)NN)r  r  r  __doc__r$  r&  r'  r*  r#   r#   r#   r$   r     s
   r   c                   @   s(  e Zd Zdd Zdd Z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edd Zedd Zedd Zdd Zedd  Zd!d" Zd#d$ Zejd%d&d'gd(d) Zed*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z d8d9 Z!ejd:d;d<gd=d> Z"d?S )@TestInterpNc              	   C   sT   t g d}t g d}t g dg dg dg dg dg dg}|||fS )N)r   r-   r/   r   r   g      @)rL   r'   rL   r'   rL   rL   )rL   r'   r[   r'   rL   rL   )rL   r'   r'   r'   rL   rL   )r   rQ   )r   r_   r`   r   r#   r#   r$   _sample_2d_data  s    
zTestInterpN._sample_2d_datac                 C   sp   |   \}}}t|||}tg dg dgj}tt||f||dd||d d df |d d df  d S )NrL   ffffff@r   r   r  333333?r[   rL   r  r0  r   r(   r   r[   	splinef2dr8   r   rL   )r-  r
   r   rQ   r   r   r	   ev)r   r_   r`   r   lutr   r#   r#   r$   test_spline_2d  s    
"zTestInterpN.test_spline_2dc                 C   sp   |   \}}}tg dg dgj}t||f|||d}t| | f| | |d}t|||d d S )Nr.  r1  r8   r   )r-  r   rQ   r   r	   r9   r   )r   r   r_   r`   r   r   r<   r=   r#   r#   r$   r>     s    
zTestInterpN.test_list_inputc              
   C   s   t g d}t g d}t g dg dg dg dg dg}t|||}t g dg dgj}t||f||ddd	d
}||d d df |d d df }d	|dd< t|| ttt||f||ddd d
 d S )Nr   rL   r'   rL   r'   rL   rL   r'   r[   r'   rL   rL   r'   r'   r'   rL   rL   r/  r   r   r  r0  r[   rL   r  r0  g      r(   r   r[   r2  FR?@r   r   rL   r'   r   )	r   rQ   r
   r   r	   r3  r   rR   rE   )r   r_   r`   r   r4  r   actualexpectedr#   r#   r$   test_spline_2d_outofbounds  s$    
$
z&TestInterpN.test_spline_2d_outofboundsc                 C   s   dgd dgd  }t g d}|d d t jt jt jf }|t jd d t jt jf }|t jt jd d t jf }|t jt jt jd d f }||d  |d  |d  }||fS r&   r   r   r#   r#   r$   _sample_4d_data  s    zTestInterpN._sample_4d_datac                 C   sH   |   \}}t||}tg dg}t|||dd}t||| d S )NrG   rI   r8   r?  r   r   r   r	   r   r   r   r    Z	interp_rgr:   rl   r#   r#   r$   test_linear_4d  s
    
zTestInterpN.test_linear_4dc                 C   sB   |   \}}tg dg}d}t|||dddd}t|| d S )Nr3   r   g333333$@rH   r;  rI   Fr   r?  r   r   r	   r   r   r   r    r:   rl   r<  r#   r#   r$   test_4d_linear_outofbounds  s    
z&TestInterpN.test_4d_linear_outofboundsc                 C   sL   |   \}}t||dd}tg dg}t|||dd}t||| d S )Nru   r8   rG   r@  rA  r#   r#   r$   test_nearest_4d  s
    zTestInterpN.test_nearest_4dc                 C   sB   |   \}}tg dg}d}t|||dddd}t|| d S )NrC  r;  ru   Fr   rD  rE  r#   r#   r$   test_4d_nearest_outofbounds   s    
z'TestInterpN.test_4d_nearest_outofboundsc                 C   sT   |   \}}tg d}t|||dd}t|||d d d f dd}t|| d S )NrG   F)r}   )r?  r   r   r	   r   r   r   r    r:   r<   r=   r#   r#   r$   
test_xi_1d)  s
    zTestInterpN.test_xi_1dc                 C   sv   |   \}}tjd tjddd}t|||ddd}t|jd t|||d	dddd}t	|||j d S )
Nr   r'   r[   r   ru   Fr   r'   r[   r   )
r?  r   r   r   r   r	   r   r   r   r   rI  r#   r#   r$   
test_xi_nd1  s    
zTestInterpN.test_xi_ndc                 C   s   |   \}}}||f}tddd}tddd}|d d d f |d d d f f}t||||dd}	t|	jd t||\}
}tj|
j	 |j	 f }t||||dd}t
|	||	j d S )Nr   rL   r'   r[   Fr   rK  )r-  r   r   r	   r   r   re   Zc_r   Zravelr   r   )r   r   r_   r`   r    r   r   yir:   r<   xxyyr=   r#   r#   r$   test_xi_broadcast@  s     zTestInterpN.test_xi_broadcastc                    s    dkrt d dgd dgd  tjd}|d|dt d	d
}t|jd d  fddtdD }t	|
ddd}t||d d d S )Nr@   r   r   r'   r   r   r   r   Fr   r   r   c              	      s&   g | ]}t d |f  ddqS .Fr   r	   )r   r   r   r   r:   r    r#   r$   r   g  s   z5TestInterpN.test_nonscalar_values.<locals>.<listcomp>r   rL   r   rc   r   )rD   rW   r   r   r   r	   r   r   r   rQ   r   r   )r   r   r   r   r   r=   r#   rS  r$   r   T  s&    



z!TestInterpN.test_nonscalar_valuesc                    s    dv rt d g dtjd}d}|dddd	g|R |d
t dd}|jdg|R kstJ  fddtjd D }t|t	|j
d d d S )N>   r@   r?   r   r  r   r  r   r   r   r	  r   Fr   rL   c                    s0   g | ](  fd dt jd D qS )c              	      s(   g | ] }t d | f ddqS rQ  rR  )r   r   )r   r   r   r:   r    r#   r$   r     s   zBTestInterpN.test_nonscalar_values_2.<locals>.<listcomp>.<listcomp>r
  )r   r   )r   rS  )r   r$   r     s   z7TestInterpN.test_nonscalar_values_2.<locals>.<listcomp>r   rc   r   )rD   rW   r   r   r   r	   r   r   r   r   r   )r   r   r   r  r   r   r#   rS  r$   r  m  s    

z#TestInterpN.test_nonscalar_values_2c                 C   sT   |   \}}tjd tjddddd}tjddd}ttt|||dd d S )	Nr   r[   r   r   r   r   r2  r8   )r?  r   r   r   r   rR   rE   r	   )r   r   r    r:   r#   r#   r$    test_non_scalar_values_splinef2d  s    z,TestInterpN.test_non_scalar_values_splinef2dc                 C   s   |dkrt d |  \}}}||f}|d|  }tg dg dgj}t||||d}t||j||d}t||j||d}	|d|	  }
t	||
 d S )NrA   rT   rU   r.  r1  r8   rV   )
rD   rW   r-  r   rQ   r   r	   rX   rY   r   )r   r   r_   r`   r    r   r:   r<   Zv2rZv2ir=   r#   r#   r$   rZ     s    

zTestInterpN.test_complexc                 C   sz   |   \}}}||f}|d|  }tg dg dgj}tjdd  t|||dd W d    n1 sl0    Y  d S )NrU   r.  r1  complexrB   rA   r8   )r-  r   rQ   r   rD   Zdeprecated_callr	   r   r_   r`   r    r   r:   r#   r#   r$   test_complex_pchip  s    
zTestInterpN.test_complex_pchipc                 C   sv   |   \}}}||f}|d|  }tg dg dgj}tt  t|||dd W d    n1 sh0    Y  d S )NrU   r.  r1  r2  r8   )r-  r   rQ   r   r   r   r	   rV  r#   r#   r$   test_complex_spline2fd  s    

z"TestInterpN.test_complex_spline2fdr   rI   ru   c                 C   sd   t ddd}t ddd}td}t||f|ddg|d	}t||f|jddg|d	}t|| d S )
Nr   r'   r   rL   r   r   rt   r   r8   )r   r   r   r	   r   r   )r   r   r_   r`   r    r<   r=   r#   r#   r$   r     s    z"TestInterpN.test_duck_typed_valuesc                 C   s   t ddd}t ddd}tt jdd}t jddd}t||f|||d}t||ft |||d}|dkrt||d	d
d n
t|| d S )Nr   r'   r   rL   r   r[   r8   r@   g-C6
?g>rd   )r   r   r   r   r   r	   r   r   )r   r   r_   r`   r    r:   r<   r=   r#   r#   r$   test_matrix_input  s    zTestInterpN.test_matrix_inputc                 C   s   t g dg}t ddgddgddgg}tdgg df||}g d}t||dd	 t d
dgddgddgg}tdgg df||dd d}t||dd	 d S )N)r3   rL   r   rL   g@g	@gffffff@)r'   r[   r   )gQ?gffffff@gffffff @rN   rO   rz   r,   gffffffFr|   )r   rQ   r	   r   )r   r    r   r   rl   r#   r#   r$   r     s    z TestInterpN.test_length_one_axisc              	   C   s  dd }t g d}t g d}t g d}t g d}||||f}|t j|ddd }d	d
t t dddt dd
df}t|||}	|d d d }
|d d d }|d d d }|d d d }|
|||f}|t j|ddd }t|||}t|	| d S )Nc                 S   s    d| d  d|d   | | S r   r#   r   r#   r#   r$   value_func_4d  s    z9TestInterpN.test_descending_points.<locals>.value_func_4d)r   rL   r'   r[   )r   r   r   r   )r   r3   r6   r   r\   Tr   r3   r   r   r   r   r   )r   rQ   re   r   r   r	   r   )r   rZ  x1Zx2Zx3Zx4r   r    r  Zcorrect_resultZ
x1_descendZ
x2_descendZ
x3_descendZ
x4_descendZpoints_shuffledZvalues_shuffledZtest_resultr#   r#   r$   test_descending_points  s.    z"TestInterpN.test_descending_pointsc                 C   s   t g d}t g d}t g dg dg dg dg dg}t g dg dgj}d}tjt|d	  t||f|| W d    n1 s0    Y  d S )
Nr   r   r6  r7  r8  r9  r:  r   rB   )r   rQ   r   rD   r   rE   r	   )r   r_   r`   r   r   rC   r#   r#   r$   r     s    
z%TestInterpN.test_invalid_points_orderc                 C   sX   dg}ddg}t d}d}tt|d t||| W d    n1 sJ0    Y  d S )N)r   rL   r   rL   )rL   rL   r[   zaThe requested sample points xi have dimension 3, but this RegularGridInterpolator has dimension 1rB   )r   r   rR   rE   r	   )r   r   r    r   msgr#   r#   r$   test_invalid_xi_dimensions  s    
z&TestInterpN.test_invalid_xi_dimensionsc                 C   s   t ddd}t ddd}t ddd}|||f}t d}t g d}|D ]}d|j_qPd|j_d|j_t||| t||| d S )	Nr   r   r   r   r   r   r   r   Gz@(\@gffffff?Fr   r   r   rQ   flagsZ	writeabler	   r   )r   r_   r`   r   r   r    pointdr#   r#   r$   test_readonly_grid&  s    


zTestInterpN.test_readonly_gridc                 C   s|   t ddd}t ddd}||f}t d}t ddg}|D ]}d|j_q@d|j_d|j_t||| t||| d S )	Nr   r   r   r   r   r   ra  rb  Frc  )r   r_   r`   r   r    re  rf  r#   r#   r$   test_2d_readonly_grid5  s    

z!TestInterpN.test_2d_readonly_gridc                 C   s   t ddd}t |t |fj d d df }|jjr@J t ddd}t ddd}|||f}t d}t 	g d}t
||| t||| d S )Nr   r   r   r   r   r_  r`  )r   r   r   Z
empty_liker   r)  rd  c_contiguousr   rQ   r	   r   )r   r_   r`   r   r   r    re  r#   r#   r$   test_non_c_contiguous_gridD  s    &

z&TestInterpN.test_non_c_contiguous_gridr   z>f8z<f8c                 C   sj   t jddd|d}t jddd|d}||f}t jd|d}t jddg|d}t||| t||| d S )	Nr   r   r   r   r   rh  ra  rb  )r   r   r   rQ   r	   r   )r   r   r_   r`   r   r    re  r#   r#   r$   test_endiannessQ  s    zTestInterpN.test_endiannessN)#r  r  r  r-  r5  r  r>   r>  r?  rB  rF  rG  rH  rJ  rL  rP  r   r  rT  rZ   rW  rX  rD   r   r!  r   rY  r   r\  r   r^  rg  ri  rk  rl  r#   r#   r#   r$   r,    sN   	


		


 





r,  )r   rD   numpyr   Znumpy.testingr   r   r   r   r   r   rR   Zscipy.interpolater   r	   r
   r   r   Zscipy.sparse._sputilsr   Zscipy._lib._utilr   r   r!  Z_ALL_METHODSr  r   r   r,  r#   r#   r#   r$   <module>   s$        !