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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ubique

v1.0.2

Published

A high-performance mathematical and quantitative library, leveraging WebAssembly for efficient linear algebra and numerical computations

Readme

Ubique

npm version npm downloads License: MIT GitHub stars JSR

Ubique is a modern mathematical and quantitative library built with contemporary JavaScript, TypeScript, and WebAssembly. It delivers high-performance numerical computations by leveraging Rust's nalgebra library compiled to WebAssembly. The library provides a comprehensive suite of functions for vectors, matrices, linear algebra, statistics, time series analysis, and computational finance.

Version 1.0 represents a complete rewrite of the original Ubique library, bringing significant improvements in performance, modern tooling, and developer experience.

Table of Contents

Overview

Ubique is designed for modern web and server-side applications requiring robust and efficient mathematical operations. By integrating WebAssembly for heavy linear algebra tasks, Ubique offers good performance while maintaining a simple and intuitive API. The library supports vectors, matrices, linear algebra, statistics, time series analysis, and computational finance—all while delivering performance gains of up to 20x compared to traditional JavaScript solutions.

Key Features

  • High Performance: Uses Rust's nalgebra compiled to WebAssembly for accelerated matrix operations (up to 20x faster than math.js)
  • WebAssembly Integration: WASM code is inlined for zero-config deployment (no separate .wasm files to manage)
  • Universal Compatibility: Works seamlessly in Node.js, browsers, and modern JavaScript runtimes
  • TypeScript Support: Full TypeScript definitions included for excellent IDE support and type safety
  • Comprehensive Functionality: Full suite of operations for vectors, matrices, statistics, time series, and financial computations
  • Zero Dependencies: Minimal external dependencies (only dayjs for date operations)

Performance Highlights

Ubique demonstrates exceptional performance gains across multiple operations compared to math.js (benchmarked on Mac mini M1):

Matrix Operations

  • Matrix Multiply (500x500): 13.05x faster
  • Matrix Add (100x100): 6.61x faster
  • Transpose (100x100): 4.63x faster

Linear Algebra

  • Determinant (50x50): 26.04x faster
  • Matrix Inverse (20x20): 7.53x faster
  • Determinant (20x20): 12.27x faster

Interactive Benchmark

Want to see these performance gains in action? Check out our interactive benchmark page with live matrix visualizations and real-time performance comparisons!

Installation

npm

npm install ubique

yarn

yarn add ubique

pnpm

pnpm add ubique

Usage

ESM (Modern Node.js, TypeScript, bundlers)

import * as ubique from "ubique";

const A = [
  [1, 2],
  [3, 4],
];

const B = [
  [5, 6],
  [7, 8],
];

const C = ubique.mtimes(A, B);
console.log(C);
// Output:
// [
//   [19, 22],
//   [43, 50],
// ]

CommonJS (Node.js)

const ubique = require("ubique");

const A = [
  [1, 2],
  [3, 4],
];

const inverse = ubique.inv(A);
console.log(inverse);

Browser (via CDN)

<script type="module">
  import * as ubique from "https://esm.sh/[email protected]";

  const matrix = ubique.eye(3); // Create 3x3 identity matrix
  console.log(matrix);
</script>

More Examples

Linear Algebra

import { eye, inv, det, lu, linsolve } from "ubique";

// Identity matrix
const I = eye(3);

// Matrix inversion
const A = [
  [1, 2],
  [3, 4],
];
const A_inv = inv(A);

// Determinant
const detA = det(A);

// LU decomposition
const luResult = lu(A);
const L = luResult.L;
const U = luResult.U;
const P = luResult.P;

// Solve linear system Ax = b
const b = [5, 6];
const x = linsolve(A, b);

Statistics

import { mean, std, corrcoef, cov, median } from "ubique";

const data = [1, 2, 3, 4, 5];

// Descriptive statistics
const avg = mean(data); // 3
const stdDev = std(data); // ~1.58
const med = median(data); // 3

// Correlation and covariance
const x = [1, 2, 3, 4, 5];
const y = [2, 4, 5, 4, 5];
const corr = corrcoef(x, y);
const covariance = cov(x, y);

Quantitative Finance

import { sharpe, sortino, drawdown, cagr, histvar } from "ubique";

const returns = [0.01, 0.02, -0.01, 0.03, -0.02];

// Risk metrics
const sharpeRatio = sharpe(returns);
const sortinoRatio = sortino(returns);
const ddResult = drawdown(returns);
const maxDD = ddResult.maxdd;

// Performance metrics
// Note: cagr requires price data and time array
const prices = [100, 101, 103, 102, 105.06, 102.96];
const time = [0, 1, 2, 3, 4, 5];
const annualReturn = cagr(prices, time);

// Risk measures
const var95 = histvar(returns, 0.95);

Matrix Operations

import {
  zeros,
  ones,
  rand,
  eye,
  transpose,
  reshape,
  diag,
  sum,
  prod,
  cumsum,
} from "ubique";

// Matrix creation
const Z = zeros(3, 3); // 3x3 zero matrix
const O = ones(2, 4); // 2x4 ones matrix
const R = rand(5, 5); // 5x5 random matrix
const I = eye(4); // 4x4 identity matrix

// Matrix manipulation
const A = [
  [1, 2, 3],
  [4, 5, 6],
];
const At = transpose(A); // Transpose
const B = reshape(A, 3, 2); // Reshape to 3x2
const d = diag(I); // Extract diagonal

// Aggregations
const s = sum(A); // Sum all elements
const p = prod(A); // Product of all elements
const cs = cumsum(A); // Cumulative sum

API Documentation

Ubique provides functions organized into the following modules:

  • Data Types (datatype): Type checking, assertions, data manipulation
  • Element Operations (elemop): Element-wise operations on arrays and matrices
  • Elementary Math (elmath): Mathematical functions (exp, log, sqrt, erf, etc.)
  • Linear Algebra (linalgebra): Matrix operations (inv, det, lu, linsolve)
  • Matrix Arrays (matarrs): Matrix creation and manipulation
  • Probability Distributions (probdistr): Statistical distributions and tests
  • Quantitative Finance (quants): Portfolio analytics and risk metrics
  • Regression (reglin): Regression and interpolation functions
  • Statistics (stats): Descriptive statistics (mean, std, median, etc.)

For complete API documentation, visit: https://nodalstudio.github.io/Ubique/

TypeScript Support

Ubique is written in TypeScript and includes full type definitions. Your IDE will provide autocomplete and type checking out of the box:

import { inv, Matrix } from "ubique";

const A: Matrix = [
  [1, 2],
  [3, 4],
];
const A_inv = inv(A); // Type: Matrix

Browser Compatibility

Ubique works in all modern browsers that support WebAssembly:

  • Chrome/Edge 57+
  • Firefox 52+
  • Safari 11+
  • Node.js 12+

The WebAssembly code is automatically inlined, so no additional configuration or file serving is required.

Contributing

Contributions are welcome and encouraged! If you have ideas or improvements, please fork the repository and submit a pull request. For issues or feature requests, use the GitHub Issues page.

License

Ubique is released under the MIT License. See the LICENSE file for details.