summaryrefslogtreecommitdiff
path: root/python/gras/GRAS_Utils.py
diff options
context:
space:
mode:
authorJosh Blum2012-11-20 22:37:17 -0800
committerJosh Blum2012-11-20 22:37:17 -0800
commit3678530226d997381addfffa9eae5e3197164348 (patch)
treec959083b069e45c2ea7c5d173239476f1654e5f6 /python/gras/GRAS_Utils.py
parent92e20173fcb8bce1c7a704ff849d95a57a0f9885 (diff)
downloadsandhi-3678530226d997381addfffa9eae5e3197164348.tar.gz
sandhi-3678530226d997381addfffa9eae5e3197164348.tar.bz2
sandhi-3678530226d997381addfffa9eae5e3197164348.zip
support for sbuffer in python
Diffstat (limited to 'python/gras/GRAS_Utils.py')
-rw-r--r--python/gras/GRAS_Utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/gras/GRAS_Utils.py b/python/gras/GRAS_Utils.py
new file mode 100644
index 0000000..a42d816
--- /dev/null
+++ b/python/gras/GRAS_Utils.py
@@ -0,0 +1,15 @@
+# Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
+
+import numpy
+
+def pointer_to_ndarray(addr, nitems, dtype=numpy.dtype(numpy.uint8), readonly=False):
+ class array_like:
+ __array_interface__ = {
+ 'data' : (addr, readonly),
+ 'typestr' : dtype.base.str,
+ 'descr' : dtype.base.descr,
+ 'shape' : (nitems,) + dtype.shape,
+ 'strides' : None,
+ 'version' : 3,
+ }
+ return numpy.asarray(array_like()).view(dtype.base)