Skip to content
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 slices_over tests go faster #5973

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ This document explains the changes made to Iris for this release
#. `@pp-mo`_ reworked benchmark peak-memory measurement to use the
`tracemalloc <https://docs.python.org/3.12/library/tracemalloc.html>`_
package.
(:pull: `5948`)
(:pull:`5948`)

#. `@pp-mo`_ added a benchmark 'trialrun' sub-command, to quickly test
benchmarks during development. (:pull: `5957`)
benchmarks during development. (:pull:`5957`)

#. `@pp-mo`_ moved several memory-measurement benchmarks from 'on-demand' to
the standard set, in hopes that use of 'tracemalloc' (:pull: `5948`) makes
the standard set, in hopes that use of 'tracemalloc' (:pull:`5948`) makes
the results consistent enough to monitor for performance changes.
(:pull: `5959`)
(:pull:`5959`)

#. `@rcomer`_ made some :meth:`~iris.cube.Cube.slices_over` tests go faster (:pull:`5973`)


.. comment
Expand Down
14 changes: 7 additions & 7 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,10 +1051,10 @@ def test_all_permutations(self):
@tests.skip_data
class Test_slices_over(tests.IrisTest):
trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
def setUp(self):
self.cube = stock.realistic_4d()
self.cube = stock.realistic_4d()[:, :7, :10, :10]
# Define expected iterators for 1D and 2D test cases.
self.exp_iter_1d = range(len(self.cube.coord("model_level_number").points))
self.exp_iter_2d = np.ndindex(6, 70, 1, 1)
self.exp_iter_2d = np.ndindex(6, 7, 1, 1)
# Define maximum number of interactions for particularly long
# (and so time-consuming) iterators.
self.long_iterator_max = 5
Expand Down Expand Up @@ -1090,7 +1090,7 @@ def test_1d_slice_nonexistent_dimension_given(self):
_ = self.cube.slices_over(self.cube.ndim + 1)

def test_2d_slice_coord_given(self):
# Slicing over these two dimensions returns 420 2D cubes, so only check
# Slicing over these two dimensions returns 42 2D cubes, so only check
# cubes up to `self.long_iterator_max` to keep test runtime sensible.
res = self.cube.slices_over(
[self.cube.coord("time"), self.cube.coord("model_level_number")]
Expand All @@ -1109,7 +1109,7 @@ def test_2d_slice_nonexistent_coord_given(self):
)

def test_2d_slice_coord_name_given(self):
# Slicing over these two dimensions returns 420 2D cubes, so only check
# Slicing over these two dimensions returns 42 2D cubes, so only check
# cubes up to `self.long_iterator_max` to keep test runtime sensible.
res = self.cube.slices_over(["time", "model_level_number"])
for ct in range(self.long_iterator_max):
Expand All @@ -1124,7 +1124,7 @@ def test_2d_slice_nonexistent_coord_name_given(self):
_ = self.cube.slices_over(["time", "wibble"])

def test_2d_slice_dimension_given(self):
# Slicing over these two dimensions returns 420 2D cubes, so only check
# Slicing over these two dimensions returns 42 2D cubes, so only check
# cubes up to `self.long_iterator_max` to keep test runtime sensible.
res = self.cube.slices_over([0, 1])
for ct in range(self.long_iterator_max):
Expand All @@ -1150,11 +1150,11 @@ def test_2d_slice_nonexistent_dimension_given(self):
_ = self.cube.slices_over([0, self.cube.ndim + 1])

def test_multidim_slice_coord_given(self):
# Slicing over surface altitude returns 100x100 2D cubes, so only check
# Slicing over surface altitude returns 10x10 2D cubes, so only check
# cubes up to `self.long_iterator_max` to keep test runtime sensible.
res = self.cube.slices_over("surface_altitude")
# Define special ndindex iterator for the different dims sliced over.
nditer = np.ndindex(1, 1, 100, 100)
nditer = np.ndindex(1, 1, 10, 10)
for ct in range(self.long_iterator_max):
indices = list(next(nditer))
# Replace the dimensions not iterated over with spanning slices.
Expand Down
Loading