Skip to content

Commit 09537f4

Browse files
author
Flax Authors
committed
Merge pull request #5084 from samanklesaria:variable_eq
PiperOrigin-RevId: 833483732
2 parents b7e66b7 + 1d2a672 commit 09537f4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

flax/nnx/variablelib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,11 @@ def __contains__(self, item) -> bool:
17101710
__rxor__ = _variable_operator('__rxor__')
17111711
__ror__ = _variable_operator('__ror__')
17121712

1713+
def __eq__(self, other) -> bool:
1714+
if isinstance(other, Variable):
1715+
other = other.value
1716+
return self.value.__eq__(other) # type: ignore
1717+
17131718
def __iadd__(self: V, other) -> V:
17141719
raise NotImplementedError(
17151720
'In-place operations are no longer supported for Variable.\n'

tests/nnx/variable_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_binary_ops(self):
8989
result = v1 + v2
9090

9191
self.assertEqual(result, 5)
92+
self.assertFalse(v1 == v2)
9293

9394
v1[...] += v2
9495

0 commit comments

Comments
 (0)