class_docstr: Dense index using Faiss. It is used to index vectors.
  Faiss is a library for efficient similarity search and clustering of dense vectors.
  It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM.
  You can find more information about Faiss here:
  - For index types and the string factory: https://github.com/facebookresearch/faiss/wiki/The-index-factory
  - For GPU settings: https://github.com/facebookresearch/faiss/wiki/Faiss-on-the-GPU
class_docstr_tok: ["Dense","index","using","Faiss",".","It","is","used","to","index","vectors",".","Faiss","is","a","library","for","efficient","similarity","search","and","clustering","of","dense","vectors",".","It","contains","algorithms","that","search","in","sets","of","vectors","of","any","size",",","up","to","ones","that","possibly","do","not","fit","in","RAM",".","You","can","find","more","information","about","Faiss","here",":","-","For","index","types","and","the","string","factory",":","https",":","\/\/github.com\/facebookresearch\/faiss\/wiki\/The-index-factory","-","For","GPU","settings",":","https",":","\/\/github.com\/facebookresearch\/faiss\/wiki\/Faiss-on-the-GPU"]
docstr: Sends a faiss index to a device.
  A device can either be a positive integer (GPU id), a negative integer (all GPUs),
      or a list of positive integers (select GPUs to use), or `None` for CPU.
docstr_tok: ["Sends","a","faiss","index","to","a","device",".","A","device","can","either","be","a","positive","integer","(","GPU","id",")",",","a","negative","integer","(","all","GPUs",")",",","or","a","list","of","positive","integers","(","select","GPUs","to","use",")",",","or","`","None","`","for","CPU","."]
code: def _faiss_index_to_device(
      index: "faiss.Index",
      device: Optional[Union[int, List[int]]] = None,
  ) -> "faiss.Index":
      """
      Sends a faiss index to a device.
      A device can either be a positive integer (GPU id), a negative integer (all GPUs),
          or a list of positive integers (select GPUs to use), or `None` for CPU.
      """
  
      # If device is not specified, then it runs on CPU.
      if device is None:
          return index
  
      import faiss  # noqa: F811
  
      # If the device id is given as an integer
      if isinstance(device, int):
          # Positive integers are directly mapped to GPU ids
          if device > -1:
              faiss_res = faiss.StandardGpuResources()
              index = faiss.index_cpu_to_gpu(faiss_res, device, index)
          # And negative integers mean using all GPUs
          else:
              index = faiss.index_cpu_to_all_gpus(index)
      # Device ids given as a list mean mapping to those devices specified.
      elif isinstance(device, (list, tuple)):
          index = faiss.index_cpu_to_gpus_list(index, gpus=list(device))
      else:
          raise TypeError(
              f"The argument type: {type(device)} is not expected. "
              + "Please pass in either nothing, a positive int, a negative int, or a list of positive ints."
          )
  
      return index
  
imports: import importlib.util
  import os
  import tempfile
  from pathlib import PurePath
  from typing import TYPE_CHECKING, Dict, List, NamedTuple, Optional, Union
  import fsspec
  import numpy
  from .utils import logging
  from .utils import tqdm
label_desc: Use image node_id 3 for calling the FaissIndex obj's underlying member method code with example usage: obj._faiss_index_to_device(index, device) and returns: index, index