npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eigenjs

v0.0.89

Published

The goal of this project is to port Eigen library into JavaScript for linear algebra.

Downloads

153

Readme

EigenJS

The goal of this project is to port Eigen library into JavaScript for linear algebar.

NPM NPM

NPM version Downloads Build Status Build status Gitter chat gittip.com/rick68

Installation

  • OS X (XCode & Command Line Tools)
  • Linux (GCC >= 4.8):
$ npm install eigenjs
  • Windows7/8 (Visual Studio 2012):
$ npm install eigenjs --msvs_version=2012

API

Complex

Complex Class Methods

Complex(real, [imag])

var C = require('eigenjs').Complex
  , c = new C(3, -4);
console.log('c = %s', c);
c = (3,-4)

Complex.polar(scalar, scalar)

var C = require('eigenjs').Complex
  , rho = 5
  , theta = -0.9272952180016122
  , c = C.polar(rho, theta);
console.log(c.conj().toString());
console.log(c.real * Math.cos(c.imag));
console.log(c.real * Math.sin(c.imag));
(5,0.927295)
3.0000000000000004
-3.9999999999999996

Complex.cos(scalar)

Complex.cos(comp)

var C = require('eigenjs').Complex
  , c1 = new C(Math.PI/4, 0)
  , c2 = C.cos(c1);
console.log(c2.toString());
(0.707107,-0)

Complex.cosh(scalar)

Complex.cosh(comp)

var C = require('eigenjs').Complex
  , c1 = new C(0, 0)
  , c2 = C.cosh(c1);
console.log(c2.toString());
(1,0)

Complex.exp(scalar)

Complex.exp(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1, 0)
  , c2 = C.exp(c1);
console.log(c2.toString());
(2.71828,0)

Complex.log(scalar)

Complex.log(comp)

var C = require('eigenjs').Complex
  , c1 = new C(Math.E, 0)
  , c2 = C.log(c1);
console.log(c2.toString());
(1,0)

Complex.log10(scalar)

Complex.log10(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1000, 0)
  , c2 = C.log10(c1);
console.log(c2.toString());
(3,0)

Complex.pow(scalar, scalar)

Complex.pow(scalar, comp)

Complex.pow(comp, scalar)

Complex.pow(comp, comp)

var C = require('eigenjs').Complex
  , c = C.pow(2, 3)
console.log(c.toString());
(8,0)

Complex.sin(scalar)

Complex.sin(comp)

var C = require('eigenjs').Complex
  , c1 = new C(Math.PI/4, 0)
  , c2 = C.sin(c1);
console.log(c2.toString());
(0.707107,0)

Complex.sinh(scalar)

Complex.sinh(comp)

var C = require('eigenjs').Complex
  , c1 = new C(0, 0)
  , c2 = C.sinh(c1);
console.log(c2.toString());
(0,0)

Complex.sqrt(scalar)

Complex.sqrt(comp)

var C = require('eigenjs').Complex
  , c1 = new C(9, 0)
  , c2 = C.sqrt(c1);
console.log(c2.toString());
(3,0)

Complex.tan(scalar)

Complex.tan(comp)

var C = require('eigenjs').Complex
  , c1 = new C(Math.PI/4, 0)
  , c2 = C.tan(c1);
console.log(c2.toString());
(1,0)

Complex.tanh(scalar)

Complex.tanh(comp)

var C = require('eigenjs').Complex
  , c1 = new C(Infinity, 0)
  , c2 = C.tanh(c1);
console.log(c2.toString());
(1,0)

Complex.acos(scalar)

Complex.acos(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1, 0)
  , c2 = C.acos(c1);
console.log(c2.toString());
(0,0)

Complex.acosh(scalar)

Complex.acosh(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1.54308, 0)
  , c2 = C.acosh(c1);
console.log(c2.toString());
(0.999999,0)

Complex.asin(scalar)

Complex.asin(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1, 0)
  , c2 = C.asin(c1);
console.log(c2.toString());
(1.5708,7.82511e-09)

Complex.asinh(scalar)

Complex.asinh(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1, 0)
  , c2 = C.asinh(c1);
console.log(c2.toString());
(0.881374,0)

Complex.atan(scalar)

