5
$\begingroup$

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

 Names["LinearAlgebra`LAPACK`*"]

An output example was offered by Nasser here.

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

$\endgroup$
7
  • $\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, 2017 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, 2017 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$ Jul 3, 2017 at 19:57
  • 1
    $\begingroup$ A related question. The BLAS functions are now documented (it wasn't before), but the LAPACK ones remain undocumented. $\endgroup$ Oct 27, 2017 at 13:36
  • 1
    $\begingroup$ I'd run my documentation generator on this stuff, but being all inside the kernel it wouldn't help at all. If you find out how things work you should write doc pages and then wrap up a doc paclet to distribute. $\endgroup$
    – b3m2a1
    Oct 27, 2017 at 21:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.