MCPcopy
hub / github.com/google-deepmind/penzai / refine

Method refine

penzai/core/selectors.py:476–499  ·  view source on GitHub ↗

Refines a selection by selecting within each selected subtree. Although selectors can already be refined by making additional calls, chained calls generally treat all selected subtrees the same way. In contrast, this method allows each selected node to be processed independently. Ad

(
      self, selector_fn: "Callable[[Any], Selection[OtherSubtree]]"
  )

Source from the content-addressed store, hash-verified

474 return _build_selection_from_boundary(self.apply(process_subselection))
475
476 def refine(
477 self, selector_fn: "Callable[[Any], Selection[OtherSubtree]]"
478 ) -> "Selection[OtherSubtree]":
479 """Refines a selection by selecting within each selected subtree.
480
481 Although selectors can already be refined by making additional calls,
482 chained calls generally treat all selected subtrees the same way. In
483 contrast, this method allows each selected node to be processed
484 independently. Additionally, similar to `apply`, the additional logic is
485 free to modify the subtree as it goes.
486
487 Args:
488 selector_fn: A function that takes a selected subtree from this selection
489 and returns a new selection object, usually a selection of some nodes in
490 the input subtree.
491
492 Returns:
493 A new selection that selects every node selected by ``selector_fn``, but
494 in the context of the original tree rather than the individual selected
495 subtrees.
496 """
497 return self.apply(
498 selector_fn, keep_selected=True
499 ).flatten_selected_selections()
500
501 def at(
502 self,

Callers 1

test_refineMethod · 0.80

Calls 2

applyMethod · 0.95

Tested by 1

test_refineMethod · 0.64