U
    O8cG                     @   s  d Z ddlZddlmZ ddlZddlZddlm	Z	m
Z
mZmZmZmZ ddlmZmZmZmZ ddlmZ e	e
eeeefZedd eD Zejeed	d
d ZejjZdKddZeZeZdd Zdd Z dd Z!dd Z"dd Z#dd Z$dd Z%dd Z&dd  Z'd!d" Z(d#d$ Z)d%d& Z*d'd( Z+d)d* Z,d+d, Z-d-d. Z.d/d0 Z/d1d2 Z0d3d4 Z1d5d6 Z2d7d8 Z3d9d: Z4d;d< Z5d=d> Z6d?d@ Z7dAdB Z8dCdD Z9dEdF Z:dGdH Z;G dIdJ dJZ<dS )LzTest inter-conversion of different polynomial classes.

This tests the convert and cast methods of all the polynomial classes.

    N)Number)
PolynomialLegendre	ChebyshevLaguerreHermiteHermiteE)assert_almost_equalassert_raisesassert_equalassert_)RankWarningc                 c   s   | ]}|j V  qd S N)__name__).0cls r   G/tmp/pip-unpacked-wheel-fd_gsd75/numpy/polynomial/tests/test_classes.py	<genexpr>   s     r   )paramsidsc                 C   s   | j S r   )param)requestr   r   r   Poly   s    r    c                 C   sp   z>t t| j|jk t t| j|jk t| j|j W n, tk
rj   d|  d| }t|Y nX d S )NzResult: z	
Target: )r   npalldomainwindowr	   coefAssertionError)p1p2msgr   r   r   assert_poly_almost_equal&   s    r$   c           
      C   s   t ddd}td}| jtdd  }| jtdd  }| |||d}|jtdd  }|jtdd  }|j|||d}	t|	j| t|	j| t|	||| d S )	Nr      
               ?r   r   )kindr   r   )r   linspacerandomr   r   convertr	   
Poly1Poly2xr   d1Zw1r!   Zd2Zw2r"   r   r   r   test_conversion8   s    r6   c           
      C   s   t ddd}td}| jtdd  }| jtdd  }| |||d}|jtdd  }|jtdd  }|j|||d}	t|	j| t|	j| t|	||| d S )Nr   r%   r&   r'   r)   r+   r,   )r   r.   r/   r   r   castr	   r1   r   r   r   	test_castI   s    r8   c                 C   sr   | j tdd  }| jtdd  }t|d |d d}| j||d}t|j | t|j| t||| d S )Nr)   r+   r   r%      r,   )r   r/   r   r   r.   identityr   r	   )r   dwr4   pr   r   r   test_identity_   s    r>   c                 C   sh   | j tdd  }| jtdd  }| jd||d}t|j | t|j| t|jdgd dg  d S )Nr)   r+      r,   r   r%   )r   r/   r   basisr   r   r   r;   r<   r=   r   r   r   
test_basisi   s    rB   c                 C   s   | j tdd  }| jtdd  }td}| j|||d}t| t| t|j | t|j| t||d tj }tj}tj	|||d}t|j
d d d S )Nr)   r+   )r?   r,   r   r%   )r   r/   r   	fromrootsr   degreelenr	   r   r7   r   )r   r;   r<   rr!   ZpdomZpwinr"   r   r   r   test_fromrootsr   s    rH   c              	   C   sT   dddg}dddg}t t}| ||d W 5 Q R X |d jjd dksPtd S )Ng        g      ?g       @g      @r*   r   z!The fit may be poorly conditioned)pytestZwarnsr   fitmessageargsr    )r   r4   yrecordr   r   r   test_bad_conditioned_fit   s
    

rO   c                 C   s  dd }t dd}||}| ||d}t|jddg t||| t| d | jtdd  }| jtdd  }| j||d||d}t||| t|j| t|j| | j||ddd	dg||d}t||| t|j| t|j| | ||dg }t|j| j t|j| j | ||ddd	dgg }t|j| j t|j| j t 	|}|t|j
d  }d|d d d	< | |d d d	 |d d d	 d}| j||d|d
}	| j||ddd	dg|d
}
t|||	| t|	||
| d S )Nc                 S   s   | | d  | d  S Nr%   r*   r   )r4   r   r   r   f   s    ztest_fit.<locals>.fr   r(   r)   r+   r,   r%   r*   )r<   )r   r.   rJ   r	   r   r   rE   r/   r   Z
zeros_likeshape)r   rQ   r4   rM   r=   r;   r<   zr!   r"   p3r   r   r   test_fit   s>    
"rU   c                 C   s   | dddgddgddgd}| dddgddgddgd}| dddgddgddgd}| dddgddgddgd}t ||k t ||k  t ||k  t ||k  d S Nr%   r*   r(   r   r,   r   r   r!   r"   rT   p4r   r   r   
test_equal   s    rZ   c                 C   s   | dddgddgddgd}| dddgddgddgd}| dddgddgddgd}| dddgddgddgd}t ||k  t ||k t ||k t ||k d S rV   rW   rX   r   r   r   test_not_equal   s    r[   c                 C   s*  t tdd }t tdd }| |}| |}|| }t|| | t|| | t|| | t|t| | tt|| | t|t| | tt|| | tttj	|| dg| j
d d tttj	|| dg| jd d | tkrtttj	|tdg ntttj	|tdg d S N         ?r'   r   r%   r   r   )listr/   r$   tupler   arrayr
   	TypeErroropaddr   r   r   r   r   c1c2r!   r"   rT   r   r   r   test_add   s"      
