code: def _slice_data_by_indices(
      data: AttackInputData,
      idx_train: np.ndarray,
      idx_test: np.ndarray,
      return_slice_indices: bool,
  ) -> AttackInputData:
      """Slices train fields with idx_train and test fields with idx_test."""
  
      result = AttackInputData()
  
      # Slice train data.
      result.logits_train = _slice_if_not_none(
          data.logits_train, idx_train
      )
      result.probs_train = _slice_if_not_none(
          data.probs_train, idx_train
      )
      result.labels_train = _slice_if_not_none(
          data.labels_train, idx_train
      )
      result.loss_train = _slice_if_not_none(data.loss_train, idx_train)
      result.entropy_train = _slice_if_not_none(
          data.entropy_train, idx_train
      )
      # Slice sample weights if provided.
      result.sample_weight_train = _slice_if_not_none(
          data.sample_weight_train, idx_train
      )
  
      # Slice test data.
      result.logits_test = _slice_if_not_none(
          data.logits_test, idx_test
      )
      result.probs_test = _slice_if_not_none(data.probs_test, idx_test)
      result.labels_test = _slice_if_not_none(
          data.labels_test, idx_test
      )
      result.loss_test = _slice_if_not_none(data.loss_test, idx_test)
      result.entropy_test = _slice_if_not_none(
          data.entropy_test, idx_test
      )
      # Slice sample weights if provided.
      result.sample_weight_test = _slice_if_not_none(
          data.sample_weight_test, idx_test
      )
  
      # A slice has the same multilabel status as the original data. This is because
      # of the way multilabel status is computed. A dataset is multilabel if at
      # least 1 sample has a label that is multihot encoded with more than one
      # positive class. A slice of this dataset could have only samples with labels
      # that have only a single positive class, even if the original dataset were
      # multilable. Therefore we ensure that the slice inherits the multilabel state
      # of the original dataset.
      result.multilabel_data = data.is_multilabel_data()
  
      if return_slice_indices:
          result.train_indices = np.where(idx_train)[0]
          result.test_indices = np.where(idx_test)[0]
  
      return result
  
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 2 for calling a global function with example usage: _slice_data_by_indices(data, idx_train, idx_test, return_slice_indices) and returns: result