Blasjs
Pure Javascript manually written :ok_hand: implementation of BLAS, Many numerical software applications use BLAS computations, including Armadillo, LAPACK, LINPACK, GNU Octave, Mathematica, MATLAB, NumPy, R, and Julia.
Install / Use
/learn @R-js/BlasjsREADME
BLASjs (<span style="font-size:small" ><span style="color:red; font-weight: bold;">B</span>asic <span style="color:red; font-weight: bold;">L</span>inear <span style="color:red; font-weight: bold;">A</span>lgebra <span style="color:red; font-weight: bold;">S</span>ubprograms</span>)
This is a 100% Pure Javascript ( TypeScript ) re-write of the reference implementation Basic Linear Algebra SubPrograms (BLAS) numerical library found [here][blas-site].
This is a full manual re-write, "emscripten" was not used.
summary
BLASjs contains all the functions (Complex, Real) of the reference implementation capable for 32 bit and 64 bit floating point arithmatic:
- :ok_hand: 100% code coverage
- 1005 tests
- Output off all tests equal to the BLAS FORTRAN reference implementation.
- Level 1: all vector-vector operations implemented.
- Level 2: all vector-matrix operations implemented.
- Level 3: all matrix-matrix operations implemented.
- Helper functions to ease the porting of FORTRAN BLAS usage to Javascript.
Node and Web
The resulting bundled blasjs file is an agnostic UMD library, it can be used in a web client
as-well as in a server side node environment.
Installation
node
$ npm i blasjs
Usage:
//node
const blas = require('blasjs');
//or typescript
import * as blas from 'blasjs';
web
The module directory contains a standalone bundle for use in html <script> insertion. The library assigns window.BLAS after loading.
<!-- <script src="your_server_url/blasjs.min.js"></script> -->
<!-- this example uses unpkg as CDN -->
<script src="https://unpkg.com/blasjs@latest/dist/lib/blasjs.min.js"></script>
<script>
const blas = window.BLAS; //UMD exposes it as BLAS
//fetch some level3 complex 64 bit precision matrix-matrix operations
const {
level3: { zsyrk, ztrmm, ztrsm }
} = blas;
</script>
Table of Contents
- BLASjs (<span style="font-size:small" ><span style="color:red; font-weight: bold;">B</span>asic <span style="color:red; font-weight: bold;">L</span>inear <span style="color:red; font-weight: bold;">A</span>lgebra <span style="color:red; font-weight: bold;">S</span>ubprograms</span>) - summary - Node and Web
- Table of Contents
- Language differences with FORTRAN/BLAS
- Helper functions
- Types
fpArrayFortranArrType ComplexMatrix- Float[32/64]Array Complex number storage for Matrix.
- Handling FORTRAN matrices (multidimensional Arrays).
- Performance
- Creating new transformed Matrix instances from existing ones
Matrix.prototype.sliceMatrix.prototype.setLowerMatrix.prototype.setUpperMatrix.prototype.upperBandMatrix.prototype.lowerBandMatrix.prototype.realMatrix.prototype.imaginary- Packed Matrices
Matrix.prototype.packedUpperMatrix.prototype.packedLower- Convert Matrix object to a JS array
Matrix.prototype.toArr- Summary: Full type declaration of Matrix
- Matrix Examples
- General Helpers
- Vector Constructors
- Matrix Constructors
- Types
- A note on numeric precision
- Mimicking FORTRAN OUT Arguments
- Level 1 routines
- Euclidean norm: √(xᴴ·x) or √(xᵀ·x)
- Construct a Givens plane rotation
- Construct the modified Givens rotation matrix
H - Apply the modified Givens Transformation
- Applies a plane rotation
- Scale a vector by a constant
- Takes the sum of the absolute values of the components of vector
- Interchanges 2 vectors
- Dot product of two complex vectors
- Dot product of two non complex vectors
- Finds the index of the first element having maximum absolut value.
- Copy a vector x to a vector y
- Constant times a vector plus a vector
- Level 2 Routines
- The hermitian rank 2 operation A ⟵ α·x·yᴴ + conjg( α )·y·xᴴ + A
- The symmetric rank 2 operation A ⟵ α·x·yᵀ + α·y·xᵀ + A
- The rank 1 operation A ⟵ α·x·yᴴ + A or A ⟵ α·x·yᵀ + A
- The hermitian rank 1 operation A ⟵ α·x·xᴴ + A
- The symmetric rank 1 operation A ⟵ α·x·xᵀ + A
- The matrix-vector operation, y ⟵ α·A·x + β·y, or y ⟵ α·Aᵀ·x + β·y or y ⟵ α·Aᴴ·x + β·y
- The matrix-vector operation, x ⟵ A·x, or x ⟵ Aᵀ·x, or x ⟵ Aᴴ·x
- Solves a systems of equations A·x = b, or Aᵀ·x = b, or Aᴴ·x = b
- Level 3 Routines
- Hermitian rank 2k: C ⟵ α·A·Bᴴ + con( α )·B·Aᴴ + β·C or C ⟵ α·Aᴴ·B + con( α )·Bᴴ·A + β·C
- Symmetric rank 2k operations C ⟵ α·A·Bᵀ + α·B·Aᵀ + β·C, or C ⟵ α·Aᵀ·B + α·Bᵀ·A + β·C
- Hermatian rank k operations C ⟵ α·A·Aᴴ + β·C, or C ⟵ α·Aᴴ·A + β·C
- Symmetric rank k operations C ⟵ α·A·Aᵀ + β·C, or C ⟵ α·Aᵀ·A + β·C
- Matrix-matrix operations C ⟵ α·f(A)·h(B) + β·C or C ⟵ α·h(B)·f(A) + β·C
- Matrix-matrix operations C ⟵ α·A·B + β·C or C ⟵ α·B·A + β·C
- Matrix-matrix operations B ⟵ α·f(A)·B or B ⟵ α·B·f(A)
- [