Complex.atan(comp)

var C = require('eigenjs').Complex
  , c1 = new C(Infinity, 0)
  , c2 = C.atan(c1);
console.log(c2.toString());
(1.5708,0)

Complex.atanh(scalar)

Complex.atanh(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1, 0)
  , c2 = C.atanh(c1);
console.log(c2.toString());
(inf,0)

Complex Instance Methods

comp.abs()

var C = require('eigenjs').Complex
  , c = new C(3, -4);
console.log(c.abs());
5

comp.arg()

var C = require('eigenjs').Complex
  , c = new C(3, -4);
console.log(c.arg());
console.log('(%d,%d)', c.abs() * Math.cos(c.arg()), c.abs() * Math.sin(c.arg()));
-0.9272952180016122
(3.0000000000000004,-3.9999999999999996)

comp.norm()

var C = require('eigenjs').Complex
  , c = new C(3, -4);
console.log(c.norm());
25

comp.conj()

var C = require('eigenjs').Complex
  , c = new C(3, -4);
console.log(c.conj().toString());
(3,4)

comp.proj(scalar)

comp.proj(comp)

var C = require('eigenjs').Complex
  , c1 = new C(0, -Infinity)
  , c2 = C.proj(c1);
console.log(c2.toString());
(inf, -0)

comp.add(scalar)

comp.add(comp)

var C = require('eigenjs').Complex
  , c1 = new C(3, 0)
  , c2 = new C(0, 4)
  , c3 = c1.add(c2);
console.log(c3.toString());
(3,4)

comp.adda(scalar)

comp.adda(comp)

var C = require('eigenjs').Complex
  , c1 = new C(3, 0)
  , c2 = new C(0, 4);
c1.adda(c2);
console.log(c1.toString());
(3,4)

comp.sub(scalar)

comp.sub(comp)

var C = require('eigenjs').Complex
  , c1 = new C(3, 4)
  , c2 = new C(2, -3)
  , c3 = c1.sub(c2);
console.log(c3.toString());
(1,7)

comp.suba(scalar)

comp.suba(comp)

var C = require('eigenjs').Complex
  , c1 = new C(5, 8)
  , c2 = new C(-3, 4);
c1.suba(c2);
console.log(c1.toString());
(8,4)

comp.mul(scalar)

comp.mul(comp)

comp.mul(mat)

comp.mul(vec)

comp.mul(rvec)

comp.mul(mblock)

comp.mul(vblock)

comp.mul(rvblock)

comp.mul(cmat)

comp.mul(cvec)

comp.mul(crvec)

comp.mul(cmblock)

comp.mul(cvblock)

comp.mul(crvblock)

var C = require('eigenjs').Complex
  , c1 = new C(1, 8)
  , c2 = new C(6, 4)
  , c3 = c1.mul(c2);
console.log(c3.toString());
(-26,52)

comp.mula(scalar)

comp.mula(comp)

var C = require('eigenjs').Complex
  , c1 = new C(3, 1)
  , c2 = new C(2, 4)
c1.mula(c2);
console.log(c1.toString());
(2,14)

comp.div(scalar)

comp.div(comp)

var C = require('eigenjs').Complex
  , c1 = new C(4, 8)
  , c2 = new C(2, 0)
  , c3 = c1.div(c2);
console.log(c3.toString());
(2,4)

comp.diva(scalar)

comp.diva(comp)

var C = require('eigenjs').Complex
  , c1 = new C(3, 9)
  , c2 = new C(9, 0)
c1.diva(c2);
console.log(c2.toString());
(0.333333,1)

comp.equals(scalar)

comp.equals(comp)

var C = require('eigenjs').Complex
  , c1 = new C(1, 0)
  , c2 = c1.conj();
console.log(c1.equals(c2));
true

comp.isApprox(comp, [prec = 1e-12])

var C = require('eigenjs').Complex
  , c1 = new C(1/3, 0)
  , c2 = new C(0.3333, 0);
console.log(c1.isApprox(c2, 1e-3));
true
comp.toString()
var C = require('eigenjs').Complex
  , c = new C(3, -4);
console.log(c.toString());
(3,-4)

Complex Properties

comp.real

comp.imag

