blasjs
v1.0.15
Published
Javascript Pure Implementation of BLAS Level 1, level 2, level 3 functions
Downloads
11
Maintainers
Readme
BLASjs (Basic Linear Algebra Subprograms)
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 (Basic Linear Algebra Subprograms) - summary - Node and Web
- Table of Contents
- Language differences with FORTRAN/BLAS
- Helper functions
- Types
fpArray
FortranArr
Type Complex
Matrix
- 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.slice
Matrix.prototype.setLower
Matrix.prototype.setUpper
Matrix.prototype.upperBand
Matrix.prototype.lowerBand
Matrix.prototype.real
Matrix.prototype.imaginary
- Packed Matrices
Matrix.prototype.packedUpper
Matrix.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)
- Solves the matrix equations: f( A )·X = α·B, or X·f( A ) = α·B
Language differences with FORTRAN/BLAS
FORTRAN language can instrinsicly work with non-zero based multidimensional arrays and complex numbers. Below are some examples from FORTRAN that have no Javascript counterpart. The reference implementation of BLAS functions expect inputs of these types.
The FORTRAN complex scalar, complex array and complex "Matrix"
! double precision Complex number
COMPLEX*16 alpha
!
! double precision Complex array with offset 2
COMPLEX*16 vector(2,10)
!
! double precision complex MultiDimensional Array (matrix)
! rows 1 to 5 , columns 1 to 10
COMPLEX*16 A(1:5,1:10)
To work with the concept of non-zero based arrays and complex numbers in JS,
these FORTRAN constructs have equivalents in the blasjs
library.
The blasjs
helpers to create complex scalar, complex array and complex "Matrix" objects
const blas = require('blasjs');
const {
helper:{
/* create complex Object from 2 real numbers */
complex,
/* create single precision Real/complex arrays, */
fortranArrComplex32,
/* create double precision Real/Complex arrays */
fortranArrComplex64,
/* create single precision 2 dimensional Real/Complex arrays */
fortranMatrixComplex32,
/* Double precision 2 dimensional Real/Complex arrays */
fortranMatrixComplex64,
}
} = blas;
These functions are extensively documented in the helper functions. It is recommended you read this introductory part of the documentation first. before anything else.
Helper functions
blasjs
uses "FORTRAN like" complex number 32/64 bit precision multidimensional complex/real data.
These helper functions have been designed to significantly ease the use of working with these
data types in JavaScript.
Types
Typescript types/interfaces to mimic FORTRAN native (complex) multidimensional arrays.
fpArray
Wraps JS types [Float32Array][float32-array] and [Float64Array][float64-array] into a single type.
decl:
export type fpArray = Float32Array | Float64Array;
FortranArr
Abstraction of a 1 dimensional single/double precision complex/real FORTRAN array.
Used by level 1 and level 2 blasjs
functions.
FortranArr
objects should be created by the [fortranArrComplex32
][float32-array] and [fortranArrComplex64
][float64-array] helper functions.
decl:
export declare type FortranArr = {
base: number;
r: fpArray;
i?: fpArray;
s: (index: number) => (re?: number, im?: number) => number | Complex;
toArr: () => Complex[] | number[];
};
fields:
base
: fortran by default has a 1-value based array. Mimiced by this property.r
: See decl fpArray. The Real part of complex array.i
: (optional). See decl fpArray. The Imaginary part of the complex array.s
: set, get values of the array. Uses FORTRAN style array indexes taking the value ofbase
into account.toArr
generates an JavaScript array from ther
andi
(optional) data.
Usage:
const blas = require('blasjs');
const { helper: { fortranArrComplex64 } } = blas;
// You can also use the helper "complex" or "muxComplex"
// to generate JS complex arrays
const complexDataArr = [
{ re: 1.8, im: -0.2 },
{ re: 2.3, im: 0.6 }
];
// Create an object that mimics FORTRAN COMPLEX*16 SP(2:3)
// and fill it with above data
const sp = fortranArrComplex64(complexArr)(2);
// fast! normal JS TypedArray access
let re = sp.r[ 2 - sp.base ];
// 1.8
let im = sp.i[ 2 - sp.base ];
// -0.2
// not so fast, but easier syntax
let v = sp.s(2)(); // Terse syntax,
// { re: 1.8, im: -0.2 }
// sets the value at index 3 to complex: 0.11 - i0.9
// and returns the old value: 2.3 + i0.6
let old = sp.s(3)(0.11, -0.9);
sp.toArr();
// [ { re:1.8, im: -0.2 },
// { re:0.11, im: -0.9 } ]
Usage TypeScript:
import {
// pure types
Complex,
fpArray,
FortranArr,
// helper
helper
} from 'blasjs';
const { fortranArrComplex64 } = helper;
const complexArr: Complex[] [
{ re: 1.8, im: -0.2 },
{ re: 2.3, im: 0.6 }
];
// Create an object that mimics FORTRAN COMPLEX*16 SP(2:3)
// and fill it with above data
const sp: FortranArr = fortranArrComplex64(complexArr)(2);
let re = sp.r[ 2 - sp.base ]; //fastest! direct TypedArray access
// 1.8
let im = sp.i[ 2 - sp.base ]; //fastest! direct TypedArray access
// -0.2
// not so fast, but easier syntax
let v = sp.s(2)(); // Terse syntax,
// { re: 1.8, im: -0.2 }
// sets the value at index 3 to complex: 0.11 - i0.9
// and returns the old value: 2.3 + i0.6
let old = sp.s(3)(0.11, -0.9);
// {re: 2.3, im: 0.6 }
Type Complex
Typescript definition of a complex scalar.
decl:
declare type Complex = {
re: number;
im?: number;
}
Usage:
import { Complex /* pure type */ } from 'blasjs';
const complexArr: Complex[] [
{ re: 1.8, im: -0.2 },
{ re: 2.3, im: 0.6 }
];
Matrix
The Matrix
object is the input of many level-2 and level-3 blasjs
functions.
Matrix
is created by the helpers fortranMatrixComplex32 and
fortranMatrixComplex64.
Matrix
encapsulates objects of [Float32Array][float32-array] or [Float64Array][float64-array], the blasjs.
In this section the internals of Matrix
are explained in detail and how blasjs
accesses the data in the JS TypesArrays.
Float[32/64]Array Complex number storage for Matrix.
The Matrix
object has 2 properties r
and i
for respectively real and imaginary parts of matrix elements. These are the actual aforementioned JS TypedArrays. The imaginary property part is optional if it is not defined the Matrix represents solely an array of real elements.
declare type Matrix = { //Incomplete declaration
.
r: Float64Array|Float32Array;
i: Float64Array|Float32Array;
.
}
Handling FORTRAN matrices (multidimensional Arrays).
Contrary to languages like JavaScript. FORTRAN defines arrays ( aka DIMENSIONS
in FORTRAN lingo ) as 1 based arrays by default.. This can be changed by specifying a different base in the declaration.
Some examples:
DOUBLE PRECISION A1(4) ! array indexes 1,2,3,4
DOUBLE PRECISION A2(-1:3) ! array indexes -1,0,2,3
DOUBLE PRECISION A3(0:3) ! Javascript like Array with 4 elements
This expands to 2-dimensional arrays (matrices).
! (default) first index loops from 1 to 4(inclusive), second index loops from 1 to 5(inclusive)
DOUBLE PRECISION A1(4,5)
! first index loops from -2 to 4(inclusive), second index loops from -5 to -7(inclusive)
DOUBLE PRECISION A2(-2:4,-5:-7)
The values of the FORTRAN array basis are preserved as rowBase
(first index) and colBase
(second index).
declare type Matrix = { //SHOW PARTIAL TYPE
.
rowBase: number;
colBase: number;
.
}
JavaScript doesn't have the notion of typed 2-dimensional arrays
. The Matrix
objects handles this by mapping 2 dimensional arrays to single 1-dimensional array, by serializing data on a column-first basis.
For example the elements 2x2 Matrix will be mapped in a TypedArray as:
matrix A =
* *
| a11 a12 |
| a21 a22 |
* *
# Stored in TypedArray as
At = [a11,a21, a12, a22]
In case of complex values for A, the real part will be stored in r
and the imaginary part in i
each in the same column-first manner.
Performance
Direct access to TypedArrays within the Matrix
object is the preferable way to get/set matrix data.
Since BLAS (and therefore blasjs
) functions access matrices mostly to iterate over matrix row's first . It was decided to story 2 dimensional an a column-first basis.
To help with the calculation of finding/setting an element A(i,j) in Matrix
the following helper member functions have been added to Matrix
.
declare type Matrix = { //SHOW PARTIAL TYPE
.
rowBase: number;
colBase: number;
nrCols: number;
nrRows: number;
.
colOfEx(number): number;
coord(col): (row) => number;
setCol(col: number, rowStart: number, rowEnd: number, value: number): void;
.
}
Explanation:
nrRows
: The number of rows in the matrix.nrCols
: The number of columns in the matrix.colofEx
: Calculates the physical location of acolumn offset
within theTypedArray
. Taking int account the column basecolBase
and row basecolBase
. The index of A(i,j)= (j - colBase)*nrRows + i - rowBase
.coord
: Curried, emulates non-zero based FORTRAN index values for 2 dimensional Arrays. The index that is iterated over the least (usually) is used as the first to create the curried function.setCol
: Uses underlyingTypedArray
,fill
method to set multiple column elements to a single value.
Creating new transformed Matrix instances from existing ones
One can create/transform new Matrix instances form existing onces. A copy of all relevant data is made into the new Matrix
instance.
Matrix.prototype.slice
Slices a rectangular piece of data out of an matrix into a new Matrix
instance. All arguments are FORTRAN-style non-zero based indexes.
declare type Matrix = { // only "slice" is shown
.
slice(rowStart: number, rowEnd: number, colStart: number, colEnd: number): Matrix;
.
}
rowStart
: The row in the matrix to begin slicing.rowEnd
: The last row to include in the slice.colStart
: The column in the matrix to begin slicing.colEnd
: The last column to include in the slice.
Matrix.prototype.setLower
Returns a new Matrix where everything below the matrix diagonal is set to a value
.
Sets the real (and imaginary part, if it exist) to said value.
declare type Matrix = { // only "setLower" is shown.
.
setLower(value = 0): Matrix;
.
}
Matrix.prototype.setUpper
Returns a new Matrix where everything below the matrix diagonal is set to a value
.
Sets the real (and imaginary part, if it exist) to said value.
declare type Matrix = { //only "setUpper" is shown
.
setUpper(value = 0): Matrix;
.
}
Matrix.prototype.upperBand
Returns a new Matrix
object where the k
super-diagonals are retained into the new copy.
The efficient storage format of BLAS
band matrices is used.
declare type Matrix = { //only "upperBand" is shown
.
upperBand(k = nrRows - 1): Matrix;
.
}
The default value for k
is the the maximum size possible for the number of super-diagonals: ( nrRows-1
)
Matrix.prototype.lowerBand
Returns a new Matrix
object where the k
sub-diagonals are retained into the new copy.
The efficient storage format of BLAS
band matrices is used.
declare type Matrix = { // Only "lowerBand" is shown
.
lowerBand(k = nrRows-1): Matrix;
.
}
The default value for k
is the the maximum size possible for the number of sub-diagonals: ( nrRows-1
)
Matrix.prototype.real
Returns a new Matrix
object where with only real elements (omits the imaginary part during copy).
declare type Matrix = { // Only "real" is shown
.
real(): Matrix;
.
}
Matrix.prototype.imaginary
Returns a new Matrix
object where with only imaginary part of the element (omits the real part during copy).
If there were now imaginary elements
declare type Matrix = { // Only "imaginary" is shown.
.
imaginary(): Matrix;
.
}
Packed Matrices
BLAS ( and therefore blasjs
) can work with upper/lower-matrices and band-matrices in the most compacted form, aka packed matrices
.
With packed matrices
there are no unused elements in the matrix (no zeros). Packed matrices are instances of FortranArr. BLAS reference implementation in FORTRAN uses 1 dimensional arrays as an analog.
Matrix.prototype.packedUpper
Creates a packed array from a normal/upper Matrix only referencing the diagonal and super-diagonals.
declare type Matrix = { // Only "packedUpper" is shown.
.
packedUpper(k = nrRows-1): FortranArr;
.
}
The default value for k
is the the maximum size possible for the number of super-diagonals: ( nrRows-1
)
Matrix.prototype.packedLower
Creates a packed array from a normal/upper Matrix only referencing the diagonal and sub-diagonals.
declare type Matrix = { // Only "packedUpper" is shown.
.
packedLower(k = nrRows-1): FortranArr;
.
}
The default value for k
is the the maximum size possible for the number of sub-diagonals: ( nrRows-1
)
declare type Matrix = { // Only "packedUpper" is shown.
.
packedLower(k = nrRows - 1): FortranArr;
.
}
The default value for k
is the the maximum size possible for the number of sub-diagonals: ( nrRows - 1
)
Convert Matrix object to a JS array
The Matrix
object can convert the underlying TypedArray(s) to real JavaScript arrays.
Matrix.prototype.toArr
Creates a normal JS Array with element of type 'number' or of type Complex
declare type Matrix = { // Only "toArr" is shown.
.
toArr(): number[]|Complex[];
.
}
Summary: Full type declaration of Matrix
Putting it all together, here is the full type declaration of Matrix
:
declare type Matrix = {
rowBase: number;
colBase: number;
nrCols: number;
nrRows: number;
r: fpArray;
i?: fpArray; //optional
//
// methods
//
colOfEx(column: number): void;
coord(col: number): (row: number): void;
setCol(col: number, rowStart: number, rowEnd: number, value: number): void;
//
slice(rowStart: number, rowEnd: number, colStart: number, colEnd: number): Matrix;
setLower(value?: number): Matrix;
setUpper(value?: number): Matrix;
upperBand(k: number): Matrix;
lowerBand(k: number): Matrix;
real(): Matrix;
imaginary(): Matrix;
//
packedUpper(value?: number): FortranArr;
packedLower(value?: number): FortranArr;
//
toArr(): Complex[] | number[];
}
Matrix Examples
Common usage of the Matrix type.
const blas = require('../blasjs');
const { fortranMatrixComplex64 } = blas.helper;
// some matrix data 3x3 array aka a_row_column
const a11 = { re: .2, im: -.11 };
const a21 = { re: .1, im: -.2 };
const a31 = { re: .3, im: .9 };
const a12 = { re: .4, im: .5 };
const a22 = { re: .9, im: -.34 };
const a32 = { re: -.2, im: .45 };
const a13 = { re: -.1, im: .89 };
const a23 = { re: .43, im: .23 };
const a33 = { re: .23, im: .56 };
//create Matrix A
const A = fortranMatrixComplex64([
a11, a21, a31, a12, a22, a32, a13, a23, a33
])(3, 3);
// get the second column
const columnj = A.colOfEx(3); // formula: (j - colBase )* nrRows
A.r[A.coord(1, 2)] === a12.re // true
A.slice(1, 2, 2, 3);// creates new matrix with elements from A
/*[
a12 a13
a22 a23
]*/
A.setLower(0); // creates new Matrix object from A
/*[
a11 a12 a13
0 a22 a23
0 0 a33
]*/
A.setUpper(0); //creates new Matrix object from A
/*[
a11 0 0
a21 a22 0
a31 a32 a33
]*/
A.upperBand(1); // banded array storage for BLAS(js)
/*[
0 a12 a23
a11 a22 a33
]*/
A.lowerBand(1); // banded array storage for BLAS(js)
/*[
a11 a22 a33
a21 a32 0
]*/
const Areal = A.real();
// Areal.i is undefined
// Areal.r =
/*[
0.2 0.4 -0.1
0.1 0.9 0.43
0.3 -0.2, 0.23
]*/
const Aimag = A.imaginary();
// imaginary parts are copied to real side in new Matrix
// Aimag.i is undefined
// Aimag.r =
/*[
-0.11 0.5, 0.89
-0.2 -0.34 0.23
0.9 0.45 0.56
]*/
A.packedUpper(1)
/* [ a11 a12 a22 a23 a 33] */
A.packedLower(1)
/* [ a11 a21 a22 a32 a33] */
A.toArr(); // returns JavaScript Array
/*[
{ re: 0.2, im: -0.11 },
{ re: 0.1, im: -0.2 },
{ re: 0.3, im: 0.9 },
{ re: 0.4, im: 0.5 },
{ re: 0.9, im: -0.34 },
{ re: -0.2, im: 0.45 },
{ re: -0.1, im: 0.89 },
{ re: 0.43, im: 0.23 },
{ re: 0.23, im: 0.56 }
]
*/
General Helpers
Collection of helper function to manipulate common JS array and object types in a functional way.
arrayrify
Creates a new function from an existing one, to add the ability to accept vectorized input.
Example:
const blas = require('blasjs');
const { helper: { arrayrify } } = blas;
const PI = Math.PI;
//
const sin = arrayrify(Math.sin)
sin([PI/3, PI/4, PI/6]); // returns array aswell
// [ 0.866025, 0.7071067811, 0.5 ]
sin(PI/3); // returns scalar
sin( [ PI/3 ] ); // returns scalar
// 0.866025
sin([]) // edge case
// undefined
sin() //
//NaN same as Math.sin()
complex
Mimics the GNU Fortran extension complex.
Creates a JS object that represents a complex scalar number.
Used by blasjs
for scalar input arguments.
Example:
const blas = require('blasjs');
const { helper: { complex } } = blas;
const c1 = complex(0.1,0.3);
//c1 = { re: 0.1, im: 0.3 }
const c2 = complex();
//c2 = { re: 0, im: 0 }
const c3 = complex(0.5);
//c3 = { re: 0.5, im:0 }
each
Curried functional analog to Array.prototype.forEach
, but takes arbitrary input.
Example:
const blas = require('blasjs');
const { helper: { each } } = blas;
//Iterates over an object like a map
const curry1 = each( { hello: 'world', ts: new Date() })
curry1( (val, key) => console.log(`${val} ':' ${key}`)))
//world: hello
//2018-05-10T13:57:08.923Z : ts
//Handles array also
each( ['a','b','c','d'])( (v,idx) =>console.log(v,idx, typeof idx))
//a 0 number
//b 1 number
//c 2 number
//d 3 number
//Edge cases
each()(console.log)
//nothing happens
each(null)(console.log)
//nothing happens
each([])(console.log)
//nothing happens
map
Curried functional analog to Array.prototype.map
, but takes arbitrary input.
:warning: Forces the output to be a an array regardless of the input.
Example:
const blas = require('blasjs');
const { helper: { map } } = blas;
//trivial
map([1,2,3])(v=>v*2);
//[ 2, 4, 6 ]
//key properties
map({ a:'A', b:'B' })( (val, key) => key+'='+val);
//[ 'a=A', 'b=B' ]
map(null)( v => '/'+v);
//[]
map()( v => '/'+v);
//[]
map()()
//[]
muxCmplx
Creates an array of complex numbers from arrayed input. The result is always an array type.
Example:
const blas = require('blasjs');
const { helper: { muxCmplx } } = blas;
const reals = [ 0.1, -0.2, 0.3, 0.45 ];
const imaginary = [ 0.1, -0.2, 0.3, 0.45 ];
// normal usage
muxCmplx(reals, imaginary)
/*[ { re: 0.1, im: 0.1 },
{ re: -0.2, im: -0.2 },
{ re: 0.3, im: 0.3 },
{ re: 0.45, im: 0.45 } ]*/
//R recycling rule is used
muxCmplx([1,2], imaginary)
/*^[ { re: 1, im: 0.1 },
{ re: 2, im: -0.2 },
{ re: 1, im: 0.3 },
{ re: 2, im: 0.45 } ]*/
//dont care about imaginary
muxCmplx(reals)
/*[ { re: 0.1, im: undefined },
{ re: -0.2, im: undefined },
{ re: 0.3, im: undefined },
{ re: 0.45, im: undefined } ]*/
muxCmplx() //
// [ { re: undefined, im: undefined } ]
muxCmplx(1) //
// [ { re: 1, im: undefined } ]
//3 specify real and imaginary
muxCmplx(1,-2)//
//[ { re: 1, im: -2 } ]
numberPrecision
Enforces significant figure of a number, or on the properties of a JS object (deep search) with numeric values.
Example:
const blas = require('blasjs');
const { helper: { numberPrecision } } = blas;
const _4 = numberPrecision(4);
_4(0.123456789);
//0.1235
_4(123456789)
//123500000
//enforce significance over properties
_4( { car: 'Mazda' , aux: { priceUSD: 24.3253E+3, maxWarpSpeed:3.42111E-4 } } );
//{ car: 'Mazda', aux: { priceUSD: 24330, maxWarpSpeed: 0.0003421 } }
_4([0.123456, 0.78901234]);
//[ 0.1235, 0.789 ]
Vector Constructors
These constructors create the FortranArr
object for working with single/double precision complex/real Arrays.
fortranArrComplex32
Constructs a FortranArr object using [Float32Array][float32-array] as the underlying array(s) (plural in the case of complex) elements.
declare function fortranArrComplex32(
...rest: (number | number[] | Complex | Complex[])[]
): (offset = 1) => FortranArr;
Argument list
:
rest
: takes as input.offset
: the Fortran dimension offset (defaults to 1)
See Examples
fortranArrComplex64
Constructs a FortranArr object using [Float64Array][float64-array] as the underlying array(s) (plural in the case of complex) elements.
declare function fortranArrComplex64(
...rest: (number | number[] | Complex | Complex[])[]
): (offset = 1) => FortranArr;
Argument list
:
rest
: takes as input.offset
: the Fortran dimension offset (defaults to 1)
Vector creation examples
const blas = require('blasjs');
const { fortranArrComplex64, fortranArrComplex32 } = blas.helper;
const complexDataArr = [
{ re: 1.8, im: -0.2 },
{ re: 2.3, im: 0.6 }
];
const realData = [ 0.1, 2, 0.34, .56 ];
const sp1 = fortranArrComplex32(complexDataArr)();
//sp1.r = [ 1.7999999523162842, 2.299999952316284 ],
//sp1.i = [ -0.20000000298023224, 0.6000000238418579 ],
const sp2 = fortranArrComplex32(realData)();
//sp2.r = [ 0.10000000149011612, 2, 0.3400000035762787, 0.5600000023841858 ]
//sp2.i = undefined
const sp3 = fortranArrComplex32({re:0.2, im:-0.3})();
//[ 0.20000000298023224 ]
//[ -0.30000001192092896 ]
const sp4 = fortranArrComplex32(123)(4);
/*{
base: 4,
r: Float32Array [ 123 ],
i: undefined,
}*/
const sdp1 = fortranArrComplex64(complexDataArr)();
//sp1.r = [ 1.8, 2.3 ],
//sp1.i = [ -0.2, 0.6 ],
const sdp2 = fortranArrComplex64(realData)();
//sp2.r = [ 0.1, 2, 0.34, 0.56 ]
//sp2.i = undefined
const sp3 = fortranArrComplex64({re:0.2, im:-0.3})();
//[ 0.2 ]
//[ -0.3 ]
const sp4 = fortranArrComplex64(123)(4);
/*{
base: 4,
r: Float32Array [ 123 ],
i: undefined,
}*/
Matrix Constructors
These constructors create the Matrix
object for working with single/double precision complex/real Matrices.
fortranMatrixComplex32
Constructs a Matrix object using [Float32Array][float32-array] as the underlying array(s) (plural in the case of complex) elements.
declare function fortranMatrixComplex32(...rest: (Complex | Complex[])[]):
(nrRows: number, nrCols: number, rowBase?: number, colBase?: number) => Matrix
Argument list
:
rest
: takes as input.nrRows
: where nrRows is equal ton
in the matrix A(m,n).nrCols
: where nrCols is equal tom
in the matrix A(m,n).rowBase
: FORTRAN offset for the first dimension (rows) as explained in [Language differences][language-differences].rowBase
: FORTRAN offset for the second dimension (columns) as explained in [Language differences][language-differences].
See Examples
fortranMatrixComplex64
Constructs a Matrix object using [Float64Array][float64-array] as the underlying array(s) (plural in the case of complex) elements.
declare function fortranMatrixComplex64(...rest: (Complex | Complex[])[]):
(nrRows: number, nrCols: number, rowBase?: number, colBase?: number) => Matrix
Argument list
:
rest
: takes as input.nrRows
: where rnRows is equal ton
in the matrix A(m,n).nrCols
: where nrCols is equal tom
in the matrix A(m,n).rowBase
: FORTRAN offset for the first dimension (rows) as explained in [Language differences][language-differences].rowBase
: FORTRAN offset for the second dimension (columns) as explained in [Language differences][language-differences].
Matrix Creation Examples
const blas = require('blasjs');
const {
fortranMatrixComplex64,
fortranMatrixComplex32
} = blas.helper;
// some matrix data 3x3 array aka a_row_column
const a11 = { re: .2, im: -.11 };
const a21 = { re: .1, im: -.2 };
const a31 = { re: .3, im: .9 };
const a12 = { re: .4, im: .5 };
const a22 = { re: .9, im: -.34 };
const a32 = { re: -.2, im: .45 };
const a13 = { re: -.1, im: .89 };
const a23 = { re: .43, im: .23 };
const a33 = { re: .23, im: .56 };
const {
fortranMatrixComplex64,
fortranMatrixComplex32
} = blas.helper;
// Some matrix data 3x3 array aka a_row_column
const a11 = { re: .2, im: -.11 };
const a21 = { re: .1, im: -.2 };
const a31 = { re: .3, im: .9 };
const a12 = { re: .4, im: .5 };
const a22 = { re: .9, im: -.34 };
const a32 = { re: -.2, im: .45 };
const a13 = { re: -.1, im: .89 };
const a23 = { re: .43, im: .23 };
const a33 = { re: .23, im: .56 };
//functional curry to prepare for different mappings of A()
const A32 = fortranMatrixComplex64([
a11, a21, a31, a12, a22, a32, a13, a23, a33
]);
//matrix 1
const m1 = A32(3, 3); // 3x3 matrix with rowBase=1, colBase=1
// mimic FORTRAN "COMPLEX*8 A(-2:1, -3:0)"
const m2 = A32(3, 3, -2, -3);
//same as FORTRAN default COMPLEX*8 A(3,3) !aka A(1:3,1:3)
const m3 = A32(3, 3, 1, 1)
/* double precision */
/* double precision */
/* double precision */
const A64 = fortranMatrixComplex64([
a11, a21, a31, a12, a22, a32, a13, a23, a33
]);
// matrix 1 FORTRAN "COMPLEX*16 A(-2:1, -3:0).
const m1 = A64(3, 3); // 3x3 matrix with rowBase=1, colBase=1
// mimic FORTRAN "COMPLEX*16 A(-2:1, -3:0)"
const m2 = A64(3, 3, -2, -3);
// same as FORTRAN default COMPLEX*16 A(3,3) !aka A(1:3,1:3)
const m3 = A64(3, 3, 1, 1);
A note on numeric precision
In blasjs
, contrary to the FORTRAN reference implementation, the numeric precision of a routine, is not determined by its name but by how its arguments like FortranArr
and Matrix
are constructed before used as arguments in blasjs
routines. The original FORTRAN names are kept for backwards compatibility to ease the porting of FORTRAN code toward blasjs
.
Mimicking FORTRAN OUT Arguments
In FORTRAN a subroutine can have IN, OUT and IN/OUT scalar arguments. In JavaScript only arguments of type object
are passed by reference. To mimic OUT and IN/OUT FORTRAN arguments, scalars are wrapped in a JS object. See Construct a Givens plane rotation for an example.
Level 1 routines
Routines categorized as Level 1 perform scalar-vector and vector-vector operations.
Euclidean norm: √(xᴴ·x) or √(xᵀ·x)
Calculates the norm of a (complex) vector.
xᴴ is the conjugate of x
xᵀ is the transpose of x
scrnm2/dznrm2, snrm2/dnrm2
scrnm2
: complex, [single or double precision][precision-note]. See [blas ref][ref-scnrm2].dznrm2
: complex, (alias forscrnm2
). See [blas ref][ref-dznrm2].snrm2
: real, [single or double precision][precision-note]. See [blas ref][ref-snrm2].dnrm2
: real, (alias fordnrm2
). See [blas ref][ref-dnrm2].
decl
function scnrm2(n: number, x: FortranArr, incx: number): number;
function dznrm2(n: number, x: FortranArr, incx: number): number;
function snrm2(n: number, x: FortranArr, incx: number): number;
function dnrm2(n: number, x: FortranArr, incx: number): number;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { scnrm2, dznrm2, snrm2, dnrm2 } = BLAS.level1;
Construct a Givens plane rotation
See [wiki][givens-rotation].
|c -s| × |a| = |r |
|s c| |b| |0 |
r = √( a² + b² )
srotg/drotg, crotg/zrotg
srotg
: real, (alias fordrotg
). See [blas ref][ref-srotg].drotg
: real, [single or double precision][precision-note]. See [blas ref][ref-drotg].crotg
: complex, [single or double precision][precision-note]. See [blas ref][ref-crotg].zrotg
: complex, (alias forcrotg
). See [blas ref][ref-zrotg].
decl
function srotg(p: { sa: number, sb: number, c: number, s: number } ): void;
function drotg(p: { sa: number, sb: number, c: number, s: number } ): void;
function crotg(ca: Complex, cb: Complex, c: { val: number }, s: Complex ): void
function zrotg(ca: Complex, cb: Complex, c: { val: number }, s: Complex ): void
Usage:
const BLAS = require('blasjs');
const { srotg, drotg, crotg, zrotg } = BLAS.level1;
Construct the modified Givens rotation matrix H
Construct the modified Givens transformation matrix H which zeros the second component of the 2 vector ( sx1√(sd1) , sy1 √(sd2) ) See [researchgate.net][construct-modified-givens-transformation].
srotmg/drotmg
srotmg
: real, (alias fordrotmg
). See [blas ref][ref-srotmg].drotmg
: real, [single or double precision][precision-note]. See [blas ref][ref-drotmg].
decl
function srotmg(p: { sd1: number, sd2: number, sx1: number, sy1: number, sparam: FortranArr }): void;
function drotmg(p: { sd1: number, sd2: number, sx1: number, sy1: number, sparam: FortranArr }): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { srotmg, drotmg } = BLAS.level1;
Apply the modified Givens Transformation
See [wiki][apply-modified-givens-transformation].
srotm/drotm
srotm
: real, (alias fordrotm
). See [blas ref][ref-srotm].drotm
: real, [single or double precision][precision-note]. See [blas ref][ref-drotm].
decl
function srotm(n: number, sy: FortranArr, incx: number, sy: FortranArr, incy: number, sparam: FortranArr)): void;
function drotm(n: number, sy: FortranArr, incx: number, sy: FortranArr, incy: number, sparam: FortranArr)): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { srotm, drotm } = BLAS.level1;
Applies a plane rotation
See [researchgate.net][construct-modified-givens-transformation].
srot/drot, csrot/zdrot
srot
: real, (alias fordrot
). See [blas ref][ref-srot].drot
: real, [single or double precision][precision-note]. See [blas ref][ref-drot].csrot
: complex, (alias forzdrot
). See [blas ref][ref-csrot].zdrot
: complex, [single or double precision][precision-note]. See [blas ref][ref-zdrot].
decl
function srot(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number, c: number, s: number): void;
function drot(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number, c: number, s: number): void;
function csrot: (n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number, c: number, s: number): void;
function zdrot: (n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number, c: number, s: number): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { srot, drot, csrot, zdrot } = BLAS.level1;
Scale a vector by a constant
x ⟵ α·x
sscal/dscal, cscal/zscal, csscal/zdscal
sscal
: Alias fordscal
. See [blas ref][ref-sscal].dscal
: by a REAL constant. See [blas ref][ref-dscal].cscal
: Alias forzscal
. See [blas ref][ref-cscal].zscal
: Scales a COMPLEX vector with a COMPLEX constant. See [blas ref][ref-zscal].csscal
: Alias forzdscal
. [blas ref][ref-csscal].zdscal
: Scales a COMPLEX vector with a REAL constant. See [blas ref][ref-zdscal].
decl
function sscal(n: number, sa: number, sx: FortranArr, incx: number): void;
function dscal(n: number, sa: number, sx: FortranArr, incx: number): void;
function cscal(n: number, ca: Complex,cx: FortranArr, incx: number): void;
function zscal(n: number, ca: Complex,cx: FortranArr, incx: number): void;
function csscal(n: number, sa: number, cx: FortranArr, incx: number): void;
function zdscal(n: number, sa: number, cx: FortranArr, incx: number): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { sscal, dscal, cscal, zscal, csscal, zdscal } = BLAS.level1;
Takes the sum of the absolute values of the components of vector
s ⟵ ∑ ∥ Re( x ) ∥ + ∥ Im( x ) ∥
sasum/dasum, scasum/dzasum
sasum
: Alias fordasum
. See [blas ref][ref-sasum]dasum
: uses REAL vector, ( [single or double precision][precision-note] ). See [blas-ref][ref-dasum].scasum
: Alias fordzasum
. See [blas ref][ref-scasum].dzasum
: uses Complex vector, ( [single or double precision][precision-note] ). See [blas-ref][ref-dzasum].
decl
function sasum(n: number, sx: FortranArr, incx: number): number;
function dasum(n: number, sx: FortranArr, incx: number): number;
function scasum(n: number, cx: FortranArr, incx: number): number;
function dzasum(n: number, cx: FortranArr, incx: number): number;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { sasum, dasum, scasum, dzasum } = BLAS.level1;
Interchanges 2 vectors
Swap 2 vectors.
sswap/dswap, cswap/zswap
sswap
: Alias fordswap
. See [blas ref][ref-sswap].dswap
: REAL vector, ( [single or double precision][precision-note] ). See [blas ref][ref-dasum].cswap
: Alias forzswap
. See [blas ref][ref-xcswap].zswap
: REAL vector, ( [single or double precision][precision-note] ). See [blas ref][ref-zswap].
decl
function sswap(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number ): void;
function dswap(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number ): void;
function cswap(n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number ): void;
function zswap(n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number ): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { sswap, dswap, cswap, zswap } = BLAS.level1;
Dot product of two complex vectors
xᵀ·y or xᴴ·y
cdotu/cdotc, zdotu/zdotc
cdotu
: Alias forzdotu
. See [blas ref][ref-zdotc].cdotc
: Alias forzdotc
. See [blas ref][ref-cdotc].zdotu
:xᵀ·y
. Complex arguments, ( [single or double precision][precision-note] ). See [blas-ref][ref-zdotu].zdotc
:xᴴ·y
. The fist complex vector argument is made conjugate, ( [single or double precision][precision-note] ). See [blas-ref][ref-zdotc].
decl
function cdotu(n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number): Complex;
// first argument sx is made conjugate
function cdotc(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number ): Complex;
function zdotu(n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number ): Complex;
// first argument sx is made conjugate
function zdotc(n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number ): Complex;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { cdotu, cdotc, zdotu, zdotc } = BLAS.level1;
Dot product of two non complex vectors
xᵀ·y
sdot/ddot, sdsdot/dsdot
sdot
: Alias fordsdot
. See [blas ref][ref-sdot].ddot
: Alias fordsdot
. See [blas ref][ref-ddot].sdsdot
: Alias fordsdot
. See [blas ref][ref-sdsdot].dsdot
:xᵀ·y
Inner product of 2 vectors ( [single or double precision][precision-note] ). See [blas ref][ref-dsdot].
decl
function sdot(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): number;
function ddot(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): number;
function sdsdot(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): number;
function dsdot(n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): number;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { sdot, ddot, sdsdot, dsdot } = BLAS.level1;
Finds the index of the first element having maximum absolut value.
Find k for wich: ∥ xₖ ∥ > ∥ xₜ ∥ for all t ∈ [1, n].
isamax/idamax, icamax/izamax
isamax
: Alias foridamax
. See [blas ref]:[ref-isamax]idamax
: Find the index of the maximum element of a REAL vector ( [single or double precision][precision-note] ). See [blas ref][ref-idamax].icamax
: Alias forizamax
. See [blas ref]:[ref-icamax]izamax
: Find the index of the maximum element of a COMPLEX vector ( [single or double precision][precision-note] ). See [blas ref][ref-izamax].
decl
function isamax: (n: number, sx: FortranArr, incx: number): number;
function idamax: (n: number, sx: FortranArr, incx: number): number;
function icamax: (n: number, sx: FortranArr, incx: number): number;
function izamax: (n: number, sx: FortranArr, incx: number): number;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { isamax, idamax, icamax, izamax } = BLAS.level1;
Copy a vector x to a vector y
scopy/dcopy, ccopy/zcopy
scopy
: Alias fordcopy
. See [blas ref]:[ref-scopy]dcopy
: Copies a REAL vector ( [single or double precision][precision-note] ). See [blas ref][ref-dcopy].ccopy
: Alias forzcopy
. See [blas ref]:[ref-ccopy]zcopy
: Copies a COMPLEX vector ( [single or double precision][precision-note] ). See [blas ref][ref-zcopy].
decl
function scopy (n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): void;
function dcopy (n: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): void;
function ccopy (n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number): void;
function zcopy (n: number, cx: FortranArr, incx: number, cy: FortranArr, incy: number): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { scopy, dcopy, ccopy, zcopy } = BLAS.level1;
Constant times a vector plus a vector
y ⟵ y + a·x where y, a and x can be complex or a real number.
saxpy/daxpy, caxpy/zaxpy
saxpy
: Alias fordaxpy
. See [blas ref]:[ref-saxpy].daxpy
: REAL constant used in multiplication with a vector ( [single or double precision][precision-note] ). See [blas ref]:[ref-daxpy].caxpy
: Alias forzaxpy
. See [blas ref]:[ref-saxpy].zaxpy
: Complex constant used in multiplication with a vector ( [single or double precision][precision-note] ). See [blas ref]:[ref-zaxpy].
decl
function saxpy(n: number, sa: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): void;
function daxpy(n: number, sa: number, sx: FortranArr, incx: number, sy: FortranArr, incy: number): void;
function caxpy(n: number, ca: Complex, cx: FortranArr, incx: number, cy: FortranArr, incy: number): void;
function zaxpy(n: number, ca: Complex, cx: FortranArr, incx: number, cy: FortranArr, incy: number): void;
See: how to create fortranArr.
Usage:
const BLAS = require('blasjs');
const { saxpy, daxpy, caxpy, zaxpy } = BLAS.level1;
Level 2 Routines
Routines categorized as Level 2 perform Matrix-vector operations.
The hermitian rank 2 operation A ⟵ α·x·yᴴ + conjg( α )·y·xᴴ + A
( ᴴ means conjugate transpose )
For the routines chpr2
and zhpr2
the matrix A is in packed form ( a fortranArr ).
For the routines cher2
and zher2
the matrix symmetry is exploited (use only upper/lower triangular part of the matrix).
cher2/zher2, chpr2|zhpr2
cher2
: alias forzher2
. See [blas ref][ref-cher2].zher2
: The MatrixA
is in upper or lower triangular form ( [single or double precision][precision-note] ). See [blas ref][ref-zher2].chpr2
: alias forzhpr2
. See [blas ref][ref-chpr2].zhpr2
: The matrixA
is in packed form ( [single or double precision][precision-note] ). See [blas ref][ref-zhpr2].
decl
function cher2|zher2(
uplo: "u" | "l",
n: number,
alpha: Complex,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
a: Matrix,
lda: number): void;
function chpr2|zhpr2(
uplo: "u" | "l",
n: number,
alpha: Complex,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
ap: FortranArr): void;
See: how to create fortranArr.
See: how to create Matrix.
Usage:
const BLAS = require('blasjs');
const { cher2, zher2, chpr, zhpr } = BLAS.level2;
The symmetric rank 2 operation A ⟵ α·x·yᵀ + α·y·xᵀ + A
For the routines sspr2
and dspr2
the matrix A is in packed form ( a fortranArr ).
For the routines ssyr2
and dsyr2
the matrix symmetry is exploited (use only upper/lower triangular part of the matrix).
sspr2/dspr2, ssyr2/dsyr2
sspr2
: Alias for dspr2. See [blas ref][ref-sspr2].dspr2
: The matrixA
is in packed form ( [single or double precision][precision-note] ). See [blas ref][ref-dspr2].ssyr2
: Alias for dsyr2. See [blas ref][ref-ssyr2].dsyr2
: The MatrixA
is in upper or lower triangular form ( [single or double precision][precision-note] ). See [blas ref][ref-dsyr2].
decl
function sspr2|dspr2(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
ap: FortranArr):void;
function ssyr2|dsyr2(
uplo: 'u' | 'l',
n: number,
alpha: number,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
A: Matrix,
lda: number): void;
See: how to create fortranArr.
See: how to create Matrix.
Usage:
const BLAS = require('blasjs');
const { sspr2, dspr2, ssyr2, dsyr2 } = BLAS.level2;
The rank 1 operation A ⟵ α·x·yᴴ + A or A ⟵ α·x·yᵀ + A
( ᴴ means conjugate transpose )
The subroutines sger
and dger
perform A ⟵ α·x·yᵀ + A. Where α is a REAL scalar,
A, x, y are [single or double precision][precision-note] REAL Matrix and vectors.
The subroutines cgerc
and zgerc
perform A ⟵ α·x·yᴴ + A. Where α is a COMPLEX scalar,
A, x, y are [single or double precision][precision-note] COMPLEX Matrix and vectors.
The subroutines cgeru
and zgeru
perform A ⟵ α·x·yᵀ + A. Where α is a COMPLEX scalar,
A, x, y are [single or double precision][precision-note] COMPLEX Matrix and vectors.
sger/dger, cgerc/zgerc, cgeru/zgeru
sger
: alias fordger
. See [blas ref][ref-sger].dger
: See [blas ref][ref-dger].cgerc
: alias forzgerc
. See [blas ref][ref-cgerc].zgerc
: See [blas ref][ref-zgerc].cgeru
: alias forzgeru
. See [blas ref][ref-cgeru].zgeru
: See [blas ref][ref-zgeru].
decl
function sger|dger(
m: number,
n: number,
alpha: number,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
a: Matrix,
lda: number):void;
function cgerc|zgerc(
m: number,
n: number,
alpha: Complex,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
a: Matrix,
lda: number): void;
function cgeru|zgeru(
m: number,
n: number,
alpha: Complex,
x: FortranArr,
incx: number,
y: FortranArr,
incy: number,
a: Matrix,
lda: number): void;
See: how to create fortranArr.
See: how to create Matrix.
Usage:
const BLAS = require('blasjs');
const { sger, dger, cgerc, zgerc, cgeru, zgeru } = BLAS.level2;
The hermitian rank 1 operation A ⟵ α·x·xᴴ + A
( ᴴ means conjugate transpose )
For the routines cher
and zher
α is a REAL scalar, the matrix symmetry of A is exploited (use only upper/lower triangular part of the matrix).
For the routines chpr
and zhpr
α is a REAL scalar, the matrix A is in packed form ( a fortranArr ).
Naming
cher
: alias forzher
. See [blas ref][ref-cher].zher
: For [single or double precision][precision-note] complexx
andA
. See [blas ref][ref-cher].chpr
: alias forzher
. See [blas ref][ref-cher].zhpr
: For [single or double precision][precision-note] complexx
andA
. See [blas ref][ref-cher].
function cher(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
a: Matrix,
lda: number): void;
function zher(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
a: Matrix,
lda: number): void;
function chpr(u
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
ap: FortranArr): void;
function zhpr(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
ap: FortranArr): void;
See: how to create fortranArr.
See: how to create Matrix.
Usage:
const BLAS = require('blasjs');
const { cher, zher, chpr, zhpr } = BLAS.level2;
The symmetric rank 1 operation A ⟵ α·x·xᵀ + A
For the routines ssyr
and dsyr
α is a REAL scalar, the symmetry of the REAL matrix A is exploited (use only upper/lower triangular part of the matrix).
For the routines sspr
and dspr
α is a REAL scalar, the REAL matrix A is in packed form ( a fortranArr ).
sspr/dspr, ssyr/dsyr
sspr
: alias fordspr
. See [blas ref][ref-sspr].dspr
: For [single or double precision][precision-note] REALα
,x
andA
. See [blas ref][ref-dspr].ssyr
: alias forssyr
. See [blas ref][ref-ssyr].dsyr
: For [single or double precision][precision-note] REALα
,x
andA
. See [blas ref][ref-dsyr].
decl
function sspr(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
ap: FortranArr): void;
function dspr(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
ap: FortranArr): void;
function ssyr(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
a: Matrix,
lda: number): void;
function dsyr(
uplo: "u" | "l",
n: number,
alpha: number,
x: FortranArr,
incx: number,
a: Matrix,
lda: number): void;
See: how to create fortranArr.
See: how to create Matrix.
Usage:
const BLAS = require('blasjs');
const { sspr, dspr, ssyr, dsyr } = BLAS.level2;
The matrix-vector operation, y ⟵ α·A·x + β·y, or y ⟵ α·Aᵀ·x + β·y or y ⟵ α·Aᴴ·x + β·y
Aᴴ is the complex conjugate transpose of matrix A
The naming in blasjs does not reflect the precision used, precision is determined by [argument construction][precision-note]. The naming is maintained for compatibility with the reference implementation.
cgbmv/zgbmv, chbmv/zhbmv, ssbmv/dsbmv, sgbmv/dgbmv, stbmv/dtbmv, chemv/zhemv, sgemv/dgemv, cgemv/zgemv, chpmv/zhpmv, sspmv/dspmv, ssymv/dsymv
| subroutine | operation | complex | real | type of matrix A | blas ref link | | ----------- | ------------------------------------------------------ | ------- | ------- | ----------------------------- | ------------------------------------- | | cgbmv/zgbmv | y ⟵ α·A·x + β·y , y ⟵ α·Aᵀ·x + β·y, y ⟵ α·Aᴴ·x + β·y | α, A, β | none | upper/lower band | [cgbmv][ref-cgbmv]/[zgbmv][ref-zgbmv] | | chbmv/zhbmv | y ⟵ α·A·x + β·y | α, A, β | none | upper/lower band | [chbmv][ref-chbmv]/[zhbmv][ref-zhbmv] | | | ssbmv/dsbmv | y ⟵ α·A·x + β·y | none | α, A, β | upper/lower band | [chbmv][ref-chbmv]/[zhbmv][ref-zhbmv] | | sgbmv/dgbmv | y ⟵ α·A·x + β·y , y ⟵ α·Aᵀ·x + β·y | none | α, A, β | upper/lower band | [sgbmv][ref-sgbmv]/[dgbmv][ref-dgbmv] | | stbmv/dtbmv | y ⟵ α·A·x + β·y | none | α, A, β | upper/lower band | [stbmv][ref-stbmv]/[dtbmv][ref-dtbmv] | | chemv/zhemv | y ⟵ α·A·x + β·y | α, A, β | none | triangular upper/lower | [chemv][ref-chemv]/[zhemv][ref-zhemv] | | | sgemv/dgemv | y ⟵ α·A·x + β·y , y ⟵ α·Aᵀ·x + β·y | none | α, A, β | full m x n | [sgemv][ref-sgemv]/[dgemv][ref-dgemv] | | | cgemv/zgemv | y ⟵ α·A·x + β·y , y ⟵ α·Aᵀ·x + β·y, y ⟵ α·Aᴴ·x + β·y | α, A, β | none | full m x n | [cgemv][ref-cgemv]/[zgemv][ref-zgemv] | | chpmv/zhpmv | y ⟵ α·A·x + β·y | α, A, β | none | packed upper/lower triangular | [cgemv][ref-cgemv]/[zgemv][ref-zgemv] | | sspmv/dspmv | y ⟵ α·A·x + β·y | none | α, A, β | packed upper/lower triangular | [sspmv][ref-sspmv]/[dspmv][ref-dspmv] | | ssymv/dsymv | y ⟵ α·A·x + β·y | α, A, β | none | upper/lower triangular | [ssymv][ref-ssymv]/[dsymv][ref-dsymv] |
decl
function cgbmv|zgbmv(
trans: 'n' | 't' | 'c',
m: number,
n: number,
kl: number,
ku: number,
alpha: Complex,
a: Matrix,
lda: number,
x: FortranArr,
incx: number,
beta: Complex,
y: FortranArr,
incy: number
): void;
function chbmv|zhbmv(
uplo: 'u' | 'l',
n: number,
k: number,
alpha: Complex,
a: Matrix,
lda: number,
x: FortranArr,
incx: number,
beta: Complex,
y: FortranArr,
incy: number
): void;
export function ssbmv|dsbmv(
uplo: string,
n: number,
k: number,
alpha: number,
a: Matrix,
lda: number,
x: FortranArr,
incx: number,
beta: number