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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@johnhenry/math-plus-adapter-math

v0.0.5

Published

Bridge between @johnhenry/math (Vector/Matrix, science/CAS side) and @johnhenry/math-plus-tensor-core (Tensor, engineering side) — Matrix/Vector <-> Tensor conversion (issue #14); Symbolic->tensor-compile IR (issue #15) and Symbolic->frame-arrow Expr (iss

Readme

@johnhenry/math-plus-adapter-math

npm version license

The bridge between @johnhenry/math (Vector/Matrix, Symbolic CAS — the science side) and @johnhenry/math-plus-tensor-core (Tensor — the engineering side). Three jobs live here: Matrix/Vector ↔ Tensor conversion, compiling Symbolic expressions into the tensor and dataframe worlds, and the tensor-native numerics (linalg, stats, FFT) that sit on top of the conversion layer.

Install

npm install @johnhenry/math-plus-adapter-math

Depends on @johnhenry/math, tensor-core, tensor-compile, and frame-arrow (all @johnhenry/math-plus-*).

Quick start

import { fromMatrix, toMatrix, compileExpr, compileFrameExpr, linalg } from "@johnhenry/math-plus-adapter-math";
import { Symbolic } from "@johnhenry/math";
import { Tensor } from "@johnhenry/math-plus-tensor-core";

// Matrix/Vector <-> Tensor — plain arrays or @johnhenry/math values
const t = fromMatrix([[1, 2, 3], [4, 5, 6]]); // 2x3 f32 Tensor
toMatrix(t.transpose());                      // [[1,4],[2,5],[3,6]] — views handled

// Compile a CAS expression to run over tensor batches
const expr = Symbolic.parse("sin(x) * y + sqrt(x^2 + 1)");
const compiled = compileExpr(expr, { variables: ["x", "y"] });
compiled.forward(Tensor.from([0.1, 1.7]), Tensor.from([1.0, 0.3]));
const { localGrads } = compiled.forwardWithGrad(Tensor.from([0.3]), Tensor.from([1]));
// gradients — tested against Symbolic.differentiate as an independent oracle

// Same Symbolic expression as a frame-arrow computed column
const formula = Symbolic.parse("sin(x) * x");
const derivative = Symbolic.differentiate(formula, "x");
frame.withColumns({
  y: compileFrameExpr(formula),        // free variables become col() refs
  dy_dx: compileFrameExpr(derivative), // differentiate symbolically, run columnar
});

// Tensor-native linear algebra
linalg.solve(a, b);
linalg.svd(a);

API surface

  • Conversion: fromMatrix / fromVector (plain arrays or @johnhenry/math Matrix/Vector; optional { dtype }), toMatrix / toVector (correct through non-contiguous views). Ragged input throws RangeError.
  • compileExpr(expr, opts?): Symbolic → tensor-compile IR. Returns a CompiledFn with forward(...tensors) and forwardWithGrad(...); default variable order is Symbolic.freeVariables (alphabetical) — pass variables to pin positions. piecewise compiles to select chains. Unsupported nodes throw UnsupportedExprError.
  • compileFrameExpr(expr): Symbolic → frame-arrow Expr. Function names map 1:1 (frame-arrow's fn.* was spelled to match Symbolic); unknown columns surface as frame-arrow's own error.
  • linalg: lu/solve/det/inv/rref/rank/nullSpace, qr, cholesky, eigSymmetric (Jacobi) and eigGeneral (complex eigenvalues, returned as @johnhenry/math ComplexNumbers), powerIteration, svd, leastSquares, pseudoInverse, norms and conditionNumber.
  • Stats: mean/median/percentile/variance/standardDeviation (+ population variants), correlation, linearRegression, Distributions, HypothesisTests, SpecialFunctions.
  • FFT: fft/ifft/fftPadded/convolve/realSignal over Float64Array pairs.
  • Graphs: toCSR/toDense for @johnhenry/math graph values.
  • ./test-utils: dualGrad/dualGradN — the DualNumber forward-mode gradient oracle, exported so other packages can check their gradients against an independent implementation.

Traps

  • compileExpr renames ln → log internally to match tensor-compile's IR; compileFrameExpr needs no rename table — if you extend one bridge, don't assume the other spells functions the same way.
  • Variable order is alphabetical unless you pass variables. Symbolic.parse("b - a") compiled without options takes (a, b) — in that order.
  • Conversion defaults to f32. Round-tripping f64 data through fromMatrix without { dtype: "f64" } quietly drops precision.

Part of the math-plus family — docs at opensource.johnhenry.me/math/.