Skip to content
Snippets Groups Projects
Unverified Commit 82a84595 authored by Alexandru Fikl's avatar Alexandru Fikl
Browse files

make failed reshape message less opaque

parent 8fb7d285
No related branches found
No related tags found
No related merge requests found
...@@ -530,9 +530,16 @@ def flatten(ary: ArrayOrContainerT, actx: ArrayContext) -> Any: ...@@ -530,9 +530,16 @@ def flatten(ary: ArrayOrContainerT, actx: ArrayContext) -> Any:
except ValueError as exc: except ValueError as exc:
# NOTE: we can't do much if the array context fails to ravel, # NOTE: we can't do much if the array context fails to ravel,
# since it is the one responsible for the actual memory layout # since it is the one responsible for the actual memory layout
raise NotImplementedError("'flatten' requires advanced reshaping " if hasattr(subary, "strides"):
"functionality that is not implemented in the array " strides_msg = f"and strides {subary.strides}"
f"context '{type(actx).__name__}'") from exc 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) result.append(flat_subary)
else: else:
...@@ -577,9 +584,11 @@ def unflatten( ...@@ -577,9 +584,11 @@ def unflatten(
except ValueError as exc: except ValueError as exc:
# NOTE: we can't do much if the array context fails to reshape, # NOTE: we can't do much if the array context fails to reshape,
# since it is the one responsible for the actual memory layout # since it is the one responsible for the actual memory layout
raise NotImplementedError("'unflatten' requires advanced reshaping " raise NotImplementedError(
"functionality that is not implemented in the array " f"'{type(actx).__name__}.np.reshape' failed to reshape "
f"context '{type(actx).__name__}'") from exc 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 hasattr(template_subary, "strides"):
if template_subary.strides != subary.strides: if template_subary.strides != subary.strides:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment