def _logm(A):
A = np.asarray(A)<EOL>if len(A.shape) != <NUM_LIT:2> or A.shape[<NUM_LIT:0>] != A.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>n = A.shape[<NUM_LIT:0>]<EOL>if issubclass(A.dtype.type, np.integer):<EOL><INDENT>A = np.asarray(A, dtype=float)<EOL><DEDENT>keep_it_real = np.isrealobj(A)<EOL>try:<EOL><INDENT>if np.array_equal(A, np.triu(A)):<EOL><INDENT>A = _logm_force_nonsingular_triangular_matrix(A)<EOL>if np.min(np.diag(A)) < <NUM_LIT:0>:<EOL><INDENT>A = A.astype(complex)<EOL><DEDENT>return _logm_triu(A)<EOL><DEDENT>else:<EOL><INDENT>if keep_it_real:<EOL><INDENT>T, Z = schur(A)<EOL>if not np.array_equal(T, np.triu(T)):<EOL><INDENT>T, Z = rsf2csf(T,Z)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>T, Z = schur(A, output='<STR_LIT>')<EOL><DEDENT>T = _logm_force_nonsingular_triangular_matrix(T, inplace=True)<EOL>U = _logm_triu(T)<EOL>ZH = np.conjugate(Z).T<EOL>return Z.dot(U).dot(ZH)<EOL><DEDENT><DEDENT>except (SqrtmError, LogmError) as e:<EOL><INDENT>X = np.empty_like(A)<EOL>X.fill(np.nan)<EOL>return X<EOL><DEDENT>
Compute the matrix logarithm.

See the logm docstring in matfuncs.py for more info.

Notes
-----
In this function we look at triangular matrices that are similar
to the input matrix.  If any diagonal entry of such a triangular matrix
is exactly zero then the original matrix is singular.
The matrix logarithm does not exist for such matrices,
but in such cases we will pretend that the diagonal entries that are zero
are actually slightly positive by an ad-hoc amount, in the interest
of returning something more useful than NaN.  This will cause a warning.