o
    h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   w/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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   d1w1r!   d2w2r"   r   r   r   test_conversion8      r9   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   r:   r<   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   rB   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@   rA   r   r   r   
test_basisi   s   rF   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+   )rC   r,   r   r%   )r   r/   r   	fromrootsr   degreelenr	   r   r;   r   )r   r?   r@   rr!   pdompwinr"   r   r   r   test_fromrootsr   s   rN   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)        rO         ?)rP   g       @g      @r*   r   z!The fit may be poorly conditioned)pytestwarnsr   fitmessageargs)r   r4   yrecordr   r   r   test_bad_conditioned_fit   s   rX   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.   rS   r	   r   r   rI   r/   r   
zeros_likeshape)r   rZ   r4   rV   rA   r?   r@   zr!   r"   p3r   r   r   test_fit   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 Nr%   r*   r(   r   r%   r*   r(   r,   )r%   r%   r%   r   r   r!   r"   r_   p4r   r   r   
test_equal   s   rf   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 ra   rc   rd   r   r   r   test_not_equal   s   rg   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"   r_   r   r   r   test_add   s"     rw   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 rh   )rn   r/   r$   ro   r   rp   r
   rq   rr   subr   r   r   r   rt   r   r   r   test_sub   s"     ry   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 )	Nri   rk   r'   r*   r   r%   rl   rm   )rn   r/   r$   ro   r   rp   r
   rq   rr   mulr   r   r   r   rt   r   r   r   test_mul   s&     r{   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 
Nri   rk   r'   r)   r*   r   r%   rl   rm   )rn   r/   r   r$   ro   r   rp   r
   rq   rr   floordivr   r   r   r   	r   ru   rv   c3r!   r"   r_   re   c4r   r   r   test_floordiv  s4   
r   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 )Nrb   rC   r   r%   )r   
ScalarType
issubclassr   boolr$   rr   truedivr
   rq   intfloatcomplexro   rn   dictrp   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 r|   )rn   r/   r   r$   ro   r   rp   r
   rq   rr   modr   r   r   r   r~   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 r|   )rn   r/   r   divmodr$   ro   r   rp   r
   rq   r   r   r   r   )r   ru   rv   r   r!   r"   r_   re   r   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%   rC   r,   )r   r   r   r.   sortrH   rootsr	   )r   r?   r@   tgtresr   r   r   
test_roots  s   
r   c                 C   s   |  d}t| d d S NrC   )rD   r   rI   r   rA   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   )rD   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(   rj   )r   r   r%   r%   r%   r%   k)r%   r*   r(   rj   )r%   r%   r%   r%   r%   )lbnd)r*   r(   rj   )r   r   r%   r%   r%   rl   )r   r;   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+   rb   r,   r*   r%   r   )r   r/   r   r   r	   derivr   )r   r?   r@   r!   r"   r_   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+   rb   r,   r   r%      r*   rl   )r   r/   r   r   r.   r	   )r   r?   r@   rA   xtgtytgtxres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,   rb   rC   g      ?rG   )	r   r/   r   ranger$   r
   
ValueErrorrr   pow)r   r?   r@   r   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=   rb   r*   r(   )r   r   r   r.   r;   r	   )r   r   r?   r4   rA   r   r   r   r   r   	test_call  s   r   c                 C   s4   | g d}g d}||}t ||t| d S )Nrb   )rG   r   r*   )r   r   rp   )r   rA   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 )Nrb   rk   rG   r(   r*   r%   r   )r
   r   cutdegr   rJ   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 )Nrb   rk   r   rj   r(   r*   r%   )r
   r   truncater   rJ   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   trimr   )r   crA   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	   mapparmsrE   r   r   r   test_mapparms1  s   r   c                 C   s:   | g d}t d}ttt j|| ttt j|| d S )Nrb   r(   )r   onesr
   rq   rs   )r   rA   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 rY   r   )selfr4   r   r   r   rZ   K  r[   zTestInterpolate.fc                 C   s(   t ttj| jd t ttj| jd d S )NrG   g      $@)r
   r   r   interpolaterZ   rq   )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%   rC   )r   r   r   r   rZ   rI   )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   rA   r   r   r   powxX  s   z0TestInterpolate.test_approximation.<locals>.powxr   r*   r&   r%   )r   rU   r=   )decimal)r   r.   r   r   r   r	   )r   r   r4   r   trA   r   r   r   test_approximationV  s   z"TestInterpolate.test_approximationN)r   
__module____qualname__rZ   r   r   r   r   r   r   r   r   I  s
    r   )r   )>__doc__operatorrr   numbersr   rQ   numpyr   numpy.polynomialr   r   r   r   r   r   numpy.testingr	   r
   r   r   numpy.exceptionsr   r   ro   classidsfixturer   r/   r$   r2   r3   r9   r<   rB   rF   rN   rX   r`   rf   rg   rw   ry   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sb     


	,-


