code: def test_multiple_test_instances_stored_grads_asym_dot(
      precompute_grads,
  ):
      """
      Test that multiple test instances get correct explanations for `grad_asym_dot`.
      """
      ds = np.array(
          [[1, 0], [0.9, 0.1], [0.5 * 100, 0.5 * 100]]
      ).astype("float32")
      model = keras.Sequential([keras.layers.Dense(1, use_bias=False)])
      # GradientSimilarity method checks weights are trainable so we need to build the model before passing it to the
      # method
      model.build((None, 2))
  
      explainer = GradientSimilarity(
          model,
          task="regression",
          loss_fn=loss_tf,
          sim_fn="grad_asym_dot",
          backend="tensorflow",
          precompute_grads=precompute_grads,
      )
      explainer = explainer.fit(ds, ds)
      explanation = explainer.explain(ds[0:2], Y=ds[0:2])
  
      # In the case of `grad_asym_dot` we manually check the similarities as the asymmetry of the metric means ordering
      # is important.
      denoms = np.array([1, (0.9**2 + 0.1**2), 2 * 50**2])
      sim_ds_0 = np.array(
          [(1 * 1 + 0 * 0), (1 * 0.9 + 0 * 0.1), (1 * 50 + 0 * 50)]
      ) / (denoms + 1e-7)
      sim_ds_0.sort()
  
      np.testing.assert_allclose(
          explanation.scores[0], sim_ds_0[::-1], atol=1e-6
      )
      sim_ds_1 = np.array(
          [
              (0.9 * 1 + 0.1 * 0),
              (0.9 * 0.9 + 0.1 * 0.1),
              (0.9 * 50 + 0.1 * 50),
          ]
      ) / (denoms + 1e-7)
      sim_ds_1.sort()
  
      np.testing.assert_allclose(
          explanation.scores[1], sim_ds_1[::-1], atol=1e-6
      )
      np.testing.assert_array_equal(
          ds[explanation["ordered_indices"][0][0]], ds[1]
      )
      np.testing.assert_array_equal(
          ds[explanation["ordered_indices"][1][0]], ds[1]
      )
      explanation = explainer.explain(ds[-1], Y=ds[-1])
      scores = np.array([[50, 50, 2 * 50**2]], dtype=np.float32) / (
          denoms + 1e-7
      )
      scores.sort()
      np.testing.assert_allclose(
          explanation.scores, scores[:, ::-1], atol=1e-4
      )
  
imports: import pytest
  import numpy
  import torch.nn
  import torch
  import tensorflow
  from tensorflow import keras
  from alibi.explainers.similarity.grad import GradientSimilarity
label_desc: Use image node_id 16 for calling a global function with example usage: test_multiple_test_instances_stored_grads_asym_dot(precompute_grads) without return types