o
    &ѹgj                     @   s	  d dl Z d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZmZmZ d d
lmZ d dlmZmZmZm Z  ej!"deefdd Z#ej!"dddggidfdddgddggidfddgd ggidfgdd Z$ej!"dddgdd Z%dd Z&ej!"dg dej!"d dd!gd"d# Z'ej!"d e(dd$ej!"d%e(d!d$ej!"dd&d'gej!"dd(dgd)d* Z)ej!"d+d,gd-d.gd/d0 Z*ej!"g d1d&d!de+d dgd!d2gd3d4ggfd&d!e+g d5e+ddgd6d2gd3d4ggfd&d6de+d dgdd3gd6d7gd3d4ggfd'd!de+d dgd!d!gd3d4ggfd'd!e+g d5e+ddgd$d2gd3d4ggfgd8d9 Z,ej!"d+d,gd-d.gd:d; Z-d<d= Z.d>d? Z/ej!"d d!d$gd@dA Z0ej!"d+d,gd-d.gej!"d g dBdCdD Z1dEdF Z2ej!j3e edGk dHdIej!"d e(dd!ej!"dd&d'gej!"dg dJej!"dKdLdMgdNdO Z4ej!j3e edGkdHdIdPdQ Z5ej!"d%d$d7gej!"dKdMdLgej!"d d!d6gej!"dg dJej!"dRdLdMgdSdT Z6ej!"dd dUidVfd dWidVfd dXidVfd dYidZfgd[d\ Z7e8 d]d^ Z9ej!"d_d!dMdLe:ddfd!dLdLe:ddfd!dMdMd dgfd!dLdMdgfd`dMdLg dafd`dLdLdd!gfd`dMdMd gfd`dLdMg fgej!"dbdge e dcdd Z;e8 dedf Z<ej!"d_ddMdLe:d d3fddLdLe:dd3fddMdMg dgfddLdMg dhfdidMdLg djfdidLdLg dkfdidMdMd d6gfdidLdMd6gfd!dMdLe:ddfd!dLdLe:ddfd!dMdMg dgfd!dLdMg dhfd`dMdLg dlfd`dLdLe:d!dfd`dMdMd d6gfd`dLdMd6gfdmdMdLg dnfdmdLdLg dofdmdMdMd gfdmdLdMg fgej!"dbdge e dpdq Z=drds Z>ej!"g dtddMdLe?fddMdLe?fddMdLej@fddMdLejAfd!dLdLejAfd!dLdMejAfd6dLdLejAfd6dLdMejAfgej!"duedvdw ZBej!"g dtddMdLe?fddMdLe?fddMdLej@fddMdLejAfd!dLdLejAfd!dLdMejAfgej!"dxedydz ZCej!"d{g d|ej!"d}g d~ej!"ddMdLgej!"dKdMdLgej!"dxedd ZDej!"g dtddMdLej@fddMdLejAfd!dLdLejAfd!dLdMejAfgej!"dxedd ZEej!"g dg dej!"dxedd ZFej!"dKdgg dej!"dxedd ZGej!"g dg dej!"dxedd ZHej!"ddMdLgej!"dKdMdLgej!"dxedd ZIej!"dddde?eJeKejLjMd fdde?eJeKejLjMfgej!"ddMdLgej!"dKdMdLgej!"dxedd ZNej!"ddMdLgej!"dKdMdLgej!"dxedd ZOej!"dee dd ZPdd ZQej!jRe jSdkddMdej!"dxedd ZTdS )    N)assert_allcloseassert_array_equal)sparse)BSpline)random)LinearRegression)Pipeline)KBinsDiscretizerPolynomialFeaturesSplineTransformer)_calc_expanded_nnz_calc_total_nnz_get_sizeof_LARGEST_INT_t)assert_array_almost_equal)CSC_CONTAINERSCSR_CONTAINERSparse_version
sp_versionestc                 C   sd   t ddd}dd }||  |sJ || dd|s#J t | dd|s0J d	S )
z+Test that output array has the given order.
         c                 S   s   t | jS )N)np	isfortranT)a r   o/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/site-packages/sklearn/preprocessing/tests/test_polynomial.pyis_c_contiguous$   s   z?test_polynomial_and_spline_array_order.<locals>.is_c_contiguousC)orderFN)r   arangereshapefit_transformr   )r   Xr   r   r   r   &test_polynomial_and_spline_array_order   s
   r&   zparams, err_msgknots   z0Number of knots, knots.shape\[0\], must be >= 2.r   z*knots.shape\[1\] == n_features is violatedz(knots must be sorted without duplicates.c                 C   T   dgdgg}t jt|d tdi | | W d   dS 1 s#w   Y  dS )zATest that we raise errors for invalid input in SplineTransformer.r(   r   matchNr   pytestraises
