o
    V=ºiÅ/  ã                   @   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 )0zƒTests 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   úlC:\Users\psant\Downloads\PAF backend\school\venv\Lib\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   Z	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
   )r@   rA   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(   ÿÿÿÿrG   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_functionrE   Úcr   r   r   rI   s   s   ûrI   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)rH   ÚcopyÚi4)rK   )r   r   Zastyper   r   r%   ©r'   rE   r   r   r   Útest_array_astype~   s   

rN   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   
ÿrQ   c                  C   r-   r.   )r   r   r1   r   Úmultiplyr3   r   r   r   Útest_object_scalar_multiply™   r7   rS   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 sŠw   Y  t
jdd��G}t
 d	¡ || dd�}tt|t jƒƒ tt  |d
 ¡oÀt  |d ¡ oÀt  |d ¡ ƒ tt|ƒdkdƒ tt|d jtƒƒ W d   ƒ n1 sßw   Y  t
jdd��'}t
 d	¡ || ƒ}tt  |¡ƒ t|t j	kƒ tt|ƒdkƒ W d   ƒ qQ1 �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   rC   ÚisscalarÚnanÚwarningsÚcatch_warningsÚsimplefilterÚanyÚisnanÚlenÚ
issubclassÚcategoryÚRuntimeWarning)ÚmatÚfr   Úwr   r   r   Útest_nanfunctions_matrices¢   sJ   

û
 ÿù	
 ûïrg   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!   rT   r	   rU   )r   r   )r	   r9   )r   r   rX   Z	nanargminZ	nanargmaxZnansumZnanprodZnanmeanZnanvarZnanstdr   r   rC   rY   Z	nancumsumZ
nancumprod)rd   re   r   r   r   r   Ú"test_nanfunctions_matrices_generalË   s.   ÿ÷rh   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'   rf   Úrr   r   r   Útest_average_matrixç   s   rn   c                  C   sN   t  dd¡} | |  }t  || ¡}t  | ¡}t  |¡}t  ||¡}t||ƒ d S )Nr   r   )r   ZlinspaceZtrapzr   r   )r   rl   rm   ZmxZmyÚmrr   r   r   Útest_trapz_matrixô   s   

rp   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   $rq   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   )rt   r   r)   Úresultr   r   r   Útest_apply_along_axis_matrix  s   
rv   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 rr   )r   Zonesr   r   r%   ZkronrB   r   )r'   r   r   r   r   Útest_kron_matrix  s   
rw   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   rm   rJ   )r	   r
   r   r   c                      s   t jdˆ ˆf S )NÚrc)r   Úr_r   rM   r   r   Ú<lambda>2  s    z4TestConcatenatorMatrix.test_matrix.<locals>.<lambda>)r   rz   r   r%   r   r   r   rO   )ÚselfZab_rZab_cr   rM   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 )Nrm   r	   r
   r   )r	   r
   r   )r   rz   r   r%   r   r   )r|   rm   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   rz   Zbmatr   r%   )r|   r'   rE   rJ   Údr(   r)   r   r   r   Útest_matrix_builder9  s   

z*TestConcatenatorMatrix.test_matrix_builderN)Ú__name__Ú
__module__Ú__qualname__r}   r~   r€   r   r   r   r   rx   #  s    rx   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   rZ   Ú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[   Znumpyr   Znumpy.testingr   r   r   r   r   r   r   r   r   r*   r,   r6   r=   r>   rG   rI   rN   rQ   rS   rg   rh   rn   rp   rq   rv   rw   rx   rŒ   r�   r   r   r   r   Ú<module>   s8    $
	
	
		)
"