10000 ENH: add `norm=forward,backward` to numpy.fft functions (#16476) · numpy/numpy@0862be9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0862be9

Browse files
Chris Vavaliarisleofang
andauthored
ENH: add norm=forward,backward to numpy.fft functions (#16476)
The kwarg option norm=inverse leads to scaling of the transforms inverse (opposite) to that of the default option norm=None; i.e. the forward transform is normalized with 1/n whereas the backward one with 1. The fft routines and their tests have been modified to reflect the changes; all tests have been passed successfully. Closes #16126 * modified _unitary, fft & ifft and their tests; tests passed * modified rfft & irfft and their tests; tests passed * modified hfft & ihfft and all tests; all modifications are now done * correction in ihfft; all 79 fft tests passed successfully * undo unnecessary docstrings changes made in my previous commits * use norm=forward kwarg value name * Update numpy/fft/__init__.py Co-authored-by: Leo Fang <leofang@bnl.gov> * add code review suggestions Co-authored-by: Leo Fang <leofang@bnl.gov> * add default norm=None alias norm=backward * streamline private normalization functions * modify hermitian FFTs * add review suggestions Co-authored-by: Leo Fang <leofang@bnl.gov> * add review suggestions v2 (dict as module const) * make review suggestions v3 * Apply suggestions from code review Co-authored-by: Leo Fang <leofang@bnl.gov>
1 parent 0ce6da0 commit 0862be9

File tree

4 files changed

+268
-106
lines changed

4 files changed

+268
-106
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
``norm=backward``, ``forward`` keyword options for ``numpy.fft`` functions
2+
--------------------------------------------------------------------------
3+
The keyword argument option ``norm=backward`` is added as an alias for ``None``
4+
and acts as the default option; using it has the direct transforms unscaled
5+
and the inverse transforms scaled by ``1/n``.
6+
7+
Using the new keyword argument option ``norm=forward`` has the direct
8+
transforms scaled by ``1/n`` and the inverse transforms unscaled (i.e. exactly
9+
opposite to the default option ``norm=backward``).

numpy/fft/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,17 @@
128128
Normalization
129129
-------------
130130
131-
The default normalization has the direct transforms unscaled and the inverse
132-
transforms are scaled by :math:`1/n`. It is possible to obtain unitary
133-
transforms by setting the keyword argument ``norm`` to ``"ortho"`` (default is
134-
`None`) so that both direct and inverse transforms will be scaled by
135-
:math:`1/\\sqrt{n}`.
131+
The argument ``norm`` indicates which direction of the pair of direct/inverse
132+
transforms is scaled and with what normalization factor.
133+
The default normalization (``"backward"``) has the direct (forward) transforms
134+
unscaled and the inverse (backward) transforms scaled by :math:`1/n`. It is
135+
possible to obtain unitary transforms by setting the keyword argument ``norm``
136+
to ``"ortho"`` so that both direct and inverse transforms are scaled by
137+
:math:`1/\\sqrt{n}`. Finally, setting the keyword argument ``norm`` to
138+
``"forward"`` has the direct transforms scaled by :math:`1/n` and the inverse
139+
transforms unscaled (i.e. exactly opposite to the default ``"backward"``).
140+
`None` is an alias of the default option ``"backward"`` for backward
141+
compatibility.
136142
137143
Real and Hermitian transforms
138144
-----------------------------

0 commit comments

Comments
 (0)
0