Inventory - wlevine/nmatrix GitHub Wiki

What is it? Uses? Tests? Internal impl? External impl?

BLAS level 1 (scalar, vector and vector-vector operations)

  • cblas_rotg: For Cartesian point (a,b): compute parameters of Givens rotation (though BLAS uses different sign convention than Wikipedia: Internal implementation doesn't work for complex types (at least partially because it has a sqrt). CBLAS implementation (including complex) called if available. Need better spec for complex types. Exposed in NMatrix::BLAS#rotg.
  • cblas_rot: Given cos and sin of rotation angle, apply plane rotation to two vectors of length n representing n Cartesian points. Internal and external implementations. Spec. NMatrix::BLAS#rot
  • cblas_asum: sum of absolute values of entries of a vector. Internal and external. Spec only for float64?!. NMatrix::BLAS#asum, NMatrix#asum.
  • cblas_nrm2: calculates 2-norm (not norm squared!) of a vector. Internal and external. Spec only for float64. No spec for NMatrix#nrm2. NMatrix::BLAS#nrm2, NMatrix#nrm2. NMatrix#nrm2 doesn't work for single element vectors.
  • cblas_imax: BLAS IxAMAX. Should be called cblas_amax. Documentation is wrong. Finds the index of the element with maximum absolute value. Internal and external. Spec doesn't test negative values. Used by other C functions. Not used by any ruby code?
  • cblas_scal: Scale vector by scalar in place. Internal and external. Spec. Used in C code, not in Ruby.

BLAS Level 2 (matrix-vector operations)

  • cblas_gemv: Matrix-vector multiplication. a*A*x + b*y, where a and b are scalars, A is a matrix, x and y are vectors. Internal and external. NMatrix::BLAS.gemv, but wrong I think. Used for nmatrix matrix multiplication if applicable. Spec for NMatrix::BLAS.gemv float64 only, but it doesn't actually check anything!? Is it covered by multiplication specs?

BLAS Level 3 (matrix-matrix operations)

  • cblas_gemm: Matrix-matrix multiplication. Internal and external. NMatrix::BLAS.gemm. Used for implementing matrix multiplication. Spec for NMatrix::BLAS.gemm.
  • cblas_trsm: Solves a triangular matrix equation ( Used by internal LAPACK functions. No use in ruby. Internal and external. Spec looks confused.
  • cblas_trmm: Computes a matrix-matrix product where one input matrix is triangular. Used by internal LAUUM implementation (so we can use lauum if we have external BLAS, but no external LAPACK). No Ruby use. No spec. External implementation only.
  • cblas_herk: Performs a Hermitian rank-k update, whatever that means. Only for complex types. Again, used by lauum. No ruby use. No spec. External only.
  • cblas_syrk: Performs a symmetric rank-k update. Used by lauum. Also commented out use in gemm. No ruby use. No spec. External only.


  • clapack_getrf: Perform LU factorization. The comments are wrong for nm_clapack_getrf, but good in math/getrf.h. Ruby usage and documentation seems confused. Many users in ruby. NMatrix#getrf, #getrf!, #factorize_lu. Spec for clapack_getrf. No spec for #getrf. Spec for #factorize_lu--missing part of the matrix it's supposed to test against (also not sure if it's correct). Internal implementation. Should call external implementation, but it looks like it only does for complex types (?).
  • clapack_getri: Compute inverse given LU factorization. When available used for #invert. Spec. External only.
  • clapack_getrs: Solver for LU factorized matrix. Used by clapack_gesv ruby method. Spec OK. It looks like we have an internal impl, though it's not listed in the docs. Again, it looks like external version is only called for complex types.
  • clapack_gesv: Implemented in ruby, combines getrs and getri to solve general linear equations. Spec OK. But doesn't work if b isn't a vector.
  • clapack_potrf: Cholesky factorization of a symmetric (Hermitian) positive-definite matrix. NMatrix#potrf!, #potrf_upper!, #potrf_lower!, #factorize_cholesky. factorize_cholesky is confused. Spec for clapack_potrf--spec is confused, not technically wrong?, matrix should be symmetric, pos-def. No spec for factorize_cholesky. External only.
  • clapack_potri: Computes the inverse of a symmetric (Hermitian) positive-definite matrix, given Cholesky factorization. No users. No tests. External only.
  • clapack_potrs: Solver for Cholesky-factored matrix. Used by clapack_posv. No spec. Looks like there is an internal implementation and the external one is only called for complex types.
  • clapck_posv: Implemented in ruby, combines potrf and potrs. No spec.
  • clapack_laswp: Swap rows (for us, actually swaps columns). Used by various internal LAPACK functions. NMatrix::Lapack.laswp, Nmatrix#laswp(!) (aka #permute_columns(!)). Spec for NMatrix::LAPACK::clapack_laswp and also for #permute_columns(!). Spec OK? (It's weird--it looks like it ignores the last element of piv, but maybe this is correct?) It looks like we never use an external version.
  • clapack_lauum: Computes the product U*U^T or L^T*L for triangular matrices. No uses. No spec. Internal and external (but internal version will work only with external BLAS). I think some bad templating means that the external version never gets called, but I haven't really checked this. Why do we have this?


  • lapack_gesvd, lapack_gesdd: Singular value decomposition. I wrote these specs, so I hope they're right. External only.
  • lapack_geev: Compute eigenvalues and eigenvectors. NMatrix::LAPACK.geev. NMatrix::LAPACK.geev may actually do the right thing, but its output is in a baffling format. Spec seems very confused. External only.