Select compute dtype by input dtype
@@ -105,7 +105,14 @@ def _correlate_or_convolve(input, weights, output, mode, cval, origin,
if weights.size == 0:
return output
input = cupy.ascontiguousarray(input)
- weights = cupy.ascontiguousarray(weights, cupy.float64)
+ if input.dtype in (cupy.int32, cupy.uint32,
+ cupy.int64, cupy.uint64, cupy.float64):
+ # If the input dtype is one of the above dtypes, float64 must be used
+ # for correlation computation to get an output compatible with SciPy.
+ wdtype = cupy.float64
+ else:
+ wdtype = cupy.float32
+ weights = cupy.ascontiguousarray(weights, wdtype)
in_params, out_params, operation, name = _generate_correlete_kernel(
input.ndim, mode, cval, input.shape, wshape, origin)
return cupy.ElementwiseKernel(in_params, out_params, operation, name)(
