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

@kaosat-dev/sylvester

v0.0.21

Published

node.js implementation of James Coglan's "Sylvester" matrix math library. browserify compatible

Downloads

71

Readme

sylvester

Modern and expanded implementation of James Coglan's "Sylvester" matrix math library. The original project can be found at http://sylvester.jcoglan.com/

Documentation

The original documentation for "Sylvester" should help you through basic operations. An intro that contains node-specific features can also be found {on Chris Umbel's blog}[http://www.chrisumbel.com/article/sylvester_node_js_matrix_vector_math]. We're looking for someone to help get the documentation situation under control.

Installation

npm install sylvester

Usage

New Stuff

First I'd like to show some examples of features that aren't in the standard (non-node) Sylvester. I'll likely attempt to commit these back to Sylvester at some point soon.

Note that the decompositions are all available in pure JavaScript, but if the lapack NPM is installed with LAPACK built as a shared library then efficient native code will be used. The LAPACK integration is still highly experimental.

Vector

require('sylvester');
var a = $V([1, 2, 3]);

element-wise log:

console.log(a.log());

norm computation:

console.log(a.norm());

element-wise multiplication:

a.elementMultiply(vector);

element-wise division:

a.elementDivide(vector);

remove first n nodes:

a.chomp(n);

return vector with first n nodes:

a.top(n);

add all elements into a single scalar:

a.sum()

multiply all elements into a single scalar:

a.product()

return a vector with the elements parameter on the bottom:

a.augment(elements)

Matrix

var A = $M([[1, 2, 3], [4, 5, 6]]);

return subset of rows, columns:

// startRow, endRow, startCol, endCol
A.slice(2, 3, 2, 3);

divide matricies:

A.div($M([[0.5, 1], [1, 2], [2, 3]]));

scalar addition/subtraction

A.add(1);
A.subtract(1);

element-wise log:

console.log(A.log());

element-wise multiplication:

A.elementMultiply(vector)

add all elements into a single scalar:

A.sum()

returns a vector of the indexes of maximum values ([3 3]):

$M([[1, 2, 3], [5, 4, 6]]).maxColumnIndexes()

returns a vector of minimum column indexes ([1 2]):

$M([[1, 2, 3], [5, 4, 6]]).minColumnIndexes();

returns a vector of max values ([3 6]):

$M([[1, 2, 3], [5, 4, 6]]).maxColumns()

returns a vector of minimum values ([1 4]):

$M([[1, 2, 3], [5, 4, 6]]).minColumns()

create a 2x3 matrix of ones:

var Ones = Matrix.One(2, 3);

LU decomposition (with partial pivoting)

var lu = A.lu(); console.log(lu.L); console.log(lu.U); console.log(lu.P);

QR decomposition (feature still inefficient and experimental, but uses pure javascript):

var qr = A.qr();
console.log(qr.Q);
console.log(qr.R);

SVD decomposition (feature still inefficient and experimental, but uses pure javascript):

var svd = A.svd();
console.log(svd.U);
console.log(svd.S);
console.log(svd.V);

PCA

var A = $M([[1, 2], [5, 7]]).pcaProject(1).eql($M([
            [-2.2120098720461616],
            [-8.601913944732665]
        ]);
var pca = A.pcaProject(1);
var Z = pca.Z;
var A = Z.pcaRecover(pca.U);

Solving systems of equations

// sovle Ax = b for x
var A = $M([[2, 4], [2, 1]]);
var b = $V([1, 0]);
console.log(A.solve(b));

== Old Stuff

Below is a basic illustration of standard matrix/vector math using the standard Sylvester API. This documentation is rather incomplete and for further details please consult {the official sylvester API documentation}[http://sylvester.jcoglan.com/docs] at http://sylvester.jcoglan.com/docs.

Vectors

require('sylvester');

create two vectors:

var a = $V([1, 2, 3]);
var b = $V([2, 3, 4]);

compute the dot product:

var r = a.dot(b);

add two vectors:

var c = a.add(b);

multiply by scalar:

var d = a.x(2);

Matrices

require('sylvester');

create two matrices:

var A = $M([[1, 2], [3, 4]]);
var B = $M([[1, 2, 3], [4, 5, 6]]);

multiply the matrices:

var C = A.x(B);

transpose a matrix:

var B_T = B.transpose();
// B is 2x3, B_T is 3x2