Utilities
Computes the total number of elements from a shape array. Multiplies all dimensions together.
shape: Shape - Tensor shape (e.g., [2, 3, 4] → 24)Maps a DType to its corresponding TypedArray constructor (e.g., 'float32' → Float32Array).
Validates that a value is a valid shape (array of non-negative integers). Throws DataValidationError on failure.
Validates that a value is a supported DType string. Throws DataValidationError on failure.
Validates that a value is a supported Device string.
Normalizes a negative axis to a positive one (e.g., axis=-1 with ndim=3 → 2). Throws IndexError if out of bounds.
Normalizes axis parameter that can be a single axis, array of axes, or null (all axes).
Validates that a number is positive (> 0). Throws InvalidParameterError otherwise.
Validates that a number is non-negative (>= 0).
Validates that a number is a finite safe integer.
Validates that a number falls within [min, max].
import { shapeToSize, normalizeAxis, validateShape } from "deepbox/core";shapeToSize([2, 3, 4]); // 24shapeToSize([]); // 1 (scalar)normalizeAxis(-1, 3); // 2normalizeAxis(0, 3); // 0validateShape([2, 3], "myShape"); // [2, 3] — valid// validateShape([2, -1], "myShape"); // throws DataValidationError