diff --git a/CHANGELOG.md b/CHANGELOG.md index 38f8053..66de605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * Dropped support for `scipy.fftpack` interface [gh-185](https://github.com/IntelPython/mkl_fft/pull/185) * Dropped support for `overwrite_x` parameter in `mkl_fft` [gh-185](https://github.com/IntelPython/mkl_fft/pull/185) +* Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189) ### Fixed * Fixed a bug for N-D FFTs when both `s` and `out` are given [gh-185](https://github.com/IntelPython/mkl_fft/pull/185) diff --git a/README.md b/README.md index e7637db..46b4e2e 100644 --- a/README.md +++ b/README.md @@ -52,21 +52,21 @@ While using the interfaces module is the recommended way to leverage `mk_fft`, o ### complex-to-complex (c2c) transforms: -`fft(x, n=None, axis=-1, fwd_scale=1.0, out=None)` - 1D FFT, similar to `numpy.fft.fft` +`fft(x, n=None, axis=-1, norm=None, out=None)` - 1D FFT, similar to `numpy.fft.fft` -`fft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None)` - 2D FFT, similar to `numpy.fft.fft2` +`fft2(x, s=None, axes=(-2, -1), norm=None, out=None)` - 2D FFT, similar to `numpy.fft.fft2` -`fftn(x, s=None, axes=None, fwd_scale=1.0, out=None)` - ND FFT, similar to `numpy.fft.fftn` +`fftn(x, s=None, axes=None, norm=None, out=None)` - ND FFT, similar to `numpy.fft.fftn` and similar inverse FFT (`ifft*`) functions. ### real-to-complex (r2c) and complex-to-real (c2r) transforms: -`rfft(x, n=None, axis=-1, fwd_scale=1.0, out=None)` - r2c 1D FFT, similar to `numpy.fft.rfft` +`rfft(x, n=None, axis=-1, norm=None, out=None)` - r2c 1D FFT, similar to `numpy.fft.rfft` -`rfft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None)` - r2c 2D FFT, similar to `numpy.fft.rfft2` +`rfft2(x, s=None, axes=(-2, -1), norm=None, out=None)` - r2c 2D FFT, similar to `numpy.fft.rfft2` -`rfftn(x, s=None, axes=None, fwd_scale=1.0, out=None)` - r2c ND FFT, similar to `numpy.fft.rfftn` +`rfftn(x, s=None, axes=None, norm=None, out=None)` - r2c ND FFT, similar to `numpy.fft.rfftn` and similar inverse c2r FFT (`irfft*`) functions. diff --git a/mkl_fft/_fft_utils.py b/mkl_fft/_fft_utils.py index 160d64b..a012e31 100644 --- a/mkl_fft/_fft_utils.py +++ b/mkl_fft/_fft_utils.py @@ -198,16 +198,12 @@ def _init_nd_shape_and_axes(x, shape, axes): raise ValueError("when given, shape values must be integers") if axes.shape != shape.shape: raise ValueError( - "when given, axes and shape arguments" - " have to be of the same length" + "when given, axes and shape arguments have to be of the same length" ) shape = np.where(shape == -1, np.array(x.shape)[axes], shape) - if shape.size != 0 and (shape < 1).any(): - raise ValueError( - "invalid number of data points ({0}) specified".format(shape) - ) + raise ValueError(f"invalid number of data points ({shape}) specified") return shape, axes @@ -319,7 +315,7 @@ def _pad_array(arr, s, axes): try: shp_i = arr_shape[ai] except IndexError: - raise ValueError("Invalid axis (%d) specified" % ai) + raise ValueError(f"Invalid axis {ai} specified") if si > shp_i: no_padding = False pad_widths[ai] = (0, si - shp_i) @@ -355,7 +351,7 @@ def _trim_array(arr, s, axes): try: shp_i = arr_shape[ai] except IndexError: - raise ValueError("Invalid axis (%d) specified" % ai) + raise ValueError(f"Invalid axis {ai} specified") if si < shp_i: no_trim = False ind[ai] = slice(None, si, None) diff --git a/mkl_fft/_mkl_fft.py b/mkl_fft/_mkl_fft.py index b15c3d5..1cd49b9 100644 --- a/mkl_fft/_mkl_fft.py +++ b/mkl_fft/_mkl_fft.py @@ -24,7 +24,12 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from ._fft_utils import _c2c_fftnd_impl, _c2r_fftnd_impl, _r2c_fftnd_impl +from ._fft_utils import ( + _c2c_fftnd_impl, + _c2r_fftnd_impl, + _compute_fwd_scale, + _r2c_fftnd_impl, +) # pylint: disable=no-name-in-module from ._pydfti import _c2c_fft1d_impl, _c2r_fft1d_impl, _r2c_fft1d_impl @@ -45,57 +50,57 @@ ] -def fft(x, n=None, axis=-1, fwd_scale=1.0, out=None): - return _c2c_fft1d_impl( - x, n=n, axis=axis, out=out, direction=+1, fsc=fwd_scale - ) +def fft(x, n=None, axis=-1, norm=None, out=None): + fsc = _compute_fwd_scale(norm, n, x.shape[axis]) + return _c2c_fft1d_impl(x, n=n, axis=axis, out=out, direction=+1, fsc=fsc) -def ifft(x, n=None, axis=-1, fwd_scale=1.0, out=None): - return _c2c_fft1d_impl( - x, n=n, axis=axis, out=out, direction=-1, fsc=fwd_scale - ) +def ifft(x, n=None, axis=-1, norm=None, out=None): + fsc = _compute_fwd_scale(norm, n, x.shape[axis]) + return _c2c_fft1d_impl(x, n=n, axis=axis, out=out, direction=-1, fsc=fsc) -def fft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None): - return fftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale) +def fft2(x, s=None, axes=(-2, -1), norm=None, out=None): + return fftn(x, s=s, axes=axes, norm=norm, out=out) -def ifft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None): - return ifftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale) +def ifft2(x, s=None, axes=(-2, -1), norm=None, out=None): + return ifftn(x, s=s, axes=axes, norm=norm, out=out) -def fftn(x, s=None, axes=None, fwd_scale=1.0, out=None): - return _c2c_fftnd_impl( - x, s=s, axes=axes, out=out, direction=+1, fsc=fwd_scale - ) +def fftn(x, s=None, axes=None, norm=None, out=None): + fsc = _compute_fwd_scale(norm, s, x.shape) + return _c2c_fftnd_impl(x, s=s, axes=axes, out=out, direction=+1, fsc=fsc) -def ifftn(x, s=None, axes=None, fwd_scale=1.0, out=None): - return _c2c_fftnd_impl( - x, s=s, axes=axes, out=out, direction=-1, fsc=fwd_scale - ) +def ifftn(x, s=None, axes=None, norm=None, out=None): + fsc = _compute_fwd_scale(norm, s, x.shape) + return _c2c_fftnd_impl(x, s=s, axes=axes, out=out, direction=-1, fsc=fsc) -def rfft(x, n=None, axis=-1, fwd_scale=1.0, out=None): - return _r2c_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fwd_scale) +def rfft(x, n=None, axis=-1, norm=None, out=None): + fsc = _compute_fwd_scale(norm, n, x.shape[axis]) + return _r2c_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fsc) -def irfft(x, n=None, axis=-1, fwd_scale=1.0, out=None): - return _c2r_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fwd_scale) +def irfft(x, n=None, axis=-1, norm=None, out=None): + fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1)) + return _c2r_fft1d_impl(x, n=n, axis=axis, out=out, fsc=fsc) -def rfft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None): - return rfftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale) +def rfft2(x, s=None, axes=(-2, -1), norm=None, out=None): + return rfftn(x, s=s, axes=axes, norm=norm, out=out) -def irfft2(x, s=None, axes=(-2, -1), fwd_scale=1.0, out=None): - return irfftn(x, s=s, axes=axes, out=out, fwd_scale=fwd_scale) +def irfft2(x, s=None, axes=(-2, -1), norm=None, out=None): + return irfftn(x, s=s, axes=axes, norm=norm, out=out) -def rfftn(x, s=None, axes=None, fwd_scale=1.0, out=None): - return _r2c_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fwd_scale) +def rfftn(x, s=None, axes=None, norm=None, out=None): + fsc = _compute_fwd_scale(norm, s, x.shape) + return _r2c_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fsc) -def irfftn(x, s=None, axes=None, fwd_scale=1.0, out=None): - return _c2r_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fwd_scale) +def irfftn(x, s=None, axes=None, norm=None, out=None): + fsc = _compute_fwd_scale(norm, s, x.shape) + return _c2r_fftnd_impl(x, s=s, axes=axes, out=out, fsc=fsc) diff --git a/mkl_fft/interfaces/_numpy_fft.py b/mkl_fft/interfaces/_numpy_fft.py index f2f72d5..649485f 100644 --- a/mkl_fft/interfaces/_numpy_fft.py +++ b/mkl_fft/interfaces/_numpy_fft.py @@ -36,7 +36,7 @@ import mkl_fft -from .._fft_utils import _compute_fwd_scale, _swap_direction +from .._fft_utils import _swap_direction from ._float_utils import _downcast_float128_array __all__ = [ @@ -120,10 +120,9 @@ def fft(a, n=None, axis=-1, norm=None, out=None): """ x = _downcast_float128_array(a) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) return _trycall( - mkl_fft.fft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out} + mkl_fft.fft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out} ) @@ -135,10 +134,9 @@ def ifft(a, n=None, axis=-1, norm=None, out=None): """ x = _downcast_float128_array(a) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) return _trycall( - mkl_fft.ifft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out} + mkl_fft.ifft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out} ) @@ -171,10 +169,9 @@ def fftn(a, s=None, axes=None, norm=None, out=None): """ x = _downcast_float128_array(a) s, axes = _cook_nd_args(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) return _trycall( - mkl_fft.fftn, (x,), {"s": s, "axes": axes, "fwd_scale": fsc, "out": out} + mkl_fft.fftn, (x,), {"s": s, "axes": axes, "norm": norm, "out": out} ) @@ -187,12 +184,11 @@ def ifftn(a, s=None, axes=None, norm=None, out=None): """ x = _downcast_float128_array(a) s, axes = _cook_nd_args(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) return _trycall( mkl_fft.ifftn, (x,), - {"s": s, "axes": axes, "fwd_scale": fsc, "out": out}, + {"s": s, "axes": axes, "norm": norm, "out": out}, ) @@ -204,10 +200,9 @@ def rfft(a, n=None, axis=-1, norm=None, out=None): """ x = _downcast_float128_array(a) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) return _trycall( - mkl_fft.rfft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out} + mkl_fft.rfft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out} ) @@ -219,12 +214,11 @@ def irfft(a, n=None, axis=-1, norm=None, out=None): """ x = _downcast_float128_array(a) - fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1)) return _trycall( mkl_fft.irfft, (x,), - {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}, + {"n": n, "axis": axis, "norm": norm, "out": out}, ) @@ -257,12 +251,11 @@ def rfftn(a, s=None, axes=None, norm=None, out=None): """ x = _downcast_float128_array(a) s, axes = _cook_nd_args(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) return _trycall( mkl_fft.rfftn, (x,), - {"s": s, "axes": axes, "fwd_scale": fsc, "out": out}, + {"s": s, "axes": axes, "norm": norm, "out": out}, ) @@ -276,12 +269,11 @@ def irfftn(a, s=None, axes=None, norm=None, out=None): x = _downcast_float128_array(a) s, axes = _cook_nd_args(x, s, axes, invreal=True) - fsc = _compute_fwd_scale(norm, s, x.shape) return _trycall( mkl_fft.irfftn, (x,), - {"s": s, "axes": axes, "fwd_scale": fsc, "out": out}, + {"s": s, "axes": axes, "norm": norm, "out": out}, ) @@ -295,12 +287,10 @@ def hfft(a, n=None, axis=-1, norm=None, out=None): """ norm = _swap_direction(norm) x = _downcast_float128_array(a) - fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1)) - return _trycall( mkl_fft.irfft, (np.conjugate(x),), - {"n": n, "axis": axis, "fwd_scale": fsc, "out": out}, + {"n": n, "axis": axis, "norm": norm, "out": out}, ) @@ -313,10 +303,9 @@ def ihfft(a, n=None, axis=-1, norm=None, out=None): """ norm = _swap_direction(norm) x = _downcast_float128_array(a) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) result = _trycall( - mkl_fft.rfft, (x,), {"n": n, "axis": axis, "fwd_scale": fsc, "out": out} + mkl_fft.rfft, (x,), {"n": n, "axis": axis, "norm": norm, "out": out} ) np.conjugate(result, out=result) diff --git a/mkl_fft/interfaces/_scipy_fft.py b/mkl_fft/interfaces/_scipy_fft.py index c10b9d1..b6dcbca 100644 --- a/mkl_fft/interfaces/_scipy_fft.py +++ b/mkl_fft/interfaces/_scipy_fft.py @@ -39,7 +39,7 @@ import mkl_fft -from .._fft_utils import _compute_fwd_scale, _swap_direction +from .._fft_utils import _swap_direction from ._float_utils import _supported_array_or_not_implemented __all__ = [ @@ -235,10 +235,9 @@ def fft( _check_plan(plan) x = _validate_input(x) out = _use_input_as_out(x, overwrite_x) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) with _Workers(workers): - return mkl_fft.fft(x, n=n, axis=axis, fwd_scale=fsc, out=out) + return mkl_fft.fft(x, n=n, axis=axis, norm=norm, out=out) def ifft( @@ -253,10 +252,9 @@ def ifft( _check_plan(plan) x = _validate_input(x) out = _use_input_as_out(x, overwrite_x) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) with _Workers(workers): - return mkl_fft.ifft(x, n=n, axis=axis, fwd_scale=fsc, out=out) + return mkl_fft.ifft(x, n=n, axis=axis, norm=norm, out=out) def fft2( @@ -333,10 +331,9 @@ def fftn( x = _validate_input(x) out = _use_input_as_out(x, overwrite_x) s, axes = _init_nd_shape_and_axes(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) with _Workers(workers): - return mkl_fft.fftn(x, s=s, axes=axes, fwd_scale=fsc, out=out) + return mkl_fft.fftn(x, s=s, axes=axes, norm=norm, out=out) def ifftn( @@ -359,10 +356,9 @@ def ifftn( x = _validate_input(x) out = _use_input_as_out(x, overwrite_x) s, axes = _init_nd_shape_and_axes(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) with _Workers(workers): - return mkl_fft.ifftn(x, s=s, axes=axes, fwd_scale=fsc, out=out) + return mkl_fft.ifftn(x, s=s, axes=axes, norm=norm, out=out) def rfft( @@ -376,11 +372,10 @@ def rfft( """ _check_plan(plan) x = _validate_input(x) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) with _Workers(workers): # Note: overwrite_x is not utilized - return mkl_fft.rfft(x, n=n, axis=axis, fwd_scale=fsc) + return mkl_fft.rfft(x, n=n, axis=axis, norm=norm) def irfft( @@ -394,11 +389,10 @@ def irfft( """ _check_plan(plan) x = _validate_input(x) - fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1)) with _Workers(workers): # Note: overwrite_x is not utilized - return mkl_fft.irfft(x, n=n, axis=axis, fwd_scale=fsc) + return mkl_fft.irfft(x, n=n, axis=axis, norm=norm) def rfft2( @@ -474,11 +468,10 @@ def rfftn( _check_plan(plan) x = _validate_input(x) s, axes = _init_nd_shape_and_axes(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) with _Workers(workers): # Note: overwrite_x is not utilized - return mkl_fft.rfftn(x, s, axes, fwd_scale=fsc) + return mkl_fft.rfftn(x, s, axes, norm=norm) def irfftn( @@ -500,11 +493,10 @@ def irfftn( _check_plan(plan) x = _validate_input(x) s, axes = _init_nd_shape_and_axes(x, s, axes, invreal=True) - fsc = _compute_fwd_scale(norm, s, x.shape) with _Workers(workers): # Note: overwrite_x is not utilized - return mkl_fft.irfftn(x, s, axes, fwd_scale=fsc) + return mkl_fft.irfftn(x, s, axes, norm=norm) def hfft( @@ -522,11 +514,10 @@ def hfft( norm = _swap_direction(norm) x = np.array(x, copy=True) np.conjugate(x, out=x) - fsc = _compute_fwd_scale(norm, n, 2 * (x.shape[axis] - 1)) with _Workers(workers): # Note: overwrite_x is not utilized - return mkl_fft.irfft(x, n=n, axis=axis, fwd_scale=fsc) + return mkl_fft.irfft(x, n=n, axis=axis, norm=norm) def ihfft( @@ -541,11 +532,10 @@ def ihfft( _check_plan(plan) x = _validate_input(x) norm = _swap_direction(norm) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) with _Workers(workers): # Note: overwrite_x is not utilized - result = mkl_fft.rfft(x, n=n, axis=axis, fwd_scale=fsc) + result = mkl_fft.rfft(x, n=n, axis=axis, norm=norm) np.conjugate(result, out=result) return result @@ -628,11 +618,10 @@ def hfftn( x = np.array(x, copy=True) np.conjugate(x, out=x) s, axes = _init_nd_shape_and_axes(x, s, axes, invreal=True) - fsc = _compute_fwd_scale(norm, s, x.shape) with _Workers(workers): # Note: overwrite_x is not utilized - return mkl_fft.irfftn(x, s, axes, fwd_scale=fsc) + return mkl_fft.irfftn(x, s, axes, norm=norm) def ihfftn( @@ -655,11 +644,10 @@ def ihfftn( x = _validate_input(x) norm = _swap_direction(norm) s, axes = _init_nd_shape_and_axes(x, s, axes) - fsc = _compute_fwd_scale(norm, s, x.shape) with _Workers(workers): # Note: overwrite_x is not utilized - result = mkl_fft.rfftn(x, s, axes, fwd_scale=fsc) + result = mkl_fft.rfftn(x, s, axes, norm=norm) np.conjugate(result, out=result) return result diff --git a/mkl_fft/tests/test_fftnd.py b/mkl_fft/tests/test_fftnd.py index f50da97..007f0bd 100644 --- a/mkl_fft/tests/test_fftnd.py +++ b/mkl_fft/tests/test_fftnd.py @@ -152,16 +152,13 @@ def test_matrix6(self): """fftn with tuple, list and ndarray axes and s""" for ar in [self.md, self.mz, self.mf, self.mc]: d = ar.copy() - for norm in ["forward", "backward", "ortho"]: + for norm in [None, "forward", "backward", "ortho"]: for container in [tuple, list, np.array]: axes = container(range(d.ndim)) s = container(d.shape) kwargs = dict(s=s, axes=axes, norm=norm) r_tol, a_tol = _get_rtol_atol(d) - t = mkl_fft.interfaces.numpy_fft.fftn( - mkl_fft.interfaces.numpy_fft.ifftn(d, **kwargs), - **kwargs, - ) + t = mkl_fft.fftn(mkl_fft.ifftn(d, **kwargs), **kwargs) assert_allclose( d, t, @@ -194,7 +191,6 @@ def test_cf_contig(self): assert_allclose(f1, f2, rtol=r_tol, atol=a_tol) def test_rfftn(self): - """Test that rfftn works as expected""" axes = [ (0, 1, 2), (0, 2, 1), @@ -211,80 +207,20 @@ def test_rfftn(self): assert_allclose(rfft_tr, tr_rfft, rtol=r_tol, atol=a_tol) def test_gh64(self): - """Test example from #64""" a = np.arange(12).reshape((3, 4)) x = a.astype(np.cdouble) - # should executed successfully r1 = mkl_fft.fftn(a, s=None, axes=(-2, -1)) r2 = mkl_fft.fftn(x) r_tol, a_tol = _get_rtol_atol(x) assert_allclose(r1, r2, rtol=r_tol, atol=a_tol) -class Test_Scales(TestCase): - def setUp(self): - pass - - def test_scale_1d_vector(self): - X = np.ones(128, dtype="d") - f1 = mkl_fft.fft(X, fwd_scale=0.25) - f2 = mkl_fft.fft(X) - r_tol, a_tol = _get_rtol_atol(X) - assert_allclose(4 * f1, f2, rtol=r_tol, atol=a_tol) - - X1 = mkl_fft.ifft(f1, fwd_scale=0.25) - assert_allclose(X, X1, rtol=r_tol, atol=a_tol) - - f3 = mkl_fft.rfft(X, fwd_scale=0.5) - X2 = mkl_fft.irfft(f3, fwd_scale=0.5) - assert_allclose(X, X2, rtol=r_tol, atol=a_tol) - - def test_scale_1d_array(self): - X = np.ones( - ( - 8, - 4, - 4, - ), - dtype="d", - ) - f1 = mkl_fft.fft(X, axis=1, fwd_scale=0.25) - f2 = mkl_fft.fft(X, axis=1) - r_tol, a_tol = _get_rtol_atol(X) - assert_allclose(4 * f1, f2, rtol=r_tol, atol=a_tol) - - X1 = mkl_fft.ifft(f1, axis=1, fwd_scale=0.25) - assert_allclose(X, X1, rtol=r_tol, atol=a_tol) - - f3 = mkl_fft.rfft(X, axis=0, fwd_scale=0.5) - X2 = mkl_fft.irfft(f3, axis=0, fwd_scale=0.5) - assert_allclose(X, X2, rtol=r_tol, atol=a_tol) - - def test_scale_nd(self): - X = np.empty((2, 4, 8, 16), dtype="d") - X.flat[:] = np.cbrt(np.arange(0, X.size, dtype=X.dtype)) - f = mkl_fft.fftn(X) - f_scale = mkl_fft.fftn(X, fwd_scale=0.2) - - r_tol, a_tol = _get_rtol_atol(X) - assert_allclose(f, 5 * f_scale, rtol=r_tol, atol=a_tol) - - def test_scale_nd_axes(self): - X = np.empty((4, 2, 16, 8), dtype="d") - X.flat[:] = np.cbrt(np.arange(X.size, dtype=X.dtype)) - f = mkl_fft.fftn(X, axes=(0, 1, 2, 3)) - f_scale = mkl_fft.fftn(X, axes=(0, 1, 2, 3), fwd_scale=0.2) - - r_tol, a_tol = _get_rtol_atol(X) - assert_allclose(f, 5 * f_scale, rtol=r_tol, atol=a_tol) - - def test_gh109(): b_int = np.array([[5, 7, 6, 5], [4, 6, 4, 8], [9, 3, 7, 5]], dtype=np.int64) b = np.asarray(b_int, dtype=np.float32) - r1 = mkl_fft.fftn(b, s=None, axes=(0,), fwd_scale=1 / 3) - r2 = mkl_fft.fftn(b_int, s=None, axes=(0,), fwd_scale=1 / 3) + r1 = mkl_fft.fftn(b, s=None, axes=(0,), norm="ortho") + r2 = mkl_fft.fftn(b_int, s=None, axes=(0,), norm="ortho") rtol, atol = _get_rtol_atol(b) assert_allclose(r1, r2, rtol=rtol, atol=atol)