I am trying to use the scipy
compatible finction of cupy
namely the map_coordinates
function. However, after a lot of tinkering I am unable to get it to work. So, I do something as follows:
import cupy as cp
import cupyx
import cupyx.scipy.ndimage
import numpy as np
# Generate some random data
x = np.random.rand(10, 10, 10)
# Move it to the GPU
x = cp.array(x)
# Generate some coordinates
d = [cp.array(np.random.rand(10, 10, 10)),
cp.array(np.random.rand(10, 10, 10)),
cp.array(np.random.rand(10, 10, 10))]
d = cp.stack(d)
print(d.shape) # (3, 10, 10, 10)
cupyx.scipy.ndimage.map_coordinates(x, d, cp.float32, order=1,
mode='constant', cval=0)
Now, this returns the error: ValueError: Out shape is mismatched
.
I am not sure now why this should be the case as the output should be generated by the function itself. The coordinates are the correct 4D shape, think. I am really at a loss on how to make this work. Unfortunately, I could not come across any working example of this on the net as well.