a
    Re                     @   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 ejdg d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method)linearnearestslinearcubicquinticpchipc                   @   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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d.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Ze	j
dd:d;gd<d= Zd>d? Zd@dA ZdBdC Z e	j
dDdEej!ej"ge	j
dd;d:gdFdG Z#e	j
dd:d;gdHdI Z$e	j
dd:d;gdJdK Z%ee	j
dLdMdNdO fdPdQdO fdRdSdO fdTdUdO fgdVdW Z&dXdY Z'edZd[ Z(ed\d] Z)ee	j
d^d_d`gdadb Z*dcdd Z+e	j
deej,ej-ej.ej/ge	j
dfej,ej-gdgdh Z0dES )i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(   T/var/www/sunrise/env/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_46   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皙?r8   r   ?皙?r8   g?g?r   r   r   r   r   )r5   r   r    r   tolistr   )r#   r   r$   r%   sampleinterpv1v2r(   r(   r)   test_list_inputA   s    z+TestRegularGridInterpolator.test_list_inputr   )r   r   r   c                 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matchr=   r7   r:   r<   )r6   pytestr   
ValueErrorr   r   r    )r#   r   r$   r%   rE   r@   r?   r(   r(   r)   test_spline_dim_errorR   s    ,
z1TestRegularGridInterpolator.test_spline_dim_errorzpoints_values, sampler7   r:   r<   r8   r8   r.         "@c                 C   sF   || \}}t ||dd}||}t ||dd}||}t|| d S )Nr   r=   r   )r   r   )r#   Zpoints_valuesr?   r$   r%   r@   rA   rB   r(   r(   r)   test_linear_and_slinear_closeb   s    z9TestRegularGridInterpolator.test_linear_and_slinear_closec           
      C   s   |   \}}|d|  }tg dg dg dg}t|||d}t||j|d}t||j|d}||}||d||  }	t||	 d S )N               @r7   r:   r<   r=                 ?)r5   r   r    r   realimagr   )
r#   r   r$   r%   r?   r@   ZrinterpZiinterprA   rB   r(   r(   r)   test_complexx   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)   r,      r   ij)indexingc                 S   s   | d |d  S )Nr   r(   xyr(   r(   r)   <lambda>       zATestRegularGridInterpolator.test_cubic_vs_pchip.<locals>.<lambda>r   r=   r   r1   r,   +=r   )atolZrtol)r   meshgridr   Zallclose)
r#   rV   rW   xgygr%   r   r   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 )NrI   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 )Nr7   r:   r<   r`   gq@g     \@r*   r   r   r    r   rb   r(   r(   r)   test_linear_xi3d   s    
z,TestRegularGridInterpolator.test_linear_xi3dzsample, wanted)r8   r8   r9   r9   g     0@)r8   r8   r8   r8   r   r   r   r   r   r   r   r   r        \@)r8   皙?g333333?r9   g     |@c                 C   s,   |   \}}t||dd}t||| d S )Nr   r=   )r*   r   r   )r#   r?   rc   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 )Nrh   ri   r   rj   rf   rb   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   undefmethodr=   )r   r    r!   assert_raisesrG   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 )Nrh   ri   rn   )r   r   r   )r   r   r   )r   r   r   皙?)r*   r   r   r    ro   rG   )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皙rw   rw   rw   rq   rq   rq   rq       @皙ir{   r{   r|   r|   )r   rj         &@r~   r   r=   )gfffff[gfffff@g     gr   rf   rb   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 )NFrs   rv   rx   ry   r}   )r   r~   r~   r~   r   r=   )g333333(g33333`@g     gyXr   ra   rb   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 )NFrs   rv   rx   r}   r   r=   r   r7   r:   r<   re   )r*   r   r   nanr    r   rb   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 )	Nr   r=   c                 S   s   g | ]}|qS r(   r(   .0pr(   r(   r)   
<listcomp>   rY   zJTestRegularGridInterpolator.test_nearest_compare_qhull.<locals>.<listcomp>r7   r:   r<   )	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     rY   zITestRegularGridInterpolator.test_linear_compare_qhull.<locals>.<listcomp>r   r7   r:   r<   )	r*   r   r   r   r   r    r   r   r   r   r(   r(   r)   test_linear_compare_qhull  s    




z5TestRegularGridInterpolator.test_linear_compare_qhullr   r   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,      rQ      r   r   r=   rk   ffffff?)r   linspaceMyValuer   _vr   )r#   r   rV   rW   r%   r@   rA   rB   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   rQ   r   ru   y      ?       @)r   randomseedr   randr   ro   rG   )r#   rV   rW   r%   r(   r(   r)   test_invalid_fill_value  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   .  rY   zCTestRegularGridInterpolator.test_fillvalue_type.<locals>.<listcomp>r   r   )r   onesshaper   )r#   r%   r$   r(   r(   r)   test_fillvalue_type+  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(   rU   r(   r(   r)   f7  s    z;TestRegularGridInterpolator.test_length_one_axis.<locals>.frQ   r   rS   TrT   sparser   Fe   r   rt   ru   r   )r,         rZ   r[   gffffff?333333@)333333@333333@r   rq   r   333333?g      '@g?g      )@V瞯<r1   gffffff?r   g?gffffff@rR   r   )r   r   r\   r   r   arrayru   )r#   r   rV   rW   datar@   r(   r(   r)   test_length_one_axis3  sB      z0TestRegularGridInterpolator.test_length_one_axisru   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ru   rt   r   r   r,   r   r   rQ   r   )
r   r   pisinr   zerosvstackTr   r   )r#   ru   r   optionsrV   zfaZfbZx1aZzaZy1bZzbr(   r(   r)   test_length_one_axis2^  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)rQ   r,   rR   r   rQ   Fr      lJ r   sizer   r   ignoreinvalid)rR   rQ   )	r   r   isnanr   r   default_rngerrstater   r   )	r#   r   r   rngrV   iresrW   r   r(   r(   r)   test_nan_x_1dz  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   rQ   r,   )rQ   rR   r   c                 S   s   | d |d  S Nr,   r(   rU   r(   r(   r)   r     s    z4TestRegularGridInterpolator.test_nan_x_2d.<locals>.frS   Tr   Fr   rt   r   r   r1   rQ   r,   rZ   r   r   r   r   r   r      r   )r   r   r\   r   r   r   r   r   r   r   r   r   )r#   r   rV   rW   r   r]   r^   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,   rR   r(   rU   r(   r(   r)   rX     rY   z$TestRegularGridInterpolator.<lambda>rR   c                 C   s   d| d  d|d   | S r   r(   )rV   rW   r   r(   r(   r)   rX     rY   r   c                 C   s    d| d  d|d   | | S r   r(   rV   rW   r   ar(   r(   r)   rX     rY   r   c                 C   s$   d| d  d|d   | ||  S r   r(   )rV   rW   r   r   br(   r(   r)   rX     rY   c                    s   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 )N*   rQ   r   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>rS   Tr   r=   c                 S   s   g | ]}|d d d qS )Nr   r(   )r   xir(   r(   r)   r     rY   )r   r   r   uniformranger\   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  s6    

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(   rU   r(   r(   r)   val_func_2d  s    zJTestRegularGridInterpolator.test_invalid_points_order.<locals>.val_func_2dr   r2   r         @      @r   r2   r4   r   r   rS   Tr   (must be strictly ascending or descendingrD   )r   r   r\   rF   r   rG   r   )r#   r   rV   rW   r$   r%   rE   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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}||| qht |	ddd}
t
||
d|d d S )Nr   r   r   r1   r2   r3   r,   r   r-   r.         .@r         9@r   r   r   r   r   r   r   rR   r   Fr   r   rR   r   err_msgr   .rQ   r   rZ   r[   r   )r   r   r   r   r   r   r   appendr   	transposer   )r#   r   r$   r   r%   r?   r@   vvsjrB   r(   r(   r)   test_nonscalar_values  s,    

