
     h                        d dl Zd dlmZmZmZ d dlmZ d dlZd dl	m
Z
mZmZmZmZmZmZmZmZmZmZ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$c m%Z& d dl'Z' G d d          Z(d Z)d	 Z*d
 Z+d Z,d Z-d Z.ddZ/ddZ0d Z1 G d d          Z2 G d d          Z3d Z4d dZ5 G d d          Z6d Z7 G d d          Z8dS )!    N)assert_equalassert_allcloseassert_)raises)BSplineBPolyPPolymake_interp_splinemake_lsq_spline_bsplsplevsplrepsplprepsplder
splantidersprootsplintinsertCubicSplinemake_smoothing_spline)_not_a_knot_augknt_woodbury_algorithm_periodic_knots_make_interp_per_full_matrc                   n   e 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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ej         !                    d e"dd                    d              Z#d! Z$d" Z%ej         !                    d#g d$          ej         !                    d% e"d&                    d'                         Z&d( Z'd) Z(d* Z)ej         !                    d+g d,          d-             Z*ej         !                    d+g d,          d.             Z+d/ Z,d0S )1TestBSplinec           
         t          t          t          ft          fi t	          ddgdgd           t          j        d          5  t          t          t          fi t	          dt
          j        gdgd           d d d            n# 1 swxY w Y   t          t          t          fi t	          dt
          j        gdgd           t          t          t          fi t	          ddgdgd           t          t          t          fi t	          dgdggdgd           t          t          t          fi t	          g d	dgd           t          t          t          fi t	          g d
ddgd           t          t          t          fi t	          g dg dd           t          t          t          fi t	          g dg dd           t          t          t          fi t	          g dg dd           d\  }}t          j	        ||z   dz             }t
          j
        
                    |          }t          |||          }t          ||j                   t          ||j                   t          ||j                   d S )N                 ?      ?r   tckignore)invalidr   r      r   r   r*         r*   )        r.   r!          @      @      @)r!   r!   r!   cubic      @)r.   r   r   r   r*   r,   )r!   r   r   )   r,   )assert_raises	TypeError
ValueErrorr   dictnperrstatenaninfarangerandomr   r#   r$   r   r%   )selfnr%   r#   r$   bs         a/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/scipy/interpolate/tests/test_bsplines.py	test_ctorzTestBSpline.test_ctor   s+   y*-w 	1 	1!SbTQ///	1 	1 	1[*** 	S 	S*gRRBFtq1Q1Q1QRRR	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	Sj'NNTQKB41-M-M-MNNNj'JJTQGtq-I-I-IJJJj'MMTaS1#J2$!-L-L-LMMM 	j'KKTIII!-J-J-JKKKj' 	< 	<RH:::	< 	< 	< 	i 	O 	O111\\\WMMM	O 	O 	Oi 	K 	K111\\\SIII	K 	K 	K 	j' 	B 	B,,,


a@@@	B 	B 	B 1Iac!eIQAq!1313Qs   6B

BBc                 P   t                      }|j        }t          |j        |d         dd           t          |j        |d         dd           t          |j        |d                    t          j        t                    5  d|_        d d d            d S # 1 swxY w Y   d S )Nr   V瞯<atolrtolr   r*   foo)
_make_random_splinetckr   r#   r$   r   r%   pytestr   AttributeError)r?   rA   rK   s      rB   test_tckzTestBSpline.test_tck8   s    !!eSV%e<<<<SV%e<<<<QS#a&!!! ]>** 	 	AE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB"Bc                    t          j        ddd          }t          ddgdgd          }t           ||          d           t          g dddgd          }t           ||          t          j        |d	k     dd                     d S )
Nr   r   
   r0   r"   r,   )r   ffffff?r   r-   rQ   )r9   linspacer   r   wherer?   xxrA   s      rB   test_degree_0zTestBSpline.test_degree_0D   s    [Ar""q!f***"q!!!lllq!f222"rxT	1a8899999    c                    g d}g d}d}t          |||          }t          j        ddd          }t          |d         t	          |          z  |d         t	          |dz
            z  z   |d         t	          |dz
            z  z    ||          d	           t          t          ||||f           ||          d	           d S )
