#NEWLINE# def verify_polar( a ) : #NEWLINE# #INDENT# product_atol = np . sqrt ( np . finfo ( float ) . eps ) #NEWLINE# aa = np . asarray ( a ) #NEWLINE# ( m , n ) = aa . shape #NEWLINE# ( u , p ) = polar ( a , side = 'right' ) #NEWLINE# assert_equal ( u . shape , ( m , n ) ) #NEWLINE# assert_equal ( p . shape , ( n , n ) ) #NEWLINE# assert_allclose ( u . dot ( p ) , a , atol = product_atol ) #NEWLINE# if ( m >= n ) : #NEWLINE# #INDENT# assert_allclose ( u . conj ( ) . T . dot ( u ) , np . eye ( n ) , atol = 1e-15 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_allclose ( u . dot ( u . conj ( ) . T ) , np . eye ( m ) , atol = 1e-15 ) #NEWLINE# #UNINDENT# assert_allclose ( p . conj ( ) . T , p ) #NEWLINE# evals = eigh ( p , eigvals_only = True ) #NEWLINE# nonzero_evals = evals [ ( abs ( evals ) > 1e-14 ) ] #NEWLINE# assert_ ( ( nonzero_evals >= 0 ) . all ( ) ) #NEWLINE# ( u , p ) = polar ( a , side = 'left' ) #NEWLINE# assert_equal ( u . shape , ( m , n ) ) #NEWLINE# assert_equal ( p . shape , ( m , m ) ) #NEWLINE# assert_allclose ( p . dot ( u ) , a , atol = product_atol ) #NEWLINE# if ( m >= n ) : #NEWLINE# #INDENT# assert_allclose ( u . conj ( ) . T . dot ( u ) , np . eye ( n ) , atol = 1e-15 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_allclose ( u . dot ( u . conj ( ) . T ) , np . eye ( m ) , atol = 1e-15 ) #NEWLINE# #UNINDENT# assert_allclose ( p . conj ( ) . T , p ) #NEWLINE# evals = eigh ( p , eigvals_only = True ) #NEWLINE# nonzero_evals = evals [ ( abs ( evals ) > 1e-14 ) ] #NEWLINE# assert_ ( ( nonzero_evals >= 0 ) . all ( ) )