diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b8976..7bd7e4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Enabled support of Python 3.13 [gh-164](https://github.com/IntelPython/mkl_fft/pull/164) ### Changed +* Replaced `fwd_scale` parameter with `norm` in `mkl_fft` [gh-189](https://github.com/IntelPython/mkl_fft/pull/189) ### Fixed diff --git a/README.md b/README.md index 776f307..ddbb389 100644 --- a/README.md +++ b/README.md @@ -51,21 +51,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, overwrite_x=False, fwd_scale=1.0, out=None)` - 1D FFT, similar to `scipy.fft.fft` +`fft(x, n=None, axis=-1, overwrite_x=False, norm=None, out=None)` - 1D FFT, similar to `scipy.fft.fft` -`fft2(x, s=None, axes=(-2, -1), overwrite_x=False, fwd_scale=1.0, out=None)` - 2D FFT, similar to `scipy.fft.fft2` +`fft2(x, s=None, axes=(-2, -1), overwrite_x=False, norm=None, out=None)` - 2D FFT, similar to `scipy.fft.fft2` -`fftn(x, s=None, axes=None, overwrite_x=False, fwd_scale=1.0, out=None)` - ND FFT, similar to `scipy.fft.fftn` +`fftn(x, s=None, axes=None, overwrite_x=False, norm=None, out=None)` - ND FFT, similar to `scipy.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 8a6189e..4a1f1fc 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 @@ -299,7 +295,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) @@ -335,7 +331,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 92d0d53..c0d2756 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,7 +50,8 @@ ] -def fft(x, n=None, axis=-1, out=None, overwrite_x=False, fwd_scale=1.0): +def fft(x, n=None, axis=-1, norm=None, out=None, overwrite_x=False): + fsc = _compute_fwd_scale(norm, n, x.shape[axis]) return _c2c_fft1d_impl( x, n=n, @@ -53,11 +59,12 @@ def fft(x, n=None, axis=-1, out=None, overwrite_x=False, fwd_scale=1.0): out=out, overwrite_x=overwrite_x, direction=+1, - fsc=fwd_scale, + fsc=fsc, ) -def ifft(x, n=None, axis=-1, out=None, overwrite_x=False, fwd_scale=1.0): +def ifft(x, n=None, axis=-1, norm=None, out=None, overwrite_x=False): + fsc = _compute_fwd_scale(norm, n, x.shape[axis]) return _c2c_fft1d_impl( x, n=n, @@ -65,23 +72,34 @@ def ifft(x, n=None, axis=-1, out=None, overwrite_x=False, fwd_scale=1.0): out=out, overwrite_x=overwrite_x, direction=-1, - fsc=fwd_scale, + fsc=fsc, ) -def fft2(x, s=None, axes=(-2, -1), out=None, overwrite_x=False, fwd_scale=1.0): +def fft2(x, s=None, axes=(-2, -1), norm=None, out=None, overwrite_x=False): return fftn( - x, s=s, axes=axes, out=out, overwrite_x=overwrite_x, fwd_scale=fwd_scale + x, + s=s, + axes=axes, + norm=norm, + out=out, + overwrite_x=overwrite_x, ) -def ifft2(x, s=None, axes=(-2, -1), out=None, overwrite_x=False, fwd_scale=1.0): +def ifft2(x, s=None, axes=(-2, -1), norm=None, out=None, overwrite_x=False): return ifftn( - x, s=s, axes=axes, out=out, overwrite_x=overwrite_x, fwd_scale=fwd_scale + x, + s=s, + axes=axes, + norm=norm, + out=out, + overwrite_x=overwrite_x, ) -def fftn(x, s=None, axes=None, out=None, overwrite_x=False, fwd_scale=1.0): +def fftn(x, s=None, axes=None, norm=None, out=None, overwrite_x=False): + fsc = _compute_fwd_scale(norm, s, x.shape) return _c2c_fftnd_impl( x, s=s, @@ -89,11 +107,12 @@ def fftn(x, s=None, axes=None, out=None, overwrite_x=False, fwd_scale=1.0): out=out, overwrite_x=overwrite_x, direction=+1, - fsc=fwd_scale, + fsc=fsc, ) -def ifftn(x, s=None, axes=None, out=None, overwrite_x=False, fwd_scale=1.0): +def ifftn(x, s=None, axes=None, norm=None, out=None, overwrite_x=False): + fsc = _compute_fwd_scale(norm, s, x.shape) return _c2c_fftnd_impl( x, s=s, @@ -101,29 +120,33 @@ def ifftn(x, s=None, axes=None, out=None, overwrite_x=False, fwd_scale=1.0): out=out, overwrite_x=overwrite_x, direction=-1, - fsc=fwd_scale, + fsc=fsc, ) -def rfft(x, n=None, axis=-1, out=None, fwd_scale=1.0): - 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, out=None, fwd_scale=1.0): - 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), out=None, fwd_scale=1.0): - 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), out=None, fwd_scale=1.0): - 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, out=None, fwd_scale=1.0): - 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, out=None, fwd_scale=1.0): - 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..d83fe0b 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,8 @@ 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 +133,8 @@ 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 +167,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 +182,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 +198,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 +212,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 +249,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 +267,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 +285,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 +301,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 78b7dc3..405fe37 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__ = [ @@ -223,11 +223,10 @@ def fft( """ _check_plan(plan) x = _validate_input(x) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) with _Workers(workers): return mkl_fft.fft( - x, n=n, axis=axis, overwrite_x=overwrite_x, fwd_scale=fsc + x, n=n, axis=axis, overwrite_x=overwrite_x, norm=norm ) @@ -242,11 +241,10 @@ def ifft( """ _check_plan(plan) x = _validate_input(x) - fsc = _compute_fwd_scale(norm, n, x.shape[axis]) with _Workers(workers): return mkl_fft.ifft( - x, n=n, axis=axis, overwrite_x=overwrite_x, fwd_scale=fsc + x, n=n, axis=axis, overwrite_x=overwrite_x, norm=norm ) @@ -323,11 +321,10 @@ def fftn( _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): return mkl_fft.fftn( - x, s=s, axes=axes, overwrite_x=overwrite_x, fwd_scale=fsc + x, s=s, axes=axes, overwrite_x=overwrite_x, norm=norm ) @@ -350,11 +347,10 @@ def ifftn( _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): return mkl_fft.ifftn( - x, s=s, axes=axes, overwrite_x=overwrite_x, fwd_scale=fsc + x, s=s, axes=axes, overwrite_x=overwrite_x, norm=norm ) @@ -369,11 +365,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( @@ -387,11 +382,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( @@ -467,11 +461,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( @@ -493,11 +486,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( @@ -515,11 +507,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( @@ -534,11 +525,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 @@ -621,11 +611,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( @@ -648,11 +637,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 ef54f1a..11f65c6 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,82 +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,), overwrite_x=False, fwd_scale=1 / 3) - r2 = mkl_fft.fftn( - b_int, s=None, axes=(0,), overwrite_x=False, fwd_scale=1 / 3 - ) + r1 = mkl_fft.fftn(b, s=None, axes=(0,), overwrite_x=False, norm="ortho") + r2 = mkl_fft.fftn(b_int, s=None, axes=(0,), overwrite_x=False, norm="ortho") rtol, atol = _get_rtol_atol(b) assert_allclose(r1, r2, rtol=rtol, atol=atol)