o
    gw.                     @   s  d Z ddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZm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$d% Zd&d' Zd(d) Z G d*d+ d+Z!d,d- Z"d.d/ Z#dS )0zTests of interaction of matrix with other parts of numpy.

Note that tests with MaskedArray and linalg are done in separate files.
    N)assert_assert_equalassert_raisesassert_raises_regexassert_array_equalassert_almost_equalassert_array_almost_equalc                  C   s|   t ddgddgg} tt| g dd d f t j t t ddd}t|d dt d	f |d dd	f j	 d S )
N            )r   r	   r   2      
   )
npmatrixr   
isinstanceasmatrixarangereshaper   arrayT)mx r   `/var/www/html/api-tag/env/lib/python3.10/site-packages/numpy/matrixlib/tests/test_interaction.pytest_fancy_indexing   s    .r   c                  C   sD   ddg} ddg}t | | g}t jj|| |}tt|t j d S )Nr   r   r	   r   )r   r   
polynomial	polyutils	mapdomainr   r   )dom1dom2r   resr   r   r   test_polynomial_mapdomain   s
   r$   c                  C   sN   t g dg} t j| d d}t g dg}t|| tt|t ju  d S )Nr
   r	   r   axisr   r	   r
   )r   r   sortr   r   typeaactualexpectedr   r   r   test_sort_matrix_none)   s
   
r/   c                  C   sP   t g dg} t j| dd d}t g dg}t|| tt|t ju  d S )Nr%   r	   r&   r(   )r   r   	partitionr   r   r*   r+   r   r   r   test_partition_matrix_none2   s
   
r1   c                  C   N   t jddgtd} t jddggtd}tt | d| tt d| | d S Nr	   r
   dtyper      )r   r   objectr   dotarrdesiredr   r   r   %test_dot_scalar_and_matrix_of_objects<      r<   c                  C   s   t jd t jd  d D ]7} t jd| dd }t jddgdd	gg| d}t jdd
gddgg| d}tt ||| tt ||| qd S )N
AllIntegerAllFloat?r   r4   r   r	   r
   r   r6   	      )r   	typecodesr   r   r   inner)dtscar:   r;   r   r   r   test_inner_scalar_and_matrixE   s   rG   c                  C   r2   r3   )r   r   r7   r   rD   r9   r   r   r   'test_inner_scalar_and_matrix_of_objectsO   r=   rH   c               	   C   s0  t ddgddgg} t dddj}t | |d gg dgdgddgg}tt|jd t ju  tt|jd t j	u t
|jd jd t dddd}ttt j| |d gg dgdgddgg t | |d gg dgdgg d	g}tt|jd t j	u  tt|jd t ju t
|jd jd
 d S )Nr	   r
   r   r   readonly	writeonlyallocate)r
   r
   )rJ   rK   
no_subtype)r	   r
   r
   )r   r   r   r   r   nditerr   r*   operandsndarrayr   shaper   RuntimeError)r,   bir   r   r   !test_iter_allocate_output_subtypeX   s(   rT   c                  C   sh   t ddgddgg} t jt jt jfD ]}|| }tt|t ju  || dd}tt|t ju qd S )Nr	   r
   r   r   F)subok)r   r   
zeros_like	ones_like
empty_liker   r*   )r,   like_functionrR   cr   r   r   rY   s   s   rY   c                  C   s   t jg dg dgdd} | jdddd}t| |u  | jddd	}t| | tt|t j | jdddd}t| | t| |u tt|t ju d S )
Nr(   )r   r   r   f4r4   TF)rU   copyi4)r\   )r   r   astyper   r   r*   r,   rR   r   r   r   test_array_astype~   s   

r`   c                  C   s.   t ddgddgg} ttdt j| | g d S )Nr	   r
   r   r   zshape too large to be a matrix)r   r   r   
ValueErrorstack)r   r   r   r   
test_stack   s   
rc   c                  C   r2   r3   )r   r   r7   r   multiplyr9   r   r   r   test_object_scalar_multiply   r=   re   c               	   C   s:  t t d} t jt jfD ]7}|| dd}tt|t j t|jdk || dd}tt|t j t|jdk || }tt | qt j	| d< t jt jfD ]}t
jdd.}t
d	 || dd}tt|t j tt t |  tt|dk W d    n1 sw   Y  t
jddG}t
d	 || dd}tt|t j tt |d
 ot |d  ot |d   tt|dkd tt|d jt W d    n1 sw   Y  t
jdd'}t
d	 || }tt | t|t j	k tt|dk W d    n	1 sw   Y  qQd S )Nr   r   r&   r	   r   r	   r   r	   T)recordalways)r	   r   )r   r   )r
   r   zno warning raised)r   r   eyenanminnanmaxr   r   rP   isscalarnanwarningscatch_warningssimplefilteranyisnanlen
