o
    g:                     @   s   d dl Zd dlZd dlmZmZmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ G dd dZG dd dZG d	d
 d
ZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZdS )    N)matrixasmatrixbmat)assert_assert_equalassert_almost_equalassert_array_equalassert_array_almost_equalassert_raises)matrix_powerc                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestCtorc           
      C   s   t ddgddgg}t|}tt |j|k td}t||g||gg}t g dg dg dg dg}tt |j|k tt |j|k t dd	gd
dgg}tg dg dg}tt t||g|k t d}t|}	t|	jdk d S )N            A,A;A,Ar   r   r   r   r   r   r   r               r   r   r   r   r   r   r   r   )r   r   )	nparrayr   r   allAr   arangeshape)
selfr   mABCDEAEresultvecmvec r)   ^/var/www/html/api-tag/env/lib/python3.10/site-packages/numpy/matrixlib/tests/test_defmatrix.py
test_basic   s$   

zTestCtor.test_basicc                 C   s   t ttd d S )Ninvalid)r
   
ValueErrorr   r    r)   r)   r*   test_exceptions"   s   zTestCtor.test_exceptionsc                 C   s  t ddgddgg}t ddgddgg}t g d	g d
g d	g d
g}t g dg dg dg dg}tt td|k tt tdd|id|k tttdd|id tt tdd|id|id|k td||d||dd}tt ||k d S )Nr   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   )ldict)gdict)r0   r1   zA,B;C,D)r   r"   )r#   r$   )r   r   r   r   r   r
   	TypeError)r    r   r"   Aresult	mixresultb2r)   r)   r*   test_bmat_nondefault_str&   s(   

z!TestCtor.test_bmat_nondefault_strN)__name__
__module____qualname__r+   r/   r6   r)   r)   r)   r*   r      s    r   c                   @   st   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S )TestPropertiesc                 C   s   t g dg dg dg dg}t g d}t g dj}d}t||jdd	 t||jd
d	 t||  t|tj|dd	 t|tj|d
d	 t|t| dS )zeTest whether matrix.sum(axis=1) preserves orientation.
        Fails in NumPy <= 0.9.6.2127.
        )r   r   r   r   )r   r   r   r   r   r   )r      r   r   )r   r   r         r   axisr   N)r   Tr   sumr   r   )r    Msum0sum1sumallr)   r)   r*   test_sum;   s   zTestProperties.test_sumc                 C   s   t g dg dg}t| d t|dt g dg t|dt dgdgg tt|d ttj|dd	t g dg ttj|dd	t dgdgg t g d
}t| dk d S )Nr   r   r   r   r   r   i  r   )r   
      r   r   x   r>   )r   r   r   )r   r   prodr   r   r    xyr)   r)   r*   	test_prodN   s    zTestProperties.test_prodc                 C   s   t g dg dg}t| d t|dt g dg t|dt dgdgg tt|d ttj|ddt g dg ttj|ddt dgdgg d S )NrG   rH   r   r   r   r   r>   )r   r   maxr   r    rN   r)   r)   r*   test_max[      $zTestProperties.test_maxc                 C   s   t g dg dg}t| d t|dt g dg t|dt dgdgg tt|d ttj|ddt g dg ttj|ddt dgdgg d S )NrG   rH   r   r   r   r>   )r   r   minr   rR   r)   r)   r*   test_mine   rT   zTestProperties.test_minc                 C   st   t dd}|t j}t| dk tt |dt ddgk tt |dt ddgk d S )Nr   )r   r   r   r   r   r   )	r   r   reshapeviewr   r   ptpr   r   r    rN   mxr)   r)   r*   test_ptpo   s
   "&zTestProperties.test_ptpc                 C   sT   t dd}|t j}t|jdd|jdd t|jdd|jdd d S )N	   )r   r   r   )ddofr   )r   r   rW   rX   r   r   varrZ   r)   r)   r*   test_varv   s   zTestProperties.test_varc                 C   s
  dd l m} tddgddgg}t|}tt|||j tt	tt
