code: def _index_fn(fn: str, index_mapping_dir: str) -> str:
      """Return base file name of index files.
  
      This returns the base file name associated with specified index
      files. This base name is the base on top of which suffixes
      like .npy or .info are added.
  
      The parent directory is created if it does not already exist.
  
      fn may be specified in multiple ways:
      1. file name: data.jsonl,
      2. relative path to a file: relative/path/to/data.jsonl,
      3. absolute path to a file: /absolute/path/to/data.jsonl.
  
      This function returns paths in the pattern of:
      1. /path/to/input_mapping_dir/data.jsonl.idx
      2. /path/to/input_mapping_dir/relative/path/to/data.jsonl.idx
      3. /path/to/input_mapping_dir/absolute/path/to/data.jsonl.idx
  
      Args:
          fn: filename to get base name for.
          index_mapping_dir: directory to save the index mapping to.
                  If None, will write to the same folder as the dataset.
      """
      if index_mapping_dir:
          # Remove leading "/" and "..".
          while fn.startswith(("/", "..")):
              if fn.startswith(".."):
                  fn = fn.lstrip("..")
              if fn.startswith("/"):
                  fn = fn.lstrip("/")
          idx_fn = (
              f"{os.path.join(index_mapping_dir, fn)}.{__idx_suffix__}"
          )
          # Create parent directory if needed.
          os.makedirs(os.path.dirname(idx_fn), exist_ok=True)
      else:
          idx_fn = f"{fn}.{__idx_suffix__}"
      return idx_fn
  
imports: import datetime
  import json
  import multiprocessing
  import os
  import pickle
  import time
  from functools import partial
  from typing import Callable, List, Optional, Type
  import numpy
  import torch
  from nemo.core import Dataset
  from nemo.utils import AppState, logging
label_desc: Use image node_id 3 for calling a global function with example usage: _index_fn(fn, index_mapping_dir) and returns: idx_fn