-
Notifications
You must be signed in to change notification settings - Fork 284
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
Make cube.exponentiate lazy #1846
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# (C) British Crown Copyright 2015, 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/>. | ||
"""Unit tests for the :func:`iris.analysis.maths.exponentiate` function.""" | ||
|
||
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 | ||
from iris.tests.stock import simple_2d | ||
|
||
from biggus import NumpyArrayAdapter | ||
import iris | ||
from iris.analysis.maths import exponentiate | ||
import numpy as np | ||
|
||
|
||
class Test_exponentiate(tests.IrisTest): | ||
def setUp(self): | ||
self.cube = simple_2d(with_bounds=False) | ||
self.exponent = np.float32(2) | ||
|
||
def test_basic(self): | ||
expected = self.cube.data ** self.exponent | ||
result = exponentiate(self.cube, self.exponent) | ||
self.assertArrayEqual(result.data, expected) | ||
|
||
def test_masked(self): | ||
cube = self.cube.copy() | ||
mask = cube.data % 3 == 0 | ||
masked_data = np.ma.masked_array(cube.data, mask) | ||
cube.data = masked_data | ||
expected = masked_data ** 2 | ||
result = exponentiate(cube, self.exponent) | ||
self.assertMaskedArrayEqual(result.data, expected) | ||
|
||
def test_lazy_data__inplace(self): | ||
# Confirm that the cube's lazy data is preserved through an operation | ||
# that is not in-place. | ||
cube = self.cube.copy() | ||
cube.lazy_data(array=NumpyArrayAdapter(cube.data)) | ||
expected = cube.copy().data ** self.exponent | ||
exponentiate(cube, self.exponent, in_place=True) | ||
self.assertTrue(cube.has_lazy_data()) | ||
self.assertArrayAlmostEqual(cube.data, expected) | ||
|
||
def test_lazy_data__not_inplace(self): | ||
# Confirm that the cube's lazy data is preserved through an | ||
# in-place operation. | ||
cube = self.cube.copy() | ||
cube.lazy_data(array=NumpyArrayAdapter(cube.data)) | ||
expected = cube.copy().data ** self.exponent | ||
result = exponentiate(cube, self.exponent, in_place=False) | ||
self.assertTrue(result.has_lazy_data()) | ||
self.assertArrayEqual(result.data, expected) | ||
|
||
def test_exponentiate__preloaded_data__inplace(self): | ||
# Confirm that the cube's data is lazy after an in-place operation and | ||
# after pre-loading the data. | ||
cube = self.cube.copy() | ||
cube.lazy_data(array=NumpyArrayAdapter(cube.data)) | ||
expected = cube.data ** self.exponent | ||
exponentiate(cube, self.exponent, in_place=True) | ||
self.assertTrue(cube.has_lazy_data()) | ||
self.assertArrayAlmostEqual(cube.data, expected) | ||
|
||
def test_exponentiate__preloaded_data__not_inplace(self): | ||
# Confirm that the cube's data is lazy after an operation that is not | ||
# in-place and after pre-loading the data. | ||
cube = self.cube.copy() | ||
cube.lazy_data(array=NumpyArrayAdapter(cube.data)) | ||
expected = cube.data ** self.exponent | ||
result = exponentiate(cube, self.exponent, in_place=False) | ||
self.assertTrue(result.has_lazy_data()) | ||
self.assertArrayAlmostEqual(result.data, expected) | ||
|
||
|
||
if __name__ == "__main__": | ||
tests.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If the license header is the only problem, we might be ok after all.
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.
That is far from being our only problem I suspect... Is it really complaining about the license header??
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.
So far, but the tests didn't complete, so...