||jk tt	tt
||jk tt	||jk |d|  }t|}tt|||j tt	tt
||jk tt	tt
| |jk d S )Nr         ?       @      @      @y               @)numpy.linalglinalgr   r   r   r   allcloseinvIr   	transposer@   Hr   conj)r    rf   r   r!   r"   mBr)   r)   r*   r+   |   s   
   (zTestProperties.test_basicc                 C   s@   t tddd}t ddgddgdd	gg}t|j| d S )
Nr   r   r   g:gn)t?g#qg#q?gn)t?g6Bq)r   r   r   rW   r   ri   )r    rN   xpinvr)   r)   r*   	test_pinv   s   zTestProperties.test_pinvc                 C   sr  t ddd}t|}t|d }tt ||d k tt |t|d k tt |t|d k  tt ||k  tt ||k tt ||k tt ||k   tt ||k   tt ||k tt ||k tt ||k  tt ||k tt ||k  tt ||k tt t|dk  tt t|dk d S )Nd   rI   皙?r   )r   r   rW   r   r   r   anyabs)r    r   r!   rm   r)   r)   r*   test_comparisons   s&   zTestProperties.test_comparisonsc                 C   s:   t ddd}t|}d|d< t|d |d k d S )Nrp   rI   ir   r   )r   r   rW   r   r   )r    r   r!   r)   r)   r*   test_asmatrix   s   zTestProperties.test_asmatrixc                 C   s@   t ddgddgg}t| t dk t| t dk d S )Nr   r   r         ?)r   r   rA   meanr    r   r)   r)   r*   test_noaxis   s   zTestProperties.test_noaxisc                 C   s(   t ddgddgg}tt|dk d S )Nr   r   z matrix([[1, 0],
        [0, 1]]))r   r   reprry   r)   r)   r*   	test_repr   s   zTestProperties.test_reprc                 C   s*   t d}t dgdgdgg}t|| d S )NzTrue; True; FalseTF)r   r   )r    r   r"   r)   r)   r*   test_make_bool_matrix_from_str   s   z-TestProperties.test_make_bool_matrix_from_strN)r7   r8   r9   rF   rP   rS   rV   r\   r`   r+   ro   rt   rv   rz   r|   r}   r)   r)   r)   r*   r:   :   s    

r:   c                   @      e Zd Zdd ZdS )TestCastingc                 C   s   t ddd}t|}| }t dt jd }|| }t|jj	t jk tt 
||k tt 
||d k | }t dt j}|| }t|jj	t jk tt 
||k d S )Nrp   rI   )rI   rI   rq   )r   r   rW   r   copyonesfloat64r   dtypetyper   
complex128)r    r   r!   rm   OmCr)   r)   r*   r+      s   zTestCasting.test_basicNr7   r8   r9   r+   r)   r)   r)   r*   r          r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestAlgebrac                 C   s&  dd l m} tddgddgg}t|}td}tdD ]}tt|| j	| t
||}q||}td}tdD ]}tt||  j	| t
||}q@tt|| j	t
|| tt|| j	||  ttd| j	d|  t|}|d9 }tt|j	d|  d S )	Nr   ra   rb   rc   rd   r   r   r   )re   rf   r   r   r   identityranger   rg   r   dotrh   )r    rf   r   r!   r"   iAinvmA2r)   r)   r*   r+      s$   


zTestAlgebra.test_basicc                 C   st   t d}| }|dC }| }|dC }| }|dC }t||d  t|t|| tt||td dS )z<Test raising a matrix to an integer power works as expected.z1. 2.; 3. 4.r   N)r   r   r	   r   r   eye)r    mm2mim4r)   r)   r*   test_pow   s   zTestAlgebra.test_powc                 C   sD   t ddgddgg}tjtjfD ]}|d}t|d ||  qd S Nr   r   r   r   )r   r   int8uint8r	   )r    r   scalar_ttwor)   r)   r*   test_scalar_type_pow   s
   z TestAlgebra.test_scalar_type_powc                 C   s|   t ddgddgg}tt d|  W d   n1 sw   Y  tt |t   W d   dS 1 s7w   Y  dS )z:Check that 'not implemented' operations produce a failure.ra   rb   rc   rd   N)r   r
   r2   objectry   r)   r)   r*   test_notimplemented   s   


