def _stub(name):
def _f(*args, **kwargs):
raise NotImplementedError(
f"numpy.ctypeslib.{name} is not implemented in rumpy"
)
_f.__name__ = name
return _f
as_array = _stub("as_array")
as_ctypes = _stub("as_ctypes")
as_ctypes_type = _stub("as_ctypes_type")
ndpointer = _stub("ndpointer")
load_library = _stub("load_library")
try:
import ctypes as _ctypes_module ctypes = _ctypes_module
c_intp = ctypes.c_int64 if hasattr(ctypes, "c_int64") else ctypes.c_long
except ImportError:
try:
import _ctypes as _lowlevel
except ImportError:
_lowlevel = None
class _CTypesShim:
def __getattr__(self, name):
if _lowlevel is not None and hasattr(_lowlevel, name):
return getattr(_lowlevel, name)
raise AttributeError(
f"ctypes.{name} is not available in this rumpy build "
"(install rustpython-pylib for full ctypes support)"
)
ctypes = _CTypesShim()
class c_intp:
def __init__(self, value=0):
self.value = int(value)
__all__ = [
"as_array",
"as_ctypes",
"as_ctypes_type",
"ndpointer",
"load_library",
"ctypes",
"c_intp",
]