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

Function pad_to

exir/_serialize/padding.py:10–26  ·  view source on GitHub ↗

Returns the input followed by enough zero bytes to become the requested length. Args: data: The data to pad. length: The length of the returned data. Returns: The padded data. Raises: ValueError: If the requested length is less than the input length.

(data: bytes, length: int)

Source from the content-addressed store, hash-verified

8
9
10def pad_to(data: bytes, length: int) -> bytes:
11 """Returns the input followed by enough zero bytes to become the requested length.
12
13 Args:
14 data: The data to pad.
15 length: The length of the returned data.
16 Returns:
17 The padded data.
18 Raises:
19 ValueError: If the requested length is less than the input length.
20 """
21 if length < len(data):
22 raise ValueError(f"Data length {len(data)} > padded length {length}")
23 if length > len(data):
24 data = data + b"\x00" * (length - len(data))
25 assert len(data) == length
26 return data
27
28
29def padding_required(offset: int, alignment: int) -> int:

Callers 2

serialize_pte_binaryFunction · 0.90
serializeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected