class_docstr: Base class for similarity explainers.
docstr: Computes the similarity between the gradients of the test instances and all the training instances. The method
  performs the computation of the gradients of the training instance on the fly without storing them in memory.
  
  parameters
  ----------
  grad_X
      Gradients of the test instances.
docstr_tok: ["Computes","the","similarity","between","the","gradients","of","the","test","instances","and","all","the","training","instances",".","The","method","performs","the","computation","of","the","gradients","of","the","training","instance","on","the","fly","without","storing","them","in","memory",".","parameters","--","--","--","--","--","grad_X","Gradients","of","the","test","instances","."]
code: def _compute_adhoc_similarity(self, grad_X: np.ndarray) -> np.ndarray:
      """
      Computes the similarity between the gradients of the test instances and all the training instances. The method
      performs the computation of the gradients of the training instance on the fly without storing them in memory.
  
      parameters
      ----------
      grad_X
          Gradients of the test instances.
      """
      scores = np.zeros((len(grad_X), len(self.X_train)))
      X: Union[np.ndarray, List[Any]]
      for i, (X, Y) in tqdm(
          enumerate(zip(self.X_train, self.Y_train)),
          disable=not self.verbose,
      ):
          grad_X_train = self._compute_grad(self._format(X), Y[None])
          scores[:, i] = self.sim_fn(grad_X, grad_X_train[None])[:, 0]
      return scores
  
imports: from abc import ABC
  from typing import TYPE_CHECKING, Any, Callable, List, Optional, Union
  import numpy
  from alibi.api.interfaces import Explainer
  from alibi.explainers.similarity.backends import _select_backend
  from alibi.utils.frameworks import Framework, has_pytorch, has_tensorflow
  from alibi.utils.missing_optional_dependency import import_optional
  from tqdm import tqdm
  from typing_extensions import Literal
label_desc: Use image node_id 9 for calling the BaseSimilarityExplainer obj's underlying member method code with example usage: obj._compute_adhoc_similarity(grad_X) and returns: scores