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

Audio

Scale-Invariant SDR

si_sdr_scores
all-pairspairedsinglescoreAudio
\[ s=\frac{\langle e,r\rangle}{\|r\|_2^2}r,\qquad \operatorname{SI\!SDR}=\operatorname{mean}_c10\log_{10}\frac{\max(\|s\|_2^2,\delta)}{\max(\|e-s\|_2^2,\delta)} \]

First operand is estimate e, second reference r. Per-channel dB scores are averaged. zero_mean=True and energy_floor=1e-8 by default. Zero-reference projection is zero.

Shapes and Modes

InputLayout
One sample[C,T]
Collection X[...,N,C,T]
Collection Y[...,M,C,T]
ModeSelectorOutput
all-pairscompare(X,Y,metric=...)[...,N,M]
pairedcompare(X,Y,metric=...,mode="paired")[...,N]; equal sample counts
singlecompare(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 entryFunction
All-pairssi_sdr_scores
Pairedpaired_si_sdr_scores

The Python and C++ compare selectors cover every mode shown above. Use compare for this score; distance/kernel selectors have different roles. single_comparison is shorthand for single mode.

Catalog aliases: si_sdr.

Accepted metric options: zero_mean, energy_floor, chunk_size. 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.

Python
import torch
import torchpairwise as tp

X = torch.rand(2, 1, 24)  # [N=2,C=1,T=24]
Y = torch.rand(3, 1, 24)  # [M=3,C=1,T=24]

metric = "si_sdr_scores"
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
C++ / LibTorch
#include <torchpairwise.h>

namespace tp = torchpairwise::ops;
auto X = at::rand({2, 1, 24});
auto Y = at::rand({3, 1, 24});

const std::string metric = "si_sdr_scores";
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 score 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 APIs can differ in reduction, normalization, units or boundary behavior; match these before comparing values.