code: def _slice_by_class(
      data: AttackInputData,
      class_value: int,
      return_slice_indices: bool = False,
  ) -> AttackInputData:
      """Gets the indices (boolean) for examples belonging to the given class."""
      if not data.is_multilabel_data():
          idx_train = data.labels_train == class_value
          idx_test = data.labels_test == class_value
      else:
          if class_value >= data.num_classes:
              raise ValueError(
                  f"class_value ({class_value}) is larger than the number of classes"
                  " (data.num_classes)."
              )
          idx_train = data.labels_train[:, class_value].astype(bool)
          idx_test = data.labels_test[:, class_value].astype(bool)
      return _slice_data_by_indices(
          data, idx_train, idx_test, return_slice_indices
      )
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/dataset_slicing.py
imports: from collections import abc
  import copy
  import logging
  from typing import List, Optional
  import numpy
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackInputData
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SingleSliceSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingFeature
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingSpec
label_desc: Use image node_id 3 for calling a global function with example usage: _slice_by_class(data, class_value, return_slice_indices) and returns: _slice_data_by_indices