ValueErrorr   fitparamserr_msgr%   r   r   r   (test_spline_transformer_input_validation,   s   
"r4   extrapolationcontinueperiodicc                 C   sL   t ddd}ddgddgddgddgddgg}td	|| d
|}dS )zATest that SplineTransformer accepts integer value knot positions.   r   r   r   r(   r            )degreer'   r5   N)r   r"   r#   r   r$   )r5   r%   r'   _r   r   r   %test_spline_transformer_integer_knots<   s   "r>   c                  C   sp   t ddd} tdddd| }| }t|g d tdddd| }|d	d
g}t|g d dS )z<Test that SplineTransformer generates correct features name.r8   r   r   r;   T)n_knotsr<   include_bias)
Zx0_sp_0Zx0_sp_1Zx0_sp_2Zx0_sp_3Zx0_sp_4Zx1_sp_0Zx1_sp_1Zx1_sp_2Zx1_sp_3Zx1_sp_4Fr   b)Za_sp_0Za_sp_1Za_sp_2Za_sp_3Zb_sp_0Zb_sp_1Zb_sp_2Zb_sp_3N)r   r"   r#   r   r0   get_feature_names_outr   )r%   spltfeature_namesr   r   r   %test_spline_transformer_feature_namesF   s   rE   )constantlinearr6   r7   r<   r;   c                 C   sh   t ddd}t|| d|}|ddg}t||jks"J ||}|j	d t|ks2J dS )	zsTest feature names are correct for different extrapolations and degree.

    Non-regression test for gh-25292.
    r8   r   r   )r<   r5   r   rA   r(   N)
r   r"   r#   r   r0   rB   lenn_features_out_	transformshape)r5   r<   r%   rC   rD   X_transr   r   r   7test_split_transform_feature_names_extrapolation_degreel   s   

rM   r   r?   uniformquantilerF   c                 C   s   t ddddddf }t jdgg|dddddf dggf }|dddddf }|dkr5||  }t|| |d|d}|| ||fD ]}tt j||dd	d qGdS )
zTest that B-splines are indeed a decomposition of unity.

    Splines basis functions must sum up to 1 per row, if we stay in between boundaries.
    r   r(   d   Nr   r7   T)r?   r<   r'   r@   r5   Zaxis)r   linspacer_r   r0   r   sumrJ   )r<   r?   r'   r5   r%   ZX_trainZX_testrC   r   r   r   +test_spline_transformer_unity_decomposition   s    	*
rU   bias	interceptTFFTc                 C   s   t ddddddf }t |dddf d }tdtdd| d	d
fdt|dfgd}||| t|||dd dS )z7Test that B-splines fit a sinusodial curve pretty well.r   r   rP   Nr   spline   r;   rF   r?   r<   r@   r5   olsZfit_interceptZstepsMbP?rtol)	r   rR   sinr   r   r   r0   r   predict)rV   rW   r%   ypiper   r   r   )test_spline_transformer_linear_regression   s    	rg   )r'   r?   sample_weightexpected_knots         )r   r   r(   r(   r   r;   r(      r   c              
   C   sT   t ddgddgddgddgddgddgddgg}tj|| ||d	}t|| d