rk   c                 C   s2  t tdd }t tdd }| |}| |}|| }t|| |  t|| | t|| |  t|t| | tt|| |  t|t| | tt|| |  tttj	|| dg| j
d d tttj	|| dg| jd d | tkrtttj	|tdg ntttj	|tdg d S r\   )rb   r/   r$   rc   r   rd   r
   re   rf   subr   r   r   r   rh   r   r   r   test_sub   s"      
rm   c                 C   sZ  t tdd }t tdd }| |}| |}|| }t|| | t|| | t|| | t|t| | tt|| | t|t| | tt|| | t|d || dg  td| || dg  tttj	|| dg| j
d d tttj	|| dg| jd d | tkr@tttj	|tdg ntttj	|tdg d S )	Nr]   r_   r'   r*   r   r%   r`   ra   )rb   r/   r$   rc   r   rd   r
   re   rf   mulr   r   r   r   rh   r   r   r   test_mul   s&      
ro   c           	      C   sv  t tdd }t tdd }t tdd }| |}| |}| |}|| | }t |j}t|| | t|| | t|| | t|t| | tt|| | t|t| | tt|| | td| | dg t|d d|  ttt	j
|| dg| jd d ttt	j
|| dg| jd d	 | tkr\ttt	j
|tdg nttt	j
|tdg d S 
Nr]   r_   r'   r)   r*   r   r%   r`   ra   )rb   r/   r   r$   rc   r   rd   r
   re   rf   floordivr   r   r   r   	r   ri   rj   c3r!   r"   rT   rY   c4r   r   r   test_floordiv  s@    
      
ru   c                 C   s:  | dddg}|d }t jD ]D}t|trt|tr6q|d}tt||| tt	tj|| qt
tfD ].}|d}tt||| tt	tj|| qjtfD ]0}|dd}tt||| tt	tj|| qt t t t t dgfD ]$}tt	tj|| tt	tj|| qtD ]}tt	tj||d qd S )Nr%   r*   r(   r?   r   )r   Z
ScalarType
issubclassr   boolr$   rf   truedivr
   re   intfloatcomplexrc   rb   dictrd   classes)r   r!   r"   stypesptyper   r   r   test_truediv1  s*    


"r   c           	      C   sx  t tdd }t tdd }t tdd }| |}| |}| |}|| | }t |j}t|| | t|| | t|| | t|t| | tt|| | t|t| | tt|| | td| | dg t|d | dg ttt	j
|| dg| jd d ttt	j
|| dg| jd d	 | tkr^ttt	j
|tdg nttt	j
|tdg d S rp   )rb   r/   r   r$   rc   r   rd   r
   re   rf   modr   r   r   r   rr   r   r   r   test_modL  s,    
  
r   c                 C   s.  t tdd }t tdd }t tdd }| |}| |}| |}|| | }t |j}t||\}	}
t|	| t|
| t||\}	}
t|	| t|
| t||\}	}
t|	| t|
| t|t|\}	}
t|	| t|
| tt||\}	}
t|	| t|
| t|t|\}	}
t|	| t|
| tt||\}	}
t|	| t|
| t|d\}	}
t|	d|  t|
| dg td|\}	}
t|	| dg t|
| dg tt	t|| dg| j
d d tt	t|| dg| jd d	 | tkrtt	t|tdg ntt	t|tdg d S rp   )rb   r/   r   divmodr$   rc   r   rd   r
   re   r   r   r   r   )r   ri   rj   rs   r!   r"   rT   rY   rt   Zquoremr   r   r   test_divmodg  sP    















