MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _str2bytes

Function _str2bytes

imperative/python/megengine/dtr/dtr.py:13–21  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

11
12
13def _str2bytes(text: str) -> int:
14 regex = re.compile(r"(\d+(?:\.\d+)?)\s*([kmg]?b)", re.IGNORECASE)
15 order = ["b", "kb", "mb", "gb"]
16 result = regex.findall(text)
17 if len(result) != 1:
18 raise ValueError(
19 "Formatting of `value` only supports bytes(B), kilobyte(KB), megabyte(MB) and gigabyte(GB) units"
20 )
21 return int(float(result[0][0]) * 1024 ** order.index(result[0][1].lower()))
22
23
24@property

Callers 2

eviction_thresholdFunction · 0.85
evictee_minimum_sizeFunction · 0.85

Calls 1

compileMethod · 0.45

Tested by

no test coverage detected