Skip to content

Commit

Permalink
Ref: Add Shape.reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
holl- committed Jan 20, 2025
1 parent 144aae4 commit 8b51253
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions phiml/math/_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,10 @@ def non_channel(self):
def non_primal(self):
return self if self.dim_type not in PRIMAL_TYPES else EMPTY_SHAPE

@property
def reversed(self):
return self

def __repr__(self):
if self.slice_names:
items_str = ",".join(self.slice_names)
Expand Down Expand Up @@ -1357,6 +1361,10 @@ def non_channel(self):
def non_primal(self):
return self if self.dim_type not in PRIMAL_TYPES else EMPTY_SHAPE

@property
def reversed(self):
return PureShape(self.dim_type, {k: v for k, v in reversed(self.dims.items())})

def __repr__(self):
strings = [repr(dim)[1:-1] for dim in self.dims.values()]
return '(' + ', '.join(strings) + ')'
Expand Down Expand Up @@ -1787,6 +1795,11 @@ def non_channel(self):
dims = {n: dim for n, dim in self.dims.items() if dim.dim_type != CHANNEL_DIM}
return MixedShape(self.batch, self.dual, self.instance, self.spatial, EMPTY_SHAPE, dims) if dims else EMPTY_SHAPE

@property
def reversed(self):
dims = {k: v for k, v in reversed(self.dims.items())}
return MixedShape(self.batch, self.dual, self.instance, self.spatial, self.channel, dims)

def __repr__(self):
return '(' + ', '.join([repr(dim)[1:-1] for dim in self.dims.values()]) + ')'

Expand Down

0 comments on commit 8b51253

Please sign in to comment.