tomosipo.links.cupy module
This module adds support for cupy arrays as astra.data3d backends
This module is not automatically imported by tomosipo, you must import it manually as follows:
>>> import tomosipo as ts
>>> import tomosipo.cupy
Now, you may use cupy arrays as you would numpy arrays:
>>> vg = ts.volume(shape=(10, 10, 10))
>>> pg = ts.parallel(angles=10, shape=10)
>>> A = ts.operator(vg, pg)
>>> x = cupy.zeros(A.domain_shape, dtype='float32')
>>> A(x).shape == A.range_shape
True
- class tomosipo.links.cupy.CupyLink(shape, initial_value)[source]
Bases:
LinkLink implementation for cupy arrays
- clone()[source]
- context()[source]
Context-manager to manage ASTRA interactions
This context-manager makes sure that the current CUDA stream is set to the CUDA device of the current linked data.
- Returns:
- Return type:
- property data
Returns a shared array with the underlying data.
Changes to the return value will be reflected in the astra data.
If you want to avoid this, consider copying the data immediately, using x.data.copy() for instance.
NOTE: if the underlying object is an Astra projection data type, the order of the axes will be in (Y, num_angles, X) order.
- Returns:
cupy.ndarray
- Return type:
cupy.ndarray
- property linked_data
Returns a numpy array or GPULink object
- Returns:
- Return type:
- new_empty(shape)[source]
- new_full(shape, value)[source]
- new_zeros(shape)[source]