code: def test_grid_points_stress(
      num_bins, perc_bins, size_data, outside_grid
  ):
      np.random.seed(0)
      eps = 1
  
      # define the grid between [-10, 10] having `num_bins` bins
      grid = np.unique(np.random.uniform(-10, 10, size=num_bins + 1))
  
      # select specific bins to sample the data from grid defined above.
      # the number of bins is controlled by the percentage of bins given by `perc_bins`
      nbins = int(np.ceil(num_bins * perc_bins))
      bins = np.sort(
          np.random.choice(num_bins, size=nbins, replace=False)
      )
  
      # generate data
      X = []
      selected_bins = []
  
      for i in range(size_data):
          # select a bin at random and mark it as selected
          bin = np.random.choice(bins, size=1)
          selected_bins.append(bin.item())
  
          # define offset to ensure that the value is sampled within the bin
          # (i.e. avoid edge cases where  the data might land on the grid point)
          # the ALE implementation should work even in that case, only the process of constructing
          # the expected values might require additional logic
          offset = 0.1 * (grid[bin + 1] - grid[bin])
          X.append(
              np.random.uniform(
                  low=grid[bin] + offset, high=grid[bin + 1] - offset
              ).item()
          )
  
      # add values outside the grid to test that the grid is extended
      if outside_grid:
          X = X + [grid[0] - eps, grid[-1] + eps]
  
      # construct dataset, define dummy predictor, and get grid values used by ale
      X = np.array(X).reshape(-1, 1)
      predict = lambda x: x.sum(axis=1)  # noqa
      q, _, _ = ale_num(
          predictor=predict, X=X, feature=0, feature_grid_points=grid
      )
  
      # construct expected grid by merging selected bins
      if outside_grid:
          # add first and last bin corresponding to min and max value.
          # This requires incrementing all the previous values by 1
          selected_bins = np.array(selected_bins + [-1, num_bins]) + 1
  
          # update grid point to include the min and max
          grid = np.insert(grid, 0, grid[0] - eps)
          grid = np.insert(grid, len(grid), grid[-1] + eps)
  
      selected_bins = np.unique(selected_bins)
      expected_q = np.array(
          [grid[selected_bins[0]]]
          + [grid[b + 1] for b in selected_bins]
      )
      np.testing.assert_allclose(q, expected_q)
  
imports: import re
  from copy import deepcopy
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from pytest_lazyfixture import lazy_fixture
  from alibi.api.defaults import DEFAULT_DATA_ALE, DEFAULT_META_ALE
  from alibi.api.interfaces import Explanation
  from alibi.explainers.ale import _plot_one_ale_num, adaptive_grid, ale_num, get_quantiles, minimum_satisfied, plot_ale
label_desc: Use image node_id 8 for calling a global function with example usage: test_grid_points_stress(num_bins, perc_bins, size_data, outside_grid) without return types