code: def partition_masks(partition_tree):
      """Return an array of all the masks possible while following the given partition tree."""
  
      M = partition_tree.shape[0] + 1
      mask_matrix = make_masks(partition_tree)
      all_masks = []
      m00 = np.zeros(M, dtype=bool)
      all_masks.append(m00)
      all_masks.append(~m00)
      # inds_stack = [0,1]
      inds_lists = [[[], []] for i in range(M)]
      _partition_masks_recurse(
          len(partition_tree) - 1,
          m00,
          0,
          1,
          inds_lists,
          mask_matrix,
          partition_tree,
          M,
          all_masks,
      )
  
      all_masks = np.array(all_masks)
  
      # we resort the clustering matrix to minimize the sequential difference between the masks
      # this minimizes the number of model evaluations we need to run when the background sometimes
      # matches the foreground. We seem to average about 1.5 feature changes per mask with this
      # approach. This is not as clean as the grey code ordering, but a perfect 1 feature change
      # ordering is not possible with a clustering tree
      order = delta_minimization_order(all_masks)
      inverse_order = np.arange(len(order))[np.argsort(order)]
  
      for inds_list0, inds_list1 in inds_lists:
          for i in range(len(inds_list0)):
              inds_list0[i] = inverse_order[inds_list0[i]]
              inds_list1[i] = inverse_order[inds_list1[i]]
  
      # Care: inds_lists have different lengths, so partition_masks_inds is a "ragged" array. See GH #3063
      partition_masks = all_masks[order]
      partition_masks_inds = [
          [np.array(on), np.array(off)] for on, off in inds_lists
      ]
      return partition_masks, partition_masks_inds
  
file_path: shap/shap/explainers/_exact.py
imports: import logging
  import numpy
  from numba import njit
  from ..None import links
  from ..models import Model
  from ..utils import MaskedModel, delta_minimization_order, make_masks, shapley_coefficients
  from ._explainer import Explainer
label_desc: Use image node_id 4 for calling a global function with example usage: partition_masks(partition_tree) and returns: partition_masks,  partition_masks_inds