issubclasscategoryRuntimeWarning)matfr#   wr   r   r   test_nanfunctions_matrices   sL   


 	
r{   c                  C   s0  t t d} t jt jt jt jt jt jt j	fD ]7}|| dd}t
t|t j t
|jdk || dd}t
t|t j t
|jdk || }t
t | qt jt jfD ]?}|| dd}t
t|t j t
|jdk || dd}t
t|t j t
|jdk || }t
t|t j t
|jdk qVd S )	Nr   r   r&   rf   r	   rg   )r   r   )r	   rA   )r   r   rj   	nanargmin	nanargmaxnansumnanprodnanmeannanvarnanstdr   r   rP   rm   	nancumsum
nancumprod)rx   ry   r#   r   r   r   "test_nanfunctions_matrices_general   s.   r   c                  C   s   t t jdd} t| dt | d t ddgddgg}t ddgddgg}t j|d|d}tt|t j t|dd	gg d S )
Nr   r   r	   r
   r   r   )r'   weightsg      @g
@)	r   r   randomrandr   meanaverager   r*   )yr,   rz   rr   r   r   test_average_matrix   s   r   c                  C   sT   t dd} t dd}t | }t |}t | |}t ||j}t|| d S )Nr   r   )r   linspacer   r8   r   r   )r   r   mxmyr   mrr   r   r   test_dot_matrix   s   

r   c                   C   s@   t ttdtjsJ t tjtdddtjsJ d S )Nr	   )to_begin)r   r   ediff1dr   r   r   r   r   test_ediff1d_matrix   s   $r   c                  C   s   dd } t ddgddgg}t ddgddgg}t | d|}tt|t j t|| t | d|}tt|t j t|| d S )	Nc                 S   s   | d S Nr
   r   )rowr   r   r   double
  s   z,test_apply_along_axis_matrix.<locals>.doubler   r	   r
   r   r   r6   )r   r   apply_along_axisr   r   r   )r   r   r.   resultr   r   r   test_apply_along_axis_matrix  s   
r   c                  C   s|   t ddg} t | }ttt | | t j ttt ||t j ttt | |t j ttt || t j d S r   )r   onesr   r   r*   kronrO   r   )r,   r   r   r   r   test_kron_matrix  s   
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestConcatenatorMatrixc                    s   ddg ddgt jd f }t jd f }tt|t j tt|t j tt |g dg tt |dgdgdgdgg tt fdd	 d S )
Nr	   r
   r   r   r   rZ   )r	   r
   r   r   c                      s   t jd f S )Nrc)r   r_r   r_   r   r   <lambda>2  s    z4TestConcatenatorMatrix.test_matrix.<locals>.<lambda>)r   r   r   r*   r   r   r   ra   )selfab_rab_cr   r_   r   test_matrix%  s    z"TestConcatenatorMatrix.test_matrixc                 C   s>   t jdddgdf }tt|t j tt |g dg d S )Nr   r	   r
   r   )r	   r
   r   )r   r   r   r*   r   r   )r   r   r   r   r   test_matrix_scalar4  s   z)TestConcatenatorMatrix.test_matrix_scalarc                 C   sp   t dg}t dg}t dg}t dg}t jd }t ||g||gg}t|| tt|t| d S )Nr	   r
   r   r   z
a, b; c, d)r   r   r   bmatr   r*   )r   r,   rR   rZ   dr-   r.   r   r   r   test_matrix_builder9  s   

z*TestConcatenatorMatrix.test_matrix_builderN)__name__
__module____qualname__r   r   r   r   r   r   r   r   #  s    r   c                  C   sj   t t} ttddgtddg W d    n1 sw   Y  t| j}t	
d}t|| d S )Nr	   r
   zw
    Arrays are not equal

    (shapes (2,), (1, 2) mismatch)
     ACTUAL: array([1, 2])
     DESIRED: matrix([[1, 2]]))pytestraisesAssertionErrorr   r   r   r   strvaluetextwrapdedent)exc_infomsgmsg_referencer   r   r   %test_array_equal_error_message_matrixE  s    

r   c                  C   s   t ddgg} t dt jgg}t dt j gg}t t jt jgg}t ddgt jt jgg}ttfD ] }| ||||fD ]}||| t |}||| ||| q?q6d S )Ng      ?g       @)r   r   rn   infr   r   r   )m1m2m3m4m5assert_funcr   r,   r   r   r   test_array_almost_equal_matrixT  s   


r   )$__doc__r   r   ro   numpyr   numpy.testingr   r   r   r   r   r   r   r   r$   r/   r1   r<   rG   rH   rT   rY   r`   rc   re   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s8    $
	
	
		)
"