Wraps this struct in a selection, enabling functional-style mutations. This is a convenience wrapper around selectors.select to enable easier selection, using syntax like:: struct.select().at(lambda b: b.foo[3].bar).apply(baz) struct.select().at_instances_of(Sequential).at_chil
(self)
| 549 | |
| 550 | @typing.final |
| 551 | def select(self) -> selectors.Selection[Struct]: |
| 552 | """Wraps this struct in a selection, enabling functional-style mutations. |
| 553 | |
| 554 | This is a convenience wrapper around selectors.select to enable easier |
| 555 | selection, using syntax like:: |
| 556 | |
| 557 | struct.select().at(lambda b: b.foo[3].bar).apply(baz) |
| 558 | struct.select().at_instances_of(Sequential).at_children().apply(qux) |
| 559 | |
| 560 | See documentation for `selectors.Selection` for supported attributes. |
| 561 | |
| 562 | Returns: |
| 563 | A singleton selection containing this struct. |
| 564 | """ |
| 565 | # Dynamic import to avoid circular import issues. |
| 566 | from penzai.core import selectors # pylint: disable=import-outside-toplevel |
| 567 | |
| 568 | return selectors.select(self) |
| 569 | |
| 570 | def key_for_field(self, field_name: str) -> Hashable: |
| 571 | """Generates a JAX PyTree key for a given field name. |
no outgoing calls