Types & Validation
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 guard to check if a value is a valid Device.
Type guard to check if a value is a valid DType.
Create a readonly number array from mutable array with proper typing.
Get an element from a number array at the specified index.
Get an element from a BigInt64Array at the specified index.
Get an element from a TypedArray, returning as number.
Get an element from a numeric typed array at the specified index.
Get an element from a shape array at the specified index.
Safely get a string from a string array at the specified index.
Type guard to check if a typed array is a BigInt64Array.
Type guard to check if a typed array is a numeric (non-BigInt) array.
Type guard to check if a value is one of the supported TypedArray types.
Check if two shapes are equal element-wise.
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);