Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
IntroductionRenderer GalleryRenderersAnalysis
computeQuantilescomputePercentilescomputeCorrelationcomputeCovariancedetectOutliersdetectOutliersZScorecomputeExtendedStatsdescribeExtendedStatsQuantileResultCorrelationResultOutlierResultExtendedStatscreateDBSCANdbscanDBSCANDBSCAN.fitDBSCAN.destroyDBSCANOptionsDBSCANResultcreateHierarchicalClusteringhierarchicalClusteringHierarchicalClusteringHierarchicalClustering.fitHierarchicalClustering.destroyLinkageMethodDistanceMetricHierarchicalOptionsDendrogramNodeHierarchicalResultcomputeHistogramgetHistogramCentersnormalizeHistogramHistogramResultcreateKDEkdeKDEKDE.fitKDE.destroyKernelTypeKDEOptionsKDEResultcreateKMeanskmeansKMeansKMeans.fitKMeans.destroyKMeansOptionsKMeansResultcreatePCApcaPCAPCA.fitPCA.destroyPCAOptionsPCAResultthrottleProgressconsoleProgressProgressInfoProgressCallbackcomputeStatscomputeMinMaxdescribeStatsTensorStatscreateTSNEtsneTSNETSNE.fitTSNE.destroyTSNEOptionsTSNEResultcreateUMAPumapUMAPUMAP.fitUMAP.destroyUMAPOptionsUMAPResult
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. viz
  3. viz
  4. analysis
  5. computeStats

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
Previous
computeQuantiles
Next
consoleProgress