@danielsimonjr/mathts-matrix

中文文档
0.10.0发布于 2026/11/11MITTypeScriptES Module近 30 天下载 4140

Matrix operations for MathTS with WASM/WebGPU backend support

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. WASM matrix multiply (not DenseMatrix.multiply )
  4. Backends
  5. Matrix Types
  6. Status
  7. License

@danielsimonjr/mathts-matrix

High-performance matrix operations with multi-backend support (JS/WASM/GPU).

Installation

npm install @danielsimonjr/mathts-matrix

Usage

import {
  DenseMatrix,
  matMul,
  transposeNestedArray,
  svd,
  eig,
  lu,
  qr,
  cholesky,
} from '@danielsimonjr/mathts-matrix';

// Create a matrix from a 2D array
const A = DenseMatrix.fromArray([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
]);

// DenseMatrix methods use the JS backend (add, multiply, transpose, …)
const sum = A.add(A);
const product = A.multiply(A);
const transposed = A.transpose();

// `eig` / `svd` take number[][]; `lu` / `qr` / `cholesky` take DenseMatrix
const { U, S, V, rank } = svd(A.toArray());
const { values, vectors } = eig(A.toArray());
const { L, U: Ulu, P } = lu(A);

// Nested-array multiply / transpose (same kernels as decomposition internals)
const C = matMul(A.toArray(), A.toArray());
const At = transposeNestedArray(A.toArray());

WASM matrix multiply (not DenseMatrix.multiply)

After await backendManager.initialize(), backendManager.multiply(a, b) and wasmBackend.multiply(a, b) can run the AssemblyScript GEMM kernel when size gates pass. Tensor.matMul in @danielsimonjr/mathts-tensor routes through the same manager. Public lu / qr / cholesky / eig / svd stay on JS; eigWasm and svdWasm are async wrappers that still call those JS solvers.

import { backendManager, DenseMatrix } from '@danielsimonjr/mathts-matrix';

await backendManager.initialize();
const a = DenseMatrix.random(32, 32);
const c = backendManager.multiply(a, a);

Backends

BackendHow you reach itRole
JSDenseMatrix methods; lu/qr/cholesky/eig/svdDefault
WASMbackendManager.multiply, wasmBackend.multiply, Tensor.matMulSIMD GEMM (+ unused-by-public decomp methods on WASMBackend)
GPUgpuMatrixBackend.multiplyAsync; @danielsimonjr/mathts-functions with enableGpu()f32 opt-in; not registered on BackendManager

Live defaults come from one table: matrix/src/config.ts DEFAULT_CONFIG (multiply WASM 256 flop count; gpu.enabled false). DEFAULT_EXTENDED_HINTS on BackendManager is derived from that table at load time. GPU hint 65536 is dormant until a GPU backend registers. Element-wise WASM paths were retired as slower than JS (2026-07).

Matrix Types

  • DenseMatrix - Standard dense storage (row-major)
  • SparseMatrix - CSR format for sparse data

Status

This package is under active development. Currently implemented:

  • Type definitions
  • Backend infrastructure
  • Dense matrix structure
  • Sparse matrix (CSR) structure
  • Matrix operations (add, multiply, transpose, etc.)
  • WASM backend (AssemblyScript) for manager-driven GEMM
  • GPU backend (WebGPU) via GPUMatrixBackend
  • SVD decomposition (JS)
  • Eigenvalue solvers (JS)
  • LU / QR / Cholesky and related exports (see API reference)

License

MIT

版本与发布记录

@danielsimonjr/mathts-matrix 共发布 51 个版本,首次发布于 2026/04/05;过去 12 个月发布了 51 个版本。

版本发布日期距今
0.10.0latest2026/11/11今天
0.9.62026/11/10今天
0.9.52026/11/101 天前
0.9.42026/11/101 天前
0.9.32026/11/092 天前
0.9.22026/11/092 天前

关于 @danielsimonjr/mathts-matrix 的常见问题

@danielsimonjr/mathts-matrix 是什么?

Matrix operations for MathTS with WASM/WebGPU backend support

如何安装 @danielsimonjr/mathts-matrix?

在项目目录运行 npm install @danielsimonjr/mathts-matrix,或使用 pnpm add / yarn add / bun add。

@danielsimonjr/mathts-matrix 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@danielsimonjr/mathts-matrix 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@danielsimonjr/mathts-matrix 可以商用吗?

@danielsimonjr/mathts-matrix 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@danielsimonjr/mathts-matrix 的下载量有多少?

根据 npm 官方下载统计,@danielsimonjr/mathts-matrix 在 2026/10/12 – 2026/11/10 这 30 天内被下载 4,140 次,日均约 138 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@danielsimonjr/mathts-matrix 还在维护吗?

最新版本 0.10.0 发布于 2026/11/11(今天);至今共发布 51 个版本,其中过去 12 个月发布了 51 个;首次发布于 2026/04/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。