parameters: (type_p, type_q)
return_statement: return decorator
docstring: Decorator to register a pairwise function with :meth:`kl_divergence`.
      Usage::
  
          @register_kl(Normal, Normal)
          def kl_normal_normal(p, q):
              # insert implementation here
  
      Lookup returns the most specific (type,type) match ordered by subclass. If
      the match is ambiguous, a `RuntimeWarning` is raised. For example to
      resolve the ambiguous situation::
  
          @register_kl(BaseP, DerivedQ)
          def kl_version1(p, q): ...
          @register_kl(DerivedP, BaseQ)
          def kl_version2(p, q): ...
  
      you should register a third most-specific implementation, e.g.::
  
          register_kl(DerivedP, DerivedQ)(kl_version1)  # Break the tie.
  
      Args:
          type_p (type): A subclass of :class:`~torch.distributions.Distribution`.
          type_q (type): A subclass of :class:`~torch.distributions.Distribution`.
docstring_summary: Decorator to register a pairwise function with :meth:`kl_divergence`.
      Usage::
docstring_tokens: Decorator to register a pairwise function with : meth : kl_divergence . Usage ::
function: def register_kl(type_p, type_q):
      """
      Decorator to register a pairwise function with :meth:`kl_divergence`.
      Usage::
  
          @register_kl(Normal, Normal)
          def kl_normal_normal(p, q):
              # insert implementation here
  
      Lookup returns the most specific (type,type) match ordered by subclass. If
      the match is ambiguous, a `RuntimeWarning` is raised. For example to
      resolve the ambiguous situation::
  
          @register_kl(BaseP, DerivedQ)
          def kl_version1(p, q): ...
          @register_kl(DerivedP, BaseQ)
          def kl_version2(p, q): ...
  
      you should register a third most-specific implementation, e.g.::
  
          register_kl(DerivedP, DerivedQ)(kl_version1)  # Break the tie.
  
      Args:
          type_p (type): A subclass of :class:`~torch.distributions.Distribution`.
          type_q (type): A subclass of :class:`~torch.distributions.Distribution`.
      """
      if not isinstance(type_p, type) and issubclass(type_p, Distribution):
          raise TypeError('Expected type_p to be a Distribution subclass but got {}'.format(type_p))
      if not isinstance(type_q, type) and issubclass(type_q, Distribution):
          raise TypeError('Expected type_q to be a Distribution subclass but got {}'.format(type_q))
  
      def decorator(fun):
          _KL_REGISTRY[type_p, type_q] = fun
          _KL_MEMOIZE.clear()  # reset since lookup order may have changed
          return fun
  
      return decorator
function_tokens: def register_kl ( type_p , type_q ) : if not isinstance ( type_p , type ) and issubclass ( type_p , Distribution ) : raise TypeError ( 'Expected type_p to be a Distribution subclass but got {}' . format ( type_p ) ) if not isinstance ( type_q , type ) and issubclass ( type_q , Distribution ) : raise TypeError ( 'Expected type_q to be a Distribution subclass but got {}' . format ( type_q ) ) def decorator ( fun ) : _KL_REGISTRY [ type_p , type_q ] = fun _KL_MEMOIZE . clear ( ) # reset since lookup order may have changed return fun return decorator