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

Fix mpiarray global_slice Ellipsis check #284

Merged
merged 3 commits into from
Dec 11, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pip-log.txt
.tox
nosetests.xml

# Unit test files
*.tmp_test*
*/perf*

# Translations
*.mo

Expand Down
11 changes: 4 additions & 7 deletions caput/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,18 @@ def _prop(val):
for ii, item in enumerate(val):
if not isinstance(item, type_):
raise CaputConfigError(
"Expected to receive a list with items of type %s, but got "
"'%s' of type '%s' at position %i"
% (type_, item, type(item), ii)
f"Expected to receive a list with items of type {type_!s}, but got "
f"'{item!s}' of type '{type(item)!s}' at position {ii}"
)

if length and len(val) != length:
raise CaputConfigError(
"List expected to be of length %i, but was actually length %i"
% (length, len(val))
f"List expected to be of length {length}, but was actually length {len(val)}"
)

if maxlength and len(val) > maxlength:
raise CaputConfigError(
"Maximum length of list is %i is, but list was actually length %i"
% (maxlength, len(val))
f"Maximum length of list is {maxlength} is, but list was actually length {len(val)}"
)

return val
Expand Down
3 changes: 1 addition & 2 deletions caput/memh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,7 @@ def dataset_common_to_distributed(self, name, distributed_axis=0):

if dset.distributed:
warnings.warn(
"%s is already a distributed dataset, redistribute it along the required axis %d"
% (name, distributed_axis)
f"{name!s} is already a distributed dataset, redistribute it along the required axis {distributed_axis}"
)
dset.redistribute(distributed_axis)
return dset
Expand Down
17 changes: 11 additions & 6 deletions caput/mpiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,14 @@ def _resolve_slice(self, slobj):
slobj = (slobj, Ellipsis)

# Add an ellipsis if length of slice object is too short
if isinstance(slobj, tuple) and len(slobj) < ndim and Ellipsis not in slobj:
slobj = (*slobj, Ellipsis)
if isinstance(slobj, tuple) and len(slobj) < ndim:
# This is a workaround for the more straightforward
# `Ellipsis not in slobj`. If one of the axes is indexed
# by a numpy array, the simpler logic will check each element
# of the array and will fail. Comparing each object directly
# gets around this.
if not any(obj is Ellipsis for obj in slobj):
slobj = (*slobj, Ellipsis)

# Expand an ellipsis
slice_list = []
Expand Down Expand Up @@ -962,7 +968,7 @@ def from_file(
# Check that the axis is valid and wrap to an actual position
if axis < -naxis or axis >= naxis:
raise AxisException(
"Distributed axis %i not in range (%i, %i)" % (axis, -naxis, naxis - 1)
f"Distributed axis {axis} not in range ({-naxis}, {naxis - 1})"
)
axis = naxis + axis if axis < 0 else axis

Expand Down Expand Up @@ -1636,9 +1642,8 @@ def _partition_io(self, skip=False, threshold=1.99):
break
else:
raise RuntimeError(
"Can't identify an IO partition less than %.2f GB in size: "
"shape=%s, distributed axis=%i"
% (threshold, self.global_shape, self.axis)
f"Can't identify an IO partition less than {threshold:.2f} GB in size: "
f"shape={self.global_shape!s}, distributed axis={self.axis}"
)

axis_length = self.global_shape[split_axis]
Expand Down
Loading