Configuration
type DeepboxConfig = { readonly defaultDtype: DType; // Default: 'float32' readonly defaultDevice: Device; // Default: 'cpu' readonly seed: number | null; // Default: null (no seed)};Returns a copy of the current global configuration. The returned object cannot mutate the internal config.
Merges the provided settings with the current configuration. Only specified fields are updated. Validates all values and rejects unknown keys.
next: Partial<DeepboxConfig> - Fields to update. Unrecognized keys throw DataValidationError.Resets all configuration to defaults: dtype=float32, device=cpu, seed=null.
Sets the default data type for new tensors. All tensor creation functions (zeros, ones, randn, etc.) will use this dtype unless overridden.
dtype: DType - One of: float32, float64, int32, int64, uint8, bool, stringReturns the current default dtype.
Sets the default compute device. Currently only 'cpu' is fully supported.
device: Device - One of: cpu, webgpu, wasmReturns the current default device.
Sets the global random seed for reproducibility. Must be a safe integer. After setting, all random operations become deterministic.
seed: number - Integer seed value (safe integer range)Returns the current random seed, or null if not set.
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