Skip to content

Introduction

Typed Matrices in Numz are an extension of Zikojs Matrix, designed to provide high-performance, memory-efficient, and type-safe matrix operations.

Unlike regular matrices that rely on standard JavaScript arrays, Typed Matrices are backed by TypedArray structures, enabling contiguous memory layout and faster numerical computation.


Numz provides multiple TypedMatrix classes, each mapped to a specific JavaScript TypedArray implementation.

ClassBacking TypePrecisionUse case
F16MatrixFloat16Array16-bitML, GPU-style data
F32MatrixFloat32Array32-bitGPU, graphics, signals
F64MatrixFloat64Array64-bitScientific computing
ClassBacking TypeRangeUse case
I8MatrixInt8Array−128 → 127Compact data
U8MatrixUint8Array0 → 255Images, buffers
I16MatrixInt16Array−32K → 32KDSP, audio
U16MatrixUint16Array0 → 65KIndexing
I32MatrixInt32Array32-bitGeneral integers
U32MatrixUint32Array32-bitLarge indices
ClassBacking TypeNotes
BI64MatrixBigInt64ArrayRequires BigInt
BU64MatrixBigUint64ArrayLarge integer arithmetic

import { F64Matrix } from 'numz';
const A = new F64Matrix(2, 2, [
1, 2,
3, 4
]);
A.add(2).mul(3);

During the construction phase, the provided data is accepted as a regular JavaScript array only as a temporary input. Internally, Numz copies the values into a TypedArray (Float64Array in this case), and the original array is discarded and no longer used.

This guarantees:

  • contiguous memory layout
  • predictable numeric type
  • better performance for subsequent operations