a
    LfH                     @   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dMd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;dIdJ Z<G dKdL dLZ=dS )NzTest 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   \/var/www/ai-form-bot/venv/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   Zd1Zw1r!   Zd2Zw2r"   r   r   r   test_conversion8   s    r5   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    r7   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    rA   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   r6   r   )r   r:   r;   rr!   ZpdomZpwinr"   r   r   r   test_fromrootsr   s    rG   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)        rH         ?)rI   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
    ,rP   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.   rK   r	   r   r   rD   r/   r   Z
zeros_likeshape)r   rR   r4   rN   r<   r:   r;   zr!   r"   p3r   r   r   test_fit   s>    
"rV   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"   rU   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 rW   rY   rZ   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"   rU   r   r   r   test_add   s"      
rm   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^   )rd   r/   r$   re   r   rf   r
   rg   rh   subr   r   r   r   rj   r   r   r   test_sub   s"      
ro   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 )	Nr_   ra   r'   r*   r   r%   rb   rc   )rd   r/   r$   re   r   rf   r
   rg   rh   mulr   r   r   r   rj   r   r   r   test_mul   s&      
rq   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 
Nr_   ra   r'   r)   r*   r   r%   rb   rc   )rd   r/   r   r$   re   r   rf   r
   rg   rh   floordivr   r   r   r   	r   rk   rl   c3r!   r"   rU   r[   c4r   r   r   test_floordiv  s4    

rw   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 )NrX   r>   r   r%   )r   Z
ScalarType
issubclassr   boolr$   rh   truedivr
   rg   intfloatcomplexre   rd   dictrf   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 rr   )rd   r/   r   r$   re   r   rf   r
   rg   rh   modr   r   r   r   rt   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 rr   )rd   r/   r   divmodr$   re   r   rf   r
   rg   r   r   r   r   )r   rk   rl   ru   r!   r"   rU   r[   rv   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.   sortrC   rootsr	   )r   r:   r;   tgtresr   r   r   
test_roots  s    
r   c                 C   s   |  d}t| d d S Nr>   )r?   r   rD   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   )r?   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(   r`   )r   r   r%   r%   r%   r%   k)r%   r*   r(   r`   )r%   r%   r%   r%   r%   )Zlbnd)r*   r(   r`   )r   r   r%   r%   r%   rb   )r   r6   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+   rX   r,   r*   r%   r   )r   r/   r   r   r	   Zderivr   )r   r:   r;   r!   r"   rU   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+   rX   r,   r   r%      r*   rb   )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,   rX   r>   g      ?rB   )	r   r/   r   ranger$   r
   
ValueErrorrh   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%   r8   rX   r*   r(   )r   r   r   r.   r6   r	   )r   r   r:   r4   r<   r   r   r   r   r   	test_call  s    r   c                 C   s4   | g d}g d}||}t ||t| d S )NrX   )rB   r   r*   )r   r   rf   )r   r<   r4   r   r   r   r   test_call_with_list  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 )NrX   ra   rB   r(   r*   r%   r   )r
   r   Zcutdegr   rE   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 )NrX   ra   r   r`   r(   r*   r%   )r
   r   truncater   rE   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mapparmsr@   r   r   r   test_mapparms1  s    r   c                 C   s:   | g d}t d}ttt j|| ttt j|| d S )NrX   r(   )r   Zonesr
   rg   ri   )r   r<   r4   r   r   r   test_ufunc_override=  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 rQ   r   )selfr4   r   r   r   rR   K  s    zTestInterpolate.fc                 C   s(   t ttj| jd t ttj| jd d S )NrB   g      $@)r
   r   r   interpolaterR   rg   )r   r   r   r   test_raisesN  s    zTestInterpolate.test_raisesc                 C   s.   t ddD ]}tt| j| |k q
d S )Nr%   r>   )r   r   r   r   rR   rD   )r   degr   r   r   test_dimensionsR  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   powxX  s    z0TestInterpolate.test_approximation.<locals>.powxr   r*   r&   r%   )r   rM   r8   )decimal)r   r.   r   r   r   r	   )r   r   r4   r   tr<   r   r   r   test_approximationV  s    z"TestInterpolate.test_approximationN)r   
__module____qualname__rR   r   r   r   r   r   r   r   r   I  s   r   )r   )>__doc__operatorrh   numbersr   rJ   numpyr   Znumpy.polynomialr   r   r   r   r   r   Znumpy.testingr	   r
   r   r   Znumpy.exceptionsr   r   re   ZclassidsZfixturer   r/   r$   r2   r3   r5   r7   r=   rA   rG   rP   rV   r\   r]   rm   ro   rq   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s`    


	,-


