Skip to content

Commit 678cf85

Browse files
oprypintensorflower-gardener
authored andcommitted
Automated Code Change
PiperOrigin-RevId: 852404184
1 parent 739846f commit 678cf85

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

discussion/robust_inverse_graphics/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ class Example:
116116
scene_id: Any | None = None
117117
scene_embedding: Any | None = None
118118

119+
# Directly comparing members of the type `jax.Array` can throw an error:
120+
# "The truth value of an array with more than one element is ambiguous."
121+
# So we bring back an explicit implementation of __eq__ like it was prior to
122+
# Python 3.13 in order work around this possibility.
123+
def __eq__(self, other):
124+
if self is other:
125+
return True
126+
if other.__class__ is self.__class__:
127+
return tuple(
128+
getattr(self, field.name) for field in dataclasses.fields(self)
129+
) == tuple(
130+
getattr(other, field.name) for field in dataclasses.fields(other)
131+
)
132+
return NotImplemented
133+
119134
def fields_with_view_axis(self) -> tree_util.DataclassView['Example']:
120135
"""Returns a view with only fields that typically have the view axis."""
121136
return tree_util.DataclassView(self, _fields_with_view_axis_selector)

0 commit comments

Comments
 (0)