code: def _make_lookup_predict_fn(
      existing_predictions: Tuple[np.ndarray, np.ndarray],
      fuzzy_float_compare: bool,
  ) -> Callable:
      """
      Makes a predict_fn callback based on a table of existing predictions.
  
      :param existing_predictions: Tuple of (samples, labels).
      :param fuzzy_float_compare: Look up predictions using `np.isclose`, only set to True if really needed, since this
                                  severely affects performance.
      :return: Prediction function.
      """
  
      samples, labels = existing_predictions
  
      if fuzzy_float_compare:
          from sortedcontainers import SortedList
  
          # Construct a search-tree of the predictions, using fuzzy float comparison
          sorted_predictions = SortedList(
              [
                  FuzzyMapping(key, value)
                  for key, value in zip(samples, labels)
              ]
          )
  
          def fuzzy_predict_fn(batch):
              predictions = []
              for row in batch:
                  try:
                      match_idx = sorted_predictions.index(
                          FuzzyMapping(row)
                      )
                  except ValueError as err:  # pragma: no cover
                      raise ValueError(
                          "No existing prediction for queried input"
                      ) from err
  
                  predictions.append(
                      sorted_predictions[match_idx].value
                  )
  
              return np.array(predictions)
  
          return fuzzy_predict_fn
  
      # Construct a dictionary to map from samples to predictions. We use the bytes of the `ndarray` as the key,
      # because the `ndarray` itself is not hashable
      mapping = {}
      for x, y in zip(samples, labels):
          mapping[x.tobytes()] = y
  
      def predict_fn(batch):
          predictions = []
          for row in batch:
              row_bytes = row.tobytes()
              if row.tobytes() not in mapping:
                  raise ValueError(
                      "No existing prediction for queried input"
                  )
  
              predictions.append(mapping[row_bytes])
  
          return np.array(predictions)
  
      return predict_fn
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from functools import total_ordering
  import logging
  from typing import Callable, List, Optional, Union, Tuple, TYPE_CHECKING
  import numpy
  from art.estimators.estimator import BaseEstimator
  from art.estimators.regression.regressor import RegressorMixin, Regressor
  from art.estimators.classification import BlackBoxClassifier
label_desc: Use image node_id 1 for calling a global function with example usage: _make_lookup_predict_fn(existing_predictions, fuzzy_float_compare) and returns: predict_fn, fuzzy_predict_fn, np, np