diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-13 09:04:39 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-13 09:04:39 +0000 |
commit | eee00f8f7e15592a048c8b841aef9ea81faa0fda (patch) | |
tree | 74052bb733a01a84b83c3354593d2e7eb0243ef5 /numpy/core/_internal.py | |
parent | 8e24ef871ee8a58ae65d4d59d8ac916a48568c56 (diff) | |
download | numpy-eee00f8f7e15592a048c8b841aef9ea81faa0fda.tar.gz |
Remove _as_parameter_ attribute from arrays and add it to the ctypes object. Create an ndpointer class factory to return classes that check for specific array types. These can be used in argtypes list to ctypes functions.
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r-- | numpy/core/_internal.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 6f64f40f4..d538743b6 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -208,21 +208,30 @@ def _getintp_ctype(): _getintp_ctype.cache = None # Used for .ctypes attribute of ndarray + +class _missing_ctypes(object): + def cast(self, num, obj): + return num + + def c_void_p(self, num): + return num + class _ctypes(object): - def __init__(self, array): + def __init__(self, array, ptr=None): try: import ctypes self._ctypes = ctypes except ImportError: - raise AttributeError, "ctypes not available" + self._ctypes = _missing_ctypes() self._arr = array + self._data = ptr if self._arr.ndim == 0: self._zerod = True else: self._zerod = False def data_as(self, obj): - return self._ctypes.cast(self._arr._as_parameter_, obj) + return self._ctypes.cast(self._data, obj) def shape_as(self, obj): if self._zerod: @@ -235,7 +244,7 @@ class _ctypes(object): return (obj*self._arr.ndim)(*self._arr.strides) def get_data(self): - return self._ctypes.c_void_p(self._arr._as_parameter_) + return self._ctypes.c_void_p(self._data) def get_shape(self): if self._zerod: @@ -246,7 +255,11 @@ class _ctypes(object): if self._zerod: return None return (_getintp_ctype()*self._arr.ndim)(*self._arr.strides) - + + def get_as_parameter(self): + return self._data + data = property(get_data, None, doc="c-types data") shape = property(get_shape, None, doc="c-types shape") strides = property(get_strides, None, doc="c-types strides") + _as_parameter_ = property(get_as_parameter, None, doc="_as parameter_") |