o
    1ήcK8                     @   s   d dl mZmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZ d dlmZmZmZmZmZ G dd deZG dd de	ZG dd dZG d	d
 d
ZG dd dZdS )    )logspacelinspace	geomspacedtypearraysctypesarangeisnanndarraysqrt	nextafterstackerrstate)assert_assert_equalassert_raisesassert_array_equalassert_allclosec                   @   sL   e Zd Zdd Zdd ZeZdd Zdd Zd	d
 ZeZ	dd Z
dd ZdS )PhysicalQuantityc                 C   s   t | |S N)float__new__)clsvalue r   J/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/tests/test_function_base.pyr      s   zPhysicalQuantity.__new__c                 C   s"   t t|t tt|t|  S r   r   
isinstancer   r   selfxr   r   r   __add__      zPhysicalQuantity.__add__c                 C   s"   t t|t tt| t| S r   r   r   r   r   r   __sub__   r"   zPhysicalQuantity.__sub__c                 C   s"   t t|t tt|t|  S r   r   r   r   r   r   __rsub__   r"   zPhysicalQuantity.__rsub__c                 C   s   t t|t|  S r   r   r   r   r   r   r   __mul__      zPhysicalQuantity.__mul__c                 C   s   t t| t| S r   r%   r   r   r   r   __div__   r'   zPhysicalQuantity.__div__c                 C   s   t t|t|  S r   r%   r   r   r   r   __rdiv__"   r'   zPhysicalQuantity.__rdiv__N)__name__
__module____qualname__r   r!   __radd__r#   r$   r&   __rmul__r(   r)   r   r   r   r   r   
   s    r   c                   @   s   e Zd ZdZdS )PhysicalQuantity2
   N)r*   r+   r,   __array_priority__r   r   r   r   r/   &   s    r/   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestLogspacec                 C   sv   t dd}tt|dk t dddd}t|d dk t dddd	}t|d dk  t ddd
d}t|g d d S )Nr      2   d   num@B Fendpoint      r0   r5        @@     @g     j@    .A)r   r   lenr   r   yr   r   r   
test_basic,   s   
zTestLogspace.test_basicc                    s   t ddg}t ddg t| d}tdd t| D dd	}t|| t| d
 d}t fdd|D dd	}t|| t| ddd	}t||j d S )N              ?g      @      @r3   c                 S      g | ]
\}}t ||d qS )r3   r   .0_start_stopr   r   r   
<listcomp>:       z6TestLogspace.test_start_stop_array.<locals>.<listcomp>r>   axisr   c                       g | ]
}t | d  dqS )r   r3   rJ   rL   rM   stopr   r   rO   >       r8   )r   r   r   zipr   Tr   startt1t2t3t4t5r   rU   r   test_start_stop_array6   s$   

z"TestLogspace.test_start_stop_arrayc                 C   ^   t dddd}t|jtd t dddd}t|jtd t dddd}t|jtd d S Nr   r3   float32r   float64int32)r   r   r   rC   r   r   r   
test_dtypeD      zTestLogspace.test_dtypec                 C   *   t d}t d}tt||tdd d S NrG   g      @)r   r   r   r   abr   r   r   test_physical_quantitiesL      z%TestLogspace.test_physical_quantitiesc                 C   x   t dt}t dt}t||}t|tu sJ t|tdd t||d}t|tu s1J t|tddd d S Nr>   r<   rG   rH   )r   viewr/   r   typer   r   rm   rn   lsr   r   r   test_subclassQ      
zTestLogspace.test_subclassN)r*   r+   r,   rE   ra   rh   ro   rw   r   r   r   r   r2   *   s    
r2   c                   @   s\   e Z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S )TestGeomspacec                 C   s   t dd}tt|dk t dddd}t|d dk t dddd	}t|d dk  t ddd
d}t|g d t dddd}t|g d t|jd t dddd}t|g d t|jd t dddd}t|g d t|jd d S )Nr>   rA   r4   r5   r6   r8   r9   Fr:   r<   r=            )rz      r{   r   )r8   r~   )r~   r   r8   )r   r   rB   r   r   imagrC   r   r   r   rE   ^   s"   
zTestGeomspace.test_basicc                 C   s   d}d}t ||dd}t|d | t ||ddd}t|d | t ||dd}t|d | t|d	 | t ||ddd}t|d | d S )
Ng333333?gL4@r>   r6   r   Fr7   r;   r|   r8   )r   r   r   r[   rV   rD   r   r   r   ,test_boundaries_match_start_and_stop_exactlyt   s   z:TestGeomspace.test_boundaries_match_start_and_stop_exactlyc                 C   s   t dd tdddd}W d    n1 sw   Y  t|d d tt|d	d
   t|d d t dd tddddd}W d    n1 sNw   Y  t|d d tt|d	d    d S )Nignore)invalidr|   r}   r6   r   g      r>   r8   g      @Fr   )r   r   r   r   r	   allrC   r   r   r   test_nan_interior   s   zTestGeomspace.test_nan_interiorc                 C   s  t dddd}t|g d t|jd t dddd}t|g d	 t|jd t d
