code: def assertTensorAlmostEqual(
      test, actual, expected, delta=0.0001, mode="sum"
  ):
      assert isinstance(actual, torch.Tensor), (
          "Actual parameter given for " "comparison must be a tensor."
      )
      if not isinstance(expected, torch.Tensor):
          expected = torch.tensor(expected, dtype=actual.dtype)
      assert (
          actual.shape == expected.shape
      ), f"Expected tensor with shape: {expected.shape}. Actual shape {actual.shape}."
      actual = actual.cpu()
      expected = expected.cpu()
      if mode == "sum":
          test.assertAlmostEqual(
              torch.sum(torch.abs(actual - expected)).item(),
              0.0,
              delta=delta,
          )
      elif mode == "max":
          # if both tensors are empty, they are equal but there is no max
          if actual.numel() == expected.numel() == 0:
              return
  
          if actual.size() == torch.Size([]):
              test.assertAlmostEqual(
                  torch.max(torch.abs(actual - expected)).item(),
                  0.0,
                  delta=delta,
              )
          else:
              for index, (input, ref) in enumerate(
                  zip(actual, expected)
              ):
                  almost_equal = abs(input - ref) <= delta
                  if hasattr(almost_equal, "__iter__"):
                      almost_equal = almost_equal.all()
                  assert (
                      almost_equal
                  ), "Values at index {}, {} and {}, differ more than by {}".format(
                      index, input, ref, delta
                  )
      else:
          raise ValueError(
              "Mode for assertion comparison must be one of `max` or `sum`."
          )
  
file_path: captum/tests/helpers/basic.py
imports: import copy
  import random
  import unittest
  from typing import Callable
  import numpy
  import torch
  from captum.log import patch_methods
label_desc: Use image node_id 2 for calling a global function with example usage: assertTensorAlmostEqual(test, actual, expected, delta, mode) without return types