summaryrefslogtreecommitdiff
path: root/numpy/lib/utils.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-07-03 20:17:32 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-07-03 20:17:32 +0000
commit7a90a212488d7a55a939b3865b5236108fa28325 (patch)
tree9cbe2695fbe6ae915487ec22bd952e3706a45130 /numpy/lib/utils.py
parent6b7f2361d969f0ceda30c5fb10a309531aa27c03 (diff)
downloadnumpy-7a90a212488d7a55a939b3865b5236108fa28325.tar.gz
Add a require function, a issubdtype, and a load_ctypes_function to NumPy
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r--numpy/lib/utils.py32
1 files changed, 29 insertions, 3 deletions
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')
+
+