Skip to content

Commit

Permalink
make failed reshape message less opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Sep 28, 2021
1 parent 7813e53 commit 8f064ea
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions arraycontext/container/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,16 @@ def _flatten(subary: ArrayOrContainerT) -> None:
except ValueError as exc:
# NOTE: we can't do much if the array context fails to ravel,
# since it is the one responsible for the actual memory layout
raise NotImplementedError("'flatten' requires advanced reshaping "
"functionality that is not implemented in the array "
f"context '{type(actx).__name__}'") from exc
if hasattr(subary, "strides"):
strides_msg = f"and strides {subary.strides}"
else:
strides_msg = ""

raise NotImplementedError(
f"'{type(actx).__name__}.np.ravel' failed to reshape "
f"an array with shape {subary.shape}{strides_msg}. "
"This functionality needs to be implemented by the "
"array context.") from exc

result.append(flat_subary)
else:
Expand Down Expand Up @@ -577,9 +584,11 @@ def _unflatten(template_subary: ArrayOrContainerT) -> ArrayOrContainerT:
except ValueError as exc:
# NOTE: we can't do much if the array context fails to reshape,
# since it is the one responsible for the actual memory layout
raise NotImplementedError("'unflatten' requires advanced reshaping "
"functionality that is not implemented in the array "
f"context '{type(actx).__name__}'") from exc
raise NotImplementedError(
f"'{type(actx).__name__}.np.reshape' failed to reshape "
f"the flat array into shape {template_subary.shape}. "
"This functionality needs to be implemented by the "
"array context.") from exc

if hasattr(template_subary, "strides"):
if template_subary.strides != subary.strides:
Expand Down

0 comments on commit 8f064ea

Please sign in to comment.