From 3f9167ba04afd1e6eb9241c5599afacbd1e770d8 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:03:50 +1200 Subject: [PATCH] Use np.prod instead of np.product Remove usage of `np.product` that was deprecated in numpy 1.25.0, see https://github.com/numpy/numpy/pull/23314. --- xbatcher/generators.py | 2 +- xbatcher/testing.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/xbatcher/generators.py b/xbatcher/generators.py index 58799ba..f1f4a78 100644 --- a/xbatcher/generators.py +++ b/xbatcher/generators.py @@ -192,7 +192,7 @@ def _gen_empty_batch_selectors(self) -> BatchSelectorSet: Create an empty batch selector set that can be populated by appending patches to each batch. """ - n_batches = np.product(list(self._n_batches_per_dim.values())) + n_batches = np.prod(list(self._n_batches_per_dim.values())) return {k: [] for k in range(n_batches)} def _gen_patch_numbers(self, ds: Union[xr.DataArray, xr.Dataset]): diff --git a/xbatcher/testing.py b/xbatcher/testing.py index 66546ef..36de58f 100644 --- a/xbatcher/testing.py +++ b/xbatcher/testing.py @@ -109,9 +109,9 @@ def _get_sample_length( else: batch_concat_dims = [] return int( - np.product(list(non_specified_ds_dims.values())) - * np.product(list(non_input_batch_dims.values())) - * np.product(batch_concat_dims) + np.prod(list(non_specified_ds_dims.values())) + * np.prod(list(non_input_batch_dims.values())) + * np.prod(batch_concat_dims) ) @@ -209,7 +209,7 @@ def _get_nbatches_from_input_dims(generator: BatchGenerator) -> int: s : int Number of batches expected given ``input_dims`` and ``input_overlap``. """ - nbatches_from_input_dims = np.product( + nbatches_from_input_dims = np.prod( [ generator.ds.sizes[dim] // length for dim, length in generator.input_dims.items() @@ -218,7 +218,7 @@ def _get_nbatches_from_input_dims(generator: BatchGenerator) -> int: ] ) if generator.input_overlap: - nbatches_from_input_overlap = np.product( + nbatches_from_input_overlap = np.prod( [ (generator.ds.sizes[dim] - overlap) // (generator.input_dims[dim] - overlap) @@ -242,13 +242,13 @@ def validate_generator_length(generator: BatchGenerator) -> None: """ non_input_batch_dims = _get_non_input_batch_dims(generator) duplicate_batch_dims = _get_duplicate_batch_dims(generator) - nbatches_from_unique_batch_dims = np.product( + nbatches_from_unique_batch_dims = np.prod( [ generator.ds.sizes[dim] // length for dim, length in non_input_batch_dims.items() ] ) - nbatches_from_duplicate_batch_dims = np.product( + nbatches_from_duplicate_batch_dims = np.prod( [ generator.ds.sizes[dim] // length for dim, length in duplicate_batch_dims.items()