code: def _general_purpose_scan(ds, init_state, body):
      """Variant of Dataset.scan with semantics of general-purpose computation."""
      # Datasets are typically intended for data preprocessing. However, in
      # autograph loops they usually appear as general-purpose computations (for
      # example, a custom training loop). These two use cases require significantly
      # different optimization policies, the most important of which is the device
      # placement. The flag override for use_default_device below instructs the
      # runtime to treat the computation as general-purpose, rather than data
      # preprocessing.
  
      # Loaded lazily due to a circular dependency (dataset_ops ->
      # scan_op -> dataset_ops).
      # pylint: disable=g-import-not-at-top,protected-access
      from tensorflow.python.data.ops import scan_op
  
      return scan_op._ScanDataset(
          ds, init_state, body, use_default_device=False
      )
  
imports: from tensorflow.python.autograph.operators import control_flow
  from tensorflow.python.autograph.operators import py_builtins
  from tensorflow.python.data.experimental.ops import take_while_ops
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import control_flow_assert
  from tensorflow.python.ops import gen_string_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 for calling a global function with example usage: _general_purpose_scan(ds, init_state, body) and returns: scan_op