MCPcopy Create free account
hub / github.com/numpy/numpy / check_free_memory

Function check_free_memory

numpy/testing/_private/utils.py:2409–2435  ·  view source on GitHub ↗

Check whether `free_bytes` amount of memory is currently free. Returns: None if enough memory available, otherwise error message

(free_bytes)

Source from the content-addressed store, hash-verified

2407
2408
2409def check_free_memory(free_bytes):
2410 """
2411 Check whether `free_bytes` amount of memory is currently free.
2412 Returns: None if enough memory available, otherwise error message
2413 """
2414 env_var = 'NPY_AVAILABLE_MEM'
2415 env_value = os.environ.get(env_var)
2416 if env_value is not None:
2417 try:
2418 mem_free = _parse_size(env_value)
2419 except ValueError as exc:
2420 raise ValueError(f'Invalid environment variable {env_var}: {exc}')
2421
2422 msg = (f'{free_bytes/1e9} GB memory required, but environment variable '
2423 f'NPY_AVAILABLE_MEM={env_value} set')
2424 else:
2425 mem_free = _get_mem_available()
2426
2427 if mem_free is None:
2428 msg = ("Could not determine available memory; set NPY_AVAILABLE_MEM "
2429 "environment variable (e.g. NPY_AVAILABLE_MEM=16GB) to run "
2430 "the test.")
2431 mem_free = -1
2432 else:
2433 msg = f'{free_bytes/1e9} GB memory required, but {mem_free/1e9} GB available'
2434
2435 return msg if mem_free < free_bytes else None
2436
2437
2438def _parse_size(size_str):

Callers 1

wrapperFunction · 0.85

Calls 3

_parse_sizeFunction · 0.85
_get_mem_availableFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected