Source code for mrinufft.operators.interfaces.utils.utils
"""Utility functions for GPU Interface."""
import numpy as np
[docs]
def check_error(ier, message): # noqa: D103
if ier != 0:
raise RuntimeError(message)
[docs]
def sizeof_fmt(num, suffix="B"):
"""
Return a number as a XiB format.
Parameters
----------
num: int
The number to format
suffix: str, default "B"
The unit suffix
References
----------
https://stackoverflow.com/a/1094933
"""
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"