MCPcopy Create free account
hub / github.com/pytorch/executorch / _SchemaMaxAlignmentGetter

Class _SchemaMaxAlignmentGetter

exir/_serialize/_flatbuffer.py:82–98  ·  view source on GitHub ↗

Finds the largest (force_align: N) N value in flatbuffer schemas.

Source from the content-addressed store, hash-verified

80
81
82class _SchemaMaxAlignmentGetter:
83 """Finds the largest (force_align: N) N value in flatbuffer schemas."""
84
85 def __init__(self) -> None:
86 self.max_alignment: int = 0
87
88 def __call__(self, schema: bytes) -> bytes:
89 """Finds all `(force_align: N)` instances and updates max_alignment.
90
91 Returns the input schema unmodified.
92 """
93 regex = re.compile(rb"\(\s*force_align\s*:\s*(\d+)\s*\)")
94 matches = regex.findall(schema)
95 for alignment in [int(match) for match in matches]:
96 if alignment > self.max_alignment:
97 self.max_alignment = alignment
98 return schema
99
100
101class _SchemaFileIdentifierGetter:

Callers 1

_prepare_schemaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected