def ifftn(x, shape=None, axes=None, overwrite_x=False, plan=None): """Compute the N-dimensional inverse FFT. Args: x (cupy.ndarray): Array to be transformed. shape (None or tuple of ints): Shape of the transformed axes of the output. If ``shape`` is not given, the lengths of the input along the axes specified by ``axes`` are used. axes (tuple of ints): Axes over which to compute the FFT. overwrite_x (bool): If True, the contents of ``x`` can be destroyed. plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for transforming ``x`` over ``axes``, which can be obtained using:: plan = cupyx.scipy.fftpack.get_fft_plan(x, axes) Note that `plan` is defaulted to None, meaning CuPy will either use an auto-generated plan behind the scene if cupy.fft.config. enable_nd_planning = True, or use no cuFFT plan if it is set to False. Returns: cupy.ndarray: The transformed array which shape is specified by ``shape`` and type will convert to complex if that of the input is another. .. seealso:: :func:`scipy.fftpack.ifftn` .. note:: The argument `plan` is currently experimental and the interface may be changed in the future version. """ func = _default_fft_func(x, shape, axes, plan) return func(x, shape, axes, None, cufft.CUFFT_INVERSE, overwrite_x=overwrite_x, plan=plan)
def rfftn(x, s=None, axes=None, norm=None, overwrite_x=False, *, plan=None): """Compute the N-dimensional FFT for real input. Args: a (cupy.ndarray): Array to be transform. s (None or tuple of ints): Shape to use from the input. If ``s`` is not given, the lengths of the input along the axes specified by ``axes`` are used. axes (tuple of ints): Axes over which to compute the FFT. norm (None or ``"ortho"``): Keyword to specify the normalization mode. overwrite_x (bool): If True, the contents of ``x`` can be destroyed. plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for transforming ``x`` over ``axes``, which can be obtained using:: plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes, value_type='R2C') Note that ``plan`` is defaulted to ``None``, meaning CuPy will use an auto-generated plan behind the scene. Returns: cupy.ndarray: The transformed array which shape is specified by ``s`` and type will convert to complex if the input is other. The length of the last axis transformed will be ``s[-1]//2+1``. .. seealso:: :func:`scipy.fft.rfftn` """ s = _assequence(s) axes = _assequence(axes) func = _default_fft_func(x, s, axes, value_type='R2C') return func(x, s, axes, norm, cufft.CUFFT_FORWARD, 'R2C', overwrite_x=overwrite_x, plan=plan)
def ifftn(x, s=None, axes=None, norm=None, overwrite_x=False, *, plan=None): """Compute the N-dimensional inverse FFT. Args: x (cupy.ndarray): Array to be transformed. s (None or tuple of ints): Shape of the transformed axes of the output. If ``s`` is not given, the lengths of the input along the axes specified by ``axes`` are used. axes (tuple of ints): Axes over which to compute the FFT. norm (None or ``'ortho'``): Normalization mode. overwrite_x (bool): If True, the contents of ``x`` can be destroyed. plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for transforming ``x`` over ``axes``, which can be obtained using:: plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes) Note that ``plan`` is defaulted to ``None``, meaning CuPy will use an auto-generated plan behind the scene. Returns: cupy.ndarray: The transformed array which shape is specified by ``s`` and type will convert to complex if that of the input is another. .. seealso:: :func:`scipy.fft.ifftn` """ s = _assequence(s) axes = _assequence(axes) func = _default_fft_func(x, s, axes) return func(x, s, axes, norm, cufft.CUFFT_INVERSE, overwrite_x=overwrite_x, plan=plan)
def test_fftn_multiple_plan_error(self, dtype): import cupy import cupyx.scipy.fftpack as fftpack x = testing.shaped_random(self.shape, cupy, dtype) # hack: avoid testing the cases when getting a cuFFT plan is impossible if _default_fft_func(x, s=self.s, axes=self.axes) is not _fftn: return plan = fftpack.get_fft_plan(x, shape=self.s, axes=self.axes) with pytest.raises(RuntimeError) as ex, plan: fftpack.fftn(x, shape=self.s, axes=self.axes, plan=plan) assert 'Use the cuFFT plan either as' in str(ex.value)
def test_ifftn_plan(self, xp, scp, dtype): x = testing.shaped_random(self.shape, xp, dtype) # hack: avoid testing the cases when getting a cuFFT plan is impossible if _default_fft_func(x, s=self.s, axes=self.axes) is not _fftn: return x if scp is cupyx.scipy: import cupy.fft.config as config config.enable_nd_planning = False # use explicit plan plan = scp.fftpack.get_fft_plan(x, shape=self.s, axes=self.axes) out = scp.fftpack.ifftn(x, shape=self.s, axes=self.axes, plan=plan) config.enable_nd_planning = True # default else: # scipy out = scp.fftpack.ifftn(x, shape=self.s, axes=self.axes) return out
def test_ifftn_plan_manager(self, xp, scp, dtype): x = testing.shaped_random(self.shape, xp, dtype) # hack: avoid testing the cases when getting a cuFFT plan is impossible if _default_fft_func(x, s=self.s, axes=self.axes) is not _fftn: return x if scp is cupyx.scipy: from cupy.cuda.cufft import get_current_plan plan = scp.fftpack.get_fft_plan(x, shape=self.s, axes=self.axes) with plan: assert id(plan) == id(get_current_plan()) out = scp.fftpack.ifftn(x, shape=self.s, axes=self.axes) assert get_current_plan() is None else: # scipy out = scp.fftpack.ifftn(x, shape=self.s, axes=self.axes) return out
def irfftn(x, s=None, axes=None, norm=None, overwrite_x=False, *, plan=None): """Compute the N-dimensional inverse FFT for real input. Args: a (cupy.ndarray): Array to be transform. s (None or tuple of ints): Shape of the output. If ``s`` is not given, they are determined from the lengths of the input along the axes specified by ``axes``. axes (tuple of ints): Axes over which to compute the FFT. norm (``"backward"``, ``"ortho"``, or ``"forward"``): Optional keyword to specify the normalization mode. Default is ``None``, which is an alias of ``"backward"``. overwrite_x (bool): If True, the contents of ``x`` can be destroyed. plan (:class:`cupy.cuda.cufft.PlanNd` or ``None``): a cuFFT plan for transforming ``x`` over ``axes``, which can be obtained using:: plan = cupyx.scipy.fftpack.get_fft_plan(x, s, axes, value_type='C2R') Note that ``plan`` is defaulted to ``None``, meaning CuPy will use an auto-generated plan behind the scene. Returns: cupy.ndarray: The transformed array which shape is specified by ``s`` and type will convert to complex if the input is other. If ``s`` is not given, the length of final transformed axis of output will be ``2*(m-1)`` where `m` is the length of the final transformed axis of the input. .. seealso:: :func:`scipy.fft.irfftn` """ s = _assequence(s) axes = _assequence(axes) if (10020 >= cupy.cuda.runtime.runtimeGetVersion() >= 10010 and int(cupy.cuda.device.get_compute_capability()) < 70 and _size_last_transform_axis(x.shape, s, axes) == 2): warnings.warn('Output of irfftn might not be correct due to issue ' 'of cuFFT in CUDA 10.1/10.2 on Pascal or older GPUs.') func = _default_fft_func(x, s, axes, value_type='C2R') return func(x, s, axes, norm, cufft.CUFFT_INVERSE, 'C2R', overwrite_x=overwrite_x, plan=plan)