code: def _get_int_dtype(
      val: SupportsIndex,
      *,
      signed: bool | None = None,
      unsigned: bool | None = None,
  ):
      """Determine the smallest integer dtype that can store the integer ``val``.
  
      If signed or unsigned are unspecified, then signed integers are preferred
      unless the value can be represented by a smaller unsigned integer.
  
      Raises
      ------
      ValueError : If the value cannot be represented with an int dtype.
      """
      # This is similar in spirit to `np.min_scalar_type`
      if signed is not None:
          if unsigned is not None and (not signed) is (not unsigned):
              raise TypeError(
                  f"signed (={signed}) and unsigned (={unsigned}) keyword arguments "
                  "are incompatible."
              )
          signed = bool(signed)
          unsigned = not signed
      elif unsigned is not None:
          unsigned = bool(unsigned)
          signed = not unsigned
  
      val = op.index(val)  # Ensure val is integral
      if val < 0:
          if unsigned:
              raise ValueError(
                  f"Value is incompatible with unsigned int: {val}."
              )
          signed = True
          unsigned = False
  
      if signed is not False:
          # Number of bytes (and a power of two)
          signed_nbytes = (val + (val < 0)).bit_length() // 8 + 1
          signed_nbytes = next(
              filter(
                  signed_nbytes.__le__,
                  itertools.accumulate(
                      itertools.repeat(2), op.mul, initial=1
                  ),
              )
          )
      if unsigned is not False:
          # Number of bytes (and a power of two)
          unsigned_nbytes = (val.bit_length() + 7) // 8
          unsigned_nbytes = next(
              filter(
                  unsigned_nbytes.__le__,
                  itertools.accumulate(
                      itertools.repeat(2), op.mul, initial=1
                  ),
              )
          )
          if signed is None and unsigned is None:
              # Prefer signed int if same size
              signed = signed_nbytes <= unsigned_nbytes
  
      if signed:
          dtype_string = f"i{signed_nbytes}"
      else:
          dtype_string = f"u{unsigned_nbytes}"
      try:
          return np.dtype(dtype_string)
      except TypeError as exc:
          raise ValueError(
              "Value is too large to store as integer: {val}"
          ) from exc
  
file_path: cugraph/python/nx-cugraph/nx_cugraph/utils/misc.py
imports: from __future__ import annotations
  import itertools
  import operator
  import sys
  from random import Random
  from typing import TYPE_CHECKING, SupportsIndex
  import cupy
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: _get_int_dtype(val) and returns: np