def solve_sylvester(a, b, q):
 (r, u) = schur(a, output='real')
 (s, v) = schur(b.conj().transpose(), output='real')
 f = np.dot(np.dot(u.conj().transpose(), q), v)
 (trsyl,) = get_lapack_funcs(('trsyl',), (r, s, f))
 if (trsyl is None):
  raise RuntimeError('LAPACK implementation does not contain a proper Sylvester equation solver (TRSYL)')
 (y, scale, info) = trsyl(r, s, f, tranb='C')
 y = (scale * y)
 if (info < 0):
  raise LinAlgError(('Illegal value encountered in the %d term' % ((- info),)))
 return np.dot(np.dot(u, y), v.conj().transpose())

def solve_sylvester ( a , b , q ) : ( r , u ) = schur ( a , output = 'real' ) ( s , v ) = schur ( b . conj ( ) . transpose ( ) , output = 'real' ) f = np . dot ( np . dot ( u . conj ( ) . transpose ( ) , q ) , v ) ( trsyl , ) = get_lapack_funcs ( ( 'trsyl' , ) , ( r , s , f ) ) if ( trsyl is None ) : raise RuntimeError ( 'LAPACK implementation does not contain a proper Sylvester equation solver (TRSYL)' ) ( y , scale , info ) = trsyl ( r , s , f , tranb = 'C' ) y = ( scale * y ) if ( info < 0 ) : raise LinAlgError ( ( 'Illegal value encountered in the %d term' % ( ( - info ) , ) ) ) return np . dot ( np . dot ( u , y ) , v . conj ( ) . transpose ( ) )
computes a solution (x) to the sylvester equation :math:ax + xb = q .