function

transport.samples.kernels.cg_dense.hvp_dense_cg

def hvp_dense_cg(x: torch.Tensor, y: torch.Tensor, f_hat: torch.Tensor, g_hat: torch.Tensor, A: torch.Tensor, eps: float, rho_x: float | None = None, rho_y: float | None = None, tau2: float = 1e-05, max_cg_iter: int = 100, cg_rtol: float = 1e-06, cg_atol: float = 1e-06) -> tuple[torch.Tensor, DenseCgInfo]

Compute HVP using dense CG with cached transport plan.

This is a drop-in replacement for the streaming Triton HVP that is 8x faster for small problem sizes (n <= 8192).

Parameters

NameTypeDescription
xtorch.TensorSource points (n, d)
ytorch.TensorTarget points (m, d)
f_hattorch.TensorSource raw-form potential (n,)
g_hattorch.TensorTarget raw-form potential (m,)
Atorch.TensorInput matrix for HVP (n, d)
epsfloatEntropy regularization
rho_x = Nonefloat | NoneSource marginal KL penalty (None = strict constraint)
rho_y = Nonefloat | NoneTarget marginal KL penalty (None = strict constraint)
tau2 = 1e-05floatTikhonov regularization (only used for balanced OT)
max_cg_iter = 100intMaximum CG iterations
cg_rtol = 1e-06floatRelative CG tolerance
cg_atol = 1e-06floatAbsolute CG tolerance

Returns

torch.Tensor — Hessian-vector product H @ A, shape (n, d)

Source: torchmatch/transport/samples/kernels/cg_dense.py:207