Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Metric Reference

Custom Comparisons

Use a built-in comparison when its equation fits. For a user-defined formula, make_pairwise turns a scalar two-sample function into all-pairs, paired, condensed and single comparisons. Pass the same object to tp.lazy(x, y, metric) to bind the formula to the scalar streaming engine.

For learned representations, separate encoding from comparison. The caller supplies the encoder and its loaded weights; make_feature_pairwise composes one encoder, or separate query and reference towers, with an explicit head. Extracted features can feed built-in metrics, custom metrics and streamed operators.

ExtensionWhat the User ProvidesWhat TorchPairwise Reuses
User-defined metricA scalar or broadcast-tile forward, optionally a custom VJP, autograd function or nn.ModulePair indexing, modes, tiling, scalar algebra and consumers
Native metricRegistered paired-tile forward/VJP operatorsThe same source and consumer engine in Python and LibTorch
Encoded featuresOne encoder or a query/reference pair, and a comparison headEncoding once before comparison broadcasting; explicit preparation for reuse

These extensions do not add entries to the built-in comparison catalog. Python callbacks and encoders keep their own compilation and deployment requirements.