original_docstring: Get the size (number of elements) of a space
  
          :param space: Space or shape from which to obtain the number of elements
          :type space: int, tuple or list of integers, or gym.Space
  
          :raises ValueError: If the space is not supported
  
          :return: Size of the space (number of elements)
          :rtype: int
          
docstring: Get the size (number of elements) of a space
docstring_tokens: Get the size ( number of elements ) of a space
code: def _get_space_size(self, space: Union[int, Tuple[int], gym.Space]) -> int:
          """Get the size (number of elements) of a space
  
          :param space: Space or shape from which to obtain the number of elements
          :type space: int, tuple or list of integers, or gym.Space
  
          :raises ValueError: If the space is not supported
  
          :return: Size of the space (number of elements)
          :rtype: int
          """
          size = None
          if type(space) in [int, float]:
              size = space
          elif type(space) in [tuple, list]:
              size = np.prod(space)
          elif issubclass(type(space), gym.Space):
              if issubclass(type(space), gym.spaces.Discrete):
                  size = space.n
              elif issubclass(type(space), gym.spaces.Box):
                  size = np.prod(space.shape)
              elif issubclass(type(space), gym.spaces.Dict):
                  size = sum([self._get_space_size(space.spaces[key]) for key in space.spaces])
          if size is None:
              raise ValueError("Space type {} not supported".format(type(space)))
          return int(size)
code_tokens: def _get_space_size ( self , space : Union [ int , Tuple [ int ] , gym . Space ] ) -> int : size = None if type ( space ) in [ int , float ] : size = space elif type ( space ) in [ tuple , list ] : size = np . prod ( space ) elif issubclass ( type ( space ) , gym . Space ) : if issubclass ( type ( space ) , gym . spaces . Discrete ) : size = space . n elif issubclass ( type ( space ) , gym . spaces . Box ) : size = np . prod ( space . shape ) elif issubclass ( type ( space ) , gym . spaces . Dict ) : size = sum ( [ self . _get_space_size ( space . spaces [ key ] ) for key in space . spaces ] ) if size is None : raise ValueError ( "Space type {} not supported" . format ( type ( space ) ) ) return int ( size )
short_docstring: Get the size (number of elements) of a space
short_docstring_tokens: Get the size ( number of elements ) of a space
comment: """Get the size (number of elements) of a space
  
          :param space: Space or shape from which to obtain the number of elements
          :type space: int, tuple or list of integers, or gym.Space
  
          :raises ValueError: If the space is not supported
  
          :return: Size of the space (number of elements)
          :rtype: int
          """