Nr+   r   r*   r,   r   r,   2   r   r*   +=rG   )r   r9   rR   r   B_012r   )r?   r#   r$   r%   rA   xs         rB   test_degree_1zTestBSpline.test_degree_1M   s    OOIIAq!K1b!!!U1XX!U1Q3ZZ7!A$uQqSzz/I!5	* 	* 	* 	*a!Q++QQqTT>>>>>>rW   c                    d}t          j        dg|dz   z  dg|dz   z  z             }t          j        g d          }t          |                    dd          ddg          }t	          |||          }t          j        ddd          }t           ||d	
           ||d	
          d           t          t          ||||f           ||          d           d S )Nr,   r   r   r!   r/   r0   r1   r(   g      r/   rP   Textrapolater[   r\   )r9   asarrayr   reshaper   rR   r   r   )r?   r%   r#   r$   bpbsplrU   s          rB   test_bernsteinzTestBSpline.test_bernsteinX   s
   JsAaCyA3!9,--J'''((199R##aV,,q!Q[b"%%24000RT222	@ 	@ 	@ 	@b1a),,Ru	. 	. 	. 	. 	. 	.rW   c                 (   t                      }|j        \  t          j                  dz
           d          } ||          }fd|D             }t	          ||d           fd|D             }t	          ||d           d S )Nr   rZ   c                 4    g | ]}t          |          S  _naive_eval.0r^   r$   r%   r#   s     rB   
<listcomp>z4TestBSpline.test_rndm_naive_eval.<locals>.<listcomp>n   s'    3331{1aA&&333rW   r[   r\   c                 4    g | ]}t          |          S rk   )_naive_eval_2rn   s     rB   rp   z4TestBSpline.test_rndm_naive_eval.<locals>.<listcomp>q   s'    666aaAq))666rW   )rJ   rK   r9   rR   r   )	r?   rA   rU   y_by_ny_n2r$   r%   r#   s	         @@@rB   test_rndm_naive_evalz TestBSpline.test_rndm_naive_evalf   s      !!%1a[1q!Aw++aee333333333Su----6666662666T......rW   c           	          t                      }|j        \  }}}t          j        ||         || dz
           d          }t	           ||          t          ||||f          d           d S )Nr   rZ   r[   r\   rJ   rK   r9   rR   r   r   r?   rA   r#   r$   r%   rU   s         rB   test_rndm_splevzTestBSpline.test_rndm_splevt   sn    !!%1a[1q!Aw++"uR!Q33%@@@@@@rW   c                    t           j                            d           t          j        t           j                            d                    }t           j                            d          }t	          ||          }t          | }|j        |j        }}t          j        ||         || dz
           d          }t           ||          t          ||          d           d S )N     r   P   r[   r\   )r9   r>   seedsortr   r   r#   r%   rR   r   r   )r?   r^   yrK   rA   r#   r%   rU   s           rB   test_rndm_splrepzTestBSpline.test_rndm_splrepz   s    
	tGBI$$R(())IR  QllSMsAC1[1q!Aw++"uR~~E::::::rW   c                    t                      }t          j        |j                  |_        t          j        |j        |j                 |j        |j         dz
           d          }t           ||          d           d S )Nr   d   r!   )rJ   r9   	ones_liker$   rR   r#   r%   r   )r?   rA   rU   s      rB   test_rndm_unityzTestBSpline.test_rndm_unity   sg    !!l13[QS13tAv;44"r"""""rW   c                    d\  }}t          j        t           j                            |                    }t           j                            |ddf          }t          |||          }||         || dz
           }}|||z
  t           j                            d          z  z   }t	           ||          j        d           d S )N   r,         sizer   r,   r-      )r,   r-   r   r   r   )r9   r   r>   r   r   shape)	r?   r@   r%   r#   r$   rA   tmtprU   s	            rB   test_vectorizationzTestBSpline.test_vectorization   s    1GBI$$Q''((I1a),,Aq!1q!AwB27bi..y9999QQrUU[/22222rW   c           	         d\  }}t          j        t           j                            ||z   dz                       }t           j                            |          }t           j        |t           j                            |dz             f         }t	          |||          t	          |||          }}|d         |d         z
  }t          j        |d         |z
  |d         |z   d          }	t           ||	           ||	          d           t           ||	          t          |	|||f          d           t           ||	          t          |	|||f          d           d S )N)!   r,   r   r(   r   rZ   r[   r\   )r9   r   r>   r_r   rR   r   r   )
r?   r@   r%   r#   r$   c_padrA   b_paddtrU   s
             rB   
test_len_czTestBSpline.test_len_c   sJ    1GBI$$QqSU++,,IQ a))!A#.../1a##WQq%9%95rUQqT\[1AbEBJ33"uuRyyu5555"uR!Q33%@@@@"uR!UA77eDDDDDDrW   c           	          t                      }|j        \  }}}||         || dz
           }}dD ]2}t           |||g|           ||dz   |dz
  g|          d           3d S )Nr   )TF绽|=&.>r\   rJ   rK   r   )r?   rA   r#   _r%   r   r   extraps           rB   test_endpointszTestBSpline.test_endpoints   s    !!%1a1q!AwB# 	L 	LFAAr2h//ArEz2:6??dL L L L L	L 	LrW   c           	          t                      }|j        \  }}}t           |||dz   | dz
           dz
             |||dz   | dz
           dz             d           d S )Nr   r   r   r\   r   )r?   rA   r#   r   r%   s        rB   test_continuityzTestBSpline.test_continuity   s    !!%1a!AaC1H+-..!AaC1H+2E0F0F	 	 	 	 	 	rW   c           	         t                      }|j        \  }}}|d         |d         z
  }t          j        ||         |z
  || dz
           |z   d          }||         |k     ||| dz
           k     z  }t	           |||         d           |||         d                     t	           ||d          t          ||||fd                     d S )	Nr(   r   r   rZ   Trb   F)extrx   )r?   rA   r#   r$   r%   r   rU   masks           rB   test_extrapzTestBSpline.test_extrap   s    !!%1arUQqT\[1AqbdGbL"55!r	b1aRT7l+ 	"T(555"T(666	8 	8 	8 	"$///b1a)+++	- 	- 	- 	- 	-rW   c                     t                      }|j        \  }}}|d         dz
  |d         dz   g} ||          }t          t          j        t          j        |                                d S )Nr   r   r(   )rJ   rK   r   r9   allisnan)r?   rA   r#   r   r%   rU   yys          rB   test_default_extrapzTestBSpline.test_default_extrap   sj    !!%1adQh"	"QrUUBF28B<<((()))))rW   c           	         t           j                            d           t          j        t           j                            d                    }t           j                            d          }d}t	          |||d          }|j        |dz   z
  }|d         |d	         z
  }t          j        ||         |z
  ||         |z   d
          }||         |||         z
  ||         ||         z
  z  z   }t           ||          t          ||||f                     g d}||         |||         z
  ||         ||         z
  z  z   }t           ||d           ||d                     d S )Nr|      r-   r,   periodicrb   r   r(   r   rZ   )r(   r         ?r   T)
r9   r>   r   r   r   r   rR   r   r   r   )	r?   r#   r$   r%   rA   r@   r   rU   xys	            rB   test_periodic_extrapz TestBSpline.test_periodic_extrap   s^   
	tGBI$$Q''((IQAq!444Fa!erUQqT\[1AaD2Ir22qTR!A$Y1Q4!A$;//"uR!Q33444 __qTR!A$Y1Q4!A$;//QQrz222AAbd4K4K4KLLLLLrW   c                     t                      }|j        \  }}}t          j        |||f          }t	          j        ||         ||          d          }t           ||           ||          dd           d S )Nr   r[   rF   )rJ   rK   r	   from_spliner9   rR   r   )r?   rA   r#   r$   r%   pprU   s          rB   
test_ppolyzTestBSpline.test_ppoly   sz    !!%1a1ay))[1q!uc**"rr"vvE>>>>>>rW   c                 t   t                      }|j        \  }}}t          j        |d         |d         d          }t          j        ||f         }t          d|dz             D ]4}t          ||||f|          }t          | |||          d           5t           |||dz             dd           d S )	Nr   r(   rZ   r   dernur[   r\   )rJ   rK   r9   rR   r   ranger   r   )r?   rA   r#   r$   r%   rU   r   yds           rB   test_derivative_rndmz TestBSpline.test_derivative_rndm   s    !!%1a[1qub))U2q5\AaC== 	; 	;CrAq!9#...BB"E::::: 	"1qu555555rW   c                    d}g d}t           j                            d           t           j        ddt           j                            d          ddf         }t	          |||          }t          j        g d          }t           |||dk             dz
             |||dk             dz                        t          t          j         |d	           |d
                                t          j        ddg          }t           ||dz
  d           ||dz   d                     t          j        ddg          }t          t          j	        t          j         ||dz
  d           ||dz   d                                          t          t          j	        t          j         ||dz
  d           ||dz   d                                          d S )Nr*   )r(   r(   r   r   r   r,   r-   r   r   r   r   r   r|   r   r   )r   r,   r-   r   r   r   g2H@gη   @r,   r-   r   r   )
r9   r>   r   r   r   rd   r   r   allcloser   )r?   r%   r#   r$   rA   r^   x0x1s           rB   test_derivative_jumpsz!TestBSpline.test_derivative_jumps   s    222
	tE!Q	((++Q12Aq! J|||$$!AF)e+,,!AF)e+,,	. 	. 	.BK(QQwZZ888999 ZA"u*+++"u*+++	- 	- 	-ZABF2;qqe':':':'(qe':':':< < = = = 	> 	> 	> 	BF2;qqUq'9'9'9'(qUq'9'9'9; ; < < < 	= 	= 	= 	= 	=rW   c           	         t          j        ddd          }t          j        g d          }t	           ||          t          ||j        |j        |j        f          d           t	           ||          t          |          d           t          j        g d          }t          j        d	d
d          }t	           ||          t          j
        |dk     ||z  d|z
  d
z            d           d S )Nr(   r-   r}   r   r   r*   r,   )r#   r[   r\   r   r   r   r*   r   r*   rP   r   r/   )r9   rR   r   basis_elementr   r   r#   r$   r%   B_0123rS   rT   s      rB   test_basis_element_quadraticz(TestBSpline.test_basis_element_quadratic  s   [Q##!LLL111"b13QS/22	@ 	@ 	@ 	@"r

	0 	0 	0 	0 !LLL111[Ar"""aBB
33%	A 	A 	A 	A 	A 	ArW   c           	          t                      }|j        \  }}}t          j        ||         || dz
           d          }t	           ||          t          ||||          d           d S )Nr   r}   r[   r\   )rJ   rK   r9   rR   r   _sum_basis_elementsry   s         rB   test_basis_element_rndmz#TestBSpline.test_basis_element_rndm  sm    !!%1a[1q!Aw++"22q!Q??eLLLLLLrW   c                    t                      }|j        \  }}}|dz  }t          |||          }t          ||j        j        |          }t          ||j        j        |          }t          j        ||         || dz
           d          }t           ||          j         ||          d           t           ||          j         ||          d           d S )Ny      ?      @r   r}   r[   r\   )	rJ   rK   r   r$   realimagr9   rR   r   )	r?   rA   r#   r$   r%   ccb_reb_imrU   s	            rB   
test_cmplxzTestBSpline.test_cmplx$  s    !!%1a(^Ar1q!#(A&&q!#(A&&[1q!Aw++"
DDHH59999"
DDHH5999999rW   c                     t          j        g d          }t          t          j         |t          j                                       d S )Nr   )r   r   r   r9   r   r;   r?   rA   s     rB   test_nanzTestBSpline.test_nan1  s>    !,,,//26##$$$$$rW   c                 D   t          d          }|j        \  }}}t          |||          }t          j        ||         || dz
           d          }t          d|          D ]<}|                                }t           |||           ||          dd           =d S )Nr   r%   r   r}   -q=rF   )rJ   rK   r   r9   rR   r   
derivativer   )r?   rA   r#   r$   r%   b0rU   js           rB   test_derivative_methodz"TestBSpline.test_derivative_method6  s    !$$$%1aQ1[1q!Aw++q! 	F 	FAABBr1IIqquu5uEEEEE	F 	FrW   c                     t                      }|j        \  }}}t          j        ||         || dz
           d          }t	           |                                                                |           ||          dd           t          j        |||f         }t          j        ||f          }t          |||          }t	           |                                                                |           ||          dd           d S )Nr   r}   r[   rF   )
rJ   rK   r9   rR   r   antiderivativer   c_dstackr   ry   s         rB   test_antiderivative_methodz&TestBSpline.test_antiderivative_method?  s   !!%1a[1q!Aw++7((**5577;;"E	7 	7 	7 	7 E!Q'NIq!fAq!7((**5577;;"E	7 	7 	7 	7 	7 	7rW   c                 
   t          j        g d          }t          |                    dd          d           t          |                    dd          d           t          |                    dd          d           t          |                    dd          d           t          |                    ddd          d           t          |                    ddd	          d           t          |                    ddd	          d           t          |                    ddd	          t	          j        dd|j                             d
|_        |                                } |d           |d          z
  }t          |                    dd          |           t          |                    dd          d|z             t          |                    dd          |           t          |                    dd          d|z             t          |                    dd           |d           |d          z
             t          |                    dd           |d           |d          z
   |d          z    |d          z
             t          |                    dd           |d           |d          z
   |d          z    |d          z
             t          |                    dd           |d           |d          z
   |d          z    |d          z
  d|z  z              t          |                    dd           |d           |d          z
             t          |                    dd           |d           |d          z
             t          |                    dd           |d           |d          z
  d|z  z
             d S )Nr)   r   r   r   g      r(   Trb   Fr   r*   iii      ?r,   g      +@   r   ir-   )	r   r   r   	integrate_implr   rK   rc   r   )r?   rA   i
period_ints       rB   test_integralzTestBSpline.test_integralM  s   !))),,Aq))3///Aq))8444Aq))4000 	B**A...Bt<<a@@@Bu==sCCCAru==xHHH 	Aru==QAE22	4 	4 	4 #QqTTAAaDD[
Aq)):666Aq))2
?;;;B++Z888B++Q^<<<C--qqvv#???C++QQqTTAAaDD[11Q44-?!!C&&-HIIIHf55!qqttaadd*QQsVV3	5 	5 	5C00!qqttaadd*QQsVV3a*nD	F 	F 	F 	Ar**AAaDD11Q44K888B,,aaddQQqTTk:::Ar**AAaDD11Q44K!j.,HIIIIIrW   c                     g d}t          ||          }d|_        t          j        |          }dD ]=\  }}t	          |                    ||          |                    ||                     >d S )Nr+   r   ))r   )r   r   )r      )r
   rc   r	   r   r   r   )r?   r^   rA   pr   r   s         rB   test_integrate_ppolyz TestBSpline.test_integrate_ppolyr  s    OOq!$$"a  5 	1 	1FBAKKB//KKB//1 1 1 1	1 	1rW   c                      G d dt                     }|                    g d          }t          |j        |           t          |                                j        |           t          |                                j        |           d S )Nc                       e Zd ZdS )'TestBSpline.test_subclassing.<locals>.BN)__name__
__module____qualname__rk   rW   rB   Br     s        DrW   r   )r   r   r*   r*   )r   r   r   	__class__r   r   )r?   r   rA   s      rB   test_subclassingzTestBSpline.test_subclassing}  s    	 	 	 	 	 	 	 	 OOLLL))Q[!$$$Q\\^^-q111Q%%''1155555rW   axisr   r-   c                    d\  }}t          j        dd||z   dz             }g d}|dz  }|                    ||           t           j                            |          }t	          ||||          }t          |j        j        ||         g|d |         z   ||dz   d          z              t           j                            d          }	t           ||	          j        |d |         t          |	j                  z   ||dz   d          z              |j	         dz
  |j	        fD ]0}
t          t           j        t          fi t          ||||
	           1t	          ||||                                          t	          ||||                              d
          t	          ||||                                          t	          ||||                              d
          fD ]}t          |j        |j                   d S )Nr   r   r   )r   r   r   r-   r   r   r   )r#   r$   r%   r   r*   )r9   rR   r   r>   r   r   r$   r   listndimr5   	AxisErrorr8   r   r   r   )r?   r   r@   r%   r#   shpos_axisr$   rA   xpaxb1s               rB   	test_axiszTestBSpline.test_axis  s5   1K1a!eai((YY !8
		(AI"%%Aq!$'''QSYl_r)8)}4r(1*++F	H 	H 	H Yi((QQrUU[		]T"(^^3b!oE	G 	G 	G F7Q;' 	: 	:B", : : 1QR888: : : : 1a...99;;1a...99!<<1a...==??1a...==a@@B 	* 	*B !&))))		* 	*rW   c                 "   d}g d}t          j        g dg dg          }t          |||d          }t          ||d         |          }t          ||d         |          }t           |d	           |d	           |d	          g           d S )
