code: def testNumActions(self, dtype):
      if not dtype.is_integer:
          self.skipTest("testNumActions only applies to integer dtypes")
  
      batch_size = 1000
  
      # Create action spec, time_step and spec with max_num_arms = 4.
      action_spec = tensor_spec.BoundedTensorSpec((), dtype, 0, 3)
      time_step_spec, time_step_1 = self.create_time_step(
          use_per_arm_features=True, num_arms=2
      )
      _, time_step_2 = self.create_time_step(
          use_per_arm_features=True, num_arms=3
      )
      # First half of time_step batch will have num_action = 2 and second
      # half will have num_actions = 3.
      half_batch_size = int(batch_size / 2)
      time_step = nest_utils.stack_nested_tensors(
          [time_step_1] * half_batch_size
          + [time_step_2] * half_batch_size
      )
  
      # The features for the chosen arm is saved to policy_info.
      chosen_arm_features_info = (
          policy_utilities.create_chosen_arm_features_info_spec(
              time_step_spec.observation
          )
      )
      info_spec = policy_utilities.PerArmPolicyInfo(
          chosen_arm_features=chosen_arm_features_info
      )
  
      policy = random_tf_policy.RandomTFPolicy(
          time_step_spec=time_step_spec,
          action_spec=action_spec,
          info_spec=info_spec,
          accepts_per_arm_features=True,
          emit_log_probability=True,
      )
  
      action_step = policy.action(time_step)
      tf.nest.assert_same_structure(action_spec, action_step.action)
  
      # Sample from the policy 1000 times, and ensure that actions considered
      # invalid according to the mask are never chosen.
      step = self.evaluate(action_step)
      action_ = step.action
      self.assertTrue(np.all(action_ >= 0))
      self.assertTrue(np.all(action_[:half_batch_size] < 2))
      self.assertTrue(np.all(action_[half_batch_size:] < 3))
  
      # With num_action valid actions, probabilities should be 1/num_actions.
      self.assertAllClose(
          step.info.log_probability[:half_batch_size],
          tf.constant(np.log(1.0 / 2), shape=[half_batch_size]),
      )
      self.assertAllClose(
          step.info.log_probability[half_batch_size:],
          tf.constant(np.log(1.0 / 3), shape=[half_batch_size]),
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tf_agents.bandits.specs import utils
  from tf_agents.policies import random_tf_policy
  from tf_agents.policies import utils
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.utils import nest_utils
  from tf_agents.utils import test_utils
label_desc: Use image node_id 10 for calling the RandomTFPolicyTest obj's underlying member method code with example usage: obj.testNumActions(dtype) without return types