Skip to content

Commit

Permalink
[field,geom] Optimize Field.shape getter
Browse files Browse the repository at this point in the history
  • Loading branch information
holl- committed Oct 17, 2024
1 parent b639f48 commit b30ffe4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion phi/field/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def shape(self) -> Shape:
* The batch dimensions match the batch dimensions of this Field
* The channel dimensions match the channels of this Field
"""
if self.is_staggered and self.is_grid:
if self.is_grid and '~vector' in self._values.shape:
return batch(self._geometry) & self.resolution & non_dual(self._values).without(self.resolution) & self._geometry.shape['vector']
set_shape = self._geometry.sets[self.sampled_at]
return batch(self._geometry) & (channel(self._geometry) - 'vector') & set_shape & self._values
Expand Down
5 changes: 3 additions & 2 deletions phi/geom/_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(self, resolution: Shape = None, bounds: BaseBox = None, **resolutio
self._resolution = resolution.only(bounds.vector.item_names, reorder=True) # reorder only
self._bounds = bounds
self._shape = self._resolution & bounds.shape.non_spatial
staggered_shapes = [self._shape.spatial.with_dim_size(dim, self._shape.get_size(dim) + 1) for dim in self.vector.item_names]
self._face_shape = shape_stack(dual(vector=self.vector.item_names), *staggered_shapes)

@property
def resolution(self):
Expand Down Expand Up @@ -87,8 +89,7 @@ def face_areas(self) -> Tensor:

@property
def face_shape(self) -> Shape:
shapes = [self._shape.spatial.with_dim_size(dim, self._shape.get_size(dim) + 1) for dim in self.vector.item_names]
return shape_stack(dual(vector=self.vector.item_names), *shapes)
return self._face_shape

def interior(self) -> 'Geometry':
raise GeometryException("Regular grid does not have an interior")
Expand Down

0 comments on commit b30ffe4

Please sign in to comment.