diff options
Diffstat (limited to 'python/astra/pythonutils.py')
-rw-r--r-- | python/astra/pythonutils.py | 15 |
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 |