-
Notifications
You must be signed in to change notification settings - Fork 300
Reuse multidim_daskstack in merge + fast um loading. #2423
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
Changes from all commits
d150fe6
975105b
717e7cf
62e25e5
e69c46f
2b9fe09
34f810d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with Iris. If not, see <http://www.gnu.org/licenses/>. | ||
| """Test :meth:`iris._lazy data.is_lazy_data` method.""" | ||
| """Test function :func:`iris._lazy data.is_lazy_data`.""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
| from six.moves import (filter, input, map, range, zip) # noqa | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # (C) British Crown Copyright 2017, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
| # Iris is free software: you can redistribute it and/or modify it under | ||
| # the terms of the GNU Lesser General Public License as published by the | ||
| # Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Iris is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with Iris. If not, see <http://www.gnu.org/licenses/>. | ||
| """Test function :func:`iris._lazy data.multidim_lazy_stack`.""" | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
| from six.moves import (filter, input, map, range, zip) # noqa | ||
|
|
||
| # Import iris.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris.tests as tests | ||
|
|
||
| import numpy as np | ||
| import dask.array as da | ||
|
|
||
| from iris._lazy_data import as_lazy_data, multidim_lazy_stack | ||
|
|
||
|
|
||
| class Test_multidim_lazy_stack(tests.IrisTest): | ||
| def _check(self, stack_shape): | ||
| vals = np.arange(np.prod(stack_shape)).reshape(stack_shape) | ||
| stack = np.empty(stack_shape, 'object') | ||
| # Define the shape of each element in the stack. | ||
| stack_element_shape = (4, 5) | ||
| expected = np.empty(stack_shape + stack_element_shape, | ||
| dtype=int) | ||
| for index, val in np.ndenumerate(vals): | ||
| stack[index] = as_lazy_data(val * np.ones(stack_element_shape)) | ||
|
|
||
| expected[index] = val | ||
| result = multidim_lazy_stack(stack) | ||
| self.assertEqual(result.shape, stack_shape + stack_element_shape) | ||
| self.assertIsInstance(result, da.core.Array) | ||
| self.assertArrayAllClose(result.compute(), expected) | ||
|
|
||
| def test_0d_lazy_stack(self): | ||
| shape = () | ||
| result = self._check(shape) | ||
|
|
||
| def test_1d_lazy_stack(self): | ||
| shape = (2,) | ||
| result = self._check(shape) | ||
|
|
||
| def test_2d_lazy_stack(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any chance of a >2D test?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a bit unnecessary? The 2d test is already testing the recursivity
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, however part of testing is checking edge cases, and I don't know what would happen if I passed a 7D array to it. Evidently we don't need to test all possible dimensionalities (!), but it would be good to test something that's outside of the boundary of logical intent for the functionality being tested. This is just in case an unsafe assumption has been made about how the function will be used; "of course, no-one would ever use this for more than a 2D input".
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a mockist / white-box-y point of view, the existing tests do already cover all 3 code branches. |
||
| shape = (3, 2) | ||
| result = self._check(shape) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| tests.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