GitHub
deepbox/core

Types & Validation

Foundational types, constants, and validation helpers used throughout the Deepbox runtime.
deepbox/core
Shared primitives

Overview

  • Shape, Axis, DType, Device, TensorLike, and typed-array helpers are the common contracts used by every higher-level module.
  • The Device union names where tensors may logically live; only devices with a registered backend perform real execution on that path (CPU by default—see Config & Backends and Devices & execution).
  • Validation helpers are designed to fail fast with Deepbox-specific error types instead of leaking inconsistent downstream states.
  • Use deepbox/core when you need dependency-light utilities without pulling in the whole tensor or ML stack.
type Axis
export type Axis = number | "index" | "rows" | "columns";
Axis identifier.
type Device
export type Device = "cpu" | "webgpu" | "wasm";
Logical compute devices for tensors and modules.
type DType
export type DType = "float16" | "bfloat16" | "float32" | "float64" | "int32" | "int64" | "uint8" | "bool" | "complex64" | "complex128" | "string";
Supported data types for tensors.
type ElementOf
export type ElementOf<D extends DType> = D extends "string" ? string : D extends "int64" ? bigint : number;
Maps a DType to its JavaScript element type.
type ExtendedTypedArray
export type ExtendedTypedArray = import("../../ndarray/tensor/float16").Float16Array | import("../../ndarray/tensor/float16").BFloat16Array | import("../../ndarray/tensor/complex").Complex64Array | import("../../ndarray…
Extended array types for half-precision and complex dtypes.
type ScalarDType
export type ScalarDType = "float16" | "bfloat16" | "float32" | "float64" | "int32" | "uint8" | "bool";
Numeric DTypes whose JavaScript element type is `number`.
type Shape
export type Shape = readonly number[];
Represents the dimensions of a multi-dimensional array (tensor).
type TensorLike
export type TensorLike<S extends Shape = Shape, D extends DType = DType> = { readonly shape: S; readonly dtype: D; readonly device: Device; readonly data: TensorStorage; readonly strides: readonly number[]; readonly off…
Type representing a tensor-like object.
type TensorStorage
export type TensorStorage = TypedArray | ExtendedTypedArray | string[];
Backing storage for a tensor.
type TypedArray
export type TypedArray = Float32Array | Float64Array | Int32Array | BigInt64Array | Uint8Array;
Union type of all TypedArray types supported by Deepbox.
type DEVICES
export declare const DEVICES: readonly Device[];
DEVICES is a public const in deepbox/core.
type DTYPES
export declare const DTYPES: readonly DType[];
DTYPES is a public const in deepbox/core.
type NumericDType
export type NumericDType = Exclude<DType, "string">;
All DType values except "string".
type NumericTypedArray
export type NumericTypedArray = Float32Array | Float64Array | Int32Array | Uint8Array;
Numeric typed arrays (excludes BigInt64Array).
isDevice
export declare function isDevice(value: unknown): value is Device;

Type guard to check if a value is a valid Device.

isDType
export declare function isDType(value: unknown): value is DType;

Type guard to check if a value is a valid DType.

asReadonlyArray
export declare function asReadonlyArray<T extends number[]>(arr: T): readonly number[];

Create a readonly number array from mutable array with proper typing.

getArrayElement
export declare function getArrayElement(arr: readonly number[], index: number, defaultValue?: number): number;

Get an element from a number array at the specified index.

getBigIntElement
export declare function getBigIntElement(arr: BigInt64Array, index: number): bigint;

Get an element from a BigInt64Array at the specified index.

getElementAsNumber
export declare function getElementAsNumber(arr: TypedArray, index: number): number;

Get an element from a TypedArray, returning as number.

getNumericElement
export declare function getNumericElement(arr: NumericTypedArray, index: number): number;

Get an element from a numeric typed array at the specified index.

getShapeDim
export declare function getShapeDim(shape: readonly number[], index: number): number;

Get an element from a shape array at the specified index.

getStringElement
export declare function getStringElement(arr: readonly string[], index: number): string;

Safely get a string from a string array at the specified index.

isBigInt64Array
export declare function isBigInt64Array(arr: TypedArray): arr is BigInt64Array;

Type guard to check if a typed array is a BigInt64Array.

isNumericTypedArray
export declare function isNumericTypedArray(arr: TypedArray): arr is NumericTypedArray;

Type guard to check if a typed array is a numeric (non-BigInt) array.

isTypedArray
export declare function isTypedArray(value: unknown): value is TypedArray;

Type guard to check if a value is one of the supported TypedArray types.

shapesEqual
export declare function shapesEqual(a: readonly number[], b: readonly number[]): boolean;

Check if two shapes are equal element-wise.

core-types.ts
import {  DTYPES,  DEVICES,  isDType,  isDevice,  type Axis,  type DType,  type Shape,} from "deepbox/core";const shape: Shape = [2, 3];const dtype: DType = "float32";const axis: Axis = 1;console.log(DTYPES.includes(dtype), DEVICES, isDType(dtype), isDevice("cpu"), axis, shape);