code: def test_broadcastable_masks(self) -> None:
      # integration test to ensure that
      # permutation function works with custom masks
      def forward_func(x: Tensor) -> Tensor:
          return x.view(x.shape[0], -1).sum(dim=-1)
  
      batch_size = 2
      inp = torch.randn((batch_size,) + (3, 4, 4))
  
      feature_importance = FeaturePermutation(forward_func=forward_func)
  
      masks = [
          torch.tensor([0]),
          torch.tensor([[0, 1, 2, 3]]),
          torch.tensor(
              [
                  [
                      [0, 1, 2, 3],
                      [3, 3, 4, 5],
                      [6, 6, 4, 6],
                      [7, 8, 9, 10],
                  ]
              ]
          ),
      ]
  
      for mask in masks:
          attribs = feature_importance.attribute(inp, feature_mask=mask)
  
          self.assertTrue(attribs is not None)
          self.assertTrue(attribs.shape == inp.shape)
  
          fm = mask.expand_as(inp[0])
  
          features = set(mask.flatten())
          for feature in features:
              m = (fm == feature).bool()
              attribs_for_feature = attribs[:, m]
              assertTensorAlmostEqual(
                  self,
                  attribs_for_feature[0],
                  -attribs_for_feature[1],
                  delta=0.05,
                  mode="max",
              )
  
file_path: captum/tests/attr/test_feature_permutation.py
imports: from typing import List, Tuple
  import torch
  from captum.attr._core.feature_permutation import _permute_feature, FeaturePermutation
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
  from tests.helpers.basic_models import BasicModelWithSparseInputs
  from torch import Tensor
label_desc: Use image node_id 8 for calling the Test obj's underlying member method code with example usage: obj.test_broadcastable_masks() and returns: x