a
    hj                     @   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|sFJ t | dd|s`J d	S )
z+Test that output array has the given order.
         c                 S   s   t | jS )N)np	isfortranT)a r   g/var/www/html/assistant/venv/lib/python3.9/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   sR   dgdgg}t jt|d$ tf i | | W d   n1 sD0    Y  dS )zATest that we raise errors for invalid input in SplineTransformer.r(   r   matchNpytestraises
ValueErrorr   fitparamserr_msgr%   r   r   r   (test_spline_transformer_input_validation,   s    
r3   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'   r4   N)r   r"   r#   r   r$   )r4   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.r7   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   r/   get_feature_names_outr   )r%   spltfeature_namesr   r   r   %test_spline_transformer_feature_namesF   s    rD   )constantlinearr5   r6   r;   r:   c                 C   sh   t ddd}t|| d|}|ddg}t||jksDJ ||}|j	d t|ksdJ dS )	zsTest feature names are correct for different extrapolations and degree.

    Non-regression test for gh-25292.
    r7   r   r   )r;   r4   r   r@   r(   N)
r   r"   r#   r   r/   rA   lenn_features_out_	transformshape)r4   r;   r%   rB   rC   X_transr   r   r   7test_split_transform_feature_names_extrapolation_degreel   s    

rL   r   r>   uniformquantilerE   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rj||  }t|| |d|d}|| ||fD ]}tt j||dd	d qd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   r6   T)r>   r;   r'   r?   r4   Zaxis)r   linspacer_r   r/   r   sumrI   )r;   r>   r'   r4   r%   ZX_trainZX_testrB   r   r   r   +test_spline_transformer_unity_decomposition   s    	*
rT   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   rO   Nr   spline   r:   rE   r>   r;   r?   r4   olsZfit_interceptZstepsMbP?rtol)	r   rQ   sinr   r   r   r/   r   predict)rU   rV   r%   ypiper   r   r   )test_spline_transformer_linear_regression   s     	rf   )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:   rl   rj   r   ri   rk   )r%   r'   r>   rg   N)r   arrayr   Z_get_base_knot_positionsr   )r'   r>   rg   rh   r%   Z
base_knotsr   r   r   /test_spline_transformer_get_base_knot_positions   s
    4rn   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   ri   r:   )r   rb   pi)xr   r   r   f   s    z=test_spline_transformer_periodic_linear_regression.<locals>.fr   r(   e   NrY   r7   r:   r6   r[   r\   r]   r^   r   i-  g{Gz?)Zatolra   rO      r_   r`   )r   rQ   r   r   r   r/   rc   r   )rU   rV   rq   r%   re   ZX_Zpredictionsr   r   r   2test_spline_transformer_periodic_linear_regression   s&    	
 ru   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   r6   g                    ?r;   r4   r'   rl   r   )r   rQ   r   r$   rm   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   rr   Nr:   r6   rw   rx         @      @      @       @ry   g      "@)rl   r   r(   r   r:   )r   rQ   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 ]0}t j|dd}t 	| |k sJ || }q|t j|dd}t 	| dksJ dS )z?Test that spline transformation is smooth at first / last knot.rv   r   i'  Nr6   rw   rx   r~   r   r   r   ry   r(   r   rP   )
r   rQ   r   r$   maxminrG   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:   rl   r   c                 C   s\  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 s0    Y  t	j
t|d |dgg W d   n1 sN0    Y  dS )z1Test that B-spline extrapolation works correctly.rs   r(   rO   NrY   rl   rE   r[   r\   r]   ir   rF   error0X contains values beyond the limits of the knotsr)   )r   rQ   Zsqueezer   r   r   r/   r   rc   r,   r-   r.   rI   )rU   rV   r;   r%   rd   re   rB   msgr   r   r   %test_spline_transformer_extrapolationA  sN    		
.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| rt   r(   r   r   rN   T)r>   r;   r'   r?   zonehot-dense)n_binsencodeZstrategygvIh%<=r`   N)	r   r   RandomStaterandnr#   r   r$   r	   r   )rngr%   r   r>   rB   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   rE   rF   r5   r6   r?   FTc                 C   s|  t j|}|ddd}t| |||dd}t| |||dd}|| || ||}	||}
t	|	r~|	j
dksJ t|
|	  t j|dd	}t j|dd	}t jt |d |d
t ||d d
f }|dkr^d}tjt|d || W d    n1 s0    Y  d}tjt|d || W d    n1 sR0    Y  nt||||  d S )Nrt   (   r   F)r;   r'   r4   r?   sparse_outputTcsrr   rP   r   r   r   r)   zOut of bounds)r   r   r   r   r#   r   r/   rI   r   issparseformatr   toarrayZaminZamaxrR   rQ   r,   r-   r.   )r;   r'   r4   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  sJ    



"
*,r   c                  C   sN   dgdgg} t jtdd  tdd|  W d   n1 s@0    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sjJ dS )z8Test that transform results in n_features_out_ features.r   r   )r>   r;   r?   r4   r   r   r(   r   N)r   r   r,   skipr   r   rQ   r/   rI   rJ   rH   )r>   r?   r;   r4   r   rB   r%   r   r   r   &test_spline_transformer_n_features_out  s    

