o
    GgqJ                     @   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   dC:\Users\micha\Documents\internet-seite\env\Lib\site-packages\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   sh   z t t| j|jk t t| j|jk t| j|j W d S  ty3   d|  d| }t|w )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      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   r6   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   sd   g d}g d}t t}| ||d W d    n1 sw   Y  |d jjd dks0J d S )N)        rI         ?)rJ   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   rQ   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      ztest_fit.<locals>.fr   r(   r)   r+   r,   )r   r%   r*   r(   r%   r*   )r<   )r   r.   rL   r	   r   r   rE   r/   r   Z
zeros_likeshape)r   rS   r4   rO   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 rtttj	|tdg d S 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 rtttj	|tdg d S 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 rtttj	|tdg d S 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 rttt	j
|tdg d S 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   s6  | g d}|d }t jD ]"}t|trt|trq|d}tt||| tt	tj|| qt
tfD ]}|d}tt||| tt	tj|| q4tfD ]}|dd}tt||| tt	tj|| qOt t t t t dgfD ]}tt	tj|| tt	tj|| qwtD ]}tt	tj||d qd 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 rttt	j
|tdg d S 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   s0  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 d S 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.   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||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(   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   r7   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|| | || }q'| dg}| g d}tdD ]}t|| | || }qDtttj|d tttj|d d S )	Nr)   r+   r%   r,   rZ   r?   g      ?rC   )	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%   r9   rZ   r*   r(   )r   r   r   r.   r7   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 )NrZ   )rC   r   r*   )r   r   rh   )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 )NrZ   rc   rC   r(   r*   r%   r   )r
   r   Zcutdegr   rF   r   r   r   r   test_cutdeg     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   rF   r   r   r   r   test_truncate  r   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mapparmsrA   r   r   r   test_mapparms1  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_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 rR   r   )selfr4   r   r   r   rS   K  rT   zTestInterpolate.fc                 C   s(   t ttj| jd t ttj| jd d S )NrC   g      $@)r
   r   r   interpolaterS   ri   )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   rS   rE   )r   degr   r   r   test_dimensionsR  s   zTestInterpolate.test_dimensionsc                 C   sn   dd }t ddd}tddD ]$}td|d D ]}tj||ddg|fd}t|||||dd	 qqd S )
Nc                 S   s   | | S r   r   )r4   r=   r   r   r   powxX  s   z0TestInterpolate.test_approximation.<locals>.powxr   r*   r&   r%   )r   rN   r9   )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__rS   r   r   r   r   r   r   r   r   I  s
    r   )r   )>__doc__operatorrj   numbersr   rK   numpyr   Znumpy.polynomialr   r   r   r   r   r   Znumpy.testingr	   r
   r   r   Znumpy.exceptionsr   r   rg   ZclassidsZfixturer   r/   r$   r2   r3   r5   r8   r>   rB   rH   rQ   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   r   <module>   sb     


	,-


