o
    Jec.                     @   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   t/home/seandotau/au.memorygallery.club/gallery/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   Z
polynomialZ	polyutilsZ	mapdomainr   r   )Zdom1Z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
   
r,   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
   Zdtyper      )r   r   objectr   dotarrdesiredr   r   r   %test_dot_scalar_and_matrix_of_objects<      r6   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 )NZ
AllIntegerZAllFloat?r   r/   r   r	   r
   r   r0   	      )r   	typecodesr   r   r   inner)dtZscar4   r5   r   r   r   test_inner_scalar_and_matrixE   s   r>   c                  C   r-   r.   )r   r   r1   r   r<   r3   r   r   r   'test_inner_scalar_and_matrix_of_objectsO   r7   r?   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
   )rA   rB   Z
no_subtype)r	   r
   r
   )r   r   r   r   r   Znditerr   r%   Zoperandsndarrayr   shaper   RuntimeError)r'   bir   r   r   !test_iter_allocate_output_subtypeX   s(   rH   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   Z
zeros_likeZ	ones_likeZ
empty_liker   r%   )r'   like_functionrF   cr   r   r   rJ   s   s   rJ   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   Zf4r/   TF)rI   copyi4)rL   )r   r   Zastyper   r   r%   r'   rF   r   r   r   test_array_astype~   s   

rO   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   
rR   c                  C   r-   r.   )r   r   r1   r   multiplyr3   r   r   r   test_object_scalar_multiply   r7   rT   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   eyeZnanminZnanmaxr   r   rD   isscalarnanwarningscatch_warningssimplefilteranyisnanlen
issubclasscategoryRuntimeWarning)matfr   wr   r   r   test_nanfunctions_matrices   sL   


 	
rh   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!   rU   r	   rV   )r   r   )r	   r9   )r   r   rY   Z	nanargminZ	nanargmaxZnansumZnanprodZnanmeanZnanvarZnanstdr   r   rD   rZ   Z	nancumsumZ
nancumprod)re   rf   r   r   r   r   "test_nanfunctions_matrices_general   s.   ri   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   randomZrandr   meanZaverager   r%   )yr'   rg   rr   r   r   test_average_matrix   s   ro   c                  C   sN   t dd} | |  }t || }t | }t |}t ||}t|| d S )Nr   r   )r   ZlinspaceZtrapzr   r   )r   rm   rn   ZmxZmymrr   r   r   test_trapz_matrix   s   

rq   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	   )Zto_begin)r   r   Zediff1dr   r   r   r   r   test_ediff1d_matrix   s   $rr   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   r0   )r   r   Zapply_along_axisr   r   r   )ru   r   r)   resultr   r   r   test_apply_along_axis_matrix  s   
rw   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 rs   )r   Zonesr   r   r%   ZkronrC   r   )r'   r   r   r   r   test_kron_matrix  s   
rx   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   rn   rK   )r	   r
   r   r   c                      s   t jd f S )Nrc)r   r_r   rN   r   r   <lambda>2  s    z4TestConcatenatorMatrix.test_matrix.<locals>.<lambda>)r   r{   r   r%   r   r   r   rP   )selfZab_rZab_cr   rN   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 )Nrn   r	   r
   r   )r	   r
   r   )r   r{   r   r%   r   r   )r}   rn   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{   Zbmatr   r%   )r}   r'   rF   rK   dr(   r)   r   r   r   test_matrix_builder9  s   

z*TestConcatenatorMatrix.test_matrix_builderN)__name__
__module____qualname__r~   r   r   r   r   r   r   ry   #  s    ry   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
   zl
    Arrays are not equal

    (shapes (2,), (1, 2) mismatch)
     x: array([1, 2])
     y: matrix([[1, 2]]))pytestZraisesAssertionErrorr   r   r   r   strvaluetextwrapdedent)exc_infomsgZ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   r[   infr   r   r   )m1m2Zm3Zm4Zm5Zassert_funcr   r'   r   r   r   test_array_almost_equal_matrixT  s   


r   )$__doc__r   r   r\   numpyr   Znumpy.testingr   r   r   r   r   r   r   r   r   r*   r,   r6   r>   r?   rH   rJ   rO   rR   rT   rh   ri   ro   rq   rr   rw   rx   ry   r   r   r   r   r   r   <module>   s8    $
	
	
		)
"