Is there a way to find which direct solver is using solve()?

208 Views Asked by At

As the title says, is there a way to find out which matrix decomposition is applying the function solve() for a given sparse matrix in R? For example, in Matlab there is spparms('spumoni', 2); , which return some info about the algorithm used to solve the decomposition for the sparse matrix.

1

There are 1 best solutions below

3
On BEST ANSWER

Well, running R one could get to

> methods(solve)

which will produce

[1] solve.default solve.qr

If you type

> solve.default

you'll get back

function (a, b, tol = .Machine$double.eps, LINPACK = FALSE, ...)
{
    if (!missing(LINPACK))
        warning("the LINPACK argument has been defunct since R 3.1.0")
    if (is.complex(a) || (!missing(b) && is.complex(b))) {
        a <- as.matrix(a)
        if (missing(b)) {
            b <- diag(1 + (0+0i), nrow(a))
            colnames(b) <- rownames(a)
        }
        return(.Internal(La_solve_cmplx(a, b)))
    }
    if (inherits(a, "qr")) {
        warning("solve.default called with a \"qr\" object: use 'qr.solve'")
        return(solve.qr(a, b, tol))
    }
    a <- as.matrix(a)
    if (missing(b)) {
        b <- diag(1, nrow(a))
        colnames(b) <- rownames(a)
    }
    .Internal(La_solve(a, b, tol))
}

which means it is either La_solve or La_solve_cmplx. Looking at their implementations e.g. here one could find out that La_solve will call LAPACK routine DGESV, and La_solve_cmplx will call LAPACK routine ZGESV.

Easy, huh?