code: def filter(  # pylint: disable=redefined-builtin
      predicate: Callable[[str, str, T], bool],
      structure: Mapping[str, Mapping[str, T]],
  ) -> Mapping[str, Mapping[str, T]]:
      """Filters an input structure according to a user specified predicate.
  
      >>> params = {'linear': {'w': None, 'b': None}}
      >>> predicate = lambda module_name, name, value: name == 'w'
      >>> hk.data_structures.filter(predicate, params)
      {'linear': {'w': None}}
  
      Note: returns a new structure not a view.
  
      Args:
        predicate: criterion to be used to partition the input data.
          The ``predicate`` argument is expected to be a boolean function taking as
          inputs the name of the module, the name of a given entry in the module
          data bundle (e.g. parameter name) and the corresponding data.
        structure: Haiku params or state data structure to be filtered.
  
      Returns:
        All the input parameters or state as selected by the input predicate.
      """
      out = collections.defaultdict(dict)
  
      for module_name, name, value in traverse(structure):
          if predicate(module_name, name, value):
              out[module_name][name] = value
  
      return data_structures.to_haiku_dict(out)
  
file_path: dm-haiku/haiku/_src/filtering.py
imports: import collections
  from collections.abc import Generator, Mapping, MutableMapping
  from typing import Any, Callable, TypeVar
  from haiku._src import data_structures
  from haiku._src import utils
  import jax
label_desc: Use image node_id 4 for calling a global function with example usage: filter(predicate, structure) and returns: data_structures