Nr*   )r   r   r*   r,   r-   r   r   )r(   r*   r   r(   )r*   r   r   r(   r   r   r   r3   )r9   arrayr   r   )r?   r%   r#   r$   splspl0spl1s          rB   test_neg_axiszTestBSpline.test_neg_axis  s    !!!Hnnnmmm455aAB'''q!A$""q!A$""SSXXS		4499566666rW   c                     d }d}d}dD ]} ||||           t          ddd          D ]} |||d           d}t          dd	          D ]} |||d
           dS )a7  
        Splines with different boundary conditions are built on different
        types of vectors of knots. As far as design matrix depends only on
        vector of knots, `k` and `x` it is useful to make tests for different
        boundary conditions (and as following different vectors of knots).
        c                    t           j                            d           t          j        t           j                            |           dz  dz
            }t           j                            |           dz  dz
  }|dk    r|d         |d<   t          ||||          }t          j        t          |j                  |z
  dz
            } t          |j        ||          |          }t          j
        ||j        |                                          }t          ||j        z  |d	
           t          ||d	
           dS )zY
            To avoid repetition of code the following function is provided.
            r|   (   r}   r   r(   r   r%   bc_typer   r[   r\   N)r9   r>   r   r   random_sampler
   eyelenr#   r   design_matrixtoarrayr   r$   )	r@   r%   r  r^   r   rg   r$   des_matr_defdes_matr_csrs	            rB   run_design_matrix_testszHTestBSpline.test_design_matrix_bc_types.<locals>.run_design_matrix_tests  s,    INN4   	//22R7"<==A	''**R/"4A*$$u!%aaAAADs46{{Q*++A07461a0033L"015124 44;GII  L46115AAAAL,UCCCCCCrW   r4   r,   clampednaturalr   r*   
not-a-knotr   r   r   N)r   )r?   r  r@   r%   bcs        rB   test_design_matrix_bc_typesz'TestBSpline.test_design_matrix_bc_types  s    	D 	D 	D* ( 	. 	.B##Aq"---- q!Q 	8 	8A##Aq,7777 q! 	6 	6A##Aq*5555	6 	6rW   rc   )FTr   degreer   c           	         t           j                            d           t           j                            d|dz   z            }t          j        |          t          j        |          }}|}t           j        t          j        |dz
  |dz
  |          t          j        ||d|dz   z            t          j        |dz   |dz   |          f         }t          j        t          |          |z
  dz
            }t          ||||          }	t           |	|          t          j        ||||                                                     t          j        |dz
  |dz
  |dz   |dz   g          }|sKt          j        t"                    5  t          j        ||||           ddd           dS # 1 swxY w Y   dS t           |	|          t          j        ||||                                                     dS )z;Test that design_matrix(x) is equivalent to BSpline(..)(x).r|   rP   r   r*   r   N)r9   r>   r   r  aminamaxr   rR   r  r  r   r   r  r  r  rL   r   r7   )
r?   rc   r   r^   xminxmaxr%   r#   r$   bsplines
             rB   'test_design_matrix_same_as_BSpline_callz3TestBSpline.test_design_matrix_same_as_BSpline_call  s$    		tI##B&1*$566WQZZdE"+dQhq&99+dD!vz*:;;+dQhq&99: ; F3q66A:>""!Q;//GAJJ-aA{CCKKMM	
 	
 	

 HdRi4#:tbyABB 	z** < <%aA{;;;< < < < < < < < < < < < < < < < < < 

%aA{;;CCEE    s   
F//F36F3c                    t           j                            d           d}d}t          j        t           j                            |          dz  dz
            }t           j                            |          dz  dz
  }t          |||          }t          dd          D ]]}|d |         }|d |         }t          j        ||j	        |          
                                }	t          |	|j        z  |d	
           ^d S )Nr|   rP   r,   r  r}   r   r   r-   r[   r\   )r9   r>   r   r   r  r
   r   r   r  r#   r  r   r$   )
r?   r@   r%   r^   r   rg   r   xcycr  s
             rB   test_design_matrix_x_shapesz'TestBSpline.test_design_matrix_x_shapes  s   
	tGBI++A..3b899I##A&&+b0!!Q!,,,q! 	C 	CA2A2B2A2B"015124 44;GII  L4612EBBBBB	C 	CrW   c                     g d}t          j        d|d                                          }t          |g dgd           d S )N)r!   r!   r!   r/   r0   r1   r1   r1   r/   r,   )g      ?gmਪ?gK}\UU?r.   r[   r\   )r   r  r  r   )r?   r#   des_matrs      rB   test_design_matrix_t_shapesz'TestBSpline.test_design_matrix_t_shapes  s_    ,,,(Q22::<<;;;<"	$ 	$ 	$ 	$ 	$ 	$rW   c                 b   t           j                            d           d}d}t          j        t           j                            |          dz  dz
            }t           j                            |          dz  dz
  }t          |||          }t          t                    5  t          j	        ||j
        d d d         |           d d d            n# 1 swxY w Y   d}g d	}g d
}t          t                    5  t          j	        |||           d d d            d S # 1 swxY w Y   d S )Nr|   rP   r,   r  r}   r   r(   r*   )r.   r!   r/   r0   r1   g      @ra   )r9   r>   r   r   r  r
   r5   r7   r   r  r#   )r?   r@   r%   r^   r   rg   r#   s          rB   test_design_matrix_assertsz&TestBSpline.test_design_matrix_asserts  s   
	tGBI++A..3b899I##A&&+b0!!Q!,,, :&& 	6 	6!!TVDDbD\1555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6$$$:&& 	+ 	+!!Q***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s$   &%CCC D$$D(+D(r  )r  r  r   r  c                 &   t           j                            d           t          j        t           j                            d                    }t           j                            d          }|dk    r|d         |d<   t	          |||          }t          j        ||          }t          j        ddd          }t           ||           ||          d	           t          |||          }t          |j
        |j
        d	           d S )
Nr|   r}   r   r   r(   r  r   rE   r\   )r9   r>   r   r   r   r   from_power_basisrR   r   r
   r$   )r?   r  r^   r   cbrg   rU   bspl_news           rB   test_from_power_basisz!TestBSpline.test_from_power_basis   s     		tGBI$$R(())IR  j  aDAbEAw///'G<<<[Ar""2Ru5555%aG<<<
777777rW   c                    t           j                            d           t          j        t           j                            d                    }t           j                            d          t           j                            d          dz  z   }|dk    r|d         |d<   t	          |||          }t          j        ||          }t          ||j        |          }t          ||j	        |          }t          |j        j        |j        d|j        z  z   j                   t          |j        |j        d|j        z  z   d	           d S )
Nr|   r}   r    r   r   r(   r2  rE   r\   )r9   r>   r   r   r   r   r3  r
   r   r   r   r$   dtyper   )r?   r  r^   r   r4  rg   bspl_new_realbspl_new_imags           rB   test_from_power_basis_complexz)TestBSpline.test_from_power_basis_complex/  s?    		tGBI$$R(())IR  29#3#3B#7#7"#<<j  aDAbEAw///'G<<<*1afgFFF*1afgFFFTV\MO&(=?&:%;<A	C 	C 	C}.!/5:	< 	< 	< 	< 	< 	<rW   c                     t          j        g d          }t          j        g d          }t          j        t	          ||d          d          }t          |j        g dd           dS )	a}  
        For x = [0, 1, 2, 3, 4] and y = [1, 1, 1, 1, 1]
        the coefficients of Cubic Spline in the power basis:

        $[[0, 0, 0, 0, 0],\$
        $[0, 0, 0, 0, 0],\$
        $[0, 0, 0, 0, 0],\$
        $[1, 1, 1, 1, 1]]$

        It could be shown explicitly that coefficients of the interpolating
        function in B-spline basis are c = [1, 1, 1, 1, 1, 1, 1]
        r+   )r   r   r   r   r   r  r2  )r   r   r   r   r   r   r   rE   r\   N)r9   r  r   r3  r   r   r$   )r?   r^   r   rg   s       rB   test_from_power_basis_exmpz&TestBSpline.test_from_power_basis_exmp@  sy     H___%%H___%%'Aq)(L(L(L09; ; ; 5 5 5EBBBBBBrW   N)-r   r   r   rC   rN   rV   r_   rh   rv   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   markparametrizer   r  r  r  r'  r+  r.  r0  r6  r;  r=  rk   rW   rB   r   r      sX       ! ! !F
 
 
