From d6e600cb1942a90efc73cd8b7d16ad0bffccaeb3 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Fri, 11 Aug 2023 10:12:55 -0500 Subject: [PATCH 1/2] DOFArray: support untaggable arrays in setstate --- meshmode/dof_array.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/meshmode/dof_array.py b/meshmode/dof_array.py index bdcebdc7d..a01c861aa 100644 --- a/meshmode/dof_array.py +++ b/meshmode/dof_array.py @@ -333,7 +333,12 @@ def __setstate__(self, state): assert len(axes_tags[idx]) == ary.ndim assert isinstance(axes_tags[idx], list) - d = actx.from_numpy(ary)._with_new_tags(tags[idx]) + try: + d = actx.from_numpy(ary)._with_new_tags(tags[idx]) + except AttributeError: + # 'actx.from_numpy' might return an array that does not have + # '_with_new_tags' (e.g., np.ndarray). + d = actx.from_numpy(ary) for ida, ax in enumerate(axes_tags[idx]): d = actx.tag_axis(ida, ax, d) From 0c04f0e5b21cee7ced329eb8c4fd29f6e347e02e Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Fri, 18 Aug 2023 14:08:22 -0500 Subject: [PATCH 2/2] simplify code --- meshmode/dof_array.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/meshmode/dof_array.py b/meshmode/dof_array.py index a01c861aa..da2471100 100644 --- a/meshmode/dof_array.py +++ b/meshmode/dof_array.py @@ -333,12 +333,14 @@ def __setstate__(self, state): assert len(axes_tags[idx]) == ary.ndim assert isinstance(axes_tags[idx], list) + d = actx.from_numpy(ary) + try: - d = actx.from_numpy(ary)._with_new_tags(tags[idx]) + d = d._with_new_tags(tags[idx]) except AttributeError: # 'actx.from_numpy' might return an array that does not have # '_with_new_tags' (e.g., np.ndarray). - d = actx.from_numpy(ary) + pass for ida, ax in enumerate(axes_tags[idx]): d = actx.tag_axis(ida, ax, d)