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

mathlab

v0.0.14

Published

lodash like math lab

Downloads

11

Readme

mathlab

Lodash like math lab in javascript, focusing on matrix manipulation.

npm

Install

Using npm:

$ npm install mathlab --save

Using cdn:

<script src="https://npmcdn.com/mathlab/dist/axios.min.js"></script>

Sample usage

import { dot } from 'mathlab'

const A = [[1,2,3],
           [4,5,6]]

const x = [7,8,9]

// calculate dot product
dot(A, x) // [50,122]

Features

  • Modulize: only import the function you need.
  • Easy to use: no extra concepts to grasp(1D Array as vector and 2D Array as matrix)
  • Functional: no side effact on input data and the outside world
  • Multifunctional: Support sparse and complex matrix manipulation; FFT; eigenvectors & eigenvalues of matrix; and so on

Introduction to functions

Mathlab provide a collection of mathmatic functions which can be applied to numbers, arrays and two self-defined datatypes (Complex and Sparse).

Functions can be devide into 5 groups:

1. Math Object functions

abs | acos | asin | atan | ceil | cos | exp | floor | log | round | sin | sqrt | tan

The Math object functions have been adapted to work on Arrays, Complex and Sparse Objects

example

import {abs, Complex, Sparse} from './mathlab'

abs(-1)  // 1
abs([-1, 2])  // [1, 2]
abs(new Complex(3, 4))  // {re: 5, im: 0}
abs(new Sparse([[1,2,0],[0,0,-1],[1,0,0]])) // {row: col: val:}

2. Arithmetic operations

add | sub | mul | div | neg

The standard arithmetic operations have been vectorized:

example

import { add, Complex } from 'mathlab'

add(1, 2) // 3
add([1,2], 2,2) // [3,4]

3. Linear algebra

dot | solve | det | inv | norm2 | tensor | eig

example: dot

dot([[1, 1], [2, 1]], [1, 2]) // [3, 4]

4. Fast Fourier Transforms

fft | ifft

example

import {fft, ifft, Complex} from 'mathlab'

// {re: [ 15, -5.941, -3.312, -1.688, 0.941], im: [ 40, 0.941, -1.688, -3.312, -5.941]}
const fftRes = fft(new Complex([1,2,3,4,5],[6,7,8,9,10]))

// {re:[1,2,3,4,5], im:[6,7,8,9,10]}
ifft(fftRes) 

5. Utility functions

dim | same | rep | diag | identity | random | linspace

example dim

dim(1) // []
dim([1,2]) // [2]
dim([[1,2],[2,2],[3,3]]) // [3,2]

Introduction to Complex and Sparse matrix

Mathlab provided two Classes for you to initialize Complex and Sparse matrix.

Complex

Creates a Complex instance that represents a complex number or array. It accepts two arguments as the real and imaginary part of a complex number or array.

Usage

Initalize

import { Complex, abs } from 'mathlab'

// complex number
const c = new Complex(1, 2) // {re:1, im:2}

// complex array
const ca = new Complex([1,2], [1,2]) // {re:[1,2], im:[1,2]}

// mathlab functions can be applied on it
abs(ca) // {re: [ 1.414, 2.828], im: undefined}

Methods (still adding)

  • reciprocal: Pointwise 1/z
  • transjugate: The conjugate-transpose of the matrix
ca.reciprocal() // {re: [ 0.5, 0.25], im: [ -0.5, -0.25]}

Sparse

Creates a Sparse instance that represents a sparse matrix. In mathlab, sparse matrices are stored in the compressed column storage ordering.

Usage

Initialize

import { Sparse } from 'mathlab'

const z = new Sparse([[1,0,0],[5,2,0],[1,0,0]]) //  { col: [ 0, 3, 4, 4 ], row: [ 0, 1, 2, 1 ], val: [ 1, 5, 1, 2 ] }

Methods (still adding)

  • toFull: Convert to full presentation
z.toFull() // [[1,0,0],[5,2,0],[1,0,0]]

Thanks

Mathlab start as a refactoring of numeric