: : :	? 	? 	?. . ./ / /A A A
; 
; 
;# # #3 3 3E E E$L L L  - - -* * *M M M$? ? ?6 6 6= = =8A A AM M M: : :% % %
F F F7 7 7#J #J #JJ	1 	1 	16 6 6 [VUU2q\\22* * 32*:7 7 7(6 (6 (6T [],E,E,EFF[XuuQxx00  10 GF4C C C"$ $ $+ + +$ [Y )C )C )C D D8 8D D8 [Y )C )C )C D D< <D D<C C C C CrW   r   c            
          dd} dD ]e}t          |          }t          t          |                    D ]6\  }} | ||           t          d|dz             D ]} | |||dd           7fd S )	Nr   r[   c           
      4   | j         \  }}}t          j        |          }t          j        |d         dz
  d|dd          |d d         z   z  |d         dz   f         }t	          t          ||||f|           | ||          ||d|d| j                   d S )	Nr   g?r   r   r(   zder = z  k = )rG   rH   err_msg)rK   r9   uniquer   r   r   r%   )	rA   r   r   rG   rH   r#   r$   r%   r^   s	            rB   check_splevz,test_knots_multiplicity.<locals>.check_splevX  s    %1aIaLLE!A$s(C1222A2/2s:;a!QC00!!As))CCC.M	O 	O 	O 	O 	O 	OrW   )r   r*   r,   r-   r   r   r   r   )r   r[   r[   )rJ   	enumerate_make_multiplesr   )rD  r%   rA   r   r  r   s         rB   test_knots_multiplicityrG  T  s    O O O O  6 6!$$$q1122 	6 	6EArKAQ!}} 6 6B3u55556	66 6rW   c                    |dk    r#||         | cxk    r||dz            k     rn ndndS |||z            ||         k    rd}n6| ||         z
  |||z            ||         z
  z  t          | |dz
  ||          z  }|||z   dz            ||dz            k    rd}nE|||z   dz            | z
  |||z   dz            ||dz            z
  z  t          | |dz
  |dz   |          z  }||z   S )zw
    Naive way to compute B-spline basis functions. Useful only for testing!
    computes B(x; t[i],..., t[i+k+1])
    r   r   r!   r.   _naive_B)r^   r%   r   r#   c1c2s         rB   rJ  rJ  k  s   
 	Avvda((((!AaC&(((((ssc11v1~~!A$h1Q3!A$'(1ac1a*@*@@1Qx1QqS6!AhlQqs1uX!A#./(1ac1Q32J2JJGrW   c                 6              k    rnt          j                   dz
            cxk    rdz            k    sn J k    rt                    z
  k     sJ t           fdt	          ddz             D                       S )z=
    Naive B-spline evaluation. Useful only for testing!
    r   c              3   Z   K   | ]%}|z
           t          |z
            z  V  &d S NrI  )ro   r   r$   r   r%   r#   r^   s     rB   	<genexpr>z_naive_eval.<locals>.<genexpr>  sB      FF1q1vAqsA...FFFFFFrW   r   )r9   searchsortedr  sumr   )r^   r#   r$   r%   r   s   ````@rB   rm   rm   ~  s     	AaDyyOAq!!A%Q41!A#66a#a&&1*nnn$FFFFFFFFa1FFFFFFrW   c                     t                    dz   z
  }|dz   k    sJ t                    |k    sJ           cxk    r|         k    sn J t           fdt          |          D                       S )z'Naive B-spline evaluation, another way.r   c              3   N   K   | ]}|         t          |          z  V   d S rO  rI  )ro   r   r$   r%   r#   r^   s     rB   rP  z _naive_eval_2.<locals>.<genexpr>  s:      ==qqthq!Q***======rW   )r  rR  r   )r^   r#   r$   r%   r@   s   ```` rB   rr   rr     s    A!A#A!8888q66Q;;;;Q41!=======E!HH======rW   c                 2   t          |          |dz   z
  }||dz   k    sJ t          |          |k    sJ d}t          |          D ]O} t          j        ||||z   dz            d          |           }|||         t	          j        |          z  z  }P|S )Nr   r.   r*   Frb   )r  r   r   r   r9   