ddd}t|g d t dddd}t|g d t dddtd}t|g d t ddd}t|ddtd dtd  dg t ddd}t|ddtd dtd  dg t ddd}t|ddtd dtd  dg t ddd}t|ddtd dtd  dg t ddd}t|g d t dd d}t|dd g t d dd}t|d dg d S )!N              ?              0@   r6   )r   y               @y              @y               @r   r                            @t)r   y             (y             By             [r         ?      ?     @@     @@r}   )r   y      $@      $@y      Y@      Y@r               ?     @     @@)r   y      $      $@y      Y      Y@r   r8   r>   r|   r7   r   )r8   r   r>   y              @y              r   r{   y      @        y                                 @      @r<   )r   y9ҿŒ~y{xC @V]yMuU@PrN	y0@5Sy
m^>@w@@r   )r   r   r   realcomplexr   rC   r   r   r   test_complex   s4   $$$$zTestGeomspace.test_complexc                 C   s   t dddd}t|jtd t dddd}t|jtd t dddd}t|jtd t ddtd}t|jtd t ddtd}t|jtd d S )	Nr>   rA   rd   re   rf   rg   float_r   )r   r   r   r   r   rC   r   r   r   rh      s   zTestGeomspace.test_dtypec           
      C   s   t ddgdd}t ddgdd}t ddgd	d}t|d
 |d d}t|d
 |d d}t|d
 |d d}tddd}tddd}tddd}	t||dd t||dd t||	dd d S )Nx   r5   int8re   r~       uint16r   r>   r         ^@      Y@      ^      Y     @r?   g{Gz?)rtolgh㈵>)r   r   r   
