torch_quantile#

scio.scores.utils.torch_quantile(tensor, q, dim=None, *, keepdim=False, interpolation='nearest', out=None)[source]#

Improved torch.quantile() for one scalar quantile.

Parameters:
  • tensor (Tensor) – See torch.quantile.

  • q (float) – See torch.quantile. Supports only scalar values currently.

  • dim (int, optional) – See torch.quantile.

  • keepdim (bool) – See torch.quantile. Supports only False currently. Defaults to False.

  • interpolation ({"linear", "lower", "higher", "midpoint", "nearest"}) – See torch.quantile. Defaults to "nearest".

  • out (Tensor, optional) – See torch.quantile. Currently not supported.

Raises:
  • ValueError – If q is not in \([0, 1]\).

  • ValueError – If interpolation value is unsupported.

  • ValueError – If out is not None.

Notes

Uses torch.kthvalue(). Better than torch.quantile() since:

  1. it has no \(2^{24}\) tensor size limit;

  2. it is much faster, at least on big tensor sizes (up to \(5\times\)).