Skip to content

Commit

Permalink
add unary - for MultisetExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
HighDiceRoller committed Dec 21, 2023
1 parent 46ecaae commit ad309f1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/icepool/expression/multiset_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MultisetExpression(ABC, Generic[T_contra]):
| `divide_counts`, `//` | `count // n` |
| `keep_counts` | `count if count >= n else 0` |
| unary `+` | same as `keep_counts(0)` |
| unary `-` | reverses the sign of all counts |
| `unique` | `min(count, n)` |
| `keep_outcomes` | `count if outcome in t else 0` |
| `drop_outcomes` | `count if outcome not in t else 0` |
Expand Down Expand Up @@ -471,6 +472,9 @@ def divide_counts(self, constant: int,
def __pos__(self) -> 'MultisetExpression[T_contra]':
return icepool.expression.FilterCountsExpression(self, 0)

def __neg__(self) -> 'MultisetExpression[T_contra]':
return icepool.expression.MultiplyCountsExpression(self, -1)

def keep_counts(self, min_count: int) -> 'MultisetExpression[T_contra]':
"""Counts less than `min_count` are treated as zero.
Expand Down

0 comments on commit ad309f1

Please sign in to comment.