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_plan_type(x, s=self.s, axes=self.axes) != 'nd': 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_default_plan_type(self, enable_nd): # test cases where nd CUFFT plan is possible ca = cupy.ones((16, 16, 16)) for axes in [(0, 1), (1, 2), None, (0, 1, 2)]: plan_type = _default_plan_type(ca, axes=axes) if enable_nd: self.assertEqual(plan_type, 'nd') else: self.assertEqual(plan_type, '1d') # only a single axis is transformed -> 1d plan preferred for axes in [(0, ), (1, ), (2, )]: self.assertEqual(_default_plan_type(ca, axes=axes), '1d') # non-contiguous axes -> nd plan not possible self.assertEqual(_default_plan_type(ca, axes=(0, 2)), '1d') # >3 axes transformed -> nd plan not possible ca = cupy.ones((2, 4, 6, 8)) self.assertEqual(_default_plan_type(ca), '1d') # first or last axis not included -> nd plan not possible self.assertEqual(_default_plan_type(ca, axes=(1, )), '1d')
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_plan_type(x, s=self.s, axes=self.axes) != 'nd': 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_fftn_orders(self, dtype, enable_nd): for order in ['C', 'F']: a = testing.shaped_random(self.shape, cupy, dtype) if order == 'F': a = cupy.asfortranarray(a) out = cupy.fft.fftn(a, s=self.s, axes=self.axes) plan_type = _default_plan_type(a, s=self.s, axes=self.axes) if plan_type == 'nd': # nd plans have output with contiguity matching the input self.assertEqual(out.flags.c_contiguous, a.flags.c_contiguous) self.assertEqual(out.flags.f_contiguous, a.flags.f_contiguous) else: # 1d planning case doesn't guarantee preserved contiguity pass
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_plan_type(x, s=self.s, axes=self.axes) != 'nd': 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