"zTestAlgebra.test_notimplementedN)r7   r8   r9   r+   r   r   r   r)   r)   r)   r*   r      s
    r   c                   @   r~   )TestMatrixReturnc           
   	   C   s  t dgdd}dddgfdddtdgd	}g d
}t|D ]<}|ds*||v r+qt||}t|tjj	r[|
d |d ||v rJ|| }nd}|| }tt|t u d|  qtt|jt u  tt|jt u  t dg \}}	tt|tju  tt|	tju  d S )Nra   f8)r   )intc)        ra   r   )r   ru   )astypeclipcompressrepeatrW   swapaxesr   ))argminchoosedumpdumpsfillgetfieldgetAgetA1itemnonzeroputputmaskresizesearchsortedsetflagssetfieldsort	partitionargpartitionnewbyteorder	to_devicetaketofiletolisttostringtobytesr   rr   rA   argmaxr   rU   rQ   rx   r_   rY   rL   stdctypesitemsetbitwise_count_r)   z%sr   )r   r   r   dir
startswithgetattr
isinstancecollectionsabcCallabler   r   r   r   realimagr   ndarray)
r    a
methodargsexcluded_methodsattribfargsbcdr)   r)   r*   test_instance_methods  s8   
		



z&TestMatrixReturn.test_instance_methodsN)r7   r8   r9   r   r)   r)   r)   r*   r     r   r   c                   @   r~   )TestIndexingc                 C   sd   t tdt}tdt}g d|d d df< |dk|d d df< t|ddgddgddgg d S )Nr   r   )r   r   )g?g?g333333?r   rw   r   r   r   zerosfloatr   rM   r)   r)   r*   r+   9  s
    zTestIndexing.test_basicNr   r)   r)   r)   r*   r   8  r   r   c                   @   sh   e Zd Zeddgddgg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 )TestNewScalarIndexingr   r   r   r   c                 C   s   | j }|d }t|jd d S )Nr   r   )r   r   ndimr    r   rN   r)   r)   r*   test_dimesionsD  s   z$TestNewScalarIndexing.test_dimesionsc                 C   s(   | j }t||g}t|jg d d S )N)r   r   r   )r   r   r   r   r   r   r)   r)   r*   test_array_from_matrix_listI  s   z1TestNewScalarIndexing.test_array_from_matrix_listc                 C   s$   | j }t| ddgddgg d S r   )r   r   r   r    r   r)   r)   r*   test_array_to_listN  s   z(TestNewScalarIndexing.test_array_to_listc                 C   s   | j }|dg df }tt|t t|tg dg |ddg }tt|t t|tddgddgg |dgdggddgddggf }tt|t t|tddgddgg d S )Nr   )r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   r   r)   r)   r*   test_fancy_indexingR  s    z)TestNewScalarIndexing.test_fancy_indexingc                 C   s   t g dg dg}t|d d t g dg t|d d jd t|d jd t|d d df jd t d}t|d d t|d d t|d d df j|j d S )NrG   rH   r   )r   r   r   r   ru   )r   r   r   rR   r)   r)   r*   test_matrix_element^  s   z)TestNewScalarIndexing.test_matrix_elementc                 C   s*   t tdt}t|d |d d  d S )Nr   ru   r   r   rR   r)   r)   r*   test_scalar_indexingj  s   z*TestNewScalarIndexing.test_scalar_indexingc                 C   s   t td}t|dd d f ddgg t|dd d f ddgg t|d d df dgdgg t|d d df dgdgg d S )Nr   r   r   )r   r   r   r   rR   r)   r)   r*   test_row_column_indexingn  s
   "z.TestNewScalarIndexing.test_row_column_indexingc                 C   st   t d}d|_t|}t|d d t ddgf |d d df  t|t g dd d f |dd d f  d S )Nr   r   TFr   )TFF)r   r   r   r   r   r   r    r   rN   r)   r)   r*   test_boolean_indexingu  
   
