8000 Add a norm keyword arg to fft functions by Nodd · Pull Request #3883 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Add a norm keyword arg to fft functions #3883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

Nodd
Copy link
Contributor
@Nodd Nodd commented Oct 8, 2013

This fixes #2142.

8000
n = shape(a)[axis]
unitary = _unitary(norm)
return (_raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftf, _fft_cache) /
(sqrt(n) if unitary else 1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does inserting this divide by 1 do the run time in the norm=None mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know precisely, I just figured that it wasn't a problem since it is done anyway in the ifft case.
Another way to look at it is that divide by 1 is in O(n) while the fft is in O(n log(n)) so it is negligible.
I can set two separate calls to _raw_fft if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with ipython:

In [1]: x = np.random.rand(4096, 4096) + 1j * np.random.rand(4096, 4096)

In [2]: %timeit np.fft.fft(x)
1 loops, best of 3: 649 ms per loop

In [3]: %timeit (np.fft.fft(x) / 1)
1 loops, best of 3: 894 ms per loop

That's a big increase, I'll do separate calls.

@Nodd Nodd force-pushed the fft_norm branch 2 times, most recently from d39dfaf to 60e6659 Compare September 3, 2014 23:36
@@ -275,6 +297,8 @@ def rfft(a, n=None, axis=-1):
axis : int, optional
Axis over which to compute the FFT. If not given, the last axis is
used.
norm : {None, "ortho"}, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably get the ..versionadded thingy (would have to look up the exact syntax myself)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which version then, 1.10 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@seberg
Copy link
Member
seberg commented Sep 5, 2014

Anyway, should be good, and since scipy already has it I don't see why we shouldn't add it. I am still a bit suprised we don't have single precision ffts, or is that typical?

So mostly I would like a test for each of the fft functions. Other then that, looks good.

@Nodd
Copy link
Contributor Author
Nodd commented Sep 5, 2014

Testing all functions is a very good idea, I broke rfft without noticing...

@Nodd
Copy link
Contributor Author
Nodd commented Sep 5, 2014

I added tests for all fft transforms (turns out it was necessary, hum...).

@Nodd Nodd force-pushed the fft_norm branch 2 times, most recently from 8fe77e7 to 440688b Compare September 5, 2014 12:50
@Nodd
Copy link
Contributor Author
Nodd commented Sep 5, 2014

Git rebase is easy to mess up. It should be ok now.

@@ -362,6 +392,9 @@ def irfft(a, n=None, axis=-1):
axis : int, optional
Axis over which to compute the inverse FFT. If not given, the last
axis is used.
norm : {None, "ortho"}, optional
Normalization mode (see `numpy.fft`). Default is None.
.. versionadded:: 1.10.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a blank line above for this to render correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or move it to the beginning after the norm : ... line. Same thing on down. We don't have a standard for this, we should probably have one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I build the doc for the version in my local repo ? With PYTHONPATH I get:

ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if it can be done. I usually install python setup.py install --user. You can just delete it after. Building the docs has some dependencies, which I've forgotten, and you also need to git submodule update for the sphinx extensions. If you haven't tried, then switch to doc and make html.

On where to put the .. versionadded:: for new parameters, I'm leaning towards on the first line of the description. That is more compact, and it is correctly rendered. Now I need to change all the ones I did differently...

@Nodd
Copy link
Contributor Author
Nodd commented Sep 25, 2014

I think this PR is ready to be merged, if there is no additionnal remarks ?

@ewmoore
Copy link
Contributor
ewmoore commented Sep 25, 2014

Probably should be added to the release notes.

@Nodd
Copy link
Contributor Author
Nodd commented Apr 2, 2015

I added a paragraph to the release notes.

@charris
Copy link
Member
charris commented Jun 21, 2015

Rebase in #5992, so closing this.

@charris charris closed this Jun 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a norm keyword arg to fft functions (Trac #1545)
6 participants
0