code: def cardinality(gym_space):
      """Number of elements that can be represented by the space.
  
      Makes the most sense for Discrete or Box type with integral dtype, ex: number
      of actions in an action space.
  
      Args:
        gym_space: The gym space.
  
      Returns:
        np.int64 number of observations that can be represented by this space, or
        returns None when this doesn't make sense, i.e. float boxes etc.
  
      Raises:
        NotImplementedError when a space's cardinality makes sense but we haven't
        implemented it.
      """
  
      if (gym_space.dtype == np.float32) or (
          gym_space.dtype == np.float64
      ):
          tf.logging.warn(
              "Returning None for a float gym space's cardinality: %s",
              gym_space,
          )
          return None
  
      if isinstance(gym_space, Discrete):
          return gym_space.n
  
      if isinstance(gym_space, Box):
          # Construct a box with all possible values in this box and take a product.
          return np.prod(gym_space.high - gym_space.low + 1)
  
      raise NotImplementedError
  
file_path: tensor2tensor/tensor2tensor/envs/gym_spaces_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from gym.spaces import Box
  from gym.spaces import Discrete
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling a global function with example usage: cardinality(gym_space) and returns: None, gym_space, np