U
    O8cc.                     @   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   J/tmp/pip-unpacked-wheel-fd_gsd75/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   Z	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   r8   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(    rC   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_functionrA   cr   r   r   rE   s   s    rE   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)rD   copyi4)rG   )r   r   Zastyper   r   r$   r&   rA   r   r   r   test_array_astype~   s    

rJ   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
     rM   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    rO   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    


$
rc   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!   rP   r	   rQ   )r   r   )r	   r6   )r   r   rT   Z	nanargminZ	nanargmaxZnansumZnanprodZnanmeanZnanvarZnanstdr   r   r?   rU   Z	nancumsumZ
nancumprod)r`   ra   r   r   r   r   "test_nanfunctions_matrices_general   s0      rd   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&   rb   rr   r   r   test_average_matrix   s    ri   c                  C   sN   t dd} | |  }t || }t | }t |}t ||}t|| d S )Nr   r   )r   ZlinspaceZtrapzr   r   )r   rg   rh   ZmxZmymrr   r   r   test_trapz_matrix   s    

rk   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    rm   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   )rp   r   r(   resultr   r   r   test_apply_along_axis_matrix  s    
rr   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 rn   )r   Zonesr   r   r$   Zkronr>   r   )r&   r   r   r   r   test_kron_matrix  s    
rs   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   rh   rF   c                      s   t jd f S )Nrc)r   r_r   rI   r   r   <lambda>2      z4TestConcatenatorMatrix.test_matrix.<locals>.<lambda>)r   rv   r   r$   r   r   r   rK   )selfZab_rZab_cr   rI   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 )Nrh   r	   r
   r   )r   rv   r   r$   r   r   )ry   rh   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   rv   Zbmatr   r$   )ry   r&   rA   rF   dr'   r(   r   r   r   test_matrix_builder9  s    

z*TestConcatenatorMatrix.test_matrix_builderN)__name__
__module____qualname__rz   r{   r}   r   r   r   r   rt   #  s   rt   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raisesrl   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   rV   infr   r   r   )m1m2Zm3Zm4Zm5Zassert_funcr   r&   r   r   r   test_array_almost_equal_matrixT  s    


r   )$__doc__r   r   rW   Znumpyr   Znumpy.testingr   r   r   r   r   r   r   r   r   r)   r+   r4   r:   r;   rC   rE   rJ   rM   rO   rc   rd   ri   rk   rm   rr   rs   rt   r   r   r   r   r   r   <module>   s6   $
	
	
		)
"