var C = require('eigenjs').Complex
  , c = new C(3, -4);
c.real = 6;
c.imag = 8;
console.log('(%d,%d)', c.real, c.imag);
(6,8)

Matrix

Matrix Class Methods

Matrix(mat)

Matrix(vec)

Matrix(rvec)

Matrix(mblock)

Matrix(vblock)

Matrix(rvblock)

var M = require('eigenjs').Matrix
  , mat = new M.Random(2, 3)
  , mat2 = new M(mat);
console.log('mat =\n%s\n', mat);
console.log('mat2 =\n%s', mat2);
mat =
  0.381981  -0.373117  -0.866239
-0.0467884  -0.981309  -0.885573

mat2 =
  0.381981  -0.373117  -0.866239
-0.0467884  -0.981309  -0.885573

Matrix(rows, cols)

var M = require('eigenjs').Matrix
  , mat = new M(2, 3);
console.log('mat =\n%s', mat);
mat =
0 0 0
0 0 0

Matrix.Zero(n)

Matrix.Zero(rows, cols)

var M = require('eigenjs').Matrix
  , mat = M.Zero(2, 3);
console.log('mat = \n%s', mat);
mat =
0 0 0
0 0 0

Matrix.Ones(n)

Matrix.Ones(rows, cols)

var M = require('eigenjs').Matrix
  , mat = M.Ones(2, 3);
console.log('mat = \n%s', mat);
mat =
1 1 1
1 1 1

Matrix.Constant(rows, cols, scalar)

Matrix.Constant(rows, cols, comp)

var M = require('eigenjs').Matrix
  , mat = M.Constant(4, 4, 0.6);
console.log('mat = \n%s', mat);
mat =
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6
0.6 0.6 0.6 0.6

Matrix.Random(n)

Matrix.Random(rows, cols)

var M = require('eigenjs').Matrix
  , mat = M.Random(2, 3);
console.log('mat = \n%s', mat);
mat =
-0.421952 -0.671276  0.547419
 0.260209  -0.13622  0.464891

Matrix.Identity(n)

Matrix.Identity(rows, cols)

var M = require('eigenjs').Matrix
  , mat1 = M.Identity(2)
  , mat2 = M.Identity(2, 3);
console.log('mat1 = \n%s', mat1);
console.log('mat2 = \n%s', mat2);
mat1 =
1 0
0 1
mat2 =
1 0 0
0 1 0

Matrix Instance Methods

mat.rows()

mat.cols()

var M = require('eigenjs').Matrix
  , mat = new M(2, 3);
console.log(mat.rows());
console.log(mat.cols());
2
3

mat.set(row, col, scalar)

var M = require('eigenjs').Matrix
  , mat = new M(2, 2);
mat.set(0, 0, 1)
   .set(0, 1, 2)
   .set(1, 0, 3)
   .set(1, 1, 4);
console.log('mat = \n%s', mat);
mat =
1 2
3 4

mat.set(scalar_array)

var M = require('eigenjs').Matrix
  , mat = new M(3, 3);
mat.set([
  1, 2, 3,
  4, 5, 6,
  7, 8, 9
]);
console.log('mat = \n%s', mat);
mat =
1 2 3
4 5 6
7 8 9

mat.get(row, col)

var M = require('eigenjs').Matrix
  , mat = new M(2, 2);
mat.set([
  1, 2,
  3, 4
]);
console.log(mat.get(0, 0) + ' ' + mat.get(0, 1));
console.log(mat.get(1, 0) + ' ' + mat.get(1, 1));
1 2
3 4

mat.assign(mat)

mat.assign(vec)

mat.assign(rvec)

mat.assign(mblock)

mat.assign(vblock)

mat.assign(rvblock)

var M = require('eigenjs').Matrix
  , mat = M.Random(4, 4);
mat.assign(M.Zero(4, 4));
console.log('mat = \n%s', mat);
mat =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

mat.value()

Returns the unique coefficient of a 1x1 expression

var M = require('eigenjs').Matrix
  , mat = M.Random(1, 1);
console.log('%d', mat.value());
-0.7131525574778916

mat.setZero()

var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setZero());
mat =
 0.244911 -0.752925 -0.562905
 0.215088 -0.406688 -0.750836
 0.983236  0.800109  0.695126

