From 9109363d8df371260eb99efaa83d348d08fb4166 Mon Sep 17 00:00:00 2001 From: Michael Campbell <mtcampbe@illinois.edu> Date: Tue, 28 Jun 2022 15:16:57 -0500 Subject: [PATCH] Add ArrayContext.freeze_thaw --- arraycontext/context.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arraycontext/context.py b/arraycontext/context.py index 74d5863..727e1ba 100644 --- a/arraycontext/context.py +++ b/arraycontext/context.py @@ -269,6 +269,7 @@ class ArrayContext(ABC): .. automethod:: freeze .. automethod:: thaw + .. automethod:: freeze_thaw .. automethod:: tag .. automethod:: tag_axis .. automethod:: compile @@ -369,6 +370,20 @@ class ArrayContext(ABC): See also :func:`arraycontext.thaw`. """ + def freeze_thaw( + self, array: ArrayOrContainerOrScalarT + ) -> ArrayOrContainerOrScalarT: + r"""Evaluate an input array or container to "frozen" data return a new + "thawed" array or container representing the evaluation result that is + ready for use. This is a shortcut for calling :meth:`freeze` and + :meth:`thaw`. + + This method can be useful in array contexts backed by, e.g. + :mod:`pytato`, to force the evaluation of a built-up array expression + (and thereby avoid reevaluations for expressions built on the array). + """ + return self.thaw(self.freeze(array)) + @abstractmethod def tag(self, tags: ToTagSetConvertible, -- GitLab