summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r--numpy/core/_internal.py23
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_")