nan_to_num)r^   r#   r$   r%   r@   sr   rA   s           rB   r   r     s    A!A#A!8888q66Q;;;;
A1XX % %@G!!Aac!eG*%@@@CC	QqTBM!$$$$HrW   c                     t          j        |           } t          j        | | dk     | dk    z  | dk    | dk     z  | dk    | dk    z  gd d d g          S )z+ A linear B-spline function B(x | 0, 1, 2).r   r*   r   c                     dS )Nr.   rk   r^   s    rB   <lambda>zB_012.<locals>.<lambda>  s    b rW   c                     | S rO  rk   rZ  s    rB   r[  zB_012.<locals>.<lambda>  s    A rW   c                     d| z
  S Nr/   rk   rZ  s    rB   r[  zB_012.<locals>.<lambda>  s
    A rW   )r9   
atleast_1d	piecewiserZ  s    rB   r]   r]     sp    
aA<QUq1u-!VA.!VQ/1 )L++~~FH H HrW   c                     t          j        |           } | dk     | dk    | dk     z  | dk    g}|dk    r	d d d g}n!|dk    r	d d d	 g}nt          d
|z            t          j        | ||          }|S )z0A quadratic B-spline function B(x | 0, 1, 2, 3).r   r*   r   c                     | | z  dz  S r^  rk   rZ  s    rB   r[  zB_0123.<locals>.<lambda>  s    1Q3r6 rW   c                     d| dz
  dz  z
  S )Ng      ?r   r*   rk   rZ  s    rB   r[  zB_0123.<locals>.<lambda>  s    41T6A+- rW   c                     d| z
  dz  dz  S )Nr0   r*   rk   rZ  s    rB   r[  zB_0123.<locals>.<lambda>  s    BqD19q= rW   c                     dS Nr!   rk   rZ  s    rB   r[  zB_0123.<locals>.<lambda>      2 rW   c                     dS )Ng       rk   rZ  s    rB   r[  zB_0123.<locals>.<lambda>  s    3 rW   c                     dS rf  rk   rZ  s    rB   r[  zB_0123.<locals>.<lambda>  rg  rW   znever be here: der=%s)r9   r_  r7   r`  )r^   r   condsfuncspiecess        rB   r   r     s    
aAUQUq1u%q1u-E
axx!!--((* 
 036777\!UE**FMrW   #   r,   c                    t           j                            d           t          j        t           j                            | |z   dz                       }t           j                            |           }t	          j        |||          S )N{   r   )r9   r>   r   r   r   construct_fast)r@   r%   r#   r$   s       rB   rJ   rJ     sg    INN3
	  1Q''((A
	A!!Q***rW   c              #     K   | j         | j        }}| j                                        }|d         |dd<   |d         |d<   t	          |||          V  | j                                        }|d         |d|dz   <   t	          |||          V  | j                                        }|d         || dz
  d<   t	          |||          V  dS )	zIncrease knot multiplicity.         r   r   Nr   r(   )r$   r%   r#   copyr   )rA   r$   r%   t1s       rB   rF  rF    s      3qA	
B2Br"uIVBrF
"a

	
B!uBt!tH
"a

	
B2Br!tuuI
"a

rW   c                   P    e 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S )TestInteropc                 
   t          j        ddt           j        z  d          }t          j        |          }t	          ||          }|j        |j        |j        f| _        |||c| _	        | _
        | _        t          j        ddt           j        z  d          | _        t           j        |j        |j        |j        f         }t          j        ||f          | _        t!          |j        | j        |j                  | _        d S )Nr   r1   )   rt  )r9   rR   picosr
   r#   r$   r%   rK   rU   r   rA   xnewr   r   rL  r   b2)r?   rU   r   rA   rL  s        rB   setup_methodzTestInterop.setup_method  s    [BruHb))VBZZr2&&Cac?#%r1 $&K2be8R00	U13QS=!)RH%%!#tw,,rW   c                    | j         | j        | j        c}}t          t	          |           |          dd           t          t	          |j                   |          dd           t          fd|D              |          dd           t          t          d          5  t	          ||           d d d            n# 1 swxY w Y   t          t          d|j
        j                            dz   }|j
                            |          }|j        ||j        f}t          t	          ||           ||                              |          dd           d S )NrE   rF   c                 0    g | ]}t          |          S rk   )r   )ro   r^   rA   s     rB   rp   z*TestInterop.test_splev.<locals>.<listcomp>  s!    333q!333rW   zCalling splev.. with BSplinematchr   r   )r}  rA   r~  r   r   rK   r5   r7   tupler   r$   r   	transposer#   r%   )r?   r}  r~  r   r   rK   rA   s         @rB   
test_splevzTestInterop.test_splev  s   ia 	dA$e%	9 	9 	9 	9dAE**$e%	9 	9 	9 	93333d333$e%	9 	9 	9 	9
 :-KLLL 	 	$OOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 5BDI&&''$.T^^BtRdC((4**2..U	H 	H 	H 	H 	H 	Hs   /CCCc                 F   | j         | j        }}t          ||          }t          j        ||          \  }}}t	          |d         |d           t	          |d         |d           t          |d         |           t          ||d          \  }}}}t	          |d         |d           t	          |d         |d           t          |d         |           t          ||          }	t	          ||	d           t          | }
t	          | |
|          d           d S )Nr   rE   r\   r   r*   T)full_output)rU   r   r   r   r   r   r   r   )r?   r^   r   rK   r#   r$   r%   tck_fr   r   rA   s              rB   test_splrepzTestInterop.test_splrep  s/   w1Qll,q!$$1aA....A....SVQ  1$777q!Qa!%0000a!%0000U1Xq!!! 1c]]2E**** SM11Q44e,,,,,,rW   c                    | j         | j        }}t          j        ||f         }t	          t
                    5  t          ||           d d d            n# 1 swxY w Y   t	          t
                    5  t          j        ||           d d d            n# 1 swxY w Y   t	          t          d          5  t          |d d         |d d                    d d d            n# 1 swxY w Y   t	          t          d          5  t          j        |d d         |d d                    d d d            d S # 1 swxY w Y   d S )Nm > k must holdr  r,   )	rU   r   r9   r   r5   r7   r   r   r6   )r?   r^   r   y2s       rB   test_splrep_errorszTestInterop.test_splrep_errors  s*    w1U1a4[:&& 	 	1bMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	:&& 	  	 LB	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  9,=>>> 	! 	!1RaR5!BQB%   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!9,=>>> 	' 	'L2A2"1"&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'sG   AAA3BBB6!C##C'*C'&D77D;>D;c                    t          j        d                              d          }t          |          \  }}t	          j        |          \  }}t          ||d           t          t          ||          |d           t          t          ||          |d           t          |dd          \  \  }}}}}t          ||d           t          t          ||          |d           d S )Nr   r,   r   rE   r\   r   T)rW  r  )r9   r=   re   r   r   r   r   )	r?   r^   rA   urK   u1b_fu_fr   s	            rB   test_splprepzTestInterop.test_splprep'  s    IbMM!!&))qzz1-""R 	2E****aQU3333aqu5555 &a1$???
cAq!3U++++c3777777rW   c                    t          j        d                              d          }t          t          d          5  t          |           d d d            n# 1 swxY w Y   t          t          d          5  t          j        |           d d d            n# 1 swxY w Y   t          j        ddd          }t          t          d	          5  t          |g           d d d            n# 1 swxY w Y   t          t          d	          5  t          j        |g           d d d            n# 1 swxY w Y   g d
}t          t          d          5  t          |g           d d d            n# 1 swxY w Y   t          t          d          5  t          j        |g           d d d            n# 1 swxY w Y   g d}g d}t          t          d          5  t          |gd |g  d d d            d S # 1 swxY w Y   d S )N<   r   ztoo many values to unpackr  r   r  r,   )numr  ) >Ir   >Kr  zInvalid inputs)r   r,   r*   r-   )r   g333333?g?r   )	r9   r=   re   r5   r7   r   r   rR   r6   )r?   r^   r  s      rB   test_splprep_errorszTestInterop.test_splprep_errors6  s   Ie$$Y//:-HIII 	 	AJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	:-HIII 	 	M!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 K21%%%9,=>>> 	 	QCLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	9,=>>> 	 	M1#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 EDD:-=>>> 	 	QCLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	:-=>>> 	 	M1#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 LL:-=>>> 	% 	%qc4^$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s}   AA!A;BB #B C11C58C5D44D8;D8E66E:=E:F99F= F="G==HHc                 v   | j         | j        }}t          j        g d          t          j        z  }t          t          |          |dd           t          t          |j        |j        |j	        f          |dd           t          t          d          5  t          |d           d d d            n# 1 swxY w Y   |j                            dd	d
          }t          j        t          |j        ||j	        fd                    }t          |j        d           t          ||z
  d
d           d S )N)r   r   r3   g      @gHz>rF   zCalling sproot.. with BSpliner  rZ   )mestr   r*   r   )r,   r*   r-   r   r\   )rA   r~  r9   r  r{  r   r   r#   r$   r%   r5   r7   r  rd   r   r   )r?   rA   r~  rootsc2rrrs         rB   test_sprootzTestInterop.test_sprootS  sc   2---..ru4q		5t$????QS!#//TMMMM :-LMMM 	  	 2B	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  dnnQ1%%Zc240r:::;;RXy)))U
AE222222s   B88B<?B<c           	      x   | j         | j        }}t          t          dd|          t          dd|j                  d           t          t          dd|          |                    dd          d           t          t          d          5  t          dd|           d d d            n# 1 swxY w Y   |j        	                    ddd          }t          j        t          dd|j        ||j        f                    }t          |j        d           t          |t          dd|          d           d S )	Nr   r   r[   r\   zCalling splint.. with BSpliner  r*   )r,   r*   )rA   r~  r   r   rK   r   r5   r7   r$   r  r9   rd   r#   r%   r   r   )r?   rA   r~  r  integrs        rB   test_splintzTestInterop.test_splintd  s{   2q!Qq!QU++%	9 	9 	9 	9q!QAq))	7 	7 	7 	7 :-LMMM 	 	1a	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dnnQ1%%F1a"$RT):;;<<V\6***q!Qe	5 	5 	5 	5 	5 	5s   B--B14B1c           	         | j         | j        fD ]K}t          |j                  t          |j                  z
  }|dk    rFt
          j        |j        t          j        |f|j        j        dd          z             f         |_        dD ]}t          |          }t          j	        |j        |j        |j        f          }t          |j        |d         d           t          |j        |d         d           t          |j        |d                    t          t          |t                                t          t          |t"                               ѐMd S Nr   r   rY   rE   r\   r*   )rA   r~  r  r#   r$   r9   r   zerosr   r   r   r%   r   r   r   
isinstancer   r  r?   rA   ctr@   bdtck_ds         rB   test_splderzTestInterop.test_splderw  s2   &$'" 	2 	2AQSCHH$BAvveAC2%!#)ABB-*?!@!@@A 2 2AYYac13_55eAhU;;;;eAhU;;;;RT58,,,
2w//000
5%0011112	2 	2rW   c           	         | j         | j        fD ]K}t          |j                  t          |j                  z
  }|dk    rFt
          j        |j        t          j        |f|j        j        dd          z             f         |_        dD ]}t          |          }t          j	        |j        |j        |j        f          }t          |j        |d         d           t          |j        |d         d           t          |j        |d                    t          t          |t                                t          t          |t"                               ѐMd S r  )rA   r~  r  r#   r$   r9   r   r  r   r   r   r%   r   r   r   r  r   r  r  s         rB   test_splantiderzTestInterop.test_splantider  s3   &$'" 	2 	2AQSCHH$BAvveAC2%!#)ABB-*?!@!@@A 2 2]](!#qsAC99eAhU;;;;eAhU;;;;RT58,,,
2w//000
5%0011112	2 	2rW   c                    | j         | j        | j        }}}|j        j        dz  }d|j        |         |j        |dz            z   z  }t          ||          t          ||j        |j        |j        f          }}t          t          ||          t          ||          d           t          t          |t                               t          t          |t                               t          t          |j        j                            }|j                            |dd          dz             }	t          ||j        |	|j        f          }
t          ||          }t          t#          j        t          ||
                                        ddd           ||          d           t          t          |t                               t          t          |
t                               d S )Nr*   r   r   rE   r\   r  r   )rA   r~  rU   r#   r   r   r$   r%   r   r   r   r  r   r  r   r   r  r9   rd   )r?   rA   r~  rU   r   tnbntck_nr   r   tck_n2bn2s               rB   test_insertzTestInterop.test_insert  s   FDGTWr2CHM!#a&13qs8#$2qMM6"qsACo#>#>Eb"b%((u	6 	6 	6 	6
2w''(((
5%(())) 5##$$T^^BqrrFTM**RT2rt,--Rnn 	
5V#4#455??1aHHBe	- 	- 	- 	-
3(()))
65))*****rW   N)r   r   r   r  r  r  r  r  r  r  r  r  r  r  rk   rW   rB   rx  rx    s        - - -H H H6- - -0' ' ' 8 8 8% % %:3 3 3"5 5 5&2 2 2 2 2 2 + + + + +rW   rx  c                      e Zd Z ej        ddej        z            Z ej        e          Zd Z	d Z
d Zej                            dg d          d             Zej                            dg d          d	             Zd
 Zd Zej                            dg d          d             Zd Zd Zd Zej                            dg d          d             Zd Zd Zd Zd Zd Zej                            d          d             Zd Zd Z d Z!d Z"d Z#d  Z$d! Z%ej                            dg d"          d#             Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d)S )*
TestInterpr.   r/   c                     t          t                    5  t          | j        | j        d           d d d            d S # 1 swxY w Y   d S )Nr3   r   )r5   r6   r
   rU   r   )r?   s    rB   test_non_int_orderzTestInterp.test_non_int_order  s    9%% 	8 	8tw37777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   ?AAc                    t          | j        | j        d          }t           || j                  | j        dd           t          | j        | j        dd          }t           || j                  | j        dd           d S )Nr   r   r[   rF   r(   r%   r   r
   rU   r   r   r   s     rB   test_order_0zTestInterp.test_order_0      tw1555$'

DG%eDDDDtw12>>>$'

DG%eDDDDDDrW   c                    t          | j        | j        d          }t           || j                  | j        dd           t          | j        | j        dd          }t           || j                  | j        dd           d S )Nr   r   r[   rF   r(   r  r  r   s     rB   test_linearzTestInterp.test_linear  r  rW   r%   r   c                     g d}g d}t          t          d          5  t          |||           d d d            d S # 1 swxY w Y   d S )Nr   r   r*   r,   r-   r   )r   r   r*   r,   r-   r   r   r   zShapes of xr  r   r5   r7   r
   r?   r%   r^   r   s       rB   test_incompatible_x_yz TestInterp.test_incompatible_x_y  s    $$$:];;; 	* 	*q!q))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   ?AAc                    g d}g d}t          t          d          5  t          |||           d d d            n# 1 swxY w Y   g d}t          t          d          5  t          |||           d d d            n# 1 swxY w Y   g d}t          j        |                              d          }t          t          d          5  t          |||           d d d            d S # 1 swxY w Y   d S )	N)r   r   r   r*   r,   r-   r  zx to not have duplicatesr  r   )r   r*   r   r,   r-   r   zExpect x to be a 1D strictly)r   r(   )r5   r7   r
   r9   rd   re   r  s       rB   test_broken_xzTestInterp.test_broken_x  s   :-GHHH 	* 	*q!q))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* :-KLLL 	* 	*q!q))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* JqMM!!'**:-KLLL 	* 	*q!q))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s3   >AA#BB	BC..C25C2c                     dD ]C}t          | j        | j        |          }t           || j                  | j        dd           Dd S )Nr  r[   rF   r  )r?   r%   rA   s      rB   test_not_a_knotzTestInterp.test_not_a_knot  sZ     	I 	IA"47DGQ77AAAdgJJe%HHHHH	I 	IrW   c                 X   t          | j        | j        dd          }t           || j                  | j        dd           t	          dd          D ]@}t           || j        d         |           || j        d	         |          d
           At          | j        | j        ddd	          }t           || j                  | j        dd           t	          dd          D ]@}t           || j        d         |           || j        d	         |          d
           Ad S )Nr   r   r  r[   rF   r   r   r   r(   gdy=r\   r%   r  r   )r
   rU   r   r   r   )r?   rA   r   s      rB   test_periodiczTestInterp.test_periodic  sB   tw1jIII$'

DG%eDDDD q! 	S 	SAAAdgajQ///472;11E1E1EERRRRRtw1jrRRR$'

DG%eDDDDq! 	S 	SAAAdgajQ///472;11E1E1EERRRRR	S 	SrW   )r*   r,   r-   r   r   r   c                 f   d}t           j                            d           t          j        t           j                            |          dz            }t           j                            |          dz  }|d         |d<   t          |||d          }t           ||          |d	
           d S )Nr   r|   rP   r   r(   r   r   r  r[   r\   )r9   r>   r   r   r  r
   r   )r?   r%   r@   r^   r   rA   s         rB   test_periodic_randomzTestInterp.test_periodic_random  s     
	tGBI++A..344I##A&&,u!q!q*===!ae,,,,,,rW   c                    | j         j        d         }t          j                            d           t          j                            |          dz  t          j        z  }t          j        |          }d|d<   dt          j        z  |d<   t          j        d|f          }t          j	        |          |d<   t          j
        |          |d<   t          ||ddd	          }t          |          D ]-}t           |||                   |d d |f         d
           .t           ||d                    ||d                   d
           d S )Nr   r|   r*   r.   r(   r   r   r   r  r[   r\   )rU   r   r9   r>   r   r  r{  r   r  sinr|  r
   r   r   )r?   r@   r^   r   rA   r   s         rB   test_periodic_axiszTestInterp.test_periodic_axis  s/   GM!
	tI##A&&*RU2GAJJ!BE	"HaVvayy!vayy!q!q*1EEEq 	: 	:AAAadGGQqqq!tW599999!A$1R5666666rW   c                    t           j                            d           d}d}t          j        t           j                            |                    }t           j                            |          }|d         dz
  |d<   t          t                    5  t          |||d           d d d            d S # 1 swxY w Y   d S )	Nr|   r   r   r(   r   r   r   r  )r9   r>   r   r   r  r5   r7   r
   )r?   r%   r@   r^   r   s        rB   test_periodic_points_exceptionz)TestInterp.test_periodic_points_exception  s    
	tGBI++A..//I##A&&uqy!:&& 	> 	>q!q*====	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   B77B;>B;c                    t           j                            d           d}d}t          j        t           j                            |                    }t           j                            |          }t          j        |d|z  z             }t          t                    5  t          ||||d           d d d            d S # 1 swxY w Y   d S )Nr|   r,   r   r*   r   )	r9   r>   r   r   r  r  r5   r7   r
   )r?   r%   r@   r^   r   r#   s         rB   test_periodic_knots_exceptionz(TestInterp.test_periodic_knots_exception  s    
	tGBI++A..//I##A&&HQQY:&& 	7 	7q!Q:666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   "CC
C)r*   r,   r-   r   c                 |   t          | j        | j        |d          }t          | j        | j        d|          }t	          | j        |          }t          | || j                  d           t          d|          D ];}t	          | j        ||          }t          | || j        |	          d
           <d S )Nr   r  T)perr%   r[   r\   r   r   r   r   )r
   rU   r   r   r   r   r   )r?   r%   rA   rK   r	  r   s         rB   test_periodic_splevzTestInterp.test_periodic_splev#  s     tw1jIIITWdg41555DGS!!QQtwZZe4444 q! 	? 	?A!,,,CC47q!1!1!1>>>>>	? 	?rW   c                 ,   t          | j        | j        dd          }t          | j        | j        d          }t	           || j                   || j                  d           d}t          j        t
          j                            |          dz            }t
          j                            |          dz  }|d	         |d
<   t          ||dd          }t          ||d          }t	           ||           ||          d           d S )Nr,   r   r  r2  r[   r\   rP   r   r(   r   )	r
   rU   r   r   r   r9   r   r>   r  )r?   rA   cubr@   r^   r   s         rB   test_periodic_cubiczTestInterp.test_periodic_cubic0  s   tw1jIII$'47J???$'

CCLLu==== GBI++A..344I##A&&,u!q!q*===!Q
333!cc!ff5111111rW   c                 :   dt          | j        | j        d          }t          | j                  t	          | j        | j                  t          j        fd          }t           || j                   || j                  d           d S )Nr,   r   r  c                 (    t          |           S rO  rl   )r^   r$   r%   r#   s    rB   r[  z6TestInterp.test_periodic_full_matrix.<locals>.<lambda>F  s    K1a$;$; rW   r[   r\   )r
   rU   r   r   r   r9   	vectorizer   )r?   rA   r  r$   r%   r#   s      @@@rB   test_periodic_full_matrixz$TestInterp.test_periodic_full_matrix?  s     tw1jIIIDGQ''&twA>>\;;;;;;<<$'

BBtwKKe<<<<<<rW   c                    dg}t          | j        | j        dd |f          }t           || j                  | j        dd           t           || j        d         d          |d         d         dd           t          | j        | j        d|d f          }t           || j                  | j        dd           t           || j        d         d          |d         d         dd           d S )	Nr   g       @r*   r  r[   rF   r(   r   r   r  )r?   r   rA   s      rB   test_quadratic_derivzTestInterp.test_quadratic_derivI  s    i tw1tSkJJJ$'

DG%eDDDD$'"+q))3q6!95uMMMM tw1sDkJJJ$'

DG%eDDDD$'!*a((#a&)%eLLLLLLrW   c                    d}dgdg}}t          | j        | j        |||f          }t           || j                  | j        dd           t           || j        d         d           || j        d	         d          g|d         d         |d         d         gdd           d
gd
g}}t          | j        | j        |||f          }t           || j                  | j        dd           d S )Nr,   r   r0   )r   r1   r2  r[   rF   r   r   r(   r*   r   r  )r?   r%   der_lder_rrA   s        rB   test_cubic_derivzTestInterp.test_cubic_derivV  s     y7)utwUENKKK$'

DG%eDDDD471:q))11TWR[!+<+<=q!eAhqk2U	L 	L 	L 	L x&utwUENKKK$'

DG%eDDDDDDrW   c                    d\  }}t          j        |                              t           j                  }t          j        |          }ddg}ddg}t          |||||f          }t           ||          |dd           t           ||d	         d
           ||d	         d          gd |D                        t           ||d         d
           ||d         d          gd |D                        d S )N)r   r   )r   g      ()r*   r   r  )r*   r0   r  r[   rF   r   r   r*   c                     g | ]\  }}|S rk   rk   ro   r   vals      rB   rp   z2TestInterp.test_quintic_derivs.<locals>.<listcomp>n      444"c444rW   r(   c                     g | ]\  }}|S rk   rk   r  s      rB   rp   z2TestInterp.test_quintic_derivs.<locals>.<listcomp>p  r  rW   )r9   r=   astypefloat_r  r
   r   )r?   r%   r@   r^   r   r  r  rA   s           rB   test_quintic_derivszTestInterp.test_quintic_derivse  s   1IaLL	**F1IIF#'"q!q5%.AAA!ae%88881Q4QQqtQZZ044e444	6 	6 	61R5!aa"qkk244e444	6 	6 	6 	6 	6rW   unstable)reasonc                     d}t          | j        |          }ddg}t          | j        | j        |||d f          }t	           || j                  | j        dd           d S )Nr,   r  )r*   r1   r2  r[   rF   )r   rU   r
   r   r   )r?   r%   r#   r  rA   s        rB   test_cubic_deriv_unstablez$TestInterp.test_cubic_deriv_unstabler  sm     DGQ'"twAt}MMM$'

DG%eDDDDDDrW   c                    d}t           j        | j        d         f|dz   z  | j        dd          | j        d d         z   dz  | j        d         f|dz   z  f         }t          | j        | j        ||dgdgf          }t           || j                  | j        dd	           t           || j        d         d           || j        d         d          gd
d
gd           d S )Nr*   r   r   r(   r/   r  r2  r[   rF   r.   r\   )r9   r   rU   r
   r   r   )r?   r%   r#   rA   s       rB   test_knots_not_data_sitesz$TestInterp.test_knots_not_data_sites  s
    E471:-1%7122;"-372;.!A#&' ( twA)/6(';= = = 	$'

DG%eDDDD471:q))11TWR[!+<+<=Bx	 	 	 	 	 	rW   c                     d}ddg}ddg}t          |||dgdgf          }t          j        dd          }|dz  }t           ||          |dd           d S )	Nr,   r.   r!   r   r.   r  r2  r[   rF   )r
   r9   rR   r   )r?   r%   r^   r   rA   rU   r   s          rB   test_minimum_points_and_derivz(TestInterp.test_minimum_points_and_deriv  sy     HHq!Q'WI0FGGG[R  U"rE::::::rW   c                    g dx}}t          t                    5  t          ||dgd f           d d d            n# 1 swxY w Y   t          t                    5  t          ||d           d d d            n# 1 swxY w Y   t          t                    5  t          ||dg           d d d            n# 1 swxY w Y   t          t                    5  t          ||d           d d d            n# 1 swxY w Y   d\  }}t          t                    5  t          ||||f           d d d            d S # 1 swxY w Y   d S )N)r!   r*   r,   r-   r   r   r  r2  *   )r  r  r  )r?   r^   r   lrs        rB   test_deriv_speczTestInterp.test_deriv_spec  s    %$$$A:&& 	@ 	@q!wi->????	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ :&& 	6 	6q!W5555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 :&& 	8 	8q!gY7777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 :&& 	1 	1q!R0000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1
 "1:&& 	5 	5q!aV4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5sW   =AAA;;A?A?B::B>B>C88C<?C<D>>EEc                    d}| j         }| j        d| j        z  z   }dgdg}}t          |||||f          }t           ||          |dd           t           ||d         d	           ||d
         d	          g|d         d	         |d         d	         gdd           dD ]0}t          |||          }t           ||          |dd           1d S )Nr,   r    )r   y              @)r   y      @       @r2  r[   rF   r   r   r(   )r   r   r   )rU   r   r
   r   )r?   r%   rU   r   r  r  rA   s          rB   test_complexzTestInterp.test_complex  s   WWs47{" !zK=ur2q5%.AAA"rE::::2a5!aa2ll3q!eAhqk2U	L 	L 	L 	L  	? 	?A"2rQ///AAAbEE2E>>>>>	? 	?rW   c                    t          j        d                              t           j                  }t          j        d                              t           j                  }dD ]}t	          |||          } ||            d S )NrP   r   r   )r9   r=   r  int_r
   )r?   r^   r   r%   rA   s        rB   test_int_xyzTestInterp.test_int_xy  sz    IbMM  ))IbMM  ))  	 	A"1a1---AAaDDDD	 	rW   c                     t          j        ddd          }|d d d         }|d d d         }dD ]}t          |||           d S )Nr(   r   r   r   r   r   )r9   rR   r
   )r?   rU   r^   r   r%   s        rB   test_sliced_inputzTestInterp.test_sliced_input  sd    [Q$$sssGsssG 	* 	*Aq!q)))))	* 	*rW   c                     t          j        d                              t                    }|dz  }t           j        t           j        t           j         fD ]#}||d<   t          t          t          ||           $d S )NrP   r*   r(   )	r9   r=   r  floatr;   r<   r5   r7   r
   )r?   r^   r   zs       rB   test_check_finitezTestInterp.test_check_finite  ss    IbMM  ''qD&"&26'* 	@ 	@AAbE*&8!Q????	@ 	@rW   )r   r*   r,   r   c                 z    t          t          d                    }d |D             }t          |||           d S )NrP   c                     g | ]}|d z  S )r*   rk   )ro   as     rB   rp   z.TestInterp.test_list_input.<locals>.<listcomp>  s    aQTrW   r   )r   r   r
   r  s       rB   test_list_inputzTestInterp.test_list_input  sC     rOO11a1%%%%%%rW   c                    t           j        t          j        | j                  t          j        | j                  f         }dddgfg}dddgfg}t          | j        |d||f          }t           || j                  |dd	           t           || j        d
         d          |d
         d         dd	           t           || j        d         d          |d
         d         dd	           d S )Nr   r!   r/   r0   r1   r,   r  r[   rF   r   r(   )r9   r   r  rU   r|  r
   r   )r?   r   r  r  rA   s        rB   test_multiple_rhszTestInterp.test_multiple_rhs  s    U26$'??BF47OO34b"Xb"Xtwa%HHH$'

BU????$'!*a((%(1+ENNNN$'"+q))58A;UOOOOOOrW   c                 R   t           j                            d           d\  }}t          j        t           j                            |                    }t           j                            |dddf          }t	          |||          }t          |j        j        |dddf           dt           j                            d          fg}dt           j                            d          fg}t	          |||||f	          }t          |j        j        ||z   dz
  dddf           d S )
Nr|   r,   r   r   r   r   r   r   r   r   r   r2  )r9   r>   r   r   r
   r   r$   r   )r?   r%   r@   r^   r   rA   d_ld_rs           rB   test_shapeszTestInterp.test_shapes  s   
	t1GBI$$!$,,--I1aA,//q!Q''QSYAq!--- 29##I../029##I../0q!Qc
;;;QSYQAq! 455555rW   c                 J   t          j        | j                  }t          | j        |dd          }t          | j        |ddgdgf          }t	          |j        |j        d           t          | j        |dd          }t          | j        |ddgdgf          }t	          |j        |j        d           t          | j        |d	d
          }t          | j        |d	d dgf          }t	          |j        |j        d           t          | j        |dd          }t          | j        |dd           }t	          |j        |j        d           t          t                    5  t          | j        |dd           d d d            n# 1 swxY w Y   t           j        t          j        | j                  t          j	        | j                  f         }dddgfg}d	ddgfg}t          | j        |d||f          }t          | j        |dd          }t	          |j        |j        d           t           j
                            d           d\  }}t          j        t           j
        
                    |                    }t           j
        
                    |dddf          }	dt          j        d          fg}
dt          j        d          fg}t          ||	||
|f          }t          ||	|d          }t	          |j        |j        d           d S )Nr,   r  r  r  rE   r\   )r  r  )r   r   r*   )Nr  r  r  typor   r.   r  r|   r  r   r   r   r   r  r2  r  )r9   r  rU   r
   r   r$   r5   r7   r   r|  r>   r   r   r  )r?   r   r  r~  r  r  r%   r@   r^   r   r  r  s               rB   test_string_aliaseszTestInterp.test_string_aliases  ss   VDG__  q)DDDqF8fX:NOOObd////  q(>@ @ @q*0F8(<> > >bd////  q:KLLLq4(:LMMMbd////  q,GGGq$???bd//// :&& 	A 	Atwa@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A U26$'??BF47OO34b"Xb"Xq5%.IIIq(>@ @ @bd//// 		t1GBI$$!$,,--I1aA,// 28I&&'(28I&&'(1a#s<<<1a;;;bd//////s   )FFFc                    t           j                            d           d\  }}t          j        t           j                            |                    }t           j                            |          }t	          ||          }t          ||||          }t          ||||          }t          |j        |dd           d S )Nr|   )r,   r   r   r[   rF   )	r9   r>   r   r   r   r
   make_interp_full_matrr   r$   )r?   r%   r@   r^   r   r#   rA   cfs           rB   test_full_matrixzTestInterp.test_full_matrix4  s    
	t1GBI$$!$,,--I!$$1q!Q**"1aA..Re%888888rW   c                    t           j                            d           d}t          ddd          D ]0}t	          |dz
  dz            }t          j        t           j                            d|f                    }t          d|dz             D ]}|d| |dfxx         t          j        t           j                            d||z
  f                    z  cc<   ||dd| fxx         t          j        t           j                            d||z
  f                    z  cc<   t           j                            ||f          }||d|| df<   t           j                            ||f          }||| dd|f<   t          j        ||f          }t          t          || dz
  d                    D ]F\  }}	|	d	k     rt          j        ||	
          ||d|	f<   )t          j        ||	
          |||	df<   Gt           j                            |          }
t          t          ||||
|          t           j                            ||
          d           2dS )z
        Random elements in diagonal matrix with blocks in the
        left lower and right upper corners checking the
        implementation of Woodbury algorithm.
        r|      r,       r*   r   Nr(   r   )offsetr[   r\   )r9   r>   r   r   intdiagflatr  rE  diagonalr   r   linalgsolve)r?   r@   r%   r#  r  r   urlldr   rA   s              rB   test_woodburyzTestInterp.test_woodbury?  sq    		tq"a 	? 	?A!a%1%%FBI,,aV4455A1fqj)) H H#A2#qrr'


bk")*:*:Aq1u:*F*FGGG


!""crc'


bk")*:*:Aq1u:*F*FGGG



!!66"233B#%Agvgwxx !!66"233B#%Avghh !Q  A!%!R"@"@AA 8 81q55!{1Q777Aa!eHH!{1Q777AaeHH	  ##A/2r1a@@IOOAq11? ? ? ? ?#	? 	?rW   N),r   r   r   r9   rR   r{  rU   r  r   r  r  r  rL   r>  r?  r  r  r  r  r  r  r  r  r  r  r  r  r  r  xfailr  r  r  r  r  r  r  r  r  r  r  r  r  r,  rk   rW   rB   r  r    s        
RBE	"	"B	B8 8 8E E EE E E [S,,,//* * 0/* [S,,,//* * 0/*I I I
S S S [S"4"4"455- - 65-7 7 7	> 	> 	>	7 	7 	7 [S,,,//
? 
? 0/
?2 2 2= = =M M ME E E6 6 6 [j))E E *)E  
; 
; 
;5 5 5.? ? ?"  * * *@ @ @ [S,,,//& & 0/&P P P6 6 610 10 10f	9 	9 	9? ? ? ? ?rW   r  c                    | j         |j         k    sJ |j         | j         |z   dz   k    sJ | j         }t          j        ||ft          j                  }t	          |          D ]W}| |         }|||         k    r|}nt          j        ||          dz
  }t          j        ||||          }	|	||||z
  |dz   f<   Xt          j	        ||          }
|
S )zAssemble an spline order k with knots t to interpolate
    y(x) using full matrices.
    Not-a-knot BC only.

    This routine is here for testing only (even though it's functional).
    r   r8  )
r   r9   r  r  r   rQ  r   evaluate_all_bsplslr(  )r^   r   r#   r%   r@   Ar   xvalleftbbr$   s              rB   r  r  \  s     6QV6QVaZ!^####	A
!Qry)))A1XX 	! 	!t1Q4<<DD?1d++a/D $Q466 !T!VDF]

AAHrW   c                    t          t          j        | ||f          \  } }}| j        }|j        |z
  dz
  }t          j        ||ft          j                  }t          |          D ]W}| |         }|||         k    r|}	nt          j        ||          dz
  }	t          j	        ||||	          }
|
|||	|z
  |	dz   f<   Xt          j
        |j        |          }t          j
        |j        |          }t          j        ||          }|||ffS )z,Make the least-square spline, full matrices.r   r/  )mapr9   rd   r   r  r  r   rQ  r   r0  dotTr1  r(  )r^   r   r#   r%   mr@   r2  r   r3  r4  r5  r   Yr$   s                 rB   make_lsq_full_matrixr<  x  s   "*q!Qi((GAq!	A	
QA
!Qry)))A1XX 
! 
!t1Q4<<DD?1d++a/D $Q466 !T!VDF]
 	qsAA
qsAA
AAq!f9rW   c                   J   e Zd Zej                            d           d\  ZZ ej        ej                            e                    Z	ej                            e          Z
 e ej        e	d         e	d         d          e          Zd Zd Zd Zd	 Zd
 Zd Zd ZdS )TestLSQr|   )r   r,   r   r(   r   c                    | j         | j        | j        | j        f\  }}}}t	          ||||          \  }}t          ||||          }t          |j        |           t          |j        j	        |j
        |z
  dz
  f           |\  }}	t          j                            ||d          \  }
}}}t          |j        |
           d S )Nr   r(   )rcond)r^   r   r#   r%   r<  r   r   r$   r   r   r   r9   r'  lstsq)r?   r^   r   r#   r%   c0AYrA   aar   rK  r   s               rB   
test_lstsqzTestLSQ.test_lstsq  s    VTVTVTV3
1a%aAq11BAq!Q''R   QSY!a 1222 Bioob!2o66Aq!R     rW   c                 \   | j         | j        | j        | j        f\  }}}}t	          j        |          }t          ||||          }t          |||||          }t          |j        |j        d           t          |j        |j        d           t          |j        |j                   d S )N)wr[   r\   )
r^   r   r#   r%   r9   r   r   r   r$   r   )r?   r^   r   r#   r%   rG  rA   b_ws           rB   test_weightszTestLSQ.test_weights  s    VTVTVTV3
1aLOOAq!Q''aAqA...SU////SU////QS#%     rW   c                    | j         | j        | j        | j        f\  }}}}t          j                            |dddf          }t          ||||          }t          |j        j	        |j
        |z
  dz
  dddf           d S )Nr   r   r   r   r   )r^   r#   r%   r@   r9   r>   r   r   r$   r   r   )r?   r^   r#   r%   r@   r   rA   s          rB   r  zTestLSQ.test_multiple_rhs  s    VTVTVTV3
1aI1aA,//Aq!Q''QSY!Q1 566666rW   c                 ,   | j         | j        | j        }}}| j        dz  }t	          ||||          }t	          ||j        ||          }t	          ||j        ||          }t           ||           ||          d ||          z  z   dd           d S )Ny      ?       @r    rE   rF   )r^   r#   r%   r   r   r   r   r   )r?   r^   r#   r%   r*  rA   r   r   s           rB   r  zTestLSQ.test_complex  s    &$&$&a1Vx Ar1a((q"'1a00q"'1a00!dd1ggDDGG3%eLLLLLLrW   c                    t          j        d                              t           j                  }t          j        d                              t           j                  }t	          |d          }t          |||d           d S )NrP   r   r   )r9   r=   r  r  r   r   )r?   r^   r   r#   s       rB   r  zTestLSQ.test_int_xy  sh    IbMM  ))IbMM  ))AOOO1a1%%%%%%rW   c                     t          j        ddd          }|d d d         }|d d d         }t          |d          }t          |||d           d S )Nr(   r   r   r,   r   )r9   rR   r   r   )r?   rU   r^   r   r#   s        rB   r  zTestLSQ.test_sliced_input  s]    [Q$$sssGsssGAqMM1a1%%%%%%rW   c                    t          j        d                              t                    }|dz  }t	          |d          }t           j        t           j        t           j         fD ]$}||d<   t          t          t          |||           %d S )N   r*   r,   r(   )
r9   r=   r  r
  r   r;   r<   r5   r7   r   )r?   r^   r   r#   r  s        rB   test_checkfinitezTestLSQ.test_checkfinite  s    IbMM  ''qDAqMM&"&26'* 	@ 	@AAbE*oq!Q????	@ 	@rW   N)r   r   r   r9   r>   r   r@   r%   r   r^   r   r   rR   r#   rE  rI  r  r  r  r  rP  rk   rW   rB   r>  r>    s        INN4DAq	  ##$$A
	AAaD!B%++Q//A! ! !
! 
! 
!7 7 7	M 	M 	M& & && & &@ @ @ @ @rW   r>  c                     t           j                            t           j                            t           j                            t
                              d|           S )Ndata)ospathjoinabspathdirname__file__)basenames    rB   	data_filerZ    s=    7<<(A(ABB* * *rW   c                   &    e Zd Zd Zd Zd Zd ZdS )TestSmoothingSplinec                 2   t           j                            d           d}t          j        t           j                            |          dz  dz
            }|dz  t          j        d|z            z  |dz  z   t           j                            dd|          z   }t          t                    5  t          ||dd                     d d d            n# 1 swxY w Y   t          t                    5  t          |dd          |           d d d            n# 1 swxY w Y   t          t                    5  t          |
                    d|          |           d d d            n# 1 swxY w Y   t          t                    5  t          |d d d	         |           d d d            n# 1 swxY w Y   t          j        |          }|d         |d
<   t          t                    5  t          ||           d d d            d S # 1 swxY w Y   d S )Nr|   r   r-   r*   r,   r.   r   r   r(   r   )r9   r>   r   r   r  r  normalr5   r7   r   re   ru  )r?   r@   r^   r   x_dupls        rB   test_invalid_inputz&TestSmoothingSpline.test_invalid_input  s   
	tGBI++A..2Q677qD26!a%== 1a4'")*:*:2sA*F*FF :&& 	, 	,!!QqrrU+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,:&& 	, 	,!!ABB%+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,:&& 	6 	6!!))Aq//1555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 :&& 	. 	.!!DDbD'1---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 1Iq	:&& 	- 	-!&!,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-sZ   2CCC6DD"D:%E++E/2E/
F00F47F4.HHHc                     t          j        t          d                    }|d         }|d         }|d         } t          ||          |          }t	          ||dd           dS )ae  
        Data is generated in the following way:
        >>> np.random.seed(1234)
        >>> n = 100
        >>> x = np.sort(np.random.random_sample(n) * 4 - 2)
        >>> y = np.sin(x) + np.random.normal(scale=.5, size=n)
        >>> np.savetxt('x.csv', x)
        >>> np.savetxt('y.csv', y)

        We obtain the result of performing the GCV smoothing splines
        package (by Woltring, gcvspl) on the sample data points
        using its version for Octave (https://github.com/srkuberski/gcvspl).
        In order to use this implementation, one should clone the repository
        and open the folder in Octave.
        In Octave, we load up ``x`` and ``y`` (generated from Python code
        above):

        >>> x = csvread('x.csv');
        >>> y = csvread('y.csv');

        Then, in order to access the implementation, we compile gcvspl files in
        Octave:

        >>> mex gcvsplmex.c gcvspl.c
        >>> mex spldermex.c gcvspl.c

        The first function computes the vector of unknowns from the dataset
        (x, y) while the second one evaluates the spline in certain points
        with known vector of coefficients.

        >>> c = gcvsplmex( x, y, 2 );
        >>> y0 = spldermex( x, c, 2, x, 0 );

        If we want to compare the results of the gcvspl code, we can save
        ``y0`` in csv file:

        >>> csvwrite('y0.csv', y0);

        z
gcvspl.npzr^   r   y_GCVSPLg-C6?rF   N)r9   loadrZ  r   r   )r?   rR  r^   r   rb  y_comprs         rB   test_compare_with_GCVSPLz,TestSmoothingSpline.test_compare_with_GCVSPL  sq    R wy..//II
#-'1--a00
 	4@@@@@@rW   c                    t           j                            d           d}t          j        t           j                            |          dz  dz
            }|dz  t          j        d|z            z  |dz  z   t           j                            dd|          z   }t          ||d          }t          ||dd	
          }t          j	        |d         |d         d|z            }t           ||           ||          d           dS )z
        In case the regularization parameter is 0, the resulting spline
        is an interpolation spline with natural boundary conditions.
        r|   r   r-   r*   r,   r.   r   )lamr  r2  r   r(   rE   r\   N)r9   r>   r   r   r  r  r^  r   r
   rR   r   )r?   r@   r^   r   
spline_GCVspline_interpgrids          rB   test_non_regularized_casez-TestSmoothingSpline.test_non_regularized_case=  s    		tGBI++A..2Q677qD26!a%== 1a4'")*:*:2sA*F*FF*1aR888
*1aIFFF{1Q42A..

4((%d++"	$ 	$ 	$ 	$ 	$ 	$rW   c                    t           j                            d           d}t          j        t           j                            |          dz  dz
            }|dz  t          j        d|z            z  |dz  z   t           j                            dd|          z   }t          ||          }t           j                            t          d          d	          D ]}t          j
        |          }d
||<   t          |||          }t           |||                   ||         z
            }t           |||                   ||         z
            }	||	k     rt          d|dd|	d          d S )Nr|   r   r-   r*   r,   r.   r   rP   r   g      >@zJSpline with weights should be closer to the points than the original one: z.4z < )r9   r>   r   r   r  r  r^  r   choicer   onesabsr7   )
r?   r@   r^   r   r	  indrG  spl_worigweighteds
             rB   test_weighted_smoothing_splinez2TestSmoothingSpline.test_weighted_smoothing_splineP  sw   
	tGBI++A..2Q677qD26!a%== 1a4'")*:*:2sA*F*FF#Aq)) 9##E#JJR#88 	3 	3C

AAcF)!Q22E ss1S6{{QsV+,,D553==1S6122Hh  "2CG!O"2 "2$,!1"2 "2 3 3 3 	3 	3rW   N)r   r   r   r`  re  rk  rt  rk   rW   rB   r\  r\    sT        - - -04A 4A 4Al$ $ $&3 3 3 3 3rW   r\  r  )rm  r,   )r,   )9numpyr9   numpy.testingr   r   r   rL   r   r5   scipy.interpolater   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   scipy.linalgr'  r1  scipy.interpolate._bsplinesr   r   r   r   r   scipy.interpolate._fitpack_implinterpolate_fitpack_implr   rS  r   rG  rJ  rm   rr   r   r]   r   rJ   rF  rx  r  r  r<  r>  rZ  r\  rk   rW   rB   <module>r}     s       @ @ @ @ @ @ @ @ @ @ * * * * * * C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C      E E E E E E E E E E E E E E 0 / / / / / / / / 				~C ~C ~C ~C ~C ~C ~C ~CB6 6 6.  &
G 
G 
G> > >  H H H   $+ + + +  $\+ \+ \+ \+ \+ \+ \+ \+~g? g? g? g? g? g? g? g?T  8   8O@ O@ O@ O@ O@ O@ O@ O@d* * *
|3 |3 |3 |3 |3 |3 |3 |3 |3 |3rW   