GitHub
deepbox/core

Configuration

Global configuration system for default dtype, device, and random seed. Changes apply to all subsequent tensor and model operations.
DeepboxConfig
type DeepboxConfig = {  readonly defaultDtype: DType;   // Default: 'float32'  readonly defaultDevice: Device; // Default: 'cpu'  readonly seed: number | null;   // Default: null (no seed)};
getConfig
getConfig(): Readonly<DeepboxConfig>

Returns a copy of the current global configuration. The returned object cannot mutate the internal config.

setConfig
setConfig(next: Partial<DeepboxConfig>): void

Merges the provided settings with the current configuration. Only specified fields are updated. Validates all values and rejects unknown keys.

Parameters:
next: Partial<DeepboxConfig> - Fields to update. Unrecognized keys throw DataValidationError.
resetConfig
resetConfig(): void

Resets all configuration to defaults: dtype=float32, device=cpu, seed=null.

setDtype
setDtype(dtype: DType): void

Sets the default data type for new tensors. All tensor creation functions (zeros, ones, randn, etc.) will use this dtype unless overridden.

Parameters:
dtype: DType - One of: float32, float64, int32, int64, uint8, bool, string
getDtype
getDtype(): DType

Returns the current default dtype.

setDevice
setDevice(device: Device): void

Sets the default compute device. Currently only 'cpu' is fully supported.

Parameters:
device: Device - One of: cpu, webgpu, wasm
getDevice
getDevice(): Device

Returns the current default device.

setSeed
setSeed(seed: number): void

Sets the global random seed for reproducibility. Must be a safe integer. After setting, all random operations become deterministic.

Parameters:
seed: number - Integer seed value (safe integer range)
getSeed
getSeed(): number | null

Returns the current random seed, or null if not set.

config-example.ts
import { setConfig, getConfig, resetConfig, setDtype, setSeed } from "deepbox/core";// Set multiple config values at oncesetConfig({ defaultDtype: "float64", seed: 42 });// Set individual valuessetDtype("float32");setSeed(123);// Read current configconst config = getConfig();console.log(config.defaultDtype); // 'float32'console.log(config.seed);         // 123// Reset to defaultsresetConfig();

When to Use

  • Set seed at program start for reproducible experiments
  • Set dtype to float64 when you need higher numerical precision
  • Use resetConfig() in test teardown to avoid leaking state between tests