summaryrefslogtreecommitdiffstats
path: root/python/astra/pythonutils.py
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2020-06-23 15:19:06 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2020-07-02 15:54:12 +0200
commit492c0211608fa756ba6642ff7ae3b479765a955b (patch)
tree325b34d12f5969f7b90d6eaacb4d023e2a386213 /python/astra/pythonutils.py
parentecfb65a05b8ed5171ad65173581d5fe328926995 (diff)
downloadastra-492c0211608fa756ba6642ff7ae3b479765a955b.tar.gz
astra-492c0211608fa756ba6642ff7ae3b479765a955b.tar.bz2
astra-492c0211608fa756ba6642ff7ae3b479765a955b.tar.xz
astra-492c0211608fa756ba6642ff7ae3b479765a955b.zip
Check numpy array type
Diffstat (limited to 'python/astra/pythonutils.py')
-rw-r--r--python/astra/pythonutils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/astra/pythonutils.py b/python/astra/pythonutils.py
index 715df30..ef49f97 100644
--- a/python/astra/pythonutils.py
+++ b/python/astra/pythonutils.py
@@ -29,6 +29,8 @@
"""
+import numpy as np
+
def geom_size(geom, dim=None):
"""Returns the size of a volume or sinogram, based on the projection or volume geometry.
@@ -62,6 +64,19 @@ def geom_size(geom, dim=None):
return s
+def checkArrayForLink(data):
+ """Check if a numpy array is suitable for direct usage (contiguous, etc.)
+
+ This function raises an exception if not.
+ """
+
+ if not isinstance(data, np.ndarray):
+ raise ValueError("Numpy array should be numpy.ndarray")
+ if data.dtype != np.float32:
+ raise ValueError("Numpy array should be float32")
+ if not (data.flags['C_CONTIGUOUS'] and data.flags['ALIGNED']):
+ raise ValueError("Numpy array should be C_CONTIGUOUS and ALIGNED")
+
class GPULink(object):
"""Utility class for astra.data3d.link with a CUDA pointer