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-data

v0.0.4

Published

Async dataset pipelines for math-plus (issue #22) — the v2 `data` namespace: a curated Dataset facade over @johnhenry/iteration (chunk/batch/shuffle/epochs/mapConcurrent/prefetch/fold, AbortSignal cancellation) producing Tensor batches for tensor-autograd

Readme

@johnhenry/math-plus-data

npm version license

Async dataset pipelines for math-plus (issue #22): a curated Dataset facade over @johnhenry/iteration — chunk/batch/shuffle/epochs/mapConcurrent/prefetch/fold with AbortSignal cancellation — producing Tensor batches shaped exactly for @johnhenry/math-plus-tensor-autograd's trainer.fit.

Install

npm install @johnhenry/math-plus-data

Quick start

import { collate, fromAsync } from "@johnhenry/math-plus-data";

const ds = fromAsync([1, 2, 3, 4, 5, 6, 7, 8])
  .map((x) => x * 10)
  .filter((x) => x % 20 === 0)
  .drop(1)
  .take(2);
await ds.toArray(); // [40, 60] — and re-iterable, so again: [40, 60]

// Batching straight into the trainer's Batch shape
const samples = [{ x: [0, 1], y: [0] }, { x: [1, 2], y: [2] } /* ... */];
const pipeline = fromAsync(samples)
  .epochs(60, { reshuffle: { seed: 42 } })
  .batch(16, { collate: collate.xy({ dtype: "f64" }) });

const { lossHistory } = await trainer.fit(pipeline); // tensor-autograd

API surface

  • fromAsync(source) — source is an Iterable, AsyncIterable, or a factory returning one.
  • Dataset methods: map, filter, mapConcurrent(fn, { concurrency, ordered?, signal? }), prefetch(n), chunk(n), batch(n, { collate? }), shuffle({ seed?, bufferSize? }), take, drop, abortable(signal), epochs(n, { reshuffle? }), fold, toArray.
  • collate.vectors({ dtype? }) → [batch, dim] Tensor; collate.scalars({ dtype? }) → [batch]; collate.xy({ dtype? }) → { x, y } — tensor-autograd's Batch exactly.

Traps

  • One-shot vs re-iterable. Arrays/Sets are re-iterable; a bare AsyncIterable is assumed one-shot — a second pass throws with a hint, and .epochs() refuses one-shot sources up front. Pass a factory (fromAsync(() => stream())) for multi-pass pipelines.
  • collate defaults to f32, matching nn.* parameters' default dtype (f32 since @johnhenry/math-plus-tensor-autograd #123). tensor-core has no implicit dtype promotion by design, so if you build a model with { dtype: "f64" } parameters, pass collate.xy({ dtype: "f64" }) too.
  • Shuffle: omitting seed is non-reproducible. bufferSize defaults to Infinity (full materialize + Fisher-Yates); a finite buffer is the tf.data streaming shuffle with mixing quality bounded by the buffer.
  • shuffle() on top of epochs() shuffles the concatenated stream. For per-epoch reshuffling use epochs(n, { reshuffle: { seed } }) (derives seed + epochIndex).
  • Ragged batches are loud: collate.vectors throws RangeError on differing sample lengths — no silent padding.
  • Curated facade, enforced by a test: no count*, no raw group/reduce* re-exports (group collides with dataframe groupBy vocabulary; fold is the terminal reduce). Power users can import @johnhenry/iteration directly — the facade is the supported surface, not a wall.

Concurrency and cancellation

mapConcurrent delegates to iteration's mapConcurrentAsync: order preserved by default, at most concurrency in flight, source pulled only with spare capacity, source closed via return() on early exit or error. prefetch(n) is a bounded read-ahead buffer. Cancellation is plain AbortSignal end to end, rejecting with the signal's reason.

Provenance

Part of the math-plus monorepo; family docs at https://opensource.johnhenry.me/math/.