code: def _validate_rank(variable, min_rank, max_rank=None):
      """Validates if a variable has the correct rank.
  
      Args:
        variable: A `tf.Tensor` or `numpy.array`.
        min_rank: An int representing the min expected rank of the variable.
        max_rank: An int representing the max expected rank of the variable.
  
      Raises:
        ValueError: if variable doesn't have expected rank.
      """
      rank = len(variable.shape)
      if rank < min_rank or rank > max_rank:
          raise ValueError(
              "Expect variable within rank [{},{}], but got rank {}.".format(
                  min_rank, max_rank, rank
              )
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import pprint
  from typing import NamedTuple, Optional
  import numpy
  import tensorflow
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import composite
  from tf_agents.utils import nest_utils
  from tf_agents.utils import value_ops
label_desc: Use image node_id 13 for calling a global function with example usage: _validate_rank(variable, min_rank, max_rank) without return types