JavaScript · Matrix Kernels

Matrix Kernels

import * as numkong from 'numkong';import { PackedMatrix } from 'numkong'; 8.0.0-rc.1 · b1f866ab

API

ClassPackedMatrixOpaque packed matrix container.9
types.ts:379 ↗
class PackedMatrix

Packed layout is not indexable — this is a data container for packed GEMM kernels.

  • N-API path: buffer is a V8-managed ArrayBuffer, auto-freed by GC.
  • WASM path: stores a heap pointer, dispose() calls Module._free().
PackedMatrix
types.ts:387 ↗
new PackedMatrix(
    buffer: ArrayBuffer,
    columns: number,
    depth: number,
    dtype: DType,
    byteLength: number,
)
dispose
types.ts:395 ↗
dispose(): void
toString
types.ts:398 ↗
toString(): string
columns
types.ts:380 ↗
readonly columns: number
depth
types.ts:381 ↗
readonly depth: number
dtype
types.ts:382 ↗
readonly dtype: DType
byteLength
types.ts:383 ↗
readonly byteLength: number
buffer
types.ts:384 ↗
readonly buffer: ArrayBuffer
disposed
types.ts:396 ↗
readonly disposed: boolean

Functions

dotsPackedSizeQueries the packed buffer's byte count for a matrix with the given [columns,depth] and dtype, matching what dotsPack would allocate.
numkong.ts:440 ↗
function dotsPackedSize(
    columns: number,
    depth: number,
    dtype: DType,
): number

Parameters

columnsnumberNumber of vectors being packed, the matrix rows.
depthnumberDimensionality per vector, the matrix columns.
dtypeDTypeElement dtype of the source matrix.

Returns

The byte count of the packed buffer.
dotsPackPacks a Matrix for use with packed GEMM-like operations, such as dotsPacked.
numkong.ts:449 ↗
function dotsPack(matrix: Matrix): PackedMatrix

Parameters

matrixMatrixThe matrix to pack, [rows,columns] shaped.

Returns

The packed matrix, sized via dotsPackedSize.
dotsPackedComputes the dot products between every row of a and every packed vector in packed.
numkong.ts:499 ↗
function dotsPacked(
    a: Matrix,
    packed: PackedMatrix,
    out?: Matrix,
): Matrix

Parameters

aMatrixThe query matrix, [rows,columns] shaped, columns matching packed's depth.
packedPackedMatrixThe packed matrix produced by dotsPack.
outMatrixOptional output matrix to write into, [a.rows,packed.columns] shaped.

Returns

The distance matrix: out when given, otherwise a newly allocated Matrix.
angularsPackedComputes the angular distances between every row of a and every packed vector in packed.
numkong.ts:510 ↗
function angularsPacked(
    a: Matrix,
    packed: PackedMatrix,
    out?: Matrix,
): Matrix

Parameters

aMatrixThe query matrix, [rows,columns] shaped, columns matching packed's depth.
packedPackedMatrixThe packed matrix produced by dotsPack.
outMatrixOptional output matrix to write into, [a.rows,packed.columns] shaped.

Returns

The distance matrix: out when given, otherwise a newly allocated Matrix.
euclideansPackedComputes the Euclidean distances between every row of a and every packed vector in packed.
numkong.ts:521 ↗
function euclideansPacked(
    a: Matrix,
    packed: PackedMatrix,
    out?: Matrix,
): Matrix

Parameters

aMatrixThe query matrix, [rows,columns] shaped, columns matching packed's depth.
packedPackedMatrixThe packed matrix produced by dotsPack.
outMatrixOptional output matrix to write into, [a.rows,packed.columns] shaped.

Returns

The distance matrix: out when given, otherwise a newly allocated Matrix.
dotsSymmetricComputes the all-pairs dot products between every row of vectors and every other row.
numkong.ts:533 ↗
function dotsSymmetric(
    vectors: Matrix,
    out?: Matrix,
    options?: { rowsBegin?: number; rowsEnd?: number },
): Matrix

Parameters

vectorsMatrixThe matrix of vectors, [rows,columns] shaped.
outMatrixOptional output matrix to write into, [vectors.rows,vectors.rows] shaped.
options{ rowsBegin?: number; rowsEnd?: number }Optional row range: rowsBegin and rowsEnd restrict which rows of the symmetric matrix are computed, defaulting to all rows.

Returns

The distance matrix: out when given, otherwise a newly allocated Matrix.
angularsSymmetricComputes the all-pairs angular distances between every row of vectors and every other row.
numkong.ts:545 ↗
function angularsSymmetric(
    vectors: Matrix,
    out?: Matrix,
    options?: { rowsBegin?: number; rowsEnd?: number },
): Matrix

Parameters

vectorsMatrixThe matrix of vectors, [rows,columns] shaped.
outMatrixOptional output matrix to write into, [vectors.rows,vectors.rows] shaped.
options{ rowsBegin?: number; rowsEnd?: number }Optional row range: rowsBegin and rowsEnd restrict which rows of the symmetric matrix are computed, defaulting to all rows.

Returns

The distance matrix: out when given, otherwise a newly allocated Matrix.
euclideansSymmetricComputes the all-pairs Euclidean distances between every row of vectors and every other row.
numkong.ts:557 ↗
function euclideansSymmetric(
    vectors: Matrix,
    out?: Matrix,
    options?: { rowsBegin?: number; rowsEnd?: number },
): Matrix

Parameters

vectorsMatrixThe matrix of vectors, [rows,columns] shaped.
outMatrixOptional output matrix to write into, [vectors.rows,vectors.rows] shaped.
options{ rowsBegin?: number; rowsEnd?: number }Optional row range: rowsBegin and rowsEnd restrict which rows of the symmetric matrix are computed, defaulting to all rows.

Returns

The distance matrix: out when given, otherwise a newly allocated Matrix.