r   )rs   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   sR   dgdgg}t jt|d$ tf i | | W d   n1 sD0    Y  dS )zBTest that we raise errors for invalid input in PolynomialFeatures.r(   r   r)   N)r,   r-   r.   r
   r/   r0   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 )Nrj   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   s   | \}}|dur||}t |||d|}||}	|durF|	 }	t|	|dd|f  |jdkr~|jj|j|jfks~J dS )z9Test PolynomialFeatures on single feature up to degree 3.Nr;   r?   interaction_onlyr   	r
   r/   rI   r   r   n_output_features_Zpowers_rJ   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 )Nrj   r   r(   r   r   r:   )r   r"   r#   r   )r%   x1x2r   r   r   r   two_features_degree3*  s"    r   )r   r(   r   rl   )r(   r   rl   r   r   )r   r:   rl   r   )r:   rl   r   )r   r:   rl   r   rj      ri   	   r:   r:   )r   rj   r   ri   r   )rj   r   ri   r   c           
      C   s   | \}}|dur||}t |||d|}||}	|durF|	 }	t|	|dd|f  |jdkr~|jj|j|jfks~J dS )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   sj  t ddd} tddd| }| }tg d| t||| j	d ksVJ tdd	d| }|g d
}tg d| t||| j	d ksJ tdd	d| }|g d
}tg d| t||| j	d ksJ tdddd| }|g d
}tddg| t||| j	d ks8J 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   r@   c)r   r@   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
   r/   rA   r   rG   rI   rJ   )r%   polyrC   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|	rd|	j	dkshJ |	j
|
j
ksxJ t|	 |
 d S )Nr   r   rO   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|	rh|	j	dkslJ |	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(   rl   r   zmin_degree, max_degree))r   r(   )r   r   )r(   r:   )r   rl   )r:   rl   r   c           
      C   sj   |dgdg| d gff}t |||d}|| |j}t j| d|||d}	|tdd |	D ksfJ 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>      z)test_num_combinations.<locals>.<listcomp>N)r
   r/   r   Z_combinationsrS   )
r   r   r   r   r?   r   rp   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sbJ |j|	jksrJ 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|rb|jd	ksfJ |j|jksvJ t| | d S )
Nr:   r   rx   r   r   rw   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   ))TTrW   rX   )FFc                 C   sx   |t ddddd}| }td| |d}||}||}t|rR|jdksVJ |j|jksfJ t| | d S )	Nr   r   r   r   r   rl   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|rP|jdksTJ |j|jksdJ 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              	      s   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r
d}tjt|d ||
 W d   n1 s0    Y  dS ||
}| \}}|| }|||	t   |	d | }|rZdg|d  ng }|rrdg|d  ng }tdD ]}|d|  }|d| d  }|	d|  }|	d| d  }|r|d |d |||g ||t| |t| g  sZ||| || || g |||||| ||||| ||||| g n&||| g ||||||  q~t|d dt    }|j|d ksJ |j|ksJ |j||d fksJ |jj|jj  krt jksn J |j t 	t jjks J |r6t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                    sH    r(| | |d d|  d  d | S | | |d | d  | S 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   )rJ   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"   int64rm   r
   _num_combinationsr   r?   iinfointpr   r,   r-   r.   r/   r$   Znonzerointr   appendextendr   r   rJ   indptrr   int32listr   datar   )r   r?   r   r   Z	n_samplesr   Z
data_dtyper	  rowcolr%   pfnum_combinationsr   rK   Zrow_nonzeroZcol_nonzeroZn_degree_1_features_outZmax_degree_2_idxZdata_targetZcol_nonzero_targetr   rp   rd   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r.d	}tjt|d
 ||
 W d   n1 s 0    Y  dS ttdk r d}t t jj}|| }td| d D ]R}t|
j||}t|||d }||d 7 }t|||k}|| o||kO }qd|r d}tjt|d
 ||
}W d   n1 s0    Y  dS ttdk rj|dkrj| dkrj|sjd}tjt|d
 ||
}W d   n1 s\0    Y  dS ||
}|t t jjkrt jnt j}d| d t|   }t|| }|j|
jksJ |jd|jfksJ |jj|jj  kr|ksn J |j|ksJ |r2|d tdks2J t|D ]&}|d|	| f tdks:J 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`.
    rx   r(   r   r   r   rj   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   rm   r  r  r
   r   r   r?   r  r,   r-   r.   r/   r   r   r   r   r  r   r$   r   rJ   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_int64rK   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 sx0    Y  tjt|	d |	| W d    n1 s0    Y  d S )	Nr   rx   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   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 sH0    Y  tddd}d	}tjt|d || W d   n1 s0    Y  || |fD ]F}tdd
d}||}t|r|	 }t
|t |jd df qd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   rJ   )r  r%   r   r2   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s6J d S )Nwin32        Z
emscriptenri      )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rd}t	j
t|d || W d    n1 s0    Y  n6||}	tdD ]"}
|	d||
 f t	dksJ qd S )NgUUUUUU?r:   rx   r   r(   r   rj   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   rK   r  r   r   r   *test_csr_polynomial_expansion_windows_fail  s,    
"
*
r"  )Ur  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&   r3   r=   rD   rL   r   rT   rf   rm   rn   ru   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