z1TestRegularGridInterpolator.test_nonscalar_valuesflip_pointsFTc                 C   s  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szJ 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   r0   )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     rY   zGTestRegularGridInterpolator.test_nonscalar_values_2.<locals>.<listcomp>r   rR   r,   r   r   r   	   r   Fr   rQ   r   .r   ZaxisrZ   r   
r   r   r   r   r   emptyr   itemZexpand_dimsr   )r#   r   r   r$   r   trailing_pointsr%   r?   r@   r   r   r   r   rB   r(   r(   r)   test_nonscalar_values_2  s,    
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 )Nr   r   r0   r   )rR   r   r   r   r,   Fr   rQ   r  r   .r   r  rZ   r   r  )r#   r   r$   r   r	  r%   r?   r@   r   r   r   r   rB   r(   r(   r)   test_nonscalar_values_linear_2D6  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(   rU   r(   r(   r)   r   \  s    z:TestRegularGridInterpolator.test_float32_values.<locals>.frQ   r   r   r      rS   Tr   r{   g@ffffff
@g@r   g Y`@g{,c@gHz>r   )r   r   r\   Zastyper   r   r   )r#   r   r  r   rV   rW   r]   r^   r   r@   ptsr(   r(   r)   test_float32_valuesU  s    


z/TestRegularGridInterpolator.test_float32_values)1__name__
__module____qualname__r*   r/   r5   r6   parametrize_rgi_interp_methodsrC   rF   markparametrizerH   r   r    rK   rP   r_   rd   rg   rl   rm   rp   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  float32float64Z	complex64Z
complex128r  r(   r(   r(   r)   r      s   







+

$





%r   c                   @   s0   e Zd ZdZdd Zdd Zdd Z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__w  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__c                 C   s   t dd S )NzNo array representation)RuntimeErrorr  r(   r(   r)   	__array__  s    zMyValue.__array__N)r  r  r  __doc__r  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ejd#d$d%gd&d' Zed(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Z ejd8d9d: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   r2   r4   r   r   g      @)rQ   r,   rQ   r,   rQ   rQ   )rQ   r,   rR   r,   rQ   rQ   )rQ   r,   r,   r,   rQ   rQ   )r   r   )r#   rV   rW   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rQ   ffffff@r   r   r  333333?rR   rQ   r  r'  r   r-   r   rR   	splinef2dr=   r   rQ   )r$  r
   r   r   r   r   r	   ev)r#   rV   rW   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%  r(  r=   r   )r$  r   r   r   r	   r>   r   )r#   r   rV   rW   r   r   rA   rB   r(   r(   r)   rC     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   rQ   r,   rQ   r,   rQ   rQ   r,   rR   r,   rQ   rQ   r,   r,   r,   rQ   rQ   r&  r   r   r  r'  rR   rQ   r  r'  g      r-   r   rR   r)  FR?@r   r   rQ   r,   r   )	r   r   r
   r   r	   r*  r   ro   rG   )r#   rV   rW   r   r+  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 )NrI   r   r=   r6  r   r   r    r	   r   r#   r$   r%   Z	interp_rgr?   rc   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r8   rw   g333333$@rJ   r2  r   Fr   r6  r   r    r	   r   r#   r$   r%   r?   rc   r3  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 )Nr   r=   rI   r7  r8  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 )Nr:  r2  r   Fr   r;  r<  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 )NrI   F)rt   )r6  r   r    r	   r   r#   r$   r%   r?   rA   rB   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,   rR   r   r   Fr   r,   rR   r   )
r6  r   r   r   r   r	   r   r   r   r   r@  r(   r(   r)   
test_xi_nd  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   rQ   r,   rR   Fr   rB  )r$  r   r   r	   r   r   r\   Zc_r   Zravelr   r   )r#   r   rV   rW   r%   r$   r   yir?   rA   xxyyrB   r(   r(   r)   test_xi_broadcast  s     zTestInterpN.test_xi_broadcastc                    s   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   Fr   r   r   c              	      s&   g | ]}t d |f  ddqS .Fr   r	   )r   r   r   r$   r?   r%   r(   r)   r   $  s   z5TestInterpN.test_nonscalar_values.<locals>.<listcomp>r   rQ   r   rZ   r   )
r   r   r   r	   r   r   r   r   r   r   )r#   r   r   r   r   rB   r(   rJ  r)   r     s"    


z!TestInterpN.test_nonscalar_valuesc                    s   g dt jd}d}|ddddg|R |dt d	d
}|jdg|R ksbJ  fddtjd D }t|t |jd d d S )Nr   r   r  r   r   r   r  r   Fr   rQ   c                    s0   g | ](  fd dt jd D qS )c              	      s(   g | ] }t d | f ddqS rH  rI  )r   r   )r   r   r$   r?   r%   r(   r)   r   @  s   zBTestInterpN.test_nonscalar_values_2.<locals>.<listcomp>.<listcomp>r  )r   r   )r   rJ  )r   r)   r   @  s   z7TestInterpN.test_nonscalar_values_2.<locals>.<listcomp>r   rZ   r   )	r   r   r   r	   r   r   r   r    r   )r#   r   r   r	  r   r   r(   rJ  r)   r
  *  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   rR   r   r   r   r   r)  r=   )r6  r   r   r   r   ro   rG   r	   )r#   r$   r%   r?   r(   r(   r)    test_non_scalar_values_splinef2dG  s    z,TestInterpN.test_non_scalar_values_splinef2dc                 C   s   |   \}}}||f}|d|  }tg dg dgj}t||||d}t||j||d}t||j||d}	|d|	  }
t||
 d S )NrL   r%  r(  r=   rM   )r$  r   r   r   r	   rN   rO   r   )r#   r   rV   rW   r%   r$   r?   rA   Zv2rZv2irB   r(   r(   r)   rP   Q  s    
zTestInterpN.test_complexc                 C   sx   |   \}}}||f}|d|  }tg dg dgj}ttj  t|||dd W d    n1 sj0    Y  d S )NrL   r%  r(  r)  r=   )r$  r   r   r   r   ZComplexWarningr	   )r#   rV   rW   r%   r$   r?   r(   r(   r)   test_complex_spline2fd`  s    
z"TestInterpN.test_complex_spline2fdr   r   r   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   rQ   r   r   rk   r   r=   )r   r   r   r	   r   r   )r#   r   rV   rW   r%   rA   rB   r(   r(   r)   r   k  s    z"TestInterpN.test_duck_typed_valuesc                 C   sz   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}t|| d S )Nr   r,   r   rQ   r   rR   r=   )r   r   r   r   r   r	   r    r   )r#   r   rV   rW   r%   r?   rA   rB   r(   r(   r)   test_matrix_inputy  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)r8   rQ   r   rQ   g@g	@gffffff@)r,   rR   r   )gQ?gffffff@gffffff @r   r   rq   r1   gffffffFrs   )r   r   r	   r   )r#   r%   r   r   rc   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   rQ   r,   rR   )r   r   r   r   )r   r8   r;   r   rS   Tr   r8   r   r   r   r   r   )r   r   r\   r   r   r	   r   )r#   rN  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   r-  r.  r/  r0  r1  r   rD   )r   r   r   rF   r   rG   r	   )r#   rV   rW   r   r   rE   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   rQ   r   rQ   )rQ   rQ   rR   zaThe requested sample points xi have dimension 3, but this RegularGridInterpolator has dimension 1rD   )r   r   ro   rG   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   r   flagsZ	writeabler	   r   )r#   rV   rW   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   rU  rV  FrW  )r#   rV   rW   r$   r%   rY  rZ  r(   r(   r)   test_2d_readonly_grid  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   rS  rT  )r   r   r   Z
empty_liker   copyrX  c_contiguousr   r   r	   r   )r#   rV   rW   r   r$   r%   rY  r(   r(   r)   test_non_c_contiguous_grid  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   r\  rU  rV  )r   r   r   r   r	   r   )r#   r   rV   rW   r$   r%   rY  r(   r(   r)   test_endianness  s    zTestInterpN.test_endiannessN)"r  r  r  r$  r,  r  rC   r5  r6  r9  r=  r>  r?  rA  rC  rG  r   r
  rK  rP   rL  rF   r  r  r   rM  r   rP  r   rR  r[  r]  r`  ra  r(   r(   r(   r)   r#    sL   	

		








r#  )r   rF   numpyr   Znumpy.testingr   r   r   r   r   r   ro   Zscipy.interpolater   r	   r
   r   r   Zscipy.sparse._sputilsr   r  r  r  r   r   r#  r(   r(   r(   r)   <module>   s        b