mat =
0 0 0
0 0 0
0 0 0

mat.setOnes()

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setOnes());
mat =
0 0 0
0 0 0
0 0 0

mat =
1 1 1
1 1 1
1 1 1

mat.setConstant(scalar)

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setConstant(0.6));
mat =
0 0 0
0 0 0
0 0 0

mat =
0.6 0.6 0.6
0.6 0.6 0.6
0.6 0.6 0.6

mat.setRandom()

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setRandom());
mat =
0 0 0
0 0 0
0 0 0

mat =
 -0.292434 -0.0673437   0.283946
 -0.938224   0.154289   0.283845
 -0.725773  -0.862362   0.583097

mat.setIdentity()

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
console.log('mat =\n%s\n', mat);
console.log('mat =\n%s', mat.setIdentity());
mat =
0 0 0
0 0 0
0 0 0

mat =
1 0 0
0 1 0
0 0 1

mat.setDiagonal(index, vec)

mat.setDiagonal(index, rvec)

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3)
  , dia = mat.diagonal(1);
console.log('mat =\n%s\n', mat);
dia.setRandom();
console.log('mat =\n%s', mat.setDiagonal(1, dia));
mat =
0 0 0
0 0 0
0 0 0

mat =
        0 -0.294006         0
        0         0  0.634569
        0         0         0

mat.block(startRow, startCol, blockRows, blockCols)

var M = require('eigenjs').Matrix
  , mat = new M.Identity(4, 4)
  , mblock = mat.block(1, 1, 2, 2);
mblock.assign(M.Random(2, 2));
console.log('mat =\n%s', mat);
mat =
        1         0         0         0
        0 -0.822352  0.533723         0
        0  0.721993  0.287646         0
        0         0         0         1

mat.row(n)

var Eigen = require('eigenjs')
  , M = Eigen.Matrix
  , RV = Eigen.RowVector
  , mat = new M.Zero(3, 3)
  , mblock = mat.row(1);
mblock.assign(RV.Random(3));
console.log('mat =\n%s', mat);
mat =
        0         0         0
-0.843392 -0.891355  0.991578
        0         0         0

mat.col(n)

var Eigen = require('eigenjs')
  , M = Eigen.Matrix
  , V = Eigen.Vector
  , mat = new M.Zero(3, 3)
  , mblock = mat.col(1);
mblock.assign(V.Random(3));
console.log('mat =\n%s', mat);
mat =
         0   0.674939          0
         0  -0.303923          0
         0 -0.0302965          0

mat.topRows(n)

Returns a block consisting of the top rows of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.topRows(2));
 7  9 -5  3
-2 -6  1  0

mat.bottomRows(n)

Returns a block consisting of the bottom rows of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.bottomRows(2));
 6 -3  0  9
 6  6  3  9

mat.middleRows(startRow, n)

Returns a block consisting of a range of rows of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.middleRows(1, 2));
-2 -6  1  0
 6 -3  0  9

mat.leftCols(n)

Returns a block consisting of the left columns of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.leftCols(2));
 7  9
-2 -6
 6 -3
 6  6

mat.rightCols(n)

Returns a block consisting of the right columns of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.rightCols(2));
-5  3
 1  0
 0  9
 3  9

mat.middleCols(startCol, n)

Returns a block consisting of a range of columns of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.middleCols(1, 2));
 9 -5
-6  1
-3  0
 6  3

mat.topLeftCorner(cRows, cCols)

Returns a block consisting of a top-left corner of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.topLeftCorner(2, 2));
 7  9
-2 -6

mat.topRightCorner(cRows, cCols)

Returns a block consisting of a top-right corner of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.topRightCorner(2, 2));
-5  3
 1  0

mat.bottomLeftCorner(cRows, cCols)

Returns a block consisting of a bottom-left corner of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.bottomLeftCorner(2, 2));
 6 -3
 6  6

mat.bottomRightCorner(cRows, cCols)

Returns a block consisting of a bottom-right corner of *this.

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5,  3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.bottomRightCorner(2, 2));
0 9
3 9

mat.replicate(rowFactor, colFactor)

