code: def load_data_sampler(
      split="train",
      pca=None,
      clusters=None,
      bandwidth=1.0,
      permfile=None,
      download_mnist_func=download_mnist,
  ):
      """
      Loads split from the MNIST dataset and returns sampler.
      """
  
      # load dataset:
      context, rewards = load_data(
          split=split,
          pca=pca,
          clusters=clusters,
          bandwidth=bandwidth,
          download_mnist_func=download_mnist_func,
      )
      if permfile is not None:
          perm = torch.load(permfile)
          assert (
              perm.shape[0] == context.shape[0]
          ), "Incorrect perm size for context."
      else:
          perm = torch.randperm(context.size(0))
  
      # define simple dataset sampler:
      def sampler():
          idx = 0
          while idx < context.size(0):
              yield {
                  "context": context[perm[idx], :],
                  "rewards": rewards[perm[idx], :],
              }
              idx += 1
  
      # return sampler:
      return sampler
  
file_path: CrypTen/examples/bandits/launcher.py
imports: import argparse
  import logging
  import os
  import random
  import examples.util
  import torch
  import visdom
  from examples.multiprocess_launcher import MultiProcessLauncher
  from examples.util import NoopContextManager, process_mnist_files
  from torchvision.datasets.mnist import MNIST
label_desc: Use image node_id 4 for calling a global function with example usage: load_data_sampler(split, pca, clusters, bandwidth, permfile, download_mnist_func) and returns: sampler