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

simple-linalg

v1.5.0

Published

Simple linear algebra library for js

Downloads

1,550

Readme

simple-linalg 😄

Simple Linear algebra function in JS

Installation 📦

npm install simple-linalg

Motivation 🚀

simple-linalg is a spin-off project from the Kalman Filter library. We created this library to provide essential linear algebra functions in a user-friendly, efficient, and accessible way.

We believe in keeping things simple and efficient, and that's what simple-linalg is all about!

Here's what makes simple-linalg stand out:

KISS: Keep It Simple and Stupid 😇 - We focus on delivering a straightforward and easy-to-understand library. Pure Functional: All functions are designed to be pure and functional, which makes it easier to reason about the code 📚. Native JS Array Manipulation: We use native JavaScript arrays for simplicity and compatibility with a wide range of projects 🌐. Small Footprint: Our only dependency is matrix-inverse, which keeps the library lightweight and easy to integrate 🎈.

So, if you're looking for a simple, efficient, and easy-to-use linear algebra library for your JavaScript projects, look no further! simple-linalg is here to help you out! 😊

Examples

add

const {add} = require('simple-linalg');
const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

add(a, b) 
// => [[9, 9], [9, 17]];

diag

const {diag} = require('simple-linalg');

diag([3, 7]) 
// => [[3, 0], [7, 0]];

diagBlock

const {diagBlock} = require('simple-linalg');
const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

const blocks = [a, b];

const result = diagBlock({blocks});

// => [[3, 7, 0, 0], [4, 9, 0, 0], [0, 0, 6, 2], [0, 0, 5, 8]];

cosSimilarity

const {cosSimilarity} = require('simple-linalg');

const a = [0, 7];
const b = [0, 2];

cosSimilarity(a, b) 
// => 1

dotProduct

const {dotProduct} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

dotProduct(a, b) 
// => [[18, 14], [20, 72]];

euclideanDist

const {euclideanDist} = require('simple-linalg');

const a = [3, 6];
const b = [6, 2];

euclideanDist(a, b) 
// => 5

elemWise

const {elemWise} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

let sum = 0;
elemWise([a,b], function(list, rowId, colId){
	const [aValue, bValue] = list;
	sum += aValue+bValue;
	// you can use rowId and colId here
}) 

// sum is 44

frobenius

const {frobenius} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

frobenius(a, b) 
// => 6

identity

const {identity} = require('simple-linalg');

identity(2) 

// [[1,0],[0,1]]

identity

const {invert} = require('simple-linalg');

identity(2) 

// [[1,0],[0,1]]

invert

const {invert} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
invert(a) 

matMul

const {matMul} = require('simple-linalg');
const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

matMul(a, b) 
// => [[53, 62], [69, 80]];

matPermutation

const {matPermutation} = require('simple-linalg');
const a = [[3, 7], [4, 9]];

matPermutation({matrix: a, outputSize: [3,3], rowIndexes: [2, 0], colIndexes: [0,2]}) 
// => [[4, 0, 9], [0, 0, 0], [3, 0, 7]];

mapMatrix

const {mapMatrix} = require('simple-linalg');
const a = [[3, 7], [4, 9]];


let sum = 0;
mapMatrix([a,b], function(value, rowId, colId){
	sum += value;
	// you can use rowId and colId here
}) 
// => sum is 23;

norm

const {norm} = require('simple-linalg');
const a = [3, 4];

norm(a)
// => norm is 5;

padWithZeroCols

const {padWithZeroCols} = require('simple-linalg');
const a = [[3, 7], [4, 9]];

padWithZeroCols(a, {columns: 4}) 
// => [[3, 7, 0, 0], [4, 9, 0, 0]];

subtract

const {subtract} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
const b = [[6, 2], [5, 8]];

sub(a, b) 
// => [[-3, 5], [-1, 1]];

subSquareMatrix

const {subSquareMatrix} = require('simple-linalg');

const a = [[3, 7, 4, 5], [4, 9, 8, 7], [8, 7, 2, -1]];

subSquareMatrix(a, [0, 2]) 
// => [[3, 4], [8, 2]];

sum

const {sum} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
sum(a)

// => 23;

trace

const {trace} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
trace(a)

// => 7;

transpose

const {transpose} = require('simple-linalg');

const a = [[3, 7], [4, 9]];
transpose(a)

// => [[3, 9], [4, 7]];

zeros

const {zeros} = require('simple-linalg');

zeros(2)

// => [[0, 0], [0, 0]];

Going further

This library is not optimized for performance or complex usage If you want to focus on performance, I would suggest moving to Native C-bindings. For example opencv4nodejs