~/bend-docscommunity

lapack.bend relies on unsafe/foreign

raw source on the hub · import bend-blas-lapack@0.0.0.1/lapack.bend as Lapack

bend-blas: LAPACK routines on Array<F32>, one def per routine, the Fortran names without the trailing underscore. Generated by gen/effs.py: edit the table there, not this file.

The same conventions as blas.bend: sizes U32, matrices row-major and consumed, answers fresh; a general operand is copied to column major for LAPACK and back, a symmetric one as it is. A failure is Fail{(code, message)} with the routine's info as the code (the pivot or minor at fault, from 1); the .try twin dies on it. A routine with several answers hands back a pair (Sigma), opened by matching in a def of its own.

The symbols (sgesv_ and so on) come from the same library as the BLAS (Accelerate, OpenBLAS), or from liblapack beside a plain system BLAS. On the interpreter the JS twins run: LU with pivoting, Cholesky, and Jacobi for the SVD and the symmetric eigenproblem, correct and slow.

1 import
import Base

Definitions

def Lapack.sgesv.try source · line 26 · raw

@n:U32 -> @nrhs:U32 -> @a:Array<F32> -> @b:Array<F32> -> IO(Array<F32>)

def Lapack.spotrf.try source · line 36 · raw

@n:U32 -> @a:Array<F32> -> IO(Array<F32>)

def Lapack.spotrs.try source · line 45 · raw

@n:U32 -> @nrhs:U32 -> @l:Array<F32> -> @b:Array<F32> -> IO(Array<F32>)

def Lapack.sgesvd_s.try source · line 54 · raw

@m:U32 -> @n:U32 -> @a:Array<F32> -> IO(Array<F32>)

def Lapack.sgesvd.try source · line 64 · raw

@m:U32 -> @n:U32 -> @a:Array<F32> -> IO(Pair(Array<F32>, Pair(Array<F32>, Array<F32>)))

def Lapack.ssyev.try source · line 75 · raw

@n:U32 -> @a:Array<F32> -> IO(Pair(Array<F32>, Array<F32>))

Effects (foreign code)

effect Lapack.sgesv source · line 22 · raw

@n:U32 -> @nrhs:U32 -> @a:Array<F32> -> @b:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

X = A^-1 B: A is n x n, B is n x nrhs, both row-major, both consumed; answers X (n x nrhs). Fails with code i when U(i, i) of the LU factorization is exactly zero (A singular).

foreign: effs/lapack_sgesv.c, effs/lapack_sgesv.js

effect Lapack.spotrf source · line 32 · raw

@n:U32 -> @a:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

The Cholesky factor of a symmetric positive definite n x n matrix: answers L, row-major, lower triangular with zeros above, A = L L^T. Fails with code i when the leading minor of order i is not positive.

foreign: effs/lapack_spotrf.c, effs/lapack_spotrf.js

effect Lapack.spotrs source · line 41 · raw

@n:U32 -> @nrhs:U32 -> @l:Array<F32> -> @b:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

X = A^-1 B given the Cholesky factor L of A from spotrf (n x n, lower, row-major) and B (n x nrhs, row-major); both consumed, answers X.

foreign: effs/lapack_spotrs.c, effs/lapack_spotrs.js

effect Lapack.sgesvd_s source · line 50 · raw

@m:U32 -> @n:U32 -> @a:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Array<F32>>)

The singular values of an m x n row-major matrix (consumed), largest first, min(m, n) of them.

foreign: effs/lapack_sgesvd_s.c, effs/lapack_sgesvd_s.js

effect Lapack.sgesvd source · line 60 · raw

@m:U32 -> @n:U32 -> @a:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Pair(Array<F32>, Pair(Array<F32>, Array<F32>))>)

The thin SVD of an m x n row-major matrix (consumed): answers (s, (u, vt)) with s the min(m, n) singular values largest first, u m x k and vt k x n row-major, A = u diag(s) vt.

foreign: effs/lapack_sgesvd.c, effs/lapack_sgesvd.js

effect Lapack.ssyev source · line 71 · raw

@n:U32 -> @a:Array<F32> -> IO(Result<&1, &1, Pair(U32, String), Pair(Array<F32>, Array<F32>)>)

The eigenvalues and eigenvectors of a symmetric n x n row-major matrix (consumed, its lower triangle read): answers (w, v) with w the n eigenvalues ascending and v n x n row-major, row i the unit eigenvector of w[i].

foreign: effs/lapack_ssyev.c, effs/lapack_ssyev.js