diff options
author | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2020-07-02 16:15:25 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2020-07-02 16:15:25 +0200 |
commit | b126aefdda9148143971b95460f6f52010cc2358 (patch) | |
tree | ffe468575dcf47d3411e7c2467e72ddf8626c988 /python/astra/pythonutils.py | |
parent | 82fc179f39ed6da308b0f229769f899570a1d9ea (diff) | |
parent | 69ab4daf439164eb37203b69b0cca3efe4c2232e (diff) | |
download | astra-b126aefdda9148143971b95460f6f52010cc2358.tar.gz astra-b126aefdda9148143971b95460f6f52010cc2358.tar.bz2 astra-b126aefdda9148143971b95460f6f52010cc2358.tar.xz astra-b126aefdda9148143971b95460f6f52010cc2358.zip |
Merge branch 'direct_fpbp'
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 |