Skip to content

Commit

Permalink
Removal implicit conversion to pg.mutfun.Equals and `pg.mutfun.NotE…
Browse files Browse the repository at this point in the history
…quals`.

Operator `==` and `!=` were called between symbolic objects and `pg.MISSING_VALUE` for partial value check, however, the semantic change from overloading `__eq__` and `__ne__` for `pg.mutfun.Instruction` breaks the premise, causing tests to fail. Therefore, we remove implicit creations of `Eqauls` and `NotEquals` instructions to avoid such collision.

PiperOrigin-RevId: 517021118
  • Loading branch information
daiyip authored and pyglove authors committed Mar 16, 2023
1 parent 40bc014 commit 599fc01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
7 changes: 7 additions & 0 deletions pyglove/ext/mutfun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@

# Basic operators.
from pyglove.ext.mutfun.basic_ops import Operator
from pyglove.ext.mutfun.basic_ops import UnaryOperator
from pyglove.ext.mutfun.basic_ops import Negate
from pyglove.ext.mutfun.basic_ops import BinaryOperator
from pyglove.ext.mutfun.basic_ops import Add
from pyglove.ext.mutfun.basic_ops import Substract
Expand All @@ -114,5 +116,10 @@
from pyglove.ext.mutfun.basic_ops import FloorDivide
from pyglove.ext.mutfun.basic_ops import Mod
from pyglove.ext.mutfun.basic_ops import Power
from pyglove.ext.mutfun.basic_ops import Equals
from pyglove.ext.mutfun.basic_ops import NotEquals
from pyglove.ext.mutfun.basic_ops import GreaterThan
from pyglove.ext.mutfun.basic_ops import LessThan


# pylint: enable=g-bad-import-order
2 changes: 0 additions & 2 deletions pyglove/ext/mutfun/basic_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,4 @@ class LessThan(BinaryOperator):
base.Instruction.__pow__ = lambda self, y: Power(self, y)
base.Instruction.__gt__ = lambda self, y: GreaterThan(self, y)
base.Instruction.__lt__ = lambda self, y: LessThan(self, y)
base.Instruction.__eq__ = lambda self, y: Equals(self, y)
base.Instruction.__ne__ = lambda self, y: NotEquals(self, y)
# pylint: enable=unnecessary-lambda
22 changes: 0 additions & 22 deletions pyglove/ext/mutfun/basic_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,6 @@ def test_evaluate(self):
print(base.python_repr(z))
self.assertFalse(z.evaluate(variables))

def test_operator_overload(self):
self.assertTrue(
pg.eq(base.Var('x') == 1, basic_ops.Equals(base.Var('x'), 1))
)
self.assertTrue(
pg.eq(
base.Var('x') == base.Var('y'),
basic_ops.Equals(base.Var('x'), base.Var('y')),
)
)


class NotEqualsTest(unittest.TestCase):
"""Tests for NotEquals."""
Expand All @@ -350,17 +339,6 @@ def test_evaluate(self):
variables = dict(x=1, y=3)
self.assertFalse(z.evaluate(variables))

def test_operator_overload(self):
self.assertTrue(
pg.eq(base.Var('x') != 1, basic_ops.NotEquals(base.Var('x'), 1))
)
self.assertTrue(
pg.eq(
base.Var('x') != base.Var('y'),
basic_ops.NotEquals(base.Var('x'), base.Var('y')),
)
)


if __name__ == '__main__':
unittest.main()

0 comments on commit 599fc01

Please sign in to comment.