,0z+TestNewScalarIndexing.test_boolean_indexingc                 C   st   t d}d|_t|}t|d d ddgf |d d d d df  t|g dd d f |d d dd d f  d S )Nr   r   r   r   r   )r   r   r   )r   r   r   r   r   r   r)   r)   r*   test_list_indexing|  r   z(TestNewScalarIndexing.test_list_indexingN)r7   r8   r9   r   r   r   r   r   r   r   r   r   r   r   r)   r)   r)   r*   r   A  s    r   c                   @   s   e Zd Zdd Zdd ZdS )	TestPowerc                 C   sP   t ddgddgg}ttt|dt ju  t|}ttt|dtu  d S Nr   r   r   )r   r   r   r   r   r   r   r   r   r)   r)   r*   test_returntype  s   zTestPower.test_returntypec                 C   s,   t tddgddggdddgddgg d S r   )r   r   r.   r)   r)   r*   	test_list  s   ,zTestPower.test_listN)r7   r8   r9   r   r   r)   r)   r)   r*   r     s    r   c                   @   sv   e Zd ZedgdggZedgdgg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 )	TestShaper   r   c                 C   s    t | jjd t | jjd d S )Nr   )r   r   r   r   r.   r)   r)   r*   
test_shape  s   zTestShape.test_shapec                 C   s,   t t| jjd t t| jjd d S )Nr   )r   r   ravelr   r   r   r.   r)   r)   r*   test_numpy_ravel  s   zTestShape.test_numpy_ravelc                 C   (   t | j jd t | j jd d S Nr   )r   r   )r   r   r   r   r   r.   r)   r)   r*   test_member_ravel     zTestShape.test_member_ravelc                 C   r   r   )r   r   flattenr   r   r.   r)   r)   r*   test_member_flatten  r   zTestShape.test_member_flattenc                 C   s   t g dg dg}tt |g d tt j|ddg d tt |jg d tt j|jddg d tg dg dg}tt |g d tt j|ddg d tt |jg d tt j|jddg d d S NrG   rH   )r   r   r   r   r   r   F)order)r   r   r   r   r   r   r   )r   r   r   r   r@   r   rR   r)   r)   r*   test_numpy_ravel_order  s   z TestShape.test_numpy_ravel_orderc                 C   st   t g dg dg}t| g dg t|jddg dg t|j g dg t|jjddg dg d S r  )r   r   r   r@   rR   r)   r)   r*   test_matrix_ravel_order  s
   z!TestShape.test_matrix_ravel_orderc                 C   6   t t| j| j  t t| j| j   d S N)r   r   may_share_memoryr   r   r   r.   r)   r)   r*   test_array_memory_sharing     z#TestShape.test_array_memory_sharingc                 C   r  r  )r   r   r  r   r   r   r.   r)   r)   r*   test_matrix_memory_sharing  r
  z$TestShape.test_matrix_memory_sharingc                 C   sH   t ddt j}t j|dd}t|jd tt	|t j  d S )NrI   )r   r   r   r>   r   )
r   r   rW   rX   r   expand_dimsr   r   r   r   )r    r   expandedr)   r)   r*   test_expand_dims_matrix  s   z!TestShape.test_expand_dims_matrixN)r7   r8   r9   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r)   r)   r)   r*   r     s    r   )collections.abcr   numpyr   r   r   r   numpy.testingr   r   r   r   r	   r
   re   r   r   r:   r   r   r   r   r   r   r   r)   r)   r)   r*   <module>   s     / ;*	C