From 7a90a212488d7a55a939b3865b5236108fa28325 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Mon, 3 Jul 2006 20:17:32 +0000 Subject: Add a require function, a issubdtype, and a load_ctypes_function to NumPy --- numpy/lib/utils.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'numpy/lib/utils.py') diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index f91482699..dbb17ec60 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1,8 +1,10 @@ -import sys +import sys, os from numpy.core.numerictypes import obj2sctype +from numpy.core.multiarray import dtype -__all__ = ['issubclass_', 'get_numpy_include', 'issubsctype', 'deprecate', - 'get_include'] +__all__ = ['issubclass_', 'get_numpy_include', 'issubsctype', + 'issubdtype', 'deprecate', + 'get_include', 'load_ctypes_library'] def issubclass_(arg1, arg2): try: @@ -13,6 +15,9 @@ def issubclass_(arg1, arg2): def issubsctype(arg1, arg2): return issubclass(obj2sctype(arg1), obj2sctype(arg2)) +def issubdtype(arg1, arg2): + return issubclass(dtype(arg1).type, dtype(arg2).type) + def get_include(): """Return the directory in the package that contains the numpy/*.h header files. @@ -29,6 +34,25 @@ def get_include(): assert len(include_dirs)==1,`include_dirs` return include_dirs[0] +# Adapted from Albert Strasheim +def load_ctypes_library(libname, loader_path): + if '.' not in libname: + if sys.platform == 'win32': + libname = '%s.dll' % libname + elif sys.platform == 'darwin': + libname = '%s.dylib' % libname + else: + libname = '%s.so' % libname + loader_path = os.path.abspath(loader_path) + if not os.path.isdir(loader_path): + libdir = os.path.dirname(loader_path) + else: + libdir = loader_path + import ctypes + libpath = os.path.join(libdir, libname) + return ctypes.cdll[libpath] + + if sys.version_info < (2, 4): # Can't set __name__ in 2.3 import new @@ -65,3 +89,5 @@ def deprecate(func, oldname, newname): get_numpy_include = deprecate(get_include, 'get_numpy_include', 'get_include') + + -- cgit v1.2.1