#NEWLINE# def test_svd_flip( ) : #NEWLINE# #INDENT# rs = np . random . RandomState ( 1999 ) #NEWLINE# n_samples = 20 #NEWLINE# n_features = 10 #NEWLINE# X = rs . randn ( n_samples , n_features ) #NEWLINE# ( U , S , V ) = linalg . svd ( X , full_matrices = False ) #NEWLINE# ( U1 , V1 ) = svd_flip ( U , V , u_based_decision = False ) #NEWLINE# assert_almost_equal ( np . dot ( ( U1 * S ) , V1 ) , X , decimal = 6 ) #NEWLINE# XT = X . T #NEWLINE# ( U , S , V ) = linalg . svd ( XT , full_matrices = False ) #NEWLINE# ( U2 , V2 ) = svd_flip ( U , V , u_based_decision = True ) #NEWLINE# assert_almost_equal ( np . dot ( ( U2 * S ) , V2 ) , XT , decimal = 6 ) #NEWLINE# ( U_flip1 , V_flip1 ) = svd_flip ( U , V , u_based_decision = True ) #NEWLINE# assert_almost_equal ( np . dot ( ( U_flip1 * S ) , V_flip1 ) , XT , decimal = 6 ) #NEWLINE# ( U_flip2 , V_flip2 ) = svd_flip ( U , V , u_based_decision = False ) #NEWLINE# assert_almost_equal ( np . dot ( ( U_flip2 * S ) , V_flip2 ) , XT , decimal = 6 )