var M = require('eigenjs').Matrix
  , mat = new M(3, 1).set([
             7,
            -2,
             6
          ]);
console.log('%s', mat.replicate(2, 5));
 7  7  7  7  7
-2 -2 -2 -2 -2
 6  6  6  6  6
 7  7  7  7  7
-2 -2 -2 -2 -2
 6  6  6  6  6

mat.add(mat)

mat.add(vec)

mat.add(rvec)

mat.add(mblock)

mat.add(vblock)

mat.add(rvblock)

mat.add(cmat)

mat.add(cvec)

mat.add(crvec)

mat.add(cmblock)

mat.add(cvblock)

mat.add(crvblock)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2 = new M(2, 2)
  , mat3;
mat1.set([
  1, 3,
  2, 4
]);
mat2.set([
  5, 6,
  7, 8
]);
mat3 = mat1.add(mat2);
console.log('mat3 = \n%s', mat3);
mat3 =
 6  9
 9 12

mat.adda(mat)

mat.adda(vec)

mat.adda(rvec)

mat.adda(mblock)

mat.adda(vblock)

mat.adda(rvblock)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2 = new M(2, 2);
mat1.set([
  1, 3,
  2, 4
]);
mat2.set([
  5, 6,
  7, 8
]);
mat1.adda(mat2);
console.log('mat1 = \n%s', mat1);
mat1 =
 6  9
 9 12

mat.sub(mat)

mat.sub(vec)

mat.sub(rvec)

mat.sub(mblock)

mat.sub(vblock)

mat.sub(rvblock)

mat.sub(cmat)

mat.sub(cvet)

mat.sub(crvet)

mat.sub(cmblock)

mat.sub(cvblock)

mat.sub(crvblock)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2 = new M(2, 2)
  , mat3;
mat1.set([
  1, 3,
  2, 4
]);
mat2.set([
  5, 6,
  7, 8
]);
mat3 = mat1.sub(mat2);
console.log('mat3 = \n%s', mat3);
mat3 =
-4 -3
-5 -4

mat.suba(mat)

mat.suba(vec)

mat.suba(rvec)

mat.suba(mblock)

mat.suba(vblock)

mat.suba(rvblock)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2 = new M(2, 2);
mat1.set([
  1, 3,
  2, 4
]);
mat2.set([
  5, 6,
  7, 8
]);
mat1.suba(mat2);
console.log('mat1 = \n%s', mat1);
mat1 =
-4 -3
-5 -4

mat.mul(scalar)

mat.mul(comp)

mat.mul(mat)

mat.mul(vec)

mat.mul(rvec)

mat.mul(mblock)

mat.mul(vblock)

mat.mul(rvblock)

mat.mul(cmat)

mat.mul(cvec)

mat.mul(crvec)

mat.mul(cvblock)

mat.mul(crvblock)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 3)
  , vec = new M(3, 1)
  , mat2;
mat1.set([
  1, 2, 3,
  4, 5, 6
]);
vec.set([
  1,
  6,
  8
]);
mat2 = mat1.mul(vec);
console.log('mat2 = \n%s', mat2);
mat2 =
37
82

mat.mula(scalar)

mat.mula(mat)

mat.mula(vec)

mat.mula(rvec)

mat.mula(mblock)

mat.mula(vblock)

mat.mula(rvblock)

var M = require('eigenjs').Matrix
  , mat = new M(2, 3)
  , vec = new M(3, 1);
mat.set([
  1, 2, 3,
  4, 5, 6
]);
vec.set([
  1,
  6,
  8
]);
mat.mula(vec);
console.log('mat = \n%s', mat);
mat =
37
82

mat.div(scalar)

mat.div(comp)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2;
mat1.set([
  1, 2,
  3, 4
]);
mat2 = mat1.div(2);
console.log('mat2 = \n%s', mat2);
mat2 =
0.5   1
1.5   2

mat.diva(scalar)

var M = require('eigenjs').Matrix
  , mat = new M(2, 2);
mat.set([
  1, 2,
  3, 4
]);
mat.diva(2);
console.log('mat = \n%s', mat);
mat =
0.5   1
1.5   2

mat.transpose()

var M = require('eigenjs').Matrix
  , mat1 = new M.Random(3, 2)
  , mat2 = mat1.transpose();
