Skip to content

Commit 6fa98fc

Browse files
hawkinspGoogle-ML-Automation
authored andcommitted
Use "x is y" rather than "id(x) == id(y)".
The latter involves at least two object constructions. PiperOrigin-RevId: 736878098
1 parent 8fbe3b1 commit 6fa98fc

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

jax/_src/interpreters/mlir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ def __eq__(self, other):
18701870
if self.value.aval != other.value.aval:
18711871
return False
18721872
if self.data is None:
1873-
return id(self) == id(other)
1873+
return self is other
18741874
return self.data == other.data
18751875

18761876

jax/_src/mesh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def __reduce__(self):
286286
def __eq__(self, other):
287287
# This is a performance optimization. Comparing thousands of devices
288288
# can be expensive.
289-
if id(self) == id(other):
289+
if self is other:
290290
return True
291291
if not isinstance(other, Mesh):
292292
return False
@@ -454,7 +454,7 @@ def __hash__(self):
454454
return self._hash
455455

456456
def __eq__(self, other):
457-
if id(self) == id(other):
457+
if self is other:
458458
return True
459459
if not isinstance(other, AbstractMesh):
460460
return False

jax/_src/numpy/scalar_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __hash__(self) -> int:
4040
return hash(self.dtype.type)
4141

4242
def __eq__(self, other: Any) -> bool:
43-
return id(self) == id(other) or self.dtype.type == other
43+
return self is other or self.dtype.type == other
4444

4545
def __ne__(self, other: Any) -> bool:
4646
return not (self == other)

jax/_src/op_shardings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def is_op_sharding_replicated(op: xc.OpSharding | xc.HloSharding) -> bool:
5555

5656
def are_op_shardings_equal(op1: xc.OpSharding | xc.HloSharding,
5757
op2: xc.OpSharding | xc.HloSharding) -> bool:
58-
if id(op1) == id(op2):
58+
if op1 is op2:
5959
return True
6060
if is_op_sharding_replicated(op1) and is_op_sharding_replicated(op2):
6161
return True

0 commit comments

Comments
 (0)