Skip to content

Parameterize and consolidate FFT tests - #2118

Merged
mrocklin merged 8 commits into
dask:masterfrom
jakirkham:param_1d_tests
Mar 24, 2017
Merged

mrocklin merged 8 commits into
dask:masterfrom
jakirkham:param_1d_tests

Conversation

@jakirkham

Copy link
Copy Markdown
Member

No description provided.

@jakirkham

jakirkham commented Mar 23, 2017 •

Copy link
Copy Markdown
Member Author

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.

Comment thread dask/array/tests/test_fft.py Outdated
assert_eq(da_fft(darr),
np_fft(nparr))
assert_eq(da_fft(darr2, axis=0),
np_fft(nparr, axis=0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we merge this in with the test below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep. 😆 Totally overlooked this. Just pushed a fix.

@mrocklin

Copy link
Copy Markdown
Member

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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@mrocklin

mrocklin commented Mar 23, 2017 via email

Copy link
Copy Markdown
Member

@jakirkham

Copy link
Copy Markdown
Member Author

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).

@mrocklin

mrocklin commented Mar 23, 2017 via email

Copy link
Copy Markdown
Member

Comment thread dask/array/tests/test_fft.py Outdated
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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@jakirkham

Copy link
Copy Markdown
Member Author

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?

@mrocklin

Copy link
Copy Markdown
Member

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.

@mrocklin

Copy link
Copy Markdown
Member

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.

Comment thread dask/array/tests/test_fft.py Outdated
]
)
def funcname(request):
return request.param

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

...but then we need for-loops everywhere. IMHO either we should use the fixture or we should revert the last change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

...or are you saying as an argument to parametrize?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, was just misunderstanding you initially. Have made the change.

@jakirkham

jakirkham commented Mar 24, 2017 •

Copy link
Copy Markdown
Member Author

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.

@mrocklin

Copy link
Copy Markdown
Member

I agree that this is a great improvement. Merging.

@mrocklin
mrocklin merged commit 6d99bba into dask:master Mar 24, 2017
@jakirkham
jakirkham deleted the param_1d_tests branch March 24, 2017 18:25
@jakirkham

Copy link
Copy Markdown
Member Author

Thanks @mrocklin.

@sinhrks sinhrks added this to the 0.14.2 milestone May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants