def test_wrap_ffts(modname, funcname, dtype): fft_mod = pytest.importorskip(modname) try: func = getattr(fft_mod, funcname) except AttributeError: pytest.skip("`%s` missing function `%s`." % (modname, funcname)) darrc = darr.astype(dtype) darr2c = darr2.astype(dtype) nparrc = nparr.astype(dtype) if modname == "scipy.fftpack" and "rfft" in funcname: with pytest.raises(ValueError): fft_wrap(func) else: wfunc = fft_wrap(func) assert wfunc(darrc).dtype == func(nparrc).dtype assert wfunc(darrc).shape == func(nparrc).shape assert_eq(wfunc(darrc), func(nparrc)) assert_eq(wfunc(darrc, axis=1), func(nparrc, axis=1)) assert_eq(wfunc(darr2c, axis=0), func(nparrc, axis=0)) assert_eq(wfunc(darrc, n=len(darrc) - 1), func(nparrc, n=len(darrc) - 1)) assert_eq(wfunc(darrc, axis=1, n=darrc.shape[1] - 1), func(nparrc, n=darrc.shape[1] - 1)) assert_eq(wfunc(darr2c, axis=0, n=darr2c.shape[0] - 1), func(nparrc, axis=0, n=darr2c.shape[0] - 1))
def test_wrap_ffts(modname, funcname, dtype): fft_mod = pytest.importorskip(modname) try: func = getattr(fft_mod, funcname) except AttributeError: pytest.skip("`%s` missing function `%s`." % (modname, funcname)) darrc = darr.astype(dtype) darr2c = darr2.astype(dtype) nparrc = nparr.astype(dtype) if modname == "scipy.fftpack" and "rfft" in funcname: with pytest.raises(ValueError): fft_wrap(func) else: wfunc = fft_wrap(func) assert wfunc(darrc).dtype == func(nparrc).dtype assert wfunc(darrc).shape == func(nparrc).shape assert_eq(wfunc(darrc), func(nparrc)) assert_eq(wfunc(darrc, axis=1), func(nparrc, axis=1)) assert_eq(wfunc(darr2c, axis=0), func(nparrc, axis=0)) assert_eq(wfunc(darrc, n=len(darrc) - 1), func(nparrc, n=len(darrc) - 1)) assert_eq(wfunc(darrc, axis=1, n=darrc.shape[1] - 1), func(nparrc, n=darrc.shape[1] - 1)) assert_eq(wfunc(darr2c, axis=0, n=darr2c.shape[0] - 1), func(nparrc, axis=0, n=darr2c.shape[0] - 1))
def test_wrap_fftns(modname, funcname, dtype): fft_mod = pytest.importorskip(modname) try: func = getattr(fft_mod, funcname) except AttributeError: pytest.skip("`%s` missing function `%s`." % (modname, funcname)) darrc = darr.astype(dtype).rechunk(darr.shape) darr2c = darr2.astype(dtype).rechunk(darr2.shape) nparrc = nparr.astype(dtype) wfunc = fft_wrap(func) assert wfunc(darrc).dtype == func(nparrc).dtype assert wfunc(darrc).shape == func(nparrc).shape assert_eq(wfunc(darrc), func(nparrc)) assert_eq(wfunc(darrc, axes=(1, 0)), func(nparrc, axes=(1, 0))) assert_eq(wfunc(darr2c, axes=(0, 1)), func(nparrc, axes=(0, 1))) assert_eq( wfunc(darr2c, (darr2c.shape[0] - 1, darr2c.shape[1] - 1), (0, 1)), func(nparrc, (nparrc.shape[0] - 1, nparrc.shape[1] - 1), (0, 1)))
def test_wrap_fftns(modname, funcname, dtype): fft_mod = pytest.importorskip(modname) try: func = getattr(fft_mod, funcname) except AttributeError: pytest.skip("`%s` missing function `%s`." % (modname, funcname)) darrc = darr.astype(dtype).rechunk(darr.shape) darr2c = darr2.astype(dtype).rechunk(darr2.shape) nparrc = nparr.astype(dtype) wfunc = fft_wrap(func) assert wfunc(darrc).dtype == func(nparrc).dtype assert wfunc(darrc).shape == func(nparrc).shape assert_eq(wfunc(darrc), func(nparrc)) assert_eq(wfunc(darrc, axes=(1, 0)), func(nparrc, axes=(1, 0))) assert_eq(wfunc(darr2c, axes=(0, 1)), func(nparrc, axes=(0, 1))) assert_eq( wfunc(darr2c, (darr2c.shape[0] - 1, darr2c.shape[1] - 1), (0, 1)), func(nparrc, (nparrc.shape[0] - 1, nparrc.shape[1] - 1), (0, 1)) )
def test_wrap_bad_kind(): with pytest.raises(ValueError): fft_wrap(np.ones)
def test_wrap_bad_kind(): with pytest.raises(ValueError): fft_wrap(np.ones)
required, the default will be double precision. The exceptions raised by each of these functions are mostly as per their equivalents in :mod:`dask.fft`, though there are some corner cases in which this may not be true. ''' from . import numpy_fft as _numpy_fft from dask.array.fft import ( fft_wrap, fftfreq, rfftfreq, fftshift, ifftshift, ) fft = fft_wrap(_numpy_fft.fft) ifft = fft_wrap(_numpy_fft.ifft) fft2 = fft_wrap(_numpy_fft.fft2) ifft2 = fft_wrap(_numpy_fft.ifft2) fftn = fft_wrap(_numpy_fft.fftn) ifftn = fft_wrap(_numpy_fft.ifftn) rfft = fft_wrap(_numpy_fft.rfft) irfft = fft_wrap(_numpy_fft.irfft) rfft2 = fft_wrap(_numpy_fft.rfft2) irfft2 = fft_wrap(_numpy_fft.irfft2) rfftn = fft_wrap(_numpy_fft.rfftn) irfftn = fft_wrap(_numpy_fft.irfftn) hfft = fft_wrap(_numpy_fft.hfft) ihfft = fft_wrap(_numpy_fft.ihfft)
This module implements those functions that replace aspects of the :mod:`dask.fft` module. This module *provides* the entire documented namespace of :mod:`dask.fft`, but those functions that are not included here are imported directly from :mod:`dask.fft`. It is notable that unlike :mod:`numpy.fftpack`, which :mod:`dask.fft` wraps, these functions will generally return an output array with the same precision as the input array, and the transform that is chosen is chosen based on the precision of the input array. That is, if the input array is 32-bit floating point, then the transform will be 32-bit floating point and so will the returned array. Half precision input will be converted to single precision. Otherwise, if any type conversion is required, the default will be double precision. The exceptions raised by each of these functions are mostly as per their equivalents in :mod:`dask.fft`, though there are some corner cases in which this may not be true. ''' from . import numpy_fft as _numpy_fft from dask.array.fft import ( fft_wrap, ) fft = fft_wrap(_numpy_fft.fft) ifft = fft_wrap(_numpy_fft.ifft) rfft = fft_wrap(_numpy_fft.rfft) irfft = fft_wrap(_numpy_fft.irfft) hfft = fft_wrap(_numpy_fft.hfft) ihfft = fft_wrap(_numpy_fft.ihfft)