From 40ff988e64e3d717a206dc71c030cbdb3a30e4fe Mon Sep 17 00:00:00 2001 From: Tom Abel Date: Tue, 9 Aug 2022 08:18:04 -0700 Subject: [PATCH 1/4] Update to grid_patch.py to avoid calling units This is to speed up calculations of the grid coordinates x, y, z which also benefits radius calculations and other geometric operations in derived fields. --- yt/data_objects/index_subobjects/grid_patch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yt/data_objects/index_subobjects/grid_patch.py b/yt/data_objects/index_subobjects/grid_patch.py index 596f2c2b33c..02c6ee25967 100644 --- a/yt/data_objects/index_subobjects/grid_patch.py +++ b/yt/data_objects/index_subobjects/grid_patch.py @@ -338,8 +338,8 @@ def select_fcoords(self, dobj): return np.empty((0, 3), dtype="float64") coords = convert_mask_to_indices(mask, self._last_count).astype("float64") coords += 0.5 - coords *= self.dds[None, :] - coords += self.LeftEdge[None, :] + coords *= self.dds.d[None, :] + coords += self.LeftEdge.d[None, :] return coords def select_fwidth(self, dobj): From 87f011c9efdc90c74b9835d55f9d43a743929853 Mon Sep 17 00:00:00 2001 From: Tom Abel Date: Wed, 10 Aug 2022 17:08:25 -0700 Subject: [PATCH 2/4] Add same change to select_fwidth as we did for select_coord to avoid triggering calls to unyt. --- yt/data_objects/index_subobjects/grid_patch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/data_objects/index_subobjects/grid_patch.py b/yt/data_objects/index_subobjects/grid_patch.py index 02c6ee25967..de19f6285bf 100644 --- a/yt/data_objects/index_subobjects/grid_patch.py +++ b/yt/data_objects/index_subobjects/grid_patch.py @@ -348,7 +348,7 @@ def select_fwidth(self, dobj): return np.empty((0, 3), dtype="float64") coords = np.empty((count, 3), dtype="float64") for axis in range(3): - coords[:, axis] = self.dds[axis] + coords[:, axis] = self.dds.d[axis] return coords def select_ires(self, dobj): From 6896ce21e8c2fd191dc7ae42cdd7299749302c57 Mon Sep 17 00:00:00 2001 From: Tom Abel Date: Wed, 10 Aug 2022 17:08:25 -0700 Subject: [PATCH 3/4] Add same change to two more files avoiding extra unit conversions. --- yt/geometry/geometry_handler.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/yt/geometry/geometry_handler.py b/yt/geometry/geometry_handler.py index c10c16bd6de..b8b01b3975c 100644 --- a/yt/geometry/geometry_handler.py +++ b/yt/geometry/geometry_handler.py @@ -327,7 +327,7 @@ def fcoords(self): c = obj.select_fcoords(self.dobj) if c.shape[0] == 0: continue - ci[ind : ind + c.shape[0], :] = c + ci.d[ind : ind + c.shape[0], :] = c ind += c.shape[0] return ci @@ -363,7 +363,8 @@ def fwidth(self): c = obj.select_fwidth(self.dobj) if c.shape[0] == 0: continue - ci[ind : ind + c.shape[0], :] = c + ci.d[ind : ind + c.shape[0], :] = c + ind += c.shape[0] return ci @@ -419,7 +420,7 @@ def fcoords_vertex(self): c = obj.select_fcoords_vertex(self.dobj) if c.shape[0] == 0: continue - ci[ind : ind + c.shape[0], :, :] = c + ci.d[ind : ind + c.shape[0], :, :] = c ind += c.shape[0] return ci From 38f43fd92bd79075067fea3c13707b08bde39d26 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 14 Aug 2022 05:36:34 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- yt/geometry/geometry_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yt/geometry/geometry_handler.py b/yt/geometry/geometry_handler.py index b8b01b3975c..a1f80ec146e 100644 --- a/yt/geometry/geometry_handler.py +++ b/yt/geometry/geometry_handler.py @@ -327,7 +327,7 @@ def fcoords(self): c = obj.select_fcoords(self.dobj) if c.shape[0] == 0: continue - ci.d[ind : ind + c.shape[0], :] = c + ci.d[ind : ind + c.shape[0], :] = c ind += c.shape[0] return ci @@ -363,7 +363,7 @@ def fwidth(self): c = obj.select_fwidth(self.dobj) if c.shape[0] == 0: continue - ci.d[ind : ind + c.shape[0], :] = c + ci.d[ind : ind + c.shape[0], :] = c ind += c.shape[0] return ci