spd_learn.functional.get_loewner_threshold#

spd_learn.functional.get_loewner_threshold(eigenvalues: Tensor, *, config: NumericalConfig | None = None) → Tensor[source]#

Get threshold for detecting equal eigenvalues in Loewner matrix.

The Loewner matrix computation requires special handling when eigenvalues are equal or nearly equal. This function returns an appropriate threshold for detecting such cases.

Parameters:
  • eigenvalues (torch.Tensor) – The eigenvalues (used to determine dtype).

  • config (NumericalConfig, optional) – Configuration to use. If None, uses the global numerical_config.

Returns:

Thresholds of shape (..., 1, 1) for spectra of shape (..., n). Each threshold uses only its own matrix’s eigenvalues and broadcasts over its Loewner matrix.

Return type:

torch.Tensor

Notes

The threshold is computed as:

threshold = scale * max(1, |eigenvalues|.max(axis=-1)) * eps

This adaptive threshold accounts for the magnitude of eigenvalues, providing better numerical stability for matrices with large eigenvalues.