console.log('mat1 = \n%s', mat1);
console.log('mat2 = \n%s', mat2);
mat1 =
 -0.112813  -0.325566
-0.0500345   0.213005
 -0.930346  -0.022705
mat2 =
 -0.112813 -0.0500345  -0.930346
 -0.325566   0.213005  -0.022705

mat.conjugate()

var M = require('eigenjs').Matrix
  , mat1 = new M.Random(2, 2)
  , mat2 = mat1.conjugate();
console.log(mat1.equals(mat2));
true

mat.adjoint()

var M = require('eigenjs').Matrix
  , mat1 = new M.Random(3, 2)
  , mat2 = mat1.adjoint();
console.log('mat1 = \n%s', mat1);
console.log('mat2 = \n%s', mat2);
mat1 =
 0.997487 0.0670765
 0.770148 -0.645138
 -0.12185 -0.835853
mat2 =
 0.997487  0.770148  -0.12185
0.0670765 -0.645138 -0.835853

mat.determinant()

Returns the determinant of this matrix. This method uses class PartialPivLU.

var M = require('eigenjs').Matrix
  , mat = new M.Random(2, 2);
console.log('mat = \n%s\n', mat);
console.log('det = %d', mat.determinant());
mat =
 0.132371 -0.813862
 0.758326  -0.58171

det = 0.540171350604003

mat.inverse()

Returns the matrix inverse of this matrix. This method uses class PartialPivLU.

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            0, 1, 4,
            5, 6, 0
          ])
  , inv = mat.inverse();
console.log('inv = \n%s', inv);
inv =
-24  18   5
 20 -15  -4
 -5   4   1

mat.trace()

var M = require('eigenjs').Matrix
  , mat = new M(2, 3).set([
            1, 2, 3,
            4, 5, 6
          ])
  , tr = mat.trace();
console.log('mat = \n%s\n', mat);
console.log('tr = ', tr);
mat =
1 2 3
4 5 6

tr =  6

mat.diagonal([index = 0])

var M = require('eigenjs').Matrix
  , mat = new M(4, 4).set([
             7,  9, -5, -3,
            -2, -6,  1,  0,
             6, -3,  0,  9,
             6,  6,  3,  9
          ]);
console.log('%s', mat.diagonal(1).transpose());
console.log('%s', mat.diagonal(-2).transpose());
9 1 9
6 6

mat.norm()

Returns the Frobenius norm.

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            4, 5, 6,
            7, 8, 9
          ]);
console.log('%d', mat.norm());
16.881943016134134

mat.redux(func)

  • func Function The result of a full redux operation on the whoie matrix or vector using func.
var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            4, 5, 6,
            7, 8, 9
          ])
  , func = function(a, b) { return a + b; };
console.log('%d', mat.redux(func));
45

mat.sum()

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            4, 5, 6,
            7, 8, 9
          ]);
console.log('%d', mat.sum());
45

mat.prod()

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            4, 5, 6,
            7, 8, 9
          ]);
console.log('%d', mat.prod());
362880

mat.mean()

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            4, 5, 6,
            7, 8, 9
          ]);
console.log('%d', mat.mean());
5

mat.visit(func)

  • func Function Applies the func to the whole coefficients of the matrix or vector.
var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 2, 3,
            4, 5, 6,
            7, 8, 9
          ]);
mat.visit(function(value, row, col) {
  console.log('mat(%d, %d) = %d', row, col, value);
});
mat(0, 0) = 1
mat(1, 0) = 4
mat(2, 0) = 7
mat(0, 1) = 2
mat(1, 1) = 5
mat(2, 1) = 8
mat(0, 2) = 3
mat(1, 2) = 6
mat(2, 2) = 9

mat.maxCoeff()

var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3);
console.log('mat = \n%s\n', mat);
console.log('max = %d', mat.maxCoeff());
mat =
  0.175793  -0.547068  -0.959701
  0.561311  -0.579446   0.297471
-0.0382309  -0.743676  -0.411312

max = 0.5613114636211243

mat.maxCoeff(obj)

  • obj Object
var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3)
  , obj = {};
