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) – Seetorch.quantile.q (
float) – Seetorch.quantile. Supports only scalar values currently.dim (
int, optional) – Seetorch.quantile.keepdim (
bool) – Seetorch.quantile. Supports onlyFalsecurrently. Defaults toFalse.interpolation (
{"linear", "lower", "higher", "midpoint", "nearest"}) – Seetorch.quantile. Defaults to"nearest".out (
Tensor, optional) – Seetorch.quantile. Currently not supported.
- Raises:
ValueError – If
qis not in \([0, 1]\).ValueError – If
interpolationvalue is unsupported.ValueError – If
out is not None.
Notes
Uses
torch.kthvalue(). Better thantorch.quantile()since:it has no \(2^{24}\) tensor size limit;
it is much faster, at least on big tensor sizes (up to \(5\times\)).