lapack.bend source
lapack.bend on the hub · documented module
# 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.import Base# 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).def Lapack.sgesv(n: U32, nrhs: U32, a: Array<F32>, b: Array<F32>) -> IO(Result<&1, &1, U32 & String, Array<F32>>): import "./effs/lapack_sgesv.c" import "./effs/lapack_sgesv.js"def Lapack.sgesv.try(n: U32, nrhs: U32, a: Array<F32>, b: Array<F32>) -> IO(Array<F32>): IO.try(Array<F32>, Lapack.sgesv(n, nrhs, a, b))# 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.def Lapack.spotrf(n: U32, a: Array<F32>) -> IO(Result<&1, &1, U32 & String, Array<F32>>): import "./effs/lapack_spotrf.c" import "./effs/lapack_spotrf.js"def Lapack.spotrf.try(n: U32, a: Array<F32>) -> IO(Array<F32>): IO.try(Array<F32>, Lapack.spotrf(n, a))# 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.def Lapack.spotrs(n: U32, nrhs: U32, l: Array<F32>, b: Array<F32>) -> IO(Result<&1, &1, U32 & String, Array<F32>>): import "./effs/lapack_spotrs.c" import "./effs/lapack_spotrs.js"def Lapack.spotrs.try(n: U32, nrhs: U32, l: Array<F32>, b: Array<F32>) -> IO(Array<F32>): IO.try(Array<F32>, Lapack.spotrs(n, nrhs, l, b))# The singular values of an m x n row-major matrix (consumed), largest# first, min(m, n) of them.def Lapack.sgesvd_s(m: U32, n: U32, a: Array<F32>) -> IO(Result<&1, &1, U32 & String, Array<F32>>): import "./effs/lapack_sgesvd_s.c" import "./effs/lapack_sgesvd_s.js"def Lapack.sgesvd_s.try(m: U32, n: U32, a: Array<F32>) -> IO(Array<F32>): IO.try(Array<F32>, Lapack.sgesvd_s(m, n, a))# 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.def Lapack.sgesvd(m: U32, n: U32, a: Array<F32>) -> IO(Result<&1, &1, U32 & String, Array<F32> & (Array<F32> & Array<F32>)>): import "./effs/lapack_sgesvd.c" import "./effs/lapack_sgesvd.js"def Lapack.sgesvd.try(m: U32, n: U32, a: Array<F32>) -> IO(Array<F32> & (Array<F32> & Array<F32>)): IO.try(Array<F32> & (Array<F32> & Array<F32>), Lapack.sgesvd(m, n, a))# 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].def Lapack.ssyev(n: U32, a: Array<F32>) -> IO(Result<&1, &1, U32 & String, Array<F32> & Array<F32>>): import "./effs/lapack_ssyev.c" import "./effs/lapack_ssyev.js"def Lapack.ssyev.try(n: U32, a: Array<F32>) -> IO(Array<F32> & Array<F32>): IO.try(Array<F32> & Array<F32>, Lapack.ssyev(n, a))