a
    p=icG                     @   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   t/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/numpy/polynomial/tests/test_classes.py	<genexpr>       r   )paramsZidsc                 C   s   | j S r   )param)requestr   r   r   Poly   s    r    c                 C   sn   z>t t| j|jk t t| j|jk t| j|j W n* tyh   d|  d| }t|Y n0 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!   d2Zw2r"   r   r   r   test_conversion8   s    r7   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    r9   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    rC   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   r8   r   )r   r<   r=   rr!   ZpdomZpwinr"   r   r   r   test_fromrootsr   s    rI   c                 C   sd   g d}g d}t t}| ||d W d    n1 s>0    Y  |d jjd dks`J d S )N)        rJ         ?)rK   g       @g      @r*   r   z!The fit may be poorly conditioned)pytestZwarnsr   fitmessageargs)r   r4   yrecordr   r   r   test_bad_conditioned_fit   s
    ,rR   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||g d||d}t||| t|j| t|j| | ||dg }t|j| j t|j| j | ||g d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||g d|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%   r*   )r=   )r   r.   rM   r	   r   r   rF   r/   r   Z
zeros_likeshape)r   rT   r4   rP   r>   r<   r=   zr!   r"   p3r   r   r   test_fit   s>    
"rX   c                 C   s   | g dddgddgd}| g dddgddgd}| g dddgddgd}| g dddgddgd}t ||k t ||k  t ||k  t ||k  d S Nr%   r*   r(   r   r%   r*   r(   r,   )r%   r%   r%   r   r   r!   r"   rW   p4r   r   r   
test_equal   s    r^   c                 C   s   | g dddgddgd}| g dddgddgd}| g dddgddgd}| g dddgddgd}t ||k  t ||k t ||k t ||k d S rY   r[   r\   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u 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"   rW   r   r   r   test_add   s"      
ro   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u rtttj	|tdg ntttj	|tdg d S r`   )rf   r/   r$   rg   r   rh   r
   ri   rj   subr   r   r   r   rl   r   r   r   test_sub   s"      
rq   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u r@tttj	|tdg ntttj	|tdg d S )	Nra   rc   r'   r*   r   r%   rd   re   )rf   r/   r$   rg   r   rh   r
   ri   rj   mulr   r   r   r   rl   r   r   r   test_mul   s&      
rs   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u r\ttt	j
|tdg nttt	j
|tdg d S 
Nra   rc   r'   r)   r*   r   r%   rd   re   )rf   r/   r   r$   rg   r   rh   r
   ri   rj   floordivr   r   r   r   	r   rm   rn   c3r!   r"   rW   r]   c4r   r   r   test_floordiv  s4    

ry   c                 C   s8  | g d}|d }t jD ]D}t|trt|tr4q|d}tt||| tt	tj|| qt
tfD ].}|d}tt||| tt	tj|| qht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 )NrZ   r@   r   r%   )r   Z
ScalarType
issubclassr   boolr$   rj   truedivr
   ri   intfloatcomplexrg   rf   dictrh   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u r^ttt	j
|tdg nttt	j
|tdg d S rt   )rf   r/   r   r$   rg   r   rh   r
   ri   rj   modr   r   r   r   rv   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u rtt	t|tdg ntt	t|tdg d S rt   )rf   r/   r   divmodr$   rg   r   rh   r
   ri   r   r   r   r   )r   rm   rn   rw   r!   r"   rW   r]   rx   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.   sortrE   rootsr	   )r   r<   r=   tgtresr   r   r   
test_roots  s    
r   c                 C   s   |  d}t| d d S Nr@   )rA   r   rF   r   r>   r   r   r   test_degree  s    
r   c                 C   s^   |  d}| }t||k t||u t|j|ju t|j|ju t|j|ju d S r   )rA   copyr   r   r   r   )r   r!   r"   r   r   r   	test_copy  s    
r   c                 C   sz  t }| |g d}|| }||d}t||g d t||g d | |g d}||jdd}||jdddgd}t||g d t||g d | |g d}||jdd	}||jddd	}t||g d
 t||g d d| j }| j|g d|d}|| }||d}t||g d t||g d d S )N)r*         r*   )r   r*   r(   rb   )r   r   r%   r%   r%   r%   k)r%   r*   r(   rb   )r%   r%   r%   r%   r%   )Zlbnd)r*   r(   rb   )r   r   r%   r%   r%   rd   )r   r8   integr$   r   )r   Pp0r!   r"   r<   r   r   r   
test_integ  s,    
r   c                 C   s   | j tdd  }| jtdd  }| g d||d}|jdddgd}|jddgd}t|dj|j t|dj|j | g d}|jdddgd}|jddgd}t|dj|j t|dj|j d S )Nr)   r+   rZ   r,   r*   r%   r   )r   r/   r   r   r	   Zderivr   )r   r<   r=   r!   r"   rW   r   r   r   
test_deriv  s    r   c                 C   s   | j tdd  }| jtdd  }| g d||d}t|d |d d}||}|d\}}t|| t|| tddd}||}|jdddgd	\}}t|| t|| d S )
Nr)   r+   rZ   r,   r   r%      r*   rd   )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}| g d||d}tdD ]}t|| | || }qN| dg}| g d}tdD ]}t|| | || }qtttj|d tttj|d d S )	Nr)   r+   r%   r,   rZ   r@   g      ?rD   )	r   r/   r   ranger$   r
   
ValueErrorrj   pow)r   r<   r=   r   Ztstir   r   r   test_pow  s    


r   c                 C   s\   t }| j}t|d |d d}| |g d}d|dd|    }||}t|| d S )Nr   r%   r:   rZ   r*   r(   )r   r   r   r.   r8   r	   )r   r   r<   r4   r>   r   r   r   r   r   	test_call  s    r   c                 C   s|   | g d}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 )NrZ   rc   rD   r(   r*   r%   r   )r
   r   Zcutdegr   rG   r   r   r   r   test_cutdeg  s    r   c                 C   s|   | g d}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 )NrZ   rc   r   rb   r(   r*   r%   )r
   r   truncater   rG   r   r   r   r   test_truncate  s    r   c                 C   s`   g d}| |}t | j|d d  t |dj|d d  t |dj|d d  d S )N)r%   gư>g-q=r   r(   g|=r*   gh㈵>r%   )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mapparmsrB   r   r   r   test_mapparms*  s    r   c                 C   s:   | g d}t d}ttt j|| ttt j|| d S )NrZ   r(   )r   Zonesr
   ri   rk   )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 rS   r   )selfr4   r   r   r   rT   D  s    zTestInterpolate.fc                 C   s(   t ttj| jd t ttj| jd d S )NrD   g      $@)r
   r   r   interpolaterT   ri   )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   rT   rF   )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   rO   r:   )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__rT   r   r   r   r   r   r   r   r   B  s   r   )r   )=__doc__operatorrj   numbersr   rL   numpyr   Znumpy.polynomialr   r   r   r   r   r   Znumpy.testingr	   r
   r   r   Znumpy.polynomial.polyutilsr   r   rg   ZclassidsZfixturer   r/   r$   r2   r3   r7   r9   r?   rC   rI   rR   rX   r^   r_   ro   rq   rs   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s^    


	,-


