<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> def svds ( x_k33 ) : <EOL> K = len ( x_k33 ) <EOL> option = "<STR_LIT:A>" <EOL> m = <NUM_LIT:3> <EOL> n = <NUM_LIT:3> <EOL> nvt = <NUM_LIT:3> <EOL> lwork = <NUM_LIT> <EOL> iwork = np . zeros ( <NUM_LIT> , '<STR_LIT>' ) <EOL> work = np . zeros ( ( <NUM_LIT> ) ) <EOL> s_k3 = np . zeros ( ( K , <NUM_LIT:3> ) ) <EOL> fu_k33 = np . zeros ( ( K , <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> fvt_k33 = np . zeros ( ( K , <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> fx_k33 = x_k33 . transpose ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ) . copy ( ) <EOL> lapack_routine = np . linalg . lapack_lite . dgesdd <EOL> for k in xrange ( K ) : <EOL> lapack_routine ( option , m , n , fx_k33 [ k ] , m , s_k3 [ k ] , fu_k33 [ k ] , m , fvt_k33 [ k ] , nvt , <EOL> work , lwork , iwork , <NUM_LIT:0> ) <EOL> return fu_k33 . transpose ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ) , s_k3 , fvt_k33 . transpose ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> def svds_slow ( x_k33 ) : <EOL> s2 , u2 , v2 = [ ] , [ ] , [ ] <EOL> for x_33 in x_k33 : <EOL> u , s , vt = np . linalg . svd ( x_33 ) <EOL> s2 . append ( s ) <EOL> u2 . append ( u ) <EOL> v2 . append ( vt ) <EOL> s2 = np . array ( s2 ) <EOL> u2 = np . array ( u2 ) <EOL> v2 = np . array ( v2 ) <EOL> return u2 , s2 , v2 <EOL> def test_svds ( ) : <EOL> x_k33 = np . random . randn ( <NUM_LIT:1000> , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> u1 , s1 , v1 = svds ( x_k33 ) <EOL> u2 , s2 , v2 = svds_slow ( x_k33 ) <EOL> assert np . allclose ( u1 , u2 ) <EOL> assert np . allclose ( s1 , s2 ) <EOL> assert np . allclose ( v1 , v2 ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_svds ( ) </s>
