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

rename argument in unflatten_to_numpy

parent 3e81dd22
No related branches found
No related tags found
No related merge requests found
...@@ -655,25 +655,26 @@ def unflatten_from_numpy( ...@@ -655,25 +655,26 @@ def unflatten_from_numpy(
# NOTE: https://github.com/python/mypy/issues/7057 # NOTE: https://github.com/python/mypy/issues/7057
offset = 0 offset = 0
def _unflatten_from_numpy(subary: ArrayOrContainerT) -> ArrayOrContainerT: def _unflatten_from_numpy(
template_subary: ArrayOrContainerT) -> ArrayOrContainerT:
nonlocal offset nonlocal offset
try: try:
iterable = serialize_container(subary) iterable = serialize_container(template_subary)
except TypeError: except TypeError:
# NOTE: the max is needed to handle device scalars with size == 0 # NOTE: the max is needed to handle device scalars with size == 0
offset += max(1, subary.size) offset += max(1, template_subary.size)
if offset > ary.size: if offset > ary.size:
raise ValueError("'template' and 'ary' sizes do not match") raise ValueError("'template' and 'ary' sizes do not match")
# FIXME: subary can be F-contiguous and ary will always be C-contiguous # FIXME: subary can be F-contiguous and ary will always be C-contiguous
return actx.from_numpy( return actx.from_numpy(
ary[offset - subary.size:offset] ary[offset - template_subary.size:offset]
.astype(subary.dtype, copy=False) .astype(template_subary.dtype, copy=False)
.reshape(subary.shape) .reshape(template_subary.shape)
) )
else: else:
return deserialize_container(subary, [ return deserialize_container(template_subary, [
(key, _unflatten_from_numpy(isubary)) for key, isubary in iterable (key, _unflatten_from_numpy(isubary)) for key, isubary in iterable
]) ])
......
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