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

matlight

v0.2.2

Published

A light linear algebra library.

Downloads

8

Readme

MatLight: A light linear algebra library.

Build Status

Supporting most commonly used linear algebra operations like getting rank and determinant of matrix, LU, QR, SVD, pseudo-inverse, etc.

I've searched around npm and github for handy JavaScript linear algebra libraries for my web based robotics simulation project but surprisingly found nothing meets my requirements. So why not build my own!

To make it easier to maintain and update, I chose TypeScript for this project. By default if you install this package from npm you'll get the compiled version which should be able to work with es5.

Quick start

If you are using this library with npm, simply type:

npm i -S matlight

The most commonly used features are in Matrix and Vector:

var MatLight = require('matlight');

var Matrix = MatLight.Matrix;
var Vector = MatLight.Vector;
console.log(Matrix);
console.log(Vector);

You can construct a Matrix with a raw 2-D array and many other methods:

// with 2-D array
var m1 = new Matrix([
  [1,2,3,4],
  [5,6,7,8],
  [9,10,11,12]
]);

// zero matrix with height and width
var m2 = new Matrix(2,2); // [[0,0],[0,0]]

// diagonal matrix
var m3 = Matrix.constructDiag([1,2,3]);

Simular for Vectors:

// with 1-D array
var v1 = new Vector([1,2,3]);

// with length
var v2 = new Vector(4);

Element-wise opearations:

var m4 = m1.add(1);
// [[2,3,4,5],
//  [6,7,8,9],
//  [10,11,12,13]]
var m5 = m1.mul(3);

Decompositions:

var SVD = Matrix.SVD(m1);
console.log(SVD.U);
console.log(SVD.D);
console.log(SVD.Vt);
var m1_reconstruct = SVD.U.dot(SVD.D).dot(SVD.Vt);
// should still be 'equal' to m1 (note that floating point inaccuracy always happens)
console.log(m1_reconstruct);

All functions are 'constant' ones so you'll never need to worry about messing up the data of Matrices and Vectors. Most of the functions have both static style and member style versions (as long as they make sense), just pick the one you prefer!