MCPcopy Index your code
hub / github.com/numpy/numpy / check_free_memory

Function check_free_memory

numpy/testing/_private/utils.py:2705–2733  ·  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

2703
2704
2705def check_free_memory(free_bytes):
2706 """
2707 Check whether `free_bytes` amount of memory is currently free.
2708 Returns: None if enough memory available, otherwise error message
2709 """
2710 env_var = 'NPY_AVAILABLE_MEM'
2711 env_value = os.environ.get(env_var)
2712 if env_value is not None:
2713 try:
2714 mem_free = _parse_size(env_value)
2715 except ValueError as exc:
2716 raise ValueError(f'Invalid environment variable {env_var}: {exc}')
2717
2718 msg = (f'{free_bytes / 1e9} GB memory required, but environment variable '
2719 f'NPY_AVAILABLE_MEM={env_value} set')
2720 else:
2721 mem_free = _get_mem_available()
2722
2723 if mem_free is None:
2724 msg = ("Could not determine available memory; set NPY_AVAILABLE_MEM "
2725 "environment variable (e.g. NPY_AVAILABLE_MEM=16GB) to run "
2726 "the test.")
2727 mem_free = -1
2728 else:
2729 free_bytes_gb = free_bytes / 1e9
2730 mem_free_gb = mem_free / 1e9
2731 msg = f'{free_bytes_gb} GB memory required, but {mem_free_gb} GB available'
2732
2733 return msg if mem_free < free_bytes else None
2734
2735
2736def _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

Used in the wild real call sites across dependent graphs

searching dependent graphs…