console.log('mat = \n%s\n', mat);
console.log('max = %s', mat.maxCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
mat =
 -0.68294  0.690895 -0.698356
-0.174138 -0.119934  0.733219
-0.743578  0.262349 -0.795382

max = 0.7332185766348702
obj = {"maxCoeff":0.7332185766348702,"rowId":1,"colId":2}

mat.maxCoeff(func)

  • func Function
var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3)
  , func = function(rowId, colId) {
             console.log('rowId = %d, colId = %d', rowId, colId);
           };
console.log('mat = \n%s\n', mat);
console.log('max = %d', mat.maxCoeff(func));
mat =
-0.552622 -0.355055  0.141004
0.0814275   0.58272  -0.13819
 0.552011 -0.217758 -0.551142

rowId = 1, colId = 1
max = 0.5827204285109044

mat.minCoeff()

var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3);
console.log('mat = \n%s\n', mat);
console.log('min = %d', mat.minCoeff());
mat =
-0.725041  0.511321   0.29833
 0.233345  -0.22101 0.0355704
-0.167162 -0.514649 -0.168438

min = -0.7250411527813604

mat.minCoeff(obj)

  • obj Object
var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3)
  , obj = {};
console.log('mat = \n%s\n', mat);
console.log('min = %d', mat.minCoeff(obj));
console.log('obj = %s', JSON.stringify(obj));
mat =
  0.74568  0.870563  -0.82341
 0.636928 -0.455949  0.944912
 0.855648  0.872564  -0.87055

min = -0.8705498761825962
obj = {"minCoeff":-0.8705498761825962,"rowId":2,"colId":2}

mat.minCoeff(func)

  • func Function
var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3)
  , func = function(rowId, colId) {
             console.log('rowId = %d, colId = %d', rowId, colId);
           };
console.log('mat = \n%s\n', mat);
console.log('min = %d', mat.minCoeff(func));
 0.371743  0.261372  0.144462
-0.111958  0.884582  -0.02937
 0.314765 -0.823458  0.378298

rowId = 2, colId = 1
min = -0.8234578174648144

mat.equals(mat)

mat.equals(vec)

mat.equals(rvec)

mat.equals(mblock)

mat.equals(vblock)

mat.equals(rvblock)

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2 = new M(2, 2)
  , mat3 = new M(2, 2);
mat1.set([
  1, 2,
  3, 4
]);
mat2.set([
  1, 0,
  0, 1
]);
mat3.set([
  0, 2,
  3, 3
]);
console.log(mat1.equals(mat2.add(mat3)));
true

mat.isApprox(mat, [prec = 1e-12])

mat.isApprox(vec, [prec = 1e-12])

mat.isApprox(rvec, [prec = 1e-12])

mat.isApprox(mblock, [prec = 1e-12])

mat.isApprox(vblock, [prec = 1e-12])

mat.isApprox(rvblock, [prec = 1e-12])

var M = require('eigenjs').Matrix
  , mat1 = new M(2, 2)
  , mat2 = new M(2, 2);
mat1.set([
  1, 3,
  5, 7
]).diva(11);
mat2.set([
  0.091, 0.273,
  0.455, 0.636
]);
console.log(mat1.isApprox(mat2, 1e-3));
true

mat.isSquare()

var M = require('eigenjs').Matrix
  , mat1 = new M(4, 4)
  , mat2 = new M(3, 2);
console.log(mat1.isSquare());
console.log(mat2.isSquare());
true
false

mat.isZero([prec = 1e-12])

var M = require('eigenjs').Matrix
  , mat = new M(2, 3).set([
            0,      0, 0.0001,
            0,      0,      0
          ]);
console.log(mat.isZero());
console.log(mat.isZero(1e-3));
false
true

mat.isOnes([prec = 1e-12])

var M = require('eigenjs').Matrix
  , mat = new M(2, 3).set([
            1,      1, 1.0001,
            1, 0.9997,      1
          ]);
console.log(mat.isOnes());
console.log(mat.isOnes(1e-3));
false
true

mat.isIdentity([prec = 1e-12])

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1,       0, 0.0001,
            0,  0.9997,      0,
            0,       0,      1
          ]);
console.log(mat.isIdentity());
console.log(mat.isIdentity(1e-3));
false
true

