o 6a:@sddlZddlZddlmZmZmZddlmZm Z m Z m Z m Z m Z ddlmZddlmZGdddZGdd d ZGd d d ZGd d d ZGdddZGdddZGdddZGdddZGdddZdS)N)matrixasmatrixbmat)assert_ assert_equalassert_almost_equalassert_array_equalassert_array_almost_equal assert_raises) matrix_power)matc@s$eZdZddZddZddZdS)TestCtorc Cstddgddgg}t|}tt|j|ktd}t||g||gg}tgdgdgdgdg}tt|j|ktt|j|ktdd gd d gg}tgd gd g}ttt||g|ktd}t|} t| jdkdS)NA,A;A,Arrrrrrrrrrrrrrrr)rr) nparrayrrallArarangeshape) selfrmABCDEAEresultvecmvecr*F/usr/lib/python3/dist-packages/numpy/matrixlib/tests/test_defmatrix.py test_basic s$  zTestCtor.test_basiccCstttddS)Ninvalid)r ValueErrorrr!r*r*r+test_exceptions#szTestCtor.test_exceptionscCs tddgddgg}tddgddgg}tgd gd gd gd g}tgd gd gd gdg}tttd|ktttdd|id|ktttdd|idtttdd|id|id|ktd||d||dd}tt||kdS)Nrrrrrrrrrrrr)rrrr)rrrrrr)ldict)gdict)r1r2zA,B;C,D)rr#)r$r%)rrrrrr TypeError)r!rr#Aresult mixresultb2r*r*r+test_bmat_nondefault_str's(  z!TestCtor.test_bmat_nondefault_strN)__name__ __module__ __qualname__r,r0r7r*r*r*r+r s r c@steZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZdS)TestPropertiescCstgdgdgdgdg}tgd}tgdj}d}t||jdd t||jd d t||t|tj|dd t|tj|d d t|t|d S) zeTest whether matrix.sum(axis=1) preserves orientation. Fails in NumPy <= 0.9.6.2127. )rrrr)rrrrrr)r rr)rrrraxisrN)rTrsumrr)r!Msum0sum1sumallr*r*r+test_sum<s zTestProperties.test_sumcCstgdgdg}t|dt|dtgdgt|dtdgdggtt|dttj|dd tgdgttj|dd tdgdggtgd }t|dkdS) Nrrrrrrir)r rrxr?)rrr)rrprodrrr!xyr*r*r+ test_prodOs  zTestProperties.test_prodcCstgdgdg}t|dt|dtgdgt|dtdgdggtt|dttj|ddtgdgttj|ddtdgdggdS)NrHrIrrrrr?)rrmaxrr!rOr*r*r+test_max\$zTestProperties.test_maxcCstgdgdg}t|dt|dtgdgt|dtdgdggtt|dttj|ddtgdgttj|ddtdgdggdS)NrHrIrrrr?)rrminrrSr*r*r+test_minfrUzTestProperties.test_mincCshtdd}t|dktt|dtddgktt|dtddgkdS)Nr)rrrrrr)rrreshaperptprrrSr*r*r+test_ptpps"&zTestProperties.test_ptpcCsTtdd}|tj}t|jdd|jddt|jdd|jdddS)N )rrr)ddofr)rrrXviewrrvar)r!rOmxr*r*r+test_varvs zTestProperties.test_varcCs ddlm}tddgddgg}t|}tt|||jtt tt ||j ktt tt ||j ktt ||j k|d|}t|}tt|||jtt tt ||j ktt tt ||j kdS)Nr?@@@y@) numpy.linalglinalgrrrrallcloseinvIr transposerAHrconj)r!rfrr"r#mBr*r*r+r,|s      (zTestProperties.test_basiccCs@ttddd}tddgddgdd gg}t|j|dS) Nrrrg:gn)t?g#qg#q?gn)t?g6Bq)rrrrXrri)r!rOxpinvr*r*r+ test_pinvs zTestProperties.test_pinvcCsrtddd}t|}t|d}tt||dktt|t|dktt|t|dk tt||ktt||ktt||ktt||k tt||k tt||ktt||ktt||k tt||ktt||k tt||kttt|dk ttt|dkdS)NdrJ皙?r)rrrXrrranyabs)r!rr"rmr*r*r+test_comparisonss& zTestProperties.test_comparisonscCs:tddd}t|}d|d<t|d|dkdS)NrprJirr)rrrXrr)r!rr"r*r*r+ test_asmatrixszTestProperties.test_asmatrixcCs@tddgddgg}t|tdkt|tdkdS)Nrrr?)rrrBmeanr!rr*r*r+ test_noaxisszTestProperties.test_noaxiscCs(tddgddgg}tt|dkdS)Nrrz matrix([[1, 0], [0, 1]]))rrreprryr*r*r+ test_reprszTestProperties.test_reprcCs*td}tdgdgdgg}t||dS)NzTrue; True; FalseTF)rr)r!rr#r*r*r+test_make_bool_matrix_from_strsz-TestProperties.test_make_bool_matrix_from_strN)r8r9r:rGrQrTrWrZr`r,rortrvrzr|r}r*r*r*r+r;;s    r;c@eZdZddZdS) TestCastingcCstddd}t|}|}tdtjd}||}t|jj tjktt ||ktt ||dk|}tdtj }||}t|jj tj ktt ||kdS)NrprJ)rJrJrq) rrrXrcopyonesfloat64rdtypetyper complex128)r!rr"rmOmCr*r*r+r,szTestCasting.test_basicNr8r9r:r,r*r*r*r+r rc@s,eZdZddZddZddZddZd S) TestAlgebracCs&ddlm}tddgddgg}t|}td}tdD]}tt||j |t ||}q| |}td}tdD]}tt|| j |t ||}q@tt||j t ||tt||j ||ttd|j d|t|}|d9}tt|j d|dS) Nrrarbrcrdrrr) rerfrrridentityrangerrgrdotrh)r!rfrr"r#iAinvmA2r*r*r+r,s$      zTestAlgebra.test_basiccCsttd}|}|dC}|}|dC}|}|dC}t||dt|t||tt||tddS)zs    /;* C