Repository: numpy/numpy
File: numpy/lib/_function_base_impl.py (Python)

Code before:
    'closest_observation': {
        'get_virtual_index': lambda n, quantiles: _closest_observation(n, quantiles),  # noqa: PLW0108
        'fix_gamma': None,  # should never be called
    },
    # Continuous methods
    'interpolated_inverted_cdf': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 0, 1),
        'fix_gamma': lambda gamma, _: gamma,
    },
    'hazen': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 0.5, 0.5),
        'fix_gamma': lambda gamma, _: gamma,
    },
    'weibull': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 0, 0),
        'fix_gamma': lambda gamma, _: gamma,
    },
    # Default method.
    # To avoid some rounding issues, `(n-1) * quantiles` is preferred to
    # `_compute_virtual_index(n, quantiles, 1, 1)`.
    # They are mathematically equivalent.
    'linear': {
        'get_virtual_index': lambda n, quantiles: (n - np.int64(1)) * quantiles,
        'fix_gamma': lambda gamma, _: gamma,
    },
    'median_unbiased': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 1 / 3.0, 1 / 3.0),
        'fix_gamma': lambda gamma, _: gamma,
    },
    'normal_unbiased': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 3 / 8.0, 3 / 8.0),
        'fix_gamma': lambda gamma, _: gamma,
    },
    # --- OTHER METHODS
    'lower': {
        'get_virtual_index': lambda n, quantiles: np.floor(
            (n - 1) * quantiles).astype(np.intp),
        'fix_gamma': None,  # should never be called, index dtype is int
    },
    'higher': {
        'get_virtual_index': lambda n, quantiles: np.ceil(
            (n - 1) * quantiles).astype(np.intp),
        'fix_gamma': None,  # should never be called, index dtype is int
    },
    'midpoint': {
        'get_virtual_index': lambda n, quantiles: 0.5 * (

Review comment (suggestion):
This one worries me, as it feels indirect: is this effectively to upcast `float16/32` to `float64`? I can see how that solves the original issue, where what is presumably a `float16` would be multiplied with a large `n`.

But if that is the reason, should something similar not happen for all the other methods too? I think a solution that would cover them all is to ensure that `n` is an `int64` when `get_virtual_index` is called.

Code after:
    'closest_observation': {
        'get_virtual_index': lambda n, quantiles: _closest_observation(n, quantiles),  # noqa: PLW0108
        'fix_gamma': None,  # should never be called
    },
    # Continuous methods
    'interpolated_inverted_cdf': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 0, 1),
        'fix_gamma': lambda gamma, _: gamma,
    },
    'hazen': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 0.5, 0.5),
        'fix_gamma': lambda gamma, _: gamma,
    },
    'weibull': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 0, 0),
        'fix_gamma': lambda gamma, _: gamma,
    },
    # Default method.
    # To avoid some rounding issues, `(n-1) * quantiles` is preferred to
    # `_compute_virtual_index(n, quantiles, 1, 1)`.
    # They are mathematically equivalent.
    'linear': {
        'get_virtual_index': lambda n, quantiles: (n - 1) * quantiles,
        'fix_gamma': lambda gamma, _: gamma,
    },
    'median_unbiased': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 1 / 3.0, 1 / 3.0),
        'fix_gamma': lambda gamma, _: gamma,
    },
    'normal_unbiased': {
        'get_virtual_index': lambda n, quantiles:
        _compute_virtual_index(n, quantiles, 3 / 8.0, 3 / 8.0),
        'fix_gamma': lambda gamma, _: gamma,
    },
    # --- OTHER METHODS
    'lower': {
        'get_virtual_index': lambda n, quantiles: np.floor(
            (n - 1) * quantiles).astype(np.intp),
        'fix_gamma': None,  # should never be called, index dtype is int
    },
    'higher': {
        'get_virtual_index': lambda n, quantiles: np.ceil(
            (n - 1) * quantiles).astype(np.intp),
        'fix_gamma': None,  # should never be called, index dtype is int
    },
    'midpoint': {
        'get_virtual_index': lambda n, quantiles: 0.5 * (