

def _fractional_matrix_power(A, p):
    '\n    Compute the fractional power of a matrix.\n\n    See the fractional_matrix_power docstring in matfuncs.py for more info.\n\n    '
    A = np.asarray(A)
    if ((len(A.shape) != 2) or (A.shape[0] != A.shape[1])):
        raise ValueError('expected a square matrix')
    if (p == int(p)):
        return np.linalg.matrix_power(A, int(p))
    s = svdvals(A)
    if s[(- 1)]:
        k2 = (s[0] / s[(- 1)])
        p1 = (p - np.floor(p))
        p2 = (p - np.ceil(p))
        if ((p1 * (k2 ** (1 - p1))) <= ((- p2) * k2)):
            a = int(np.floor(p))
            b = p1
        else:
            a = int(np.ceil(p))
            b = p2
        try:
            R = _remainder_matrix_power(A, b)
            Q = np.linalg.matrix_power(A, a)
            return Q.dot(R)
        except np.linalg.LinAlgError:
            pass
    if (p < 0):
        X = np.empty_like(A)
        X.fill(np.nan)
        return X
    else:
        p1 = (p - np.floor(p))
        a = int(np.floor(p))
        b = p1
        (R, info) = funm(A, (lambda x: pow(x, b)), disp=False)
        Q = np.linalg.matrix_power(A, a)
        return Q.dot(R)

dataset/ETHPy150Open scipy/scipy/scipy/linalg/_matfuncs_inv_ssq.py _fractional_matrix_power/original