U
    9%ec.                     @   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| dddg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   2      
   )
npmatrixr   
isinstanceasmatrixarangereshaper   arrayT)mx r   e/var/www/html/Darija-Ai-API/env/lib/python3.8/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   sR   t dddgg} t j| d d}t dddgg}t|| tt|t jk d S Nr
   r	   r   axis)r   r   sortr   r   typeaactualexpectedr   r   r   test_sort_matrix_none)   s
    
r)   c                  C   sT   t dddgg} t j| dd d}t dddgg}t|| tt|t jk d S r    )r   r   	partitionr   r   r$   r%   r   r   r   test_partition_matrix_none2   s
    
r+   c                  C   sN   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<   s    r4   c                  C   s   t jd t jd  d D ]n} 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   r.   	      )r   	typecodesr   r   r   inner)dtZscar2   r3   r   r   r   test_inner_scalar_and_matrixE   s    r;   c                  C   sN   t jddgtd} t jddggtd}tt | d| tt d| | d S r,   )r   r   r/   r   r9   r1   r   r   r   'test_inner_scalar_and_matrix_of_objectsO   s    r<   c               	   C   s2  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k tt|jd t j	k	 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ddd	gg}tt|jd t j	k tt|jd t jk	 t
|jd jd
 d S )Nr	   r
   r   r   readonlyZ	writeonlyallocate)r
   r
   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(    rD   c                  C   sh   t ddgddgg} t jt jt jfD ]<}|| }tt|t jk || dd}tt|t jk	 q&d S )Nr	   r
   r   r   F)subok)r   r   Z
zeros_likeZ	ones_likeZ
empty_liker   r$   )r&   like_functionrB   cr   r   r   rF   s   s    rF   c                  C   s   t jdddgdddggdd} | jdd	d
d}t| |k | jdd
d}t| | tt|t j | jdd
d
d}t| | t| |k	 tt|t jk	 d S )Nr   r	   r
   r   r   r   Zf4r-   TF)rE   copyi4)rH   )r   r   Zastyper   r   r$   r&   rB   r   r   r   test_array_astype~   s    

rK   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
     rN   c                  C   sN   t jddgtd} t jddggtd}tt | d| tt d| | d S r,   )r   r   r/   r   multiplyr1   r   r   r   test_object_scalar_multiply   s    rP   c               
   C   s  t t d} t jt jfD ]n}|| 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 ]X}t
jddR}t
d	 || dd}tt|t j tt t |  tt|dk W 5 Q R X t
jdd}t
d	 || dd}tt|t j tt |d
 ort |d  ort |d   tt|dkd tt|d jt W 5 Q R X t
jddD}t
d	 || }tt | t|t j	k tt|dk W 5 Q R X qd 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   r@   isscalarnanwarningscatch_warningssimplefilteranyisnanlen
issubclasscategoryRuntimeWarning)matfr   wr   r   r   test_nanfunctions_matrices   sB    


$
rd   c                  C   s0  t t d} t jt jt jt jt jt jt j	fD ]n}|| dd}t
t|t j t
|jdk || dd}t
t|t j t
|jdk || }t
t | q0t 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 qd S )	Nr   r   r!   rQ   r	   rR   )r   r   )r	   r6   )r   r   rU   Z	nanargminZ	nanargmaxZnansumZnanprodZnanmeanZnanvarZnanstdr   r   r@   rV   Z	nancumsumZ
nancumprod)ra   rb   r   r   r   r   "test_nanfunctions_matrices_general   s0      re   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   ZmeanZaverager   r$   )yr&   rc   rr   r   r   test_average_matrix   s    rj   c                  C   sN   t dd} | |  }t || }t | }t |}t ||}t|| d S )Nr   r   )r   ZlinspaceZtrapzr   r   )r   rh   ri   ZmxZmymrr   r   r   test_trapz_matrix   s    

rl   c                   C   s@   t ttdtjstt tjtdddtjs<td S )Nr	   )Zto_begin)r   r   Zediff1dr   AssertionErrorr   r   r   r   test_ediff1d_matrix   s    rn   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   r.   )r   r   Zapply_along_axisr   r   r   )rq   r   r(   resultr   r   r   test_apply_along_axis_matrix  s    
rs   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 ro   )r   Zonesr   r   r$   Zkronr?   r   )r&   r   r   r   r   test_kron_matrix  s    
rt   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 |ddddgg tt |dgdgdgdgg tt fdd d S )	Nr	   r
   r   r   ri   rG   c                      s   t jd f S )Nrc)r   r_r   rJ   r   r   <lambda>2      z4TestConcatenatorMatrix.test_matrix.<locals>.<lambda>)r   rw   r   r$   r   r   r   rL   )selfZab_rZab_cr   rJ   r   test_matrix%  s     z"TestConcatenatorMatrix.test_matrixc                 C   s@   t jdddgdf }tt|t j tt |dddgg d S )Nri   r	   r
   r   )r   rw   r   r$   r   r   )rz   ri   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   rw   Zbmatr   r$   )rz   r&   rB   rG   dr'   r(   r   r   r   test_matrix_builder9  s    

z*TestConcatenatorMatrix.test_matrix_builderN)__name__
__module____qualname__r{   r|   r~   r   r   r   r   ru   #  s   ru   c               	   C   sV   t t$} ttddgtddg W 5 Q R X 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raisesrm   r   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~qld S )Ng      ?g       @)r   r   rW   infr   r   r   )m1m2Zm3Zm4Zm5Zassert_funcr   r&   r   r   r   test_array_almost_equal_matrixT  s    


r   )$__doc__r   r   rX   numpyr   Znumpy.testingr   r   r   r   r   r   r   r   r   r)   r+   r4   r;   r<   rD   rF   rK   rN   rP   rd   re   rj   rl   rn   rs   rt   ru   r   r   r   r   r   r   <module>   s6   $
	
	
		)
"