code: def testUseDefaultDevice(self, use_default_device):
      if not test_util.is_gpu_available():
          self.skipTest("No GPUs available.")
  
      weights = variables.Variable(
          initial_value=array_ops.zeros((1000, 1000))
      )
      result = variables.Variable(
          initial_value=array_ops.zeros((1000, 1000))
      )
  
      def scan_fn(state, sample):
          product = math_ops.matmul(sample, weights)
          result.assign_add(product)
          with ops.colocate_with(product):
              device = test_ops.device_placement_op()
          return state, device
  
      data = variables.Variable(
          initial_value=array_ops.zeros((1, 1000, 1000))
      )
      dataset = dataset_ops.Dataset.from_tensor_slices(data)
      dataset = scan_op._ScanDataset(
          dataset,
          np.int64(1),
          scan_fn,
          use_default_device=use_default_device,
      )
      get_next = self.getNext(dataset)
  
      if use_default_device:
          self.assertIn(b"CPU:0", self.evaluate(get_next()))
      else:
          self.assertIn(b"GPU:0", self.evaluate(get_next()))
  
imports: import itertools
  from absl.testing import parameterized
  import numpy
  from tensorflow.python.data.kernel_tests import checkpoint_test_base
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import options
  from tensorflow.python.data.ops import scan_op
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import test_ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import control_flow_v2_toggles
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import script_ops
  from tensorflow.python.ops import tensor_array_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
label_desc: Use image node_id 12 for calling the ScanTest obj's underlying member method code with example usage: obj.testUseDefaultDevice(use_default_device) and returns: state,  device