mat.isDiagonal([prec = 1e-12])

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1e+04,     0,     1,
                0, 1e+04,     0,
                0,     0, 1e+04
          ]);
console.log(mat.isDiagonal());
console.log(mat.isDiagonal(1e-3));
false
true

mat.all()

Returns true if all coefficients are true.

var M = require('eigenjs').Matrix
  , mat = new M.Constant(3, 3, 1);
console.log('mat = \n%s\n%s\n', mat, mat.all());
mat.set(0, 0, 0);
console.log('mat = \n%s\n%s', mat, mat.all());
mat =
1 1 1
1 1 1
1 1 1
true

mat =
0 1 1
1 1 1
1 1 1
false

mat.any()

Returns true if at least one coefficient is true.

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
console.log('mat = \n%s\n%s\n', mat, mat.any());
mat.set(0, 0, 1);
console.log('mat = \n%s\n%s', mat, mat.any());
mat =
0 0 0
0 0 0
0 0 0
false

mat =
1 0 0
0 0 0
0 0 0
true

mat.count()

Returns the number of coefficients which evaluate to true.

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
mat.block(0, 1, 3, 2).setOnes();
console.log('mat = \n%s\n', mat);
console.log('%d', mat.count());
mat =
0 1 1
0 1 1
0 1 1

6

mat.allFinite()

Returns true if *this contains only finite numbers, i.e., no NaN and no +/-INF values.

var M = require('eigenjs').Matrix
  , mat = new M.Random(3, 3);
console.log('mat = \n%s\n%s\n', mat, mat.allFinite());
mat.set(0, 0, Infinity);
console.log('mat = \n%s\n%s', mat, mat.allFinite());
mat =
 0.202332  0.271506 -0.887678
 0.592388 -0.806422  0.799406
  0.26443  0.461303 -0.389755
true

mat =
      inf  0.271506 -0.887678
 0.592388 -0.806422  0.799406
  0.26443  0.461303 -0.389755
false

mat.hasNaN()

Returns true if *this contains at least one Not A Number (NaN).

var M = require('eigenjs').Matrix
  , mat = new M.Zero(3, 3);
console.log('mat = \n%s\n%s\n', mat, mat.hasNaN());
mat.set(1, 1, NaN);
console.log('mat = \n%s\n%s', mat, mat.hasNaN());
mat =
0 0 0
0 0 0
0 0 0
false

mat =
  0   0   0
  0 nan   0
  0   0   0
true

mat.partialPivLu()

Returns the partial-pivoting LU decomposition of *this.

var M = require('eigenjs').Matrix
  , mat = new M(3, 3).set([
            1, 4, 5,
            4, 2, 6,
            5, 6, 3
          ])
  , pplu = mat.partialPivLu();
console.log('P = \n%s\n', pplu.permutationP());
console.log('L = \n%s\n', pplu.matrixL());
console.log('U = \n%s', pplu.matrixU());
P =
0 0 1
0 1 0
1 0 0

L =
  1   0   0
0.8   1   0
0.2  -1   1

U =
   5    6    3
   0 -2.8  3.6
   0    0    8

mat.fullPivLu()

Returns the full-pivoting LU decomposition of *this.

var M = require('eigenjs').Matrix
  , mat = new M(2, 4).set([
             1,  1,  1,  3,
             1,  2, -1,  4
          ])
  , fplu = mat.fullPivLu();
console.log('P = \n%s\n', fplu.permutationP());
console.log('L = \n%s\n', fplu.matrixL());
console.log('U = \n%s\n', fplu.matrixU());
console.log('Q = \n%s', fplu.permutationQ());
P =
0 1
1 0

L =
   1    0
0.75    1

U =
   4   -1    2    1
   0 1.75 -0.5 0.25

Q =
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0

mat.toString([options])

  • options Object
    • precision Number Default=6. The number of digits for floating point values.
    • fullPrecision Booleam Default=false. If set to true, then the number of digits will be computed to match the full precision of each floating-point type.
    • dontAlignCols Booleam Default=false. If set to true, it allows to disable the alignment of columnt, resulting in faster code.
    • coeffSeparator String Default=' '. The string printed between two coefficients of the same row.
    • rowSepara