viz.analysis.computeStats
function computeStats(tensor: Tensor): Promise<TensorStats>Compute all statistics (min, max, mean, std, sum) entirely on GPU.
Uses parallel reduction with workgroups computing partial stats, then reduces results on CPU. Requires tensor on WebGPU device (no data transfers except final statistics).
Parameters
tensorTensor- Input tensor on WebGPU device. Throws error if on CPU
Returns
Promise<TensorStats>– Promise resolving to TensorStats with: - min: Minimum value in tensor - max: Maximum value in tensor - mean: Arithmetic mean (sum / count) - std: Standard deviation (√variance) - sum: Sum of all elements - count: Number of elements (tensor.numel())Examples
const weights = model.parameters().next().value.to('webgpu');
const stats = await computeStats(weights);
console.log(`Weights: mean=${stats.mean.toFixed(4)}, std=${stats.std.toFixed(4)}`);See Also
- computeMinMax - For just min/max (slightly faster)
- describeStats - For human-readable string format