Skip to content

Commit

Permalink
Use np.prod instead of np.product
Browse files Browse the repository at this point in the history
Remove usage of `np.product` that was deprecated in numpy 1.25.0, see numpy/numpy#23314.
  • Loading branch information
weiji14 committed Jul 4, 2023
1 parent 43931be commit 3f9167b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion xbatcher/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
14 changes: 7 additions & 7 deletions xbatcher/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)


Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 3f9167b

Please sign in to comment.