sailfish.kernel.system.get_array_module
- sailfish.kernel.system.get_array_module(mode)[source]
Return either the numpy or cupy module, depending on the value of mode.
If mode is “cpu” or “omp”, then the numpy module is returned. Otherwise if mode is “gpu” then cupy is returned. The cupy documentation recommends assigning whichever module is returned to a variable called xp, and using that variable to access functions that are common to both, for example use
xp.zeros(100)
. This pattern facilitates writing CPU-GPU agnostic code.