code: def from_dtype(
      dtype: np.dtype,
      *,
      alphabet: Optional[st.SearchStrategy[str]] = None,
      min_size: int = 0,
      max_size: Optional[int] = None,
      min_value: Union[int, float, None] = None,
      max_value: Union[int, float, None] = None,
      allow_nan: Optional[bool] = None,
      allow_infinity: Optional[bool] = None,
      allow_subnormal: Optional[bool] = None,
      exclude_min: Optional[bool] = None,
      exclude_max: Optional[bool] = None,
      min_magnitude: Real = 0,
      max_magnitude: Optional[Real] = None,
  ) -> st.SearchStrategy[Any]:
      """Creates a strategy which can generate any value of the given dtype.
  
      Compatible parameters are passed to the inferred strategy function while
      inapplicable ones are ignored.
      This allows you, for example, to customise the min and max values,
      control the length or contents of strings, or exclude non-finite
      numbers. This is particularly useful when kwargs are passed through from
      :func:`arrays` which allow a variety of numeric dtypes, as it seamlessly
      handles the ``width`` or representable bounds for you.
      """
      check_type(np.dtype, dtype, "dtype")
      kwargs = {
          k: v
          for k, v in locals().items()
          if k != "dtype" and v is not None
      }
  
      # Compound datatypes, eg 'f4,f4,f4'
      if dtype.names is not None:
          # mapping np.void.type over a strategy is nonsense, so return now.
          subs = [
              from_dtype(dtype.fields[name][0], **kwargs)
              for name in dtype.names
          ]
          return st.tuples(*subs)
  
      # Subarray datatypes, eg '(2, 3)i4'
      if dtype.subdtype is not None:
          subtype, shape = dtype.subdtype
          return arrays(subtype, shape, elements=kwargs)
  
      def compat_kw(*args, **kw):
          """Update default args to the strategy with user-supplied keyword args."""
          assert {"min_value", "max_value", "max_size"}.issuperset(kw)
          for key in set(kwargs).intersection(kw):
              msg = f"dtype {dtype!r} requires {key}={kwargs[key]!r} to be %s {kw[key]!r}"
              if kw[key] is not None:
                  if key.startswith("min_") and kw[key] > kwargs[key]:
                      raise InvalidArgument(msg % ("at least",))
                  elif key.startswith("max_") and kw[key] < kwargs[key]:
                      raise InvalidArgument(msg % ("at most",))
          kw.update(
              {k: v for k, v in kwargs.items() if k in args or k in kw}
          )
          return kw
  
      # Scalar datatypes
      if dtype.kind == "b":
          result: st.SearchStrategy[Any] = st.booleans()
      elif dtype.kind == "f":
          result = st.floats(
              width=min(8 * dtype.itemsize, 64),
              **compat_kw(
                  "min_value",
                  "max_value",
                  "allow_nan",
                  "allow_infinity",
                  "allow_subnormal",
                  "exclude_min",
                  "exclude_max",
              ),
          )
      elif dtype.kind == "c":
          result = st.complex_numbers(
              width=min(
                  8 * dtype.itemsize, 128
              ),  # convert from bytes to bits
              **compat_kw(
                  "min_magnitude",
                  "max_magnitude",
                  "allow_nan",
                  "allow_infinity",
                  "allow_subnormal",
              ),
          )
      elif dtype.kind in ("S", "a"):
          # Numpy strings are null-terminated; only allow round-trippable values.
          # `itemsize == 0` means 'fixed length determined at array creation'
          max_size = dtype.itemsize or None
          result = st.binary(
              **compat_kw("min_size", max_size=max_size)
          ).filter(lambda b: b[-1:] != b"\0")
      elif dtype.kind == "u":
          kw = compat_kw(
              min_value=0, max_value=2 ** (8 * dtype.itemsize) - 1
          )
          result = st.integers(**kw)
      elif dtype.kind == "i":
          overflow = 2 ** (8 * dtype.itemsize - 1)
          result = st.integers(
              **compat_kw(min_value=-overflow, max_value=overflow - 1)
          )
      elif dtype.kind == "U":
          # Encoded in UTF-32 (four bytes/codepoint) and null-terminated
          max_size = (dtype.itemsize or 0) // 4 or None
          if NP_FIXED_UNICODE and "alphabet" not in kwargs:
              kwargs["alphabet"] = st.characters()
          result = st.text(
              **compat_kw("alphabet", "min_size", max_size=max_size)
          ).filter(lambda b: b[-1:] != "\0")
      elif dtype.kind in ("m", "M"):
          if "[" in dtype.str:
              res = st.just(dtype.str.split("[")[-1][:-1])
          else:
              # Note that this case isn't valid to pass to arrays(), but we support
              # it here because we'd have to guard against equivalents in arrays()
              # regardless and drawing scalars is a valid use-case.
              res = st.sampled_from(TIME_RESOLUTIONS)
          result = st.builds(
              dtype.type, st.integers(-(2**63), 2**63 - 1), res
          )
      else:
          raise InvalidArgument(f"No strategy inference for {dtype}")
      return result.map(dtype.type)
  
imports: import importlib
  import math
  from typing import TYPE_CHECKING, Any, Literal, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union
  import numpy
  from hypothesis import strategies
  from hypothesis._settings import note_deprecation
  from hypothesis.errors import HypothesisException, InvalidArgument
  from hypothesis.extra._array_helpers import NDIM_MAX, BasicIndex, BasicIndexStrategy, BroadcastableShapes, Shape, array_shapes, broadcastable_shapes, check_argument, check_valid_dims, mutually_broadcastable_shapes, order_check, valid_tuple_axes
  from hypothesis.internal.conjecture import utils
  from hypothesis.internal.coverage import check_function
  from hypothesis.internal.reflection import proxies
  from hypothesis.internal.validation import check_type
  from hypothesis.strategies._internal.numbers import Real
  from hypothesis.strategies._internal.strategies import Ex, T, check_strategy
  from hypothesis.strategies._internal.utils import defines_strategy
label_desc: Use image node_id 2 for calling a global function with example usage: from_dtype(dtype) and returns: result, st, arrays, kw