o 6ac.@sdZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddZddZdd Zd d Zd d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Z Gd*d+d+Z!d,d-Z"d.d/Z#dS)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_raisesassert_raises_regexassert_array_equalassert_almost_equalassert_array_almost_equalcCs|tddgddgg}tt|gdddftjttddd}t|ddtd f|ddd fj dS) N)rr r2 ) npmatrixr isinstanceasmatrixarangereshaperarrayT)mxrH/usr/lib/python3/dist-packages/numpy/matrixlib/tests/test_interaction.pytest_fancy_indexings .rcCsDddg}ddg}t||g}tjj|||}tt|tjdS)Nrr r r )rr polynomial polyutils mapdomainrr)dom1dom2rresrrrtest_polynomial_mapdomains r$cCsNtgdg}tj|dd}tgdg}t||tt|tjudS)Nr r raxisrr r )rrsortrrtypeaactualexpectedrrrtest_sort_matrix_none)s  r/cCsPtgdg}tj|ddd}tgdg}t||tt|tjudS)Nr%r r&r()rr partitionrrr*r+rrrtest_partition_matrix_none2s  r1cCNtjddgtd}tjddggtd}tt|d|ttd||dSNr r dtyper )rrobjectrdotarrdesiredrrr%test_dot_scalar_and_matrix_of_objects<r<cCstjdtjddD]7}tjd|dd}tjddgdd gg|d}tjdd gd d gg|d}tt|||tt|||q dS) N AllIntegerAllFloat?r r4rr r r r6 )r typecodesrrrinner)dtscar:r;rrrtest_inner_scalar_and_matrixEsrGcCr2r3)rrr7rrDr9rrr'test_inner_scalar_and_matrix_of_objectsOr=rHc Cs0tddgddgg}tdddj}t||dggdgdgddgg}tt|jdtjutt|jdtj ut |jdj dtdddd}t t tj||dggdgdgddggt||dggdgdggd g}tt|jdtj utt|jdtjut |jdj d dS) Nr r r r readonly writeonlyallocate)r r )rJrK no_subtype)r r r )rrrrrnditerrr*operandsndarrayrshaper RuntimeError)r,birrr!test_iter_allocate_output_subtypeXs(rTcCshtddgddgg}tjtjtjfD]}||}tt|tju||dd}tt|tjuqdS)Nr r r r F)subok)rr zeros_like ones_like empty_likerr*)r, like_functionrRcrrrrYss rYcCstjgdgdgdd}|jdddd}t||u|jddd }t||tt|tj|jdddd}t||t||utt|tjudS) Nr()r r rf4r4TF)rUcopyi4)r\)rrastyperrr*r,rRrrrtest_array_astype~s    r`cCs.tddgddgg}ttdtj||gdS)Nr r r r zshape too large to be a matrix)rrr ValueErrorstack)rrrr test_stacks rccCr2r3)rrr7rmultiplyr9rrrtest_object_scalar_multiplyr=rec Cs:ttd}tjtjfD]7}||dd}tt|tjt|jdk||dd}tt|tjt|jdk||}tt|qtj |d<tjtjfD]}t j dd.}t d ||dd}tt|tjtt t| tt|dkWdn1swYt j ddG}t d ||dd}tt|tjtt|d ot|d  ot|d  tt|dkd tt|djtWdn1swYt j dd'}t d ||}tt|t|tj ktt|dkWdn 1swYqQdS)Nr rr&r r r r r T)recordalways)r r)rr)r rzno warning raised)rreyenanminnanmaxrrrPisscalarnanwarningscatch_warnings simplefilteranyisnanlen issubclasscategoryRuntimeWarning)matfr#wrrrtest_nanfunctions_matricessL         r{cCs0ttd}tjtjtjtjtjtjtj fD]7}||dd}t t |tjt |j dk||dd}t t |tjt |j dk||}t t |qtjtjfD]?}||dd}t t |tjt |j dk||dd}t t |tjt |j dk||}t t |tjt |j dkqVdS) Nr rr&rfr rg)r r )r rA)rrrj nanargmin nanargmaxnansumnanprodnanmeannanvarnanstdrrrPrm nancumsum nancumprod)rxryr#rrr"test_nanfunctions_matrices_generals.     rcCsttjdd}t|dt|dtddgddgg}tddgddgg}tj|d|d}tt|tjt|dd ggdS) Nrrr r r r )r'weightsg@g @) rrrandomrandrmeanaveragerr*)yr,rzrrrrtest_average_matrixsrcCsNtdd}||}t||}t|}t|}t||}t||dS)Nrr)rlinspacetrapzrr)rrrmxmymrrrrtest_trapz_matrixs     rcCs@tttdtjsJttjtdddtjsJdS)Nr )to_begin)rrediff1drrrrrtest_ediff1d_matrixs$rcCsdd}tddgddgg}tddgddgg}t|d|}tt|tjt||t|d|}tt|tjt||dS) NcSs|dSNr r)rowrrrdouble sz,test_apply_along_axis_matrix..doublerr r r r r6)rrapply_along_axisrrr)rrr.resultrrrtest_apply_along_axis_matrixs rcCs|tddg}t|}ttt||tjttt||tjttt||tjttt||tjdSr)ronesrrr*kronrOr)r,rrrrtest_kron_matrixs  rc@s$eZdZddZddZddZdS)TestConcatenatorMatrixcsddgddgtjdf}tjdf}tt|tjtt|tjtt|gdgtt|dgdgdgdggttfdd dS) Nr r r r rrZ)r r r r cstjdfS)Nrc)rr_rr_rr2sz4TestConcatenatorMatrix.test_matrix..)rrrr*rrrra)selfab_rab_crr_r test_matrix%s z"TestConcatenatorMatrix.test_matrixcCs>tjdddgdf}tt|tjtt|gdgdS)Nrr r r )r r r )rrrr*rr)rrrrrtest_matrix_scalar4sz)TestConcatenatorMatrix.test_matrix_scalarcCsptdg}tdg}tdg}tdg}tjd}t||g||gg}t||tt|t|dS)Nr r r r z a, b; c, d)rrrbmatrr*)rr,rRrZdr-r.rrrtest_matrix_builder9s      z*TestConcatenatorMatrix.test_matrix_builderN)__name__ __module__ __qualname__rrrrrrrr#s rcCsjtt}ttddgtddgWdn1swYt|j}t d}t||dS)Nr r zl Arrays are not equal (shapes (2,), (1, 2) mismatch) x: array([1, 2]) y: matrix([[1, 2]])) pytestraisesAssertionErrorrrrrstrvaluetextwrapdedent)exc_infomsg msg_referencerrr%test_array_equal_error_message_matrixEs    rcCstddgg}tdtjgg}tdtj gg}ttjtjgg}tddgtjtjgg}ttfD] }|||||fD]}|||t|}||||||q?q6dS)Ng?g@)rrrninfrrr)m1m2m3m4m5 assert_funcrr,rrrtest_array_almost_equal_matrixTs     r)$__doc__rrronumpyr numpy.testingrrrrrrrrr$r/r1r<rGrHrTrYr`rcrer{rrrrrrrrrrrrrs8$        )   "