r   c                 C   sp   | j d d }| j}t|d |d d}t| j|||d }t|| t| | }t|| d S )Ng      ?r+   r   r%   r?   r,   )r   r   r   r.   sortrD   rootsr	   )r   r;   r<   tgtresr   r   r   
test_roots  s    
r   c                 C   s   |  d}t| d d S Nr?   )r@   r   rE   r   r=   r   r   r   test_degree  s    
r   c                 C   s^   |  d}| }t||k t||k	 t|j|jk	 t|j|jk	 t|j|jk	 d S r   )r@   copyr   r   r   r   )r   r!   r"   r   r   r   	test_copy  s    
r   c                 C   s  t }| |dddg}|| }||d}t||ddddg t||dddddg | |dddg}||jdd}||jdddgd}t||ddddg t||dddddg | |dddg}||jdd	}||jddd	}t||d
dddg t||dd
dddg d| j }| j|dddg|d}|| }||d}t||ddddg t||dddddg d S )Nr*         r   r(   r^   r%   k)Zlbndir`   )r   r7   integr$   r   )r   PZp0r!   r"   r;   r   r   r   
test_integ  s,    
r   c                 C   s   | j tdd  }| jtdd  }| dddg||d}|jdddgd}|jddgd}t|dj|j t|dj|j | dddg}|jdddgd}|jddgd}t|dj|j t|dj|j d S )Nr)   r+   r%   r*   r(   r,   r   )r   r/   r   r   r	   Zderivr   )r   r;   r<   r!   r"   rT   r   r   r   
test_deriv  s    r   c                 C   s   | j tdd  }| jtdd  }| dddg||d}t|d |d d}||}|d\}}t|| t|| tddd}||}|jdddgd	\}}t|| t|| d S )
Nr)   r+   r%   r*   r(   r,   r      r`   )r   r/   r   r   r.   r	   )r   r;   r<   r=   ZxtgtZytgtZxresZyresr   r   r   test_linspace  s    


r   c                 C   s   | j tdd  }| jtdd  }| dg||d}| dddg||d}tdD ]}t|| | || }qP| dg}| dddg}tdD ]}t|| | || }qtttj|d tttj|d	 d S )
Nr)   r+   r%   r,   r*   r(   r?   g      ?rC   )	r   r/   r   ranger$   r
   
ValueErrorrf   pow)r   r;   r<   r   Ztstir   r   r   test_pow  s    


r   c                 C   s^   t }| j}t|d |d d}| |dddg}d|dd|    }||}t|| d S )Nr   r%   r9   r*   r(   )r   r   r   r.   r7   r	   )r   r   r;   r4   r=   r   r   r   r   r   	test_call  s    r   c                 C   s~   | dddg}t t|jd t t|jd tt|dd tt|dd tt|dd tt|dd d S )Nr%   r*   r(   r_   rC   r   )r
   r   Zcutdegr   rF   r   r   r   r   test_cutdeg  s    r   c                 C   s~   | dddg}t t|jd t t|jd tt|dd tt|dd tt|dd tt|dd d S )Nr%   r*   r(   r_   r   r^   )r
   r   truncater   rF   r   r   r   r   test_truncate  s    r   c                 C   sd   ddddg}| |}t | j|d d  t |dj|d d  t |dj|d d  d S )	Nr%   gư>g-q=r   r(   g|=r*   gh㈵>)r   Ztrimr   )r   cr=   r   r   r   	test_trim"  s
    r   c                 C   s`   | j }| j}| dg||d}tddg|  d| d }| dg||d}tddg|  d S )Nr%   r,   r   r*   )r   r   r	   ZmapparmsrA   r   r   r   test_mapparms*  s    r   c                 C   s<   | dddg}t d}ttt j|| ttt j|| d S )Nr%   r*   r(   )r   Zonesr
   re   rg   )r   r=   r4   r   r   r   test_ufunc_override6  s    
r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestInterpolatec                 C   s   ||d  |d  S rP   r   )selfr4   r   r   r   rQ   D  s    zTestInterpolate.fc                 C   s(   t ttj| jd t ttj| jd d S )NrC   g      $@)r
   r   r   interpolaterQ   re   )r   r   r   r   test_raisesG  s    zTestInterpolate.test_raisesc                 C   s.   t ddD ]}tt| j| |k q
d S )Nr%   r?   )r   r   r   r   rQ   rE   )r   degr   r   r   test_dimensionsK  s    zTestInterpolate.test_dimensionsc                 C   sn   dd }t ddd}tddD ]H}td|d D ]4}tj||ddg|fd}t|||||dd	 q2q d S )
Nc                 S   s   | | S r   r   )r4   r=   r   r   r   powxQ  s    z0TestInterpolate.test_approximation.<locals>.powxr   r*   r&   r%   )r   rL   r9   )decimal)r   r.   r   r   r   r	   )r   r   r4   r   tr=   r   r   r   test_approximationO  s    z"TestInterpolate.test_approximationN)r   
__module____qualname__rQ   r   r   r   r   r   r   r   r   B  s   r   )r   )=__doc__operatorrf   Znumbersr   rI   Znumpyr   Znumpy.polynomialr   r   r   r   r   r   Znumpy.testingr	   r
   r   r   Znumpy.polynomial.polyutilsr   r}   rc   ZclassidsZfixturer   r/   r$   r2   r3   r6   r8   r>   rB   rH   rO   rU   rZ   r[   rk   rm   ro   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sf        


	,-


