1 # bend-blas: LAPACK routines on Array, one def per routine, the 2 # Fortran names without the trailing underscore. Generated by 3 # gen/effs.py: edit the table there, not this file. 4 # 5 # The same conventions as blas.bend: sizes U32, matrices row-major and 6 # consumed, answers fresh; a general operand is copied to column major 7 # for LAPACK and back, a symmetric one as it is. A failure is 8 # Fail{(code, message)} with the routine's info as the code (the pivot 9 # or minor at fault, from 1); the .try twin dies on it. A routine with 10 # several answers hands back a pair (Sigma), opened by matching in a 11 # def of its own. 12 # 13 # The symbols (sgesv_ and so on) come from the same library as the BLAS 14 # (Accelerate, OpenBLAS), or from liblapack beside a plain system BLAS. 15 # On the interpreter the JS twins run: LU with pivoting, Cholesky, and 16 # Jacobi for the SVD and the symmetric eigenproblem, correct and slow. 17 import Base 18 19 # X = A^-1 B: A is n x n, B is n x nrhs, both row-major, both consumed; 20 # answers X (n x nrhs). Fails with code i when U(i, i) of the LU 21 # factorization is exactly zero (A singular). 22 def Lapack.sgesv(n: U32, nrhs: U32, a: Array, b: Array) -> IO(Result<&1, &1, U32 & String, Array>): 23 import "./effs/lapack_sgesv.c" 24 import "./effs/lapack_sgesv.js" 25 26 def Lapack.sgesv.try(n: U32, nrhs: U32, a: Array, b: Array) -> IO(Array): 27 IO.try(Array, Lapack.sgesv(n, nrhs, a, b)) 28 29 # The Cholesky factor of a symmetric positive definite n x n matrix: 30 # answers L, row-major, lower triangular with zeros above, A = L L^T. 31 # Fails with code i when the leading minor of order i is not positive. 32 def Lapack.spotrf(n: U32, a: Array) -> IO(Result<&1, &1, U32 & String, Array>): 33 import "./effs/lapack_spotrf.c" 34 import "./effs/lapack_spotrf.js" 35 36 def Lapack.spotrf.try(n: U32, a: Array) -> IO(Array): 37 IO.try(Array, Lapack.spotrf(n, a)) 38 39 # X = A^-1 B given the Cholesky factor L of A from spotrf (n x n, lower, 40 # row-major) and B (n x nrhs, row-major); both consumed, answers X. 41 def Lapack.spotrs(n: U32, nrhs: U32, l: Array, b: Array) -> IO(Result<&1, &1, U32 & String, Array>): 42 import "./effs/lapack_spotrs.c" 43 import "./effs/lapack_spotrs.js" 44 45 def Lapack.spotrs.try(n: U32, nrhs: U32, l: Array, b: Array) -> IO(Array): 46 IO.try(Array, Lapack.spotrs(n, nrhs, l, b)) 47 48 # The singular values of an m x n row-major matrix (consumed), largest 49 # first, min(m, n) of them. 50 def Lapack.sgesvd_s(m: U32, n: U32, a: Array) -> IO(Result<&1, &1, U32 & String, Array>): 51 import "./effs/lapack_sgesvd_s.c" 52 import "./effs/lapack_sgesvd_s.js" 53 54 def Lapack.sgesvd_s.try(m: U32, n: U32, a: Array) -> IO(Array): 55 IO.try(Array, Lapack.sgesvd_s(m, n, a)) 56 57 # The thin SVD of an m x n row-major matrix (consumed): answers 58 # (s, (u, vt)) with s the min(m, n) singular values largest first, u 59 # m x k and vt k x n row-major, A = u diag(s) vt. 60 def Lapack.sgesvd(m: U32, n: U32, a: Array) -> IO(Result<&1, &1, U32 & String, Array & (Array & Array)>): 61 import "./effs/lapack_sgesvd.c" 62 import "./effs/lapack_sgesvd.js" 63 64 def Lapack.sgesvd.try(m: U32, n: U32, a: Array) -> IO(Array & (Array & Array)): 65 IO.try(Array & (Array & Array), Lapack.sgesvd(m, n, a)) 66 67 # The eigenvalues and eigenvectors of a symmetric n x n row-major matrix 68 # (consumed, its lower triangle read): answers (w, v) with w the n 69 # eigenvalues ascending and v n x n row-major, row i the unit eigenvector 70 # of w[i]. 71 def Lapack.ssyev(n: U32, a: Array) -> IO(Result<&1, &1, U32 & String, Array & Array>): 72 import "./effs/lapack_ssyev.c" 73 import "./effs/lapack_ssyev.js" 74 75 def Lapack.ssyev.try(n: U32, a: Array) -> IO(Array & Array): 76 IO.try(Array & Array, Lapack.ssyev(n, a))