S )zJCheck the behaviour to find knot positions with and without sample_weight.r   r   r;   rm   rk   r   rj   rl   )r%   r'   r?   rh   N)r   arrayr   Z_get_base_knot_positionsr   )r'   r?   rh   ri   r%   Z
base_knotsr   r   r   /test_spline_transformer_get_base_knot_positions   s
   4ro   c                 C   s   dd }t ddddddf }tdtdd	| d
dfdt|dfgd}||||dddf  t ddddddf }||}t|||dddf ddd t|dd |dd dd dS )z5Test that B-splines fit a periodic curve pretty well.c                 S   s,   t dt j |  t dt j |   d S )Nr   rj   r;   )r   rc   pi)xr   r   r   f   s   ,z=test_spline_transformer_periodic_linear_regression.<locals>.fr   r(   e   NrZ   r8   r;   r7   r\   r]   r^   r_   r   i-  g{Gz?)Zatolrb   rP      r`   ra   )r   rR   r   r   r   r0   rd   r   )rV   rW   rr   r%   rf   ZX_Zpredictionsr   r   r   2test_spline_transformer_periodic_linear_regression   s&   	
 "rv   c                  C   s   t ddddddf } d}t|ddgdgd	ggd
}|| }t d	dgdd	gd	dgdd	gg}tt dd||d}|| dddf }t|| dS )z@Test that the backport of extrapolate="periodic" works correctlyg      @r   Nr   r7   g                    ?r<   r5   r'   rm   r   )r   rR   r   r$   rn   r   r"   r   )r%   r<   transformerXtZcoefZsplZXsplr   r   r   0test_spline_transformer_periodic_spline_backport   s   
"r~   c               	   C   s   t ddddddf } tdddgdgd	gd
gdgdggd}tdddgd	gd
gdgdgdggd}|| }|| }t||ddg df  dS )zJTest if shifted knots result in the same transformation up to permutation.r   r   rs   Nr;   r7   rx   ry         @      @      @       @rz   g      "@)rm   r   r(   r   r;   )r   rR   r   r$   r   )r%   Ztransformer_1Ztransformer_2ZXt_1ZXt_2r   r   r   4test_spline_transformer_periodic_splines_periodicity  s   

r   c           	   	   C   s   t ddddddf }t| ddgdgdgd	gd
gdggd}||}| |  t| }d| }|}td| d D ]}t j|dd}t 	| |k sRJ || }q>t j|dd}t 	| dksiJ dS )z?Test that spline transformation is smooth at first / last knot.rw   r   i'  Nr7   rx   ry   r   r   r   r   rz   r(   r   rQ   )
r   rR   r   r$   maxminrH   rangediffabs)	r<   r%   r|   r}   deltaZtolZdXtdr   r   r   r   3test_spline_transformer_periodic_splines_smoothness  s    


r   )r(   r   r;   rm   r   c                 C   sZ  t ddddddf }| }tdtd|| ddgd	t|d
gg}||| t|dgdggddg tdtd|| ddgd	t|d
gg}||| t|dgdggddg td|| dd}|| d}t	j
t|d |dgg W d   n1 sw   Y  t	j
t|d |dgg W d   dS 1 sw   Y  dS )z1Test that B-spline extrapolation works correctly.rt   r(   rP   NrZ   rm   rF   r\   r]   r^   ir   rG   error0X contains values beyond the limits of the knotsr*   )r   rR   Zsqueezer   r   r   r0   r   rd   r-   r.   r/   rJ   )rV   rW   r<   r%   re   rf   rC   msgr   r   r   %test_spline_transformer_extrapolationA  sR   		
"r   c                  C   sn   t jd} | ddd}d}|d }t|dddd}||}t|d	dd
}||}t||dd dS )zCTest that a B-spline of degree=0 is equivalent to KBinsDiscretizer.i| ru   r(   r   r   rO   T)r?   r<   r'   r@   zonehot-dense)n_binsencodeZstrategygvIh%<=ra   N)	r   r   RandomStaterandnr#   r   r$   r	   r   )rngr%   r   r?   rC   ZsplinesZkbdZkbinsr   r   r   'test_spline_transformer_kbindiscretizery  s   

r   1.8.09The option `sparse_output` is available as of scipy 1.8.0)reason)r   rF   rG   r6   r7   r@   FTc                 C   sz  t j|}|ddd}t| |||dd}t| |||dd}|| || ||}	||}
t	|	r?|	j
dksAJ t|
|	  t j|dd	}t j|dd	}t jt |d |d
t ||d d
f }|dkrd}tjt|d || W d    n1 sw   Y  d}tjt|d || W d    d S 1 sw   Y  d S t||||  d S )Nru   (   r   F)r<   r'   r5   r@   sparse_outputTcsrr   rQ   r   r   r   r*   zOut of bounds)r   r   r   r   r#   r   r0   rJ   r   issparseformatr   toarrayZaminZamaxrS   rR   r-   r.   r/   )r<   r'   r5   r@   Zglobal_random_seedr   r%   Z
splt_denseZsplt_sparseZX_trans_sparseZX_trans_denseZX_minZX_maxZX_extrar   r   r   r   %test_spline_transformer_sparse_output  sN   



""r   c                  C   sP   dgdgg} t jtdd tdd|  W d   dS 1 s!w   Y  dS )zDTest that SplineTransformer with sparse=True raises for scipy<1.8.0.r(   r   zscipy>=1.8.0r*   T)r   Nr,   )r%   r   r   r   ?test_spline_transformer_sparse_output_raise_error_for_old_scipy  s   "r   r   c                 C   sn   |rt tdk rtd t| ||||d}tddddddf }|| ||j	d |j
ks5J dS )z8Test that transform results in n_features_out_ features.r   r   )r?   r<   r@   r5   r   r   r(   r   N)r   r   r-   skipr   r   rR   r0   rJ   rK   rI   )r?   r@   r<   r5   r   rC   r%   r   r   r   &test_spline_transformer_n_features_out  s   

r   )rt   r   z&degree=\(min_degree, max_degree\) must)r   g      ?r;   r   )r(   r   r;   z'int or tuple \(min_degree, max_degree\)c                 C   r)   )zBTest that we raise errors for invalid input in PolynomialFeatures.r(   r   r*   Nr   )r-   r.   r/   r
   r0   r1   r   r   r   )test_polynomial_features_input_validation  s   "r   c                  C   s@   t dd d t jf } t t | | | d | d g}| |fS )Nrk   r   r;   )r   r"   ZnewaxishstackZ	ones_like)r%   Pr   r   r   single_feature_degree3  s    r   z/degree, include_bias, interaction_only, indicesr   r;   )r   r   r;   X_containerc           
      C      | \}}|dur||}t |||d|}||}	|dur#|	 }	t|	|dd|f  |jdkr?|jj|j|jfksAJ dS dS )z9Test PolynomialFeatures on single feature up to degree 3.Nr<   r@   interaction_onlyr   	r
   r0   rJ   r   r   n_output_features_Zpowers_rK   Zn_features_in_)
r   r<   r@   r   indicesr   r%   r   tfoutr   r   r   $test_polynomial_features_one_feature  s    

r   c                  C   s   t dd} | d d d df }| d d dd f }t |d |d  |d |d  |d |d  |d |d  |d |d  |d |d  |d |d  |d |d  |d |d  |d |d  g
}| |fS )Nrk   r   r(   r   r   r;   )r   r"   r#   r   )r%   x1x2r   r   r   r   two_features_degree3*  s"   r   )r   r(   r   rm   )r(   r   rm   r   r   )r   r;   rm   r   )r;   rm   r   )r   r;   rm   r   rk      rj   	   r;   r;   )r   rk   r   rj   r   )rk   r   rj   r   c           
      C   r   )z5Test PolynomialFeatures on 2 features up to degree 3.Nr   r   r   )
r   r<   r@   r   r   r   r%   r   r   r   r   r   r   %test_polynomial_features_two_features@  s    #

r   c                  C   sh  t ddd} tddd| }| }tg d| t||| j	d ks+J tdd	d| }|g d
}tg d| t||| j	d ksPJ tdd	d| }|g d
}tg d| t||| j	d ksuJ tdddd| }|g d
}tddg| t||| j	d ksJ tddd| }|g d}tg d| d S )N   r   r;   r   Tr<   r@   )
1Zx0r   r   zx0^2zx0 x1zx0 x2zx1^2zx1 x2zx2^2r(   F)r   rA   c)r   rA   r   a^2a ba cb^2b cc^2a^3a^2 ba^2 ca b^2a b ca c^2b^3b^2 cb c^2c^3r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )F40D   ☮   א)r   r   r   r   )
r   r"   r#   r
   r0   rB   r   rH   rJ   rK   )r%   polyrD   r   r   r   test_polynomial_feature_namesq  sB   r   )degr@   r   dtypecsc_containerc                 C   s   t jd}|ddd}||}t| ||d}|||}	|||}
t|	r2|	j	dks4J |	j
|
j
ks<J t|	 |
 d S )Nr   r   rP   r   r@   r   Zcscr   r   r   randintr
   r$   astyper   r   r   r   r   r   )r   r@   r   r   r   r   r%   ZX_cscr   ZXt_cscXt_denser   r   r   test_polynomial_features_csc_X  s   r   csr_containerc                 C   s   t jd}|ddd}||}t| ||d}|||}	||j|dd}
t|	r4|	j	dks6J |	j
|
j
ks>J t|	 |
 d S )Nr   r   r   r   F)copyr   r   )r   r@   r   r   r   r   r%   X_csrr   Xt_csrr   r   r   r   test_polynomial_features_csr_X  s   r   
n_features)r(   rm   r   zmin_degree, max_degree))r   r(   )r   r   )r(   r;   )r   rm   )r;   rm   r   c           
      C   sj   |dgdg| d gff}t |||d}|| |j}t j| d|||d}	|tdd |	D ks3J dS )z?
    Test that n_output_features_ is calculated correctly.
    r(   r   )r<   r   r@   r   
min_degree
max_degreer   r@   c                 S   s   g | ]}d qS )r(   r   ).0r=   r   r   r   
<listcomp>  s    z)test_num_combinations.<locals>.<listcomp>N)r
   r0   r   Z_combinationsrT   )
r   r   r   r   r@   r   rq   r   Z
num_combosZcombosr   r   r   test_num_combinations  s    
r   c           
      C   s   |t ddddd}| }t| ||d}|||}|||}	t|r/|jdks1J |j|	jks9J t	| |	 d S )N  r         ?r   Zrandom_stater   r   )
sparse_randomr   r
   r$   r   r   r   r   r   r   )
r   r@   r   r   r   r   r%   r   r   r   r   r   r   %test_polynomial_features_csr_X_floats  s   r   )zero_row_indexr   r   ))r   r   T)r(   r   Tr   r   T)r   r;   T)r(   r;   T)r   r;   T)r   r   F)r(   r   Fr   r   F)r   r;   F)r(   r;   F)r   r;   Fc           	      C   s   |t ddddd}d|| d d f< | }t|d|d}||}||}t|r1|jd	ks3J |j|jks;J t| | d S )
Nr;   r   ry   r   r   rx   Fr   r   	r   r   r
   r$   r   r   r   r   r   )	r   r   r   r   r   r%   r   r   r   r   r   r   'test_polynomial_features_csr_X_zero_row6  s   

r   ))TTrX   rY   )FFc                 C   sx   |t ddddd}| }td| |d}||}||}t|r)|jdks+J |j|jks3J t| | d S )	Nr   r   r   r   r   rm   r   r   r   )r@   r   r   r   r%   r   r   r   r   r   r   'test_polynomial_features_csr_X_degree_4Z  s   

r   )r   dimr   )
)r   r(   Tr   )r;   r(   T)r;   r   T)r;   r;   T)r   r(   Fr   )r;   r(   F)r;   r   F)r;   r;   Fc           	      C   sv   |t d|ddd}| }t| |d}||}||}t|r(|jdks*J |j|jks2J t| | d S )Nr   r   r   r   r   r   r   )	r   r   r   r   r   r%   r   r   r   r   r   r   (test_polynomial_features_csr_X_dim_edgesp  s   

r   c              	      sx   fdd}d}d}t j}t jddt jd}t |d |d |d |d g}t j|d |d |d |d gt jd}	||||	ff||f|d	}
t |dd
}|j|dd|j|jd}|t 	t j
jkrd}tjt|d ||
 W d   dS 1 s~w   Y  dS ||
}| \}}|| }|||	t   |	d | }|rdg|d  ng }|rdg|d  ng }tdD ]}|d|  }|d| d  }|	d|  }|	d| d  }|r|d |d |||g ||t| |t| g  s)||| || || g |||||| ||||| ||||| g q||| g ||||||  qt|d dt    }|j|d ksTJ |j|ks\J |j||d fkshJ |jj|jj  krzt jks}J  J |j t 	t jjksJ |rtt|d ng }||d g| |d g|   t|j| t|| t|| dS )a  Check the automatic index dtype promotion to `np.int64` when needed.

    This ensures that sufficiently large input configurations get
    properly promoted to use `np.int64` for index and indptr representation
    while preserving data integrity. Non-regression test for gh-16803.

    Note that this is only possible for Python runtimes with a 64 bit address
    space. On 32 bit platforms, a `ValueError` is raised instead.
    c                    sD    r| | |d d|  d  d | S | | |d | d  | S )Nr   r;   r(   r   )r   ijr   r   r   degree_2_calc  s   $zRtest_csr_polynomial_expansion_index_overflow_non_regression.<locals>.degree_2_calc   i r(   r   r   r   )rK   r   r   r@   r<   r   r   tThe output that would result from the current configuration would have \d* features which is too large to be indexedr*   Nr;   ) r   float32r"   int64rn   r
   _num_combinationsr   r@   iinfointpr   r-   r.   r/   r0   r$   Znonzerointr   appendextendr   r   rK   indptrr   int32listr   datar   )r   r@   r   r   Z	n_samplesr   Z
data_dtyper
  rowcolr%   pfnum_combinationsr   rL   Zrow_nonzeroZcol_nonzeroZn_degree_1_features_outZmax_degree_2_idxZdata_targetZcol_nonzero_targetr   rq   re   Zx_idxZy_idxZnnz_per_rowZrow_nonzero_targetr   r   r   ;test_csr_polynomial_expansion_index_overflow_non_regression  s   "




*
r  zdegree, n_features)r     )r;   i(	  )r;   r  c                 C   s  dg}|d t t jjkrt jnt j}t jdg|d}t j|d g|d}|d t| g}	|	||d  d |	d   |	||d  |d  d |	d   ||||ff}
t||| d}|j	|d| |j
|jd}|t t jjkrd	}tjt|d
 ||
 W d   dS 1 sw   Y  dS ttdk rd}t t jj}|| }td| d D ]'}t|
j||}t|||d }||d 7 }t|||k}|| o||kO }q|rd}tjt|d
 ||
}W d   dS 1 sw   Y  dS ttdk r1|dkr1| dkr1|s1d}tjt|d
 ||
}W d   dS 1 s*w   Y  dS ||
}|t t jjkrCt jnt j}d| d t|   }t|| }|j|
jks`J |jd|jfkskJ |jj|jj  kr||ksJ  J |j|ksJ |r|d tdksJ t|D ]}|d|	| f tdksJ q|| }| dkr|d| 9 }|j|	| d  d | ksJ dS )zTests known edge-cases to the dtype promotion strategy and custom
    Cython code, including a current bug in the upstream
    `scipy.sparse.hstack`.
    ry   r(   r   r   r   rk   r   r   r   r*   Nr   Fz>In scipy versions `<1.8.0`, the function `scipy.sparse.hstack`z1.9.2r  z>In scipy versions `<1.9.2`, the function `scipy.sparse.hstack`r   r   r;   )r   r  r  r   r   rn   r  r  r
   r  r   r@   r  r-   r.   r/   r0   r   r   r   r   r  r   r$   r   rK   r   r   Znnzapprox)r<   r   r   r@   r   r
  Zindices_dtyper  r  expected_indicesr%   r  r  r   Zhas_bugZ	max_int32Zcumulative_sizer   Z
