@teakit/matrix

Use this skill when writing code for @teakit/matrix.

A TypeScript toolkit for keyed business matrices (Record<string, readonly T[]>) — fixed period matrices, aggregation, rollup/rolldown, and transform/combine helpers. Not a linear-algebra library.

Core Rules

  1. Import with the canonical named import.
  2. Do not use default imports unless this package explicitly supports them.
  3. Use the canonical creation or entry API.
  4. Do not generate unsupported aliases, constructors, or compatibility APIs.
  5. Prefer exact inputs and explicit options when relevant.
  6. Read the relevant reference file before generating code.

Workflow

  1. Identify the operation or concept.
  2. Load only the relevant reference file from references/.
  3. Read examples, API Reference, Agent Contract, and Agent Notes.
  4. Generate code using only documented public APIs.
  5. For repository changes, run relevant verification commands.

Quick Example

import { Matrix } from "@teakit/matrix";

const forecast = Matrix.range("2024-Q2", "2025-Q1", { by: "quarter" }).fill(0);
const yearly = Matrix.rollup(forecast, { to: "year" }); // skips "-"; default sum

Reference Selection

Read the smallest reference that answers the current task.

NeedRead
Matrix shape, no-data, key order, immutabilitymatrix
The four fixed period shapes & detectionperiod-shapes
Error type and codeserrors
Validate & clone unknown inputfrom
Check a value is a matrixisMatrix
Assert a value is a matrixassertMatrix
Build a fixed period matrixrange
Sum a matrixsum
Average a matrixmean
Median of a matrixmedian
Roll finer periods up to coarserrollup
Expand coarser periods down to finerrolldown
Map every cell into a new matrixmap
Fold a matrix to a single valuereduce
Flatten a matrix into entriesentries
Build from sparse entriesfromEntries
Copy a known matrixclone
Stabilize key set & row lengthnormalize
Turn rows into columnstranspose
Merge matrices with a resolvermerge
Pair matrices into tupleszip
Plain-object formtoObject
JSON-serializable formtoJSON