docstr: Tests log_probs_from_logits_and_actions.
docstr_tok: ["Tests","log_probs_from_logits_and_actions","."]
code: def test_log_probs_from_logits_and_actions(self):
      """Tests log_probs_from_logits_and_actions."""
      seq_len = 7
      num_actions = 3
      batch_size = 4
  
      for fw, sess in framework_iterator(
          frameworks=("torch", "tf"), session=True
      ):
          vtrace = vtrace_tf if fw != "torch" else vtrace_torch
          policy_logits = Box(
              -1.0, 1.0, (seq_len, batch_size, num_actions), np.float32
          ).sample()
          actions = np.random.randint(
              0,
              num_actions - 1,
              size=(seq_len, batch_size),
              dtype=np.int32,
          )
  
          if fw == "torch":
              action_log_probs_tensor = (
                  vtrace.log_probs_from_logits_and_actions(
                      torch.from_numpy(policy_logits),
                      torch.from_numpy(actions),
                  )
              )
          else:
              action_log_probs_tensor = (
                  vtrace.log_probs_from_logits_and_actions(
                      policy_logits, actions
                  )
              )
  
          # Ground Truth
          # Using broadcasting to create a mask that indexes action logits
          action_index_mask = actions[..., None] == np.arange(
              num_actions
          )
  
          def index_with_mask(array, mask):
              return array[mask].reshape(*array.shape[:-1])
  
          # Note: Normally log(softmax) is not a good idea because it's not
          # numerically stable. However, in this test we have well-behaved
          # values.
          ground_truth_v = index_with_mask(
              np.log(softmax(policy_logits)), action_index_mask
          )
  
          if sess:
              action_log_probs_tensor = sess.run(
                  action_log_probs_tensor
              )
          check(action_log_probs_tensor, ground_truth_v)
  
file_path: ray/rllib/algorithms/impala/tests/test_vtrace.py
imports: from gymnasium.spaces import Box
  import numpy
  import unittest
  from ray.rllib.algorithms.impala import vtrace_tf
  from ray.rllib.algorithms.impala import vtrace_torch
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.numpy import softmax
  from ray.rllib.utils.test_utils import check, framework_iterator
label_desc: Use image node_id 1 for calling the LogProbsFromLogitsAndActionsTest obj's underlying member method code with example usage: obj.test_log_probs_from_logits_and_actions() and returns: array