DeviceChange

class odl.DeviceChange(domain_device: str, range_device: str, subspace_index: int | list[int] = [])

Bases: AdapterOperator

A pseudo-operator that copies arrays from one computational device to another. This is useful as an adapter in a pipeline of operators that need to use different devices for some reason. Note that it is usually more efficient to implement your whole pipeline on a single device, if possible.

Further reading: Switching between array backends

__init__(domain_device: str, range_device: str, subspace_index: int | list[int] = [])[source]

Create an operator tying two equivalent spaces with different storage together.

Parameters

domain_device, range_devicestr

Device specifiers such as 'cpu' or 'cuda:0'. Which ones are supported depends on the backend and hardware.

subspace_index: int or sequence of ints

If the domain is a compound space (i.e. ProductSpace), you may wish to only change the device of one of the constituent spaces. This can be done with this index into the product space structure. If a list is provided, this is understood as recursive indexing into a nested product space.