Repository navigation
Parameterize and consolidate FFT tests - #2118
Conversation
|
When you have a chance, could you please take a look at this, @mrocklin? 😄 Should make things a little cleaner and more maintainable in the FFT test suite. |
| assert_eq(da_fft(darr), | ||
| np_fft(nparr)) | ||
| assert_eq(da_fft(darr2, axis=0), | ||
| np_fft(nparr, axis=0)) |
There was a problem hiding this comment.
Should we merge this in with the test below?
There was a problem hiding this comment.
Yep. 😆 Totally overlooked this. Just pushed a fix.
|
This looks great to me |
| assert_eq(ihfft(darr), np.fft.ihfft(nparr)) | ||
| assert_eq(ihfft(darr2, axis=0), np.fft.ihfft(nparr, axis=0)) | ||
| assert_eq(da_fft(darr), | ||
| np_fft(nparr)) |
There was a problem hiding this comment.
Sorry, I meant to say, is it possible to merge this entire test_fft with the test below? Perhaps something like
@pytest.mark.parametrize('axis', [-1, 0])
@pytest.mark.parametrize('n', [0, 5, 13])
@pytest.mark.paramtrize('funcname', ...)
def test_fft(funcname, axis, n):
da_fft = getattr(da.fft, funcname)
np_fft = getattr(np.fft, funcname)
assert_eq(da_fft(darr, n=n, axis=axis),
np_fft(nparr, n=n, axis=axis)There was a problem hiding this comment.
I think part of the test is trying to not always provide all the args though, right? Though I didn't write it. So I could be wrong.
|
I wouldn't worry too much about the previous test suite. I would focus on
what makes the most sense for today.
…On Thu, Mar 23, 2017 at 5:09 PM, jakirkham ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In dask/array/tests/test_fft.py
<#2118 (comment)>:
>
-def test_ihfft():
- assert_eq(ihfft(darr), np.fft.ihfft(nparr))
- assert_eq(ihfft(darr2, axis=0), np.fft.ihfft(nparr, axis=0))
+ assert_eq(da_fft(darr),
+ np_fft(nparr))
I think part of the test is trying to not always provide all the args
though, right? Though I didn't write it. So I could be wrong.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2118 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszBHGtGk0pCD8NvEadnBaFGjI6NDbks5rot-ngaJpZM4MnNkL>
.
|
|
In that case, I'd probably just pick one combination each arg/kwarg instead of having multiple and parameterizing over them. It's not clear to me that having so many |
|
How expensive in terms of testing time is it just to blanket everything
like this? This sort of test gives me a great deal of confidence that
things operate well.
…On Thu, Mar 23, 2017 at 5:58 PM, jakirkham ***@***.***> wrote:
In that case, I'd probably just pick one combination each arg/kwarg
instead of having multiple and parameterizing over them. It's not clear to
me that having so many axis values or n values is helpful. If it turns
out these are helpful, they should really be in a different test function
that is descriptive of what they offer instead. For example testing sizes
that have particular relevance in comparison to the array size (i.e. larger
than, smaller than, and equal to).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2118 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASszCdTW6c2Vg_mL1a4HGZEyXnm85nvks5rousPgaJpZM4MnNkL>
.
|
| assert_eq(hfft(darr2, 13, axis=0), np.fft.hfft(nparr, 13, axis=0)) | ||
| assert_eq(hfft(darr2, 12, axis=0), np.fft.hfft(nparr, 12, axis=0)) | ||
|
|
||
| @pytest.mark.parametrize( |
There was a problem hiding this comment.
@jakirkham might as well go whole hog
@pytest.fixture(params=['fft', 'ifft' .....])
def funcname(request):
return request.param
then can just include funcname which will cycle all of these
There was a problem hiding this comment.
Sorry I'm very new to pytest (used nose more). I think I have a vague idea of what this fixture thing is doing and did try to read the docs, but could you please help me understand what is happening with this? Does it just let me delete the parameterize decorator from the tests if I add those 3 lines to this file? Is it doing anything more than that?
There was a problem hiding this comment.
This is similar to parametrizing a single function, but its generic.
so pytest takes a fixture and will create a new test for the matrix of fixtures / paramaters to it (so if you pass 2 fixtures, then you get a cartesian product, not always useful, but sometimes).
so yes it will remove the duplicate code :>
fixtures generally are quite useful (not @mrocklin gen_cluster) and such.
these are like nose setup/teardown contexts, but simpler / better.
There was a problem hiding this comment.
Thanks for the explanation. ATM I'm not clear how many tests will be left. So I won't worry about for now, but may revisit after.
|
Not sure what you are asking, @mrocklin, but the current test time for this module is ~0.5s. Once the N-D FFTs come in it is ~1s. Also what sort of test are you referring too? |
Ah sorry, I should have included this message in the thread above that included this test. function_names = ['fft', 'ifft', 'hfft', 'ihfft', ...]
@pytest.mark.parametrize('axis', [-1, 0])
@pytest.mark.parametrize('n', [0, 5, 13])
@pytest.mark.paramtrize('funcname', function_names)
def test_fft(funcname, axis, n):
da_fft = getattr(da.fft, funcname)
np_fft = getattr(np.fft, funcname)
assert_eq(da_fft(darr, n=n, axis=axis),
np_fft(nparr, n=n, axis=axis)It occurs to me that this test covers all of the test cases except as you mention the possibilities of defaults. I would personally prefer to have such a test than to have a bunch of small tests. I agree that this can cause some parameter blowup, but if it's fast (and I think that 1s is fast enough) then I think it's better to just have a single comprehensive test like this than to have many small tests that are all individually named. |
|
Generally I suspect that if we disagree on many fine-grained tests and a giant parameterized tests that that disagreement comes from a difference in attention span. This module is called to my attention once every few months and I am expected to verify that everything works or see if something has gone wrong. Poring over a detailed test suite with many fine tests takes a lot of time. Seeing a large parametrized test that covers all possibilities is something that I can look at and understand how it works in a very short amount of time. Concision in test suites is a virtue for long-term maintenance. However concision also shouldn't get in the way of writing more tests. There will always cases that aren't well covered by a comprehensive test, such as the default behavior case that you bring up (what if the user just doesn't provide any keywords? are the defaults set the same). But I think that we should add these only after we've established a comprehensive test, and only add tests that aren't well covered by that comprehensive test. Anyway, that's just my perspective. I'm not sure there is a well established way of going about this at the moment. |
| ] | ||
| ) | ||
| def funcname(request): | ||
| return request.param |
There was a problem hiding this comment.
FWIW I actually disagree with @jreback here. I think that it's way simpler to just set
funcname = ['fft', 'ifft', 'rfft', ...]In this case this has exactly the same effect and uses less technology.
There was a problem hiding this comment.
...but then we need for-loops everywhere. IMHO either we should use the fixture or we should revert the last change.
There was a problem hiding this comment.
...or are you saying as an argument to parametrize?
There was a problem hiding this comment.
Oh, I'm still in favor of fixtures. I would just use parametrize. I don't really care though, both are good.
@pytest.parametrize('funcname', function_names)
def test_foo(funcname)
...Totally happy with both though. I would leave things as is. I'm just pontificating.
There was a problem hiding this comment.
Yep, was just misunderstanding you initially. Have made the change.
|
So it is less a question of whether this can or cannot be more compact for me (or whether that is a good thing). It is more a question of priorities and time. Personally I want to prioritize PR ( #2116 ) and there are always other things (e.g. changes by infrastructure providers at conda-forge). Right now I feel like this is in a healthy place. We have cut 42 lines from this file (~27% reduction). Gone from 16 test functions down to 6 test functions (~62.5% reduction), all of which cover the same (and in some cases more) of the parameter space while having a negligible impact on the test run time. All of this to say we definitely made a marked improvement. While we can always find ways to make it better, we shouldn't let perfect be the enemy of the good. If you agree, let's merge this and get to work on these other problems. |
|
I agree that this is a great improvement. Merging. |
|
Thanks @mrocklin. |
No description provided.