<s> """<STR_LIT>""" <EOL> from numpy import zeros , cos , sin , sqrt <EOL> from numpy . lib . twodim_base import diag <EOL> from numpy . linalg import svd <EOL> from scipy . linalg . basic import solve_triangular <EOL> class MatrixTools ( object ) : <EOL> @ staticmethod <EOL> def rotation_matrix ( theta ) : <EOL> """<STR_LIT>""" <EOL> R = zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> R [ <NUM_LIT:0> , <NUM_LIT:0> ] = cos ( theta ) <EOL> R [ <NUM_LIT:0> , <NUM_LIT:1> ] = - sin ( theta ) <EOL> R [ <NUM_LIT:1> , <NUM_LIT:0> ] = sin ( theta ) <EOL> R [ <NUM_LIT:1> , <NUM_LIT:1> ] = cos ( theta ) <EOL> return R <EOL> @ staticmethod <EOL> def low_rank_approx ( K , d ) : <EOL> """<STR_LIT>""" <EOL> U , s , V = svd ( K ) <EOL> U = U [ : , <NUM_LIT:0> : d ] <EOL> V = V [ <NUM_LIT:0> : d , : ] <EOL> s = s [ <NUM_LIT:0> : d ] <EOL> S = diag ( s ) <EOL> L = sqrt ( S ) . dot ( V ) <EOL> return ( L , s , V ) <EOL> @ staticmethod <EOL> def cholesky_solve ( L , x ) : <EOL> """<STR_LIT>""" <EOL> x = solve_triangular ( L , x . T , lower = True ) <EOL> x = solve_triangular ( L . T , x , lower = False ) <EOL> return x </s>
