code: def _slice_by_custom_indices(
      data: AttackInputData,
      custom_train_indices: np.ndarray,
      custom_test_indices: np.ndarray,
      group_value: int,
      return_slice_indices: bool = False,
  ) -> AttackInputData:
      """Slices attack inputs by custom indices.
  
      Args:
        data: Data to be used as input to the attack models.
        custom_train_indices: The group indices of each training example.
        custom_test_indices: The group indices of each test example.
        group_value: The group value to pick.
        return_slice_indices: if true, the returned AttackInputData will include
          indices of the train and test data samples that were used for this slice.
  
      Returns:
        AttackInputData object containing the sliced data.
      """
      train_size, test_size = (
          data.get_train_size(),
          data.get_test_size(),
      )
      if custom_train_indices.shape[0] != train_size:
          raise ValueError(
              "custom_train_indices should have the same number of elements as "
              f"the training data, but got {custom_train_indices.shape} and "
              f"{train_size}"
          )
      if custom_test_indices.shape[0] != test_size:
          raise ValueError(
              "custom_test_indices should have the same number of elements as "
              f"the test data, but got {custom_test_indices.shape} and "
              f"{test_size}"
          )
      idx_train = custom_train_indices == group_value
      idx_test = custom_test_indices == group_value
      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 7 for calling a global function with example usage: _slice_by_custom_indices(data, custom_train_indices, custom_test_indices, group_value, return_slice_indices) and returns: _slice_data_by_indices