r   lim1lim2lim3r\   r]   r^   r_   r`   t6r   r   r   test_start_stop_array_scalar   s   z*TestGeomspace.test_start_stop_array_scalarc                    s   t g d}t g d t| d}tdd t| D dd}t|| t| d d}t fd	d|D dd}t|| t| dd
d}t||j d S )N)rG   g      @@r   r   r   r8   )r@          @r   r   y     @     @r>   r   c                 S   rI   r   r   rK   r   r   r   rO      rP   z7TestGeomspace.test_start_stop_array.<locals>.<listcomp>r>   rQ   r   c                    rS   r   r   r   rT   rU   r   r   rO      rW   r8   )r   r   r   rX   r   rY   rZ   r   rU   r   ra      s$   

z#TestGeomspace.test_start_stop_arrayc                 C   rj   rk   )r   r   r   rl   r   r   r   ro      rp   z&TestGeomspace.test_physical_quantitiesc                 C   rq   rr   )r   rs   r/   r   rt   r   )r   rm   rn   gsr   r   r   rw      rx   zTestGeomspace.test_subclassc                 C   s.   t ttdd t ttdd t ttdd d S )Nr   r0   )r   
ValueErrorr   r   r   r   r   test_bounds   s   zTestGeomspace.test_boundsN)r*   r+   r,   rE   r   r   r   rh   r   ra   ro   rw   r   r   r   r   r   ry   \   s    (
ry   c                   @   s   e Z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S ) TestLinspacec                 C   sl   t dd}tt|dk t dddd}t|d dk t dddd	}t|d dk  ttt dddd d S )
Nr   r0   r4   r{   r5   r6   r8   Fr:   )r   r   rB   r   r   rC   r   r   r   rE     s   
zTestLinspace.test_basicc                 C   s6   t tddd}t|dgk| tttdddd d S )Nr   r>   rF   g      @r6   )listr   r   r   	TypeErrorrC   r   r   r   test_corner  s   zTestLinspace.test_cornerc                 C   sB   t dddj}t dddj}t dddj}t|| t|| d S )Nr   r>   r{   )r   r   r   )r   r\   r]   r^   r   r   r   	test_type  s
   
zTestLinspace.test_typec                 C   rb   rc   )r   r   r   rC   r   r   r   rh     ri   zTestLinspace.test_dtypec           
      C   s   t ddgdd}t ddgdd}t ddgd	d}t|d
 |d d}t|d
 |d d}t|d
 |d d}tddd}tddd}tddd}	t|| t|| t||	 d S )Nr   r5   r   re   r   r~   r   r   r   r   r>   r   r   r   r   r   r   r?   )r   r   r   r   r   r   r   r     s   

z)TestLinspace.test_start_stop_array_scalarc                    s   t ddgdd}t ddgdd t| d}tdd	 t| D d
d}t|| t| d d}t fdd	|D d
d}t|| t| ddd}t||j d S )Nr   r   r   re   r5   r~   r   c                 S   rI   r   r   rK   r   r   r   rO   1  rP   z6TestLinspace.test_start_stop_array.<locals>.<listcomp>r>   rQ   r   c                    rS   r   r   rT   rU   r   r   rO   5  rW   r8   )r   r   r   rX   r   rY   rZ   r   rU   r   ra   -  s$   

z"TestLinspace.test_start_stop_arrayc                 C   sH   t ddd}tg d}t ddd}tg d}t|| t|| d S )N      ?       @      @      @r   )r   y      ?      @y       @      @y      @      @r   r   r0   )r   y      @      ?y      @      ?y      @      ?y      $@        )r   r   r   )r   r   r\   r   r]   r   r   r   r   ;  s   
zTestLinspace.test_complexc                 C   rj   )NrF   rG   )r   r   r   rl   r   r   r   ro   C  rp   z%TestLinspace.test_physical_quantitiesc                 C   sx   t dt}t dt}t||}t|tu sJ t|tdd t||d}t|tu s1J t|tddd d S )Nr   r>   rF   rG   )r   rs   r/   r   rt   r   ru   r   r   r   rw   H  rx   zTestLinspace.test_subclassc                 C   sH   G dd d}|t ddd}|t ddd}tt||tdd d S )Nc                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	z3TestLinspace.test_array_interface.<locals>.Arrayisha  
            A generic object that supports the __array_interface__ and hence
            can in principle be converted to a numeric scalar, but is not
            otherwise recognized as numeric, but also happens to support
            multiplication by floats.

            Data should be an object that implements the buffer interface,
            and contains at least 4 bytes.
            c                 S   s
   || _ d S r   _data)r   datar   r   r   __init__b  s   
z<TestLinspace.test_array_interface.<locals>.Arrayish.__init__c                 S   s   dd| j ddS )Nr   <i4r|   )shapetypestrr   versionr   r   r   r   r   __array_interface__e  s   zGTestLinspace.test_array_interface.<locals>.Arrayish.__array_interface__c                 S   s   | S r   r   )r   otherr   r   r   r&   j  s   z;TestLinspace.test_array_interface.<locals>.Arrayish.__mul__N)r*   r+   r,   __doc__r   propertyr   r&   r   r   r   r   ArrayishW  s    

r   r>   r   re   r   )r   r   r   )r   r   onefiver   r   r   test_array_interfaceR  s   z!TestLinspace.test_array_interfacec              
   C   sB   t d D ]}t|d|dd }tttd|dd|d qd S )Nr   r   r>   r   r0   F)r;   r   )r   r   r   anyr   )r   ftyperV   r   r   r   test_denormal_numberst  s   z"TestLinspace.test_denormal_numbersc                 C   s8   t dD ]}ttd||d tdt|d td qd S )Nr   r   r>   re   )ranger   r   intr   )r   jr   r   r   test_equivalent_to_arange{  s
   z&TestLinspace.test_equivalent_to_arangec              	   C   s   dD ]f}dD ]a}t dd||dd}t|trt|dksJ |dkr=|r(dd	gndd
g}t|d | t|d |d  q|dkrS|sSt|d dg t|d d	 qt|d dgd |  t|d sgJ qqd S )N)r   r>   r{   )FTr   r>   T)r;   retstepr{   rF   rG   g      ?)r   r   tuplerB   r   r   r	   )r   r7   eptrD   	y0_expectr   r   r   test_retstep  s   zTestLinspace.test_retstepc                 C   s:   t ddd}t ddd}t||d}t|t g d d S )Nr>   Ore   r{   r|   )rG   g      ?r   )r   r   r   r   r   r   r   test_object  s   zTestLinspace.test_objectc                 C   s.   t dddtd}tg dtd}t|| d S )Nr8   r|   rz   r   )r8   r8   r   r   r>   r>   r{   r|   re   )r   r   r   r   )r   rD   tr   r   r   test_round_negative  s   z TestLinspace.test_round_negativeN)r*   r+   r,   rE   r   r   rh   r   ra   r   ro   rw   r   r   r   r   r   r   r   r   r   r   r      s     	
"r   N)numpyr   r   r   r   r   r   r   r	   r
   r   r   r   r   numpy.testingr   r   r   r   r   r   r   r/   r2   ry   r   r   r   r   r   <module>   s   < 2 %