@defun
def schur(ctx, A, overwrite_a = False):

    n = A.rows

    if n == 1:
        return (ctx.matrix([[1]]), A)

    if not overwrite_a:
        A = A.copy()

    T = ctx.matrix(n, 1)

    hessenberg_reduce_0(ctx, A, T)
    Q = A.copy()
    hessenberg_reduce_1(ctx, Q, T)

    for x in xrange(n):
        for y in xrange(x + 2, n):
            A[y,x] = 0

    hessenberg_qr(ctx, A, Q)

    return Q, A
This routine computes the Schur decomposition of a square matrix A.
dataset/ETHPy150Open fredrik-johansson/mpmath/mpmath/matrices/eigen.py/schur