Does anybody use the functions provided in the context LinearAlgebra`LAPACK directly? Is there any documentation out there? Guessing the argument patterns for these function by trial and error is somewhat a nuisance...

Edit: Here is a usage example, computing an LU-factorization for a rectanguar matrix.

m = RandomReal[{-10, 10}, RandomInteger[{100, 2500}, 2]];
lu = m;
n = Min[Dimensions[lu]];
p = ConstantArray[0, n];
c = 0.;
LinearAlgebra`LAPACK`GETRF[lu, p, c];
u = UpperTriangularize[lu];
l = LowerTriangularize[lu, -1] + IdentityMatrix[Dimensions[lu]];
(* computing permuations *)
r = s = Range[Length[lu]];
Do[s[[{i, p[[i]]}]] = s[[{p[[i]], i}]], {i, 1, n}];
r[[s]] = Range[Length[lu]];

Max[Abs[l[[r, 1 ;; n]].u[[1 ;; n, All]] - m]]
Max[Abs[l[[All, 1 ;; n]].u[[1 ;; n, All]] - m[[s]]]]

Note that the arrays lu and p and the integer c are passed by reference and get modified. This can be considered evil behavior by the generic Mathematica user but it is of course more effecient than copying arrays.

We can also compare it to what LUDecomposition provides us with:

{LU, S, a} = LUDecomposition[m];
Max[Abs[lu - LU]]
S == s

Surprisingly, LUDecomposition tends to be faster than GETRF called this way.

Edit: And as Nasser suggested: You can see those commands by issueing


An output example was offered by Nasser here.

However, they are not documented -- although they give some feedback when entering wrong input.

  • $\begingroup$ How do you use LinearAlgebra`LAPACK ? Do you need to load a package first? Can you show how to even call it? And which version of Mathematica is this supported at? Lapack itself is documented at netlib.org/lapack $\endgroup$ – Nasser Jul 3 '17 at 19:25
  • 2
    $\begingroup$ there is a web page here showing mapping between Lapack calls and Mathematica own functions (which many most likely end up calling it and BLAS at one point) $\endgroup$ – Nasser Jul 3 '17 at 19:33
  • $\begingroup$ @Nasser: The context is automatically loaded at startup. (I am currently using version 11.0.1 but I know that this context has been there for quite some versions before.) It is not added to the context Global`, most likely because these functions are solely meant as helpers for LinearSolve, LUDecomposition and friends. I am interested in calling LAPACK rather directly, e.g., because I observed a rather weird behavior of LUDecomposition with non-square matrices. $\endgroup$ – Henrik Schumacher Jul 3 '17 at 19:57
  • $\begingroup$ @Nasser: Anyway, many thanks for the given link, although I already know how to use LinearSolve... $\endgroup$ – Henrik Schumacher Jul 3 '17 at 19:59
  • 1
    $\begingroup$ A related question. The BLAS functions are now documented (it wasn't before), but the LAPACK ones remain undocumented. $\endgroup$ – J. M. will be back soon Oct 27 '17 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.