(self,
                         variable_predicate=is_variable,
                         module_predicate=None,
                         with_path=False)
Return reparameterizable elements of this module.

    Args:
      variable_predicate: (Optional) A predicate that filters variables
        belonging to this `ReparameterizableModule` by properties of the
        variable; a variable is returned if it satisfies this predicate.
      module_predicate: (Optional) A predicate that filters the variables
        belonging to this `ReparameterizableModule` by which submodule owns
        them; a variable is returned if any submodules that refer to the
        variable, directly (i.e., as a parent) or indirectly (i.e., as an
        ancestor), satisfy this predicate.
      with_path: (Optional) Whether to include the path to each variable as well
        as the variable itself.

    Returns:
      A flattened generator for elements of the current module and all
      submodules satisfying the given predicates.
Return reparameterizable elements of this module.
Return reparameterizable elements of this module .
def reparameterizables(self,
                         variable_predicate=is_variable,
                         module_predicate=None,
                         with_path=False):
    """Return reparameterizable elements of this module.

    Args:
      variable_predicate: (Optional) A predicate that filters variables
        belonging to this `ReparameterizableModule` by properties of the
        variable; a variable is returned if it satisfies this predicate.
      module_predicate: (Optional) A predicate that filters the variables
        belonging to this `ReparameterizableModule` by which submodule owns
        them; a variable is returned if any submodules that refer to the
        variable, directly (i.e., as a parent) or indirectly (i.e., as an
        ancestor), satisfy this predicate.
      with_path: (Optional) Whether to include the path to each variable as well
        as the variable itself.

    Returns:
      A flattened generator for elements of the current module and all
      submodules satisfying the given predicates.
    """
    if module_predicate is None:
      # Just return all the variables satisfying `variable_predicate`.
      return self._flatten(
          recursive=True, predicate=variable_predicate, with_path=with_path)

    else:
      # Need to additionally verify `module_predicate` of submodules that
      # directly or indirectly own the variable.
      variables_with_paths = self._flatten(
          recursive=True, predicate=variable_predicate, with_path=True)

      def path_prefixes(path):
        return (path[:i] for i in range(1, len(path)))

      # TODO(eringrant): This function wraps the return value from a call to
      # `tf.Module._flatten`, which only checks predicates of leaf objects and
      # therefore precludes checking containment relationships.
      # However, the performance could be improved by avoiding redoing the BFS
      # within `tf.Module._flatten`.
      def satisfies_module_predicate(variable_with_path):
        """Return True if a module in the path satisfies `module_predicate`."""
        # Check if this module satisfies `module_predicate`.
        if module_predicate(self):
          return True

        # Check if a submodule satisfies `module_predicate`.
        path, _ = variable_with_path
        for path_prefix in path_prefixes(path):
          prefix_module = chained_getattr(self, path_prefix)
          if isinstance(prefix_module,
                        tf.Module) and module_predicate(prefix_module):
            return True

        # No modules or submodules satisfied `module_predicate`.
        return False

      filtered_variables = filter(satisfies_module_predicate,
                                  variables_with_paths)
      if with_path:
        return filtered_variables
      else:
        _, variables = zip(*filtered_variables)
        # De-duplicate.
        return [v_ref.deref() for v_ref in set(v.ref() for v in variables)]
def reparameterizables ( self , variable_predicate = is_variable , module_predicate = None , with_path = False ) : if module_predicate is None : # Just return all the variables satisfying `variable_predicate`. return self . _flatten ( recursive = True , predicate = variable_predicate , with_path = with_path ) else : # Need to additionally verify `module_predicate` of submodules that # directly or indirectly own the variable. variables_with_paths = self . _flatten ( recursive = True , predicate = variable_predicate , with_path = True ) def path_prefixes ( path ) : return ( path [ : i ] for i in range ( 1 , len ( path ) ) ) # TODO(eringrant): This function wraps the return value from a call to # `tf.Module._flatten`, which only checks predicates of leaf objects and # therefore precludes checking containment relationships. # However, the performance could be improved by avoiding redoing the BFS # within `tf.Module._flatten`. def satisfies_module_predicate ( variable_with_path ) : """Return True if a module in the path satisfies `module_predicate`.""" # Check if this module satisfies `module_predicate`. if module_predicate ( self ) : return True # Check if a submodule satisfies `module_predicate`. path , _ = variable_with_path for path_prefix in path_prefixes ( path ) : prefix_module = chained_getattr ( self , path_prefix ) if isinstance ( prefix_module , tf . Module ) and module_predicate ( prefix_module ) : return True # No modules or submodules satisfied `module_predicate`. return False filtered_variables = filter ( satisfies_module_predicate , variables_with_paths ) if with_path : return filtered_variables else : _ , variables = zip ( * filtered_variables ) # De-duplicate. return [ v_ref . deref ( ) for v_ref in set ( v . ref ( ) for v in variables ) ]