def _logm_triu(T):
T = np.asarray(T)<EOL>if len(T.shape) != <NUM_LIT:2> or T.shape[<NUM_LIT:0>] != T.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>n, n = T.shape<EOL>T_diag = np.diag(T)<EOL>keep_it_real = np.isrealobj(T) and np.min(T_diag) >= <NUM_LIT:0><EOL>if keep_it_real:<EOL><INDENT>T0 = T<EOL><DEDENT>else:<EOL><INDENT>T0 = T.astype(complex)<EOL><DEDENT>theta = (None,<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>,<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>,<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>,<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>)<EOL>R, s, m = _inverse_squaring_helper(T0, theta)<EOL>nodes, weights = scipy.special.p_roots(m)<EOL>nodes = nodes.real<EOL>if nodes.shape != (m,) or weights.shape != (m,):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>nodes = <NUM_LIT:0.5> + <NUM_LIT:0.5> * nodes<EOL>weights = <NUM_LIT:0.5> * weights<EOL>ident = np.identity(n)<EOL>U = np.zeros_like(R)<EOL>for alpha, beta in zip(weights, nodes):<EOL><INDENT>U += solve_triangular(ident + beta*R, alpha*R)<EOL><DEDENT>U *= np.exp2(s)<EOL>has_principal_branch = all(x.real > <NUM_LIT:0> or x.imag != <NUM_LIT:0> for x in np.diag(T0))<EOL>if has_principal_branch:<EOL><INDENT>U[np.diag_indices(n)] = np.log(np.diag(T0))<EOL>for i in range(n-<NUM_LIT:1>):<EOL><INDENT>l1 = T0[i, i]<EOL>l2 = T0[i+<NUM_LIT:1>, i+<NUM_LIT:1>]<EOL>t12 = T0[i, i+<NUM_LIT:1>]<EOL>U[i, i+<NUM_LIT:1>] = _logm_superdiag_entry(l1, l2, t12)<EOL><DEDENT><DEDENT>if not np.array_equal(U, np.triu(U)):<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>return U<EOL>
Compute matrix logarithm of an upper triangular matrix.

The matrix logarithm is the inverse of
expm: expm(logm(`T`)) == `T`

Parameters
----------
T : (N, N) array_like
    Upper triangular matrix whose logarithm to evaluate

Returns
-------
logm : (N, N) ndarray
    Matrix logarithm of `T`

References
----------
.. [1] Awad H. Al-Mohy and Nicholas J. Higham (2012)
       "Improved Inverse Scaling and Squaring Algorithms
       for the Matrix Logarithm."
       SIAM Journal on Scientific Computing, 34 (4). C152-C169.
       ISSN 1095-7197

.. [2] Nicholas J. Higham (2008)
       "Functions of Matrices: Theory and Computation"
       ISBN 978-0-898716-46-7

.. [3] Nicholas J. Higham and Lijing lin (2011)
       "A Schur-Pade Algorithm for Fractional Powers of a Matrix."
       SIAM Journal on Matrix Analysis and Applications,
       32 (3). pp. 1056-1078. ISSN 0895-4798