Wrapper around tc.autoinit that preserves parameter requirement information
Source code in src/fdtdx/core/jax/pytrees.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513 | @dataclass_transform(
field_specifiers=(Field, tc_field, frozen_field, frozen_private_field, field, private_field),
kw_only_default=True,
)
def autoinit(klass: type[T]) -> type[T]:
"""Wrapper around tc.autoinit that preserves parameter requirement information"""
return (
klass
# if the class already has a user-defined __init__ method
# then return the class as is without any modification
if "__init__" in vars(klass)
# first convert the current class hints to fields
# then build the __init__ method from the fields of the current class
# and any base classes that are decorated with `autoinit`
else build_init_method(convert_hints_to_fields(klass))
)
|