deepbox/core
Types & Constants
Foundational type definitions and constants shared by all Deepbox modules. These types form the backbone of the entire framework.
type DType
'float32' | 'float64' | 'int32' | 'int64' | 'uint8' | 'bool' | 'string'
Data type of tensor elements. float32 is the default. Use float64 for higher precision, int32/int64 for integer data, uint8/bool for masks, string for categorical data.
type Device
'cpu' | 'webgpu' | 'wasm'
Compute device for tensor operations. Currently only 'cpu' is fully supported. webgpu and wasm are reserved for future backends.
type Shape
readonly number[]
Dimensions of a tensor. For example, [2, 3] is a 2×3 matrix. An empty array [] represents a scalar.
type TypedArray
Float32Array | Float64Array | Int32Array | BigInt64Array | Uint8Array
Underlying storage types for tensor data. Each DType maps to a specific TypedArray constructor.
type TensorLike
number | boolean | string | bigint | NestedArray | TypedArray
Any value that can be converted into a Tensor via tensor(). Includes scalars, nested arrays, and TypedArrays.
type TensorStorage
TypedArray | readonly string[]
The raw backing store of a Tensor. Numeric tensors use TypedArrays; string tensors use string arrays.
type Axis
number | null
Axis parameter for reduction operations. null means reduce over all axes.
DType ↔ TypedArray Mapping
- float32 → Float32Array (32-bit IEEE 754)
- float64 → Float64Array (64-bit IEEE 754)
- int32 → Int32Array (signed 32-bit integer)
- int64 → BigInt64Array (signed 64-bit integer)
- uint8 → Uint8Array (unsigned 8-bit, also used for bool)
- bool → Uint8Array (0 or 1)
- string → readonly string[] (not a TypedArray)
isDType
isDType(value: unknown): value is DType
Type guard that checks whether a value is a valid DType string.
isDevice
isDevice(value: unknown): value is Device
Type guard that checks whether a value is a valid Device string.
types-example.ts
import { isDType, isDevice } from "deepbox/core";import type { DType, Device, Shape, TypedArray } from "deepbox/core";isDType("float32"); // trueisDType("int16"); // falseisDevice("cpu"); // trueconst shape: Shape = [2, 3, 4]; // 3D tensor shapeconst dtype: DType = "float64"; // double precision