max_indptrZmax_indicesZneeds_int64rL   Zexpected_dtypeZnon_bias_termsZexpected_nnzidxoffsetr   r   r   ,test_csr_polynomial_expansion_index_overflow  s   "




 ($
$r  c           
      C   s   t t jjd }dg}dg}|d g}||||ff}t| |dd}d}	tjt|	d || W d    n1 s<w   Y  tjt|	d |	| W d    d S 1 sYw   Y  d S )	Nr   ry   r   r(   r   r   r   r*   )
r   r  r   r   r
   r-   r.   r/   r0   r$   )
r   r@   r   r   r
  r  r  r%   r  r   r   r   r   0test_csr_polynomial_expansion_too_large_to_index|  s    
"r  sparse_containerc                 C   s   t d}tddd}d}tjt|d || W d   n1 s$w   Y  tddd}d	}tjt|d || W d   n1 sHw   Y  || |fD ]#}tdd
d}||}t|ri|	 }t
|t |jd df qSdS )zCheck that PolynomialFeatures raises error when degree=0 and include_bias=False,
    and output a single constant column when include_bias=True
    )r   r   r   Fr   zWSetting degree to zero and include_bias to False would result in an empty output array.r*   Nr  zoSetting both min_degree and max_degree to zero and include_bias to False would result in an empty output array.Tr(   )r   Zonesr
   r-   r.   r/   r$   r   r   r   r   rK   )r  r%   r   r3   Z_Xoutputr   r   r   1test_polynomial_features_behaviour_on_zero_degree  s(   


r  c                  C   s:   t jdkst jdkrt jdkrd} nd} t | ksJ d S )Nwin32        Z
emscriptenrj      )sysplatformmaxsizer   )Zexpected_sizer   r   r   test_sizeof_LARGEST_INT_t  s   
r!  r  zyOn Windows, scikit-learn is typically compiled with MSVC that does not support int128 arithmetic (at the time of writing))r   runc                 C   s*  t ttjjd d }dg}dg}|d g}|d g}|t ||d  d |d   |t ||d  |d  d |d   | |||ff}tdddd	}tjd
krxd}t	j
t|d || W d    d S 1 sqw   Y  d S ||}	tdD ]}
|	d||
 f t	dksJ qd S )NgUUUUUU?r;   ry   r   r(   r   rk   Fr   r  r   r*   )r  r   r  r   r   r  r
   r  r   r-   r.   r/   r$   r   r  )r   r   r
  r  r  r  r%   r  r   rL   r  r   r   r   *test_csr_polynomial_expansion_windows_fail  s0   
"
"
 r#  )Ur  Znumpyr   r-   Znumpy.testingr   r   Zscipyr   Zscipy.interpolater   Zscipy.sparser   r   Zsklearn.linear_modelr   Zsklearn.pipeliner   Zsklearn.preprocessingr	   r
   r   Z/sklearn.preprocessing._csr_polynomial_expansionr   r   r   Zsklearn.utils._testingr   Zsklearn.utils.fixesr   r   r   r   markZparametrizer&   r4   r>   rE   rM   r   rU   rg   rn   ro   rv   r~   r   r   r   r   Zskipifr   r   r   r   Zfixturer   slicer   r   r   r   r  r   Zfloat64r   r   r   r   r   r   r   r  sqrtr  r   r   r  r  r  r!  Zxfailr  r#  r   r   r   r   <module>   s   


	&
"("


&6
0






	



L



	rg
