code: def make_multi_domain_set(
      directory: str,
      class_to_idx: Dict[str, int],
      domain_to_idx: Dict[str, int],
      extensions: Optional[Tuple[str, ...]] = None,
      is_valid_file: Optional[Callable[[str], bool]] = None,
  ) -> List[Tuple[str, int, int]]:
      """Generates a list of samples of a form (path_to_sample, class, domain).
      Args:
          directory (str): root dataset directory
          class_to_idx (Dict[str, int]): dictionary mapping class name to class index
          domain_to_idx (Dict[str, int]): dictionary mapping d name to class index
          extensions (optional): A list of allowed extensions. Either extensions or is_valid_file should be passed.
              Defaults to None.
          is_valid_file (optional): A function that takes path of a file and checks if the file is a valid file
              (to check corrupt files) both extensions and is_valid_file should not be passed. Defaults to None.
      Raises:
          ValueError: In case ``extensions`` and ``is_valid_file`` are None or both are not None.
      Returns:
          List[Tuple[str, int, int]]: samples of a form (path_to_sample, class, domain)
      """
      instances = []
      directory = os.path.expanduser(directory)
      both_none = extensions is None and is_valid_file is None
      both_something = (
          extensions is not None and is_valid_file is not None
      )
      if both_none or both_something:
          raise ValueError(
              "Both extensions and is_valid_file cannot be None or not None at the same time"
          )
      if extensions is not None:
  
          def is_valid_file(x: str) -> bool:
              return has_file_allowed_extension(
                  x, cast(Tuple[str, ...], extensions)
              )
  
      is_valid_file = cast(Callable[[str], bool], is_valid_file)
      for target_domain in sorted(domain_to_idx.keys()):
          domain_index = domain_to_idx[target_domain]
          domain_dir = os.path.join(directory, target_domain)
          for target_class in sorted(class_to_idx.keys()):
              class_index = class_to_idx[target_class]
              target_dir = os.path.join(domain_dir, target_class)
              if not os.path.isdir(target_dir):
                  continue
              for root, _, fnames in sorted(
                  os.walk(target_dir, followlinks=True)
              ):
                  for fname in sorted(fnames):
                      path = os.path.join(root, fname)
                      if is_valid_file(path):
                          item = path, class_index, domain_index
                          instances.append(item)
      return instances
  
imports: import logging
  import os
  from enum import Enum
  from typing import Any, Callable, cast, Dict, List, Optional, Tuple
  import numpy
  import torch.utils.data
  from sklearn.utils import check_random_state
  from torchvision.datasets import VisionDataset
  from torchvision.datasets.folder import default_loader, has_file_allowed_extension, IMG_EXTENSIONS
  from kale.loaddata.dataset_access import DatasetAccess, get_class_subset, split_by_ratios
  from kale.loaddata.sampler import FixedSeedSamplingConfig, get_labels, MultiDataLoader, SamplingConfig
label_desc: Use image node_id 3 for calling a global function with example usage: make_multi_domain_set(directory, class_to_idx, domain_to_idx, extensions, is_valid_file) and returns: instances, has_file_allowed_extension