code: def _indexes_without_grouping(
      sequence: Sequence[SupportsInt],
      search_elements: Union[None, Sequence[int]],
      sort_indexes: bool = False,
  ) -> Union[List[int], None]:
      sequence = tensor_as_list(sequence)
  
      if search_elements is None and not sort_indexes:
          # No-op
          return list(range(len(sequence)))
  
      if search_elements is not None:
          search_elements = tensor_as_list(search_elements)
  
      result: List[int]
      if search_elements is None:
          result = list(range(len(sequence)))
      else:
          # Set based "in" operator is **much** faster that its list counterpart!
          search_elements_set = set(search_elements)
          result = []
          for idx, element in enumerate(sequence):
              if element in search_elements_set:
                  result.append(idx)
  
      if sort_indexes:
          result.sort()
      elif not sort_indexes and len(result) == len(sequence):
          # All patterns selected. Also, no sorting is required
          # Return None to flag that the whole sequence can be
          # taken as it already is
          return None
      return result
  
file_path: avalanche/avalanche/benchmarks/scenarios/deprecated/new_classes/nc_utils.py
imports: from collections import OrderedDict
  from typing import List, Sequence, Dict, Any, Union, SupportsInt
  import torch
  from avalanche.benchmarks.utils import _taskaware_classification_subset, SupportedDataset
  from avalanche.benchmarks.utils import tensor_as_list
  from avalanche.benchmarks.utils.classification_dataset import TaskAwareClassificationDataset
label_desc: Use image node_id 2 for calling a global function with example usage: _indexes_without_grouping(sequence, search_elements, sort_indexes) and returns: result, list, None