Directed Hausdorff
Generic selectors return values. The named all-pairs function also returns source/target witness indices. Directional: no condensed mode.
Shapes and Modes
| Input | Layout |
|---|---|
| One sample | [P,D] |
| Collection X | [...,N,P,D] |
| Collection Y | [...,M,Q,D] |
| Mode | Selector | Output |
|---|---|---|
| all-pairs | compare(X,Y,metric=...) | [...,N,M] |
| paired | compare(X,Y,metric=...,mode="paired") | [...,N]; equal sample counts |
| single | compare(x,y,metric=...,mode="single") | [...]; leading batches only |
Leading batch dimensions broadcast. Condensed mode is not exposed for this directional comparison. See mode and shape conventions.
Entry Points
| Named Python entry | Function |
|---|---|
| All-pairs | directed_hausdorff_distances |
The Python and C++ compare selectors cover every mode shown above. cdist / pairwise_distances and paired_distances select this comparison; condensed distance selectors reject it. single_comparison is shorthand for single mode.
Catalog aliases: directed_hausdorff.
Accepted metric options: shuffle, generator, x1_lengths, x2_lengths, chunk_size, batched, feature_dim. Omitted options keep the metric defaults; unused options are rejected.
Example
Choose Python or C++ in the top bar; the setting applies across this guide.
import torch
import torchpairwise as tp
X = torch.rand(2, 3, 2) # [N=2,P=3,D=2]
Y = torch.rand(3, 4, 2) # [M=3,Q=4,D=2]
metric = "directed_hausdorff_distances"
all_pairs = tp.compare(X, Y, metric=metric) # [2,3]
paired_Y = Y[:2]
paired = tp.compare(X, paired_Y, metric=metric, mode="paired") # [2]
x, y = X[0], Y[0]
single = tp.compare(x, y, metric=metric, mode="single") # scalar
#include <torchpairwise.h>
namespace tp = torchpairwise::ops;
auto X = at::rand({2, 3, 2}); // [N=2,P=3,D=2]
auto Y = at::rand({3, 4, 2}); // [M=3,Q=4,D=2]
const std::string metric = "directed_hausdorff_distances";
tp::ComparisonOptions options;
auto all_pairs = tp::compare(X, Y, metric, "all_pairs", options); // [2,3]
auto paired_Y = Y.narrow(0, 0, 2);
auto paired = tp::compare(X, paired_Y, metric, "paired", options); // [2]
auto x = X[0], y = Y[0];
auto single = tp::compare(x, y, metric, "single", options); // scalar
Streamed Evaluation
tp.lazy(x, y, name) binds this distance for reductions, selection and products without retaining its full generated comparison matrix. Native source factories depend on the sample family; see streamed operators and C++ use.
Numerical Contract
Floating CPU/CUDA inputs use matching float32 / float64, with lower precision promoted under autocast where supported. First derivatives follow the metric’s smooth and boundary conventions. See the detailed conventions and precision and deployment.
Related Implementations
Related APIs can differ in reduction, normalization, units or boundary behavior; match these before comparing values.