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

Integration

Python and C++

Built-in comparisons and reductions execute native forward and first backward. Python binds tensors, metric names and options; standalone C++ calls the same algorithms without Python callbacks. Include <torchpairwise.h> and link the CMake target. To build your own extension on the installed package, see Extending from C++.

Structured Samples and Options

A Gaussian is a mean/covariance pair; a mixture adds weights. Python uses tuples, C++ uses ComparisonCollection. Explicit parameters use keyword arguments or a ComparisonOptions struct. Unused supplied options are errors.

Python
# mu:[D], covariance:[D,D], with optional leading batches
value = tp.compare((mu, covariance), (other_mu, other_covariance),
                   metric="gaussian_wasserstein_distances",
                   mode="single", squared=True)
C++ / LibTorch
tp::ComparisonOptions options;
options.squared = true;
tp::ComparisonCollection x{mu, covariance};
tp::ComparisonCollection y{other_mu, other_covariance};
auto value = tp::compare(x, y, "gaussian_wasserstein_distances",
                         "single", options);

Native Source Factories

Input familyScalarExpression factory / options
Vector/point-cloud distances and vector kernelspairwise_expression / PairwiseOperationOptions
Covariances, Gaussians, mixturesstructured_expression / StructuredOperationOptions
Imagesmedia_expression / ImageComparisonOptions, PairwiseOperationOptions
Audiomedia_expression / AudioComparisonOptions, PairwiseOperationOptions
Sequences, tokens, MMD statisticordered_expression / SequenceOperatorOptions, TokenOperatorOptions, MMDOperatorOptions
Caller matrixmatrix_expression / MatrixOperationOptions

torchpairwise::streaming re-exports these factories and adds the short forms pairwise, kernel, matrix, residual and image_map, plus the linalg and optimize solver namespaces used throughout the streamed operator guides. Newer helpers such as Sinkhorn, pair-mask constructors and LOVE live in torchpairwise::ops. Named C++ family APIs also exist. Their native symbol names are not always an identical per-metric Python name; use the mode-aware compare selector for a uniform call. See native headers and signatures and the LibTorch examples.

Compatibility

Match LibTorch's major/minor, ABI, toolchain and CUDA runtime with the library. Rebuild native consumers and re-export graphs when upgrading changed operator schemas. Generic cdist/pdist schemas include the broad catalog and collection overloads; older published binaries do not expose the same surface.