Skip to content

Commit ffaa1d5

Browse files
[wip] Apply suggestions from code review
Co-authored-by: Filippo Luca Ferretti <[email protected]>
1 parent b7ff488 commit ffaa1d5

File tree

4 files changed

+57
-94
lines changed

4 files changed

+57
-94
lines changed

src/jaxsim/api/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __hash__(self) -> int:
5252
hash(self.state),
5353
HashedNumpyArray.hash_of_array(self.gravity),
5454
hash(self.soft_contacts_params),
55-
hash(tuple(self.time_ns.flatten().tolist())),
55+
HashedNumpyArray.hash_of_array(self.time_ns.flatten()),
5656
)
5757
)
5858

src/jaxsim/parsers/descriptions/joint.py

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -100,52 +100,29 @@ def __eq__(self, other: JointDescription) -> bool:
100100
if not isinstance(other, JointDescription):
101101
return False
102102

103-
if self.name != other.name:
104-
return False
105-
106-
if not np.allclose(self.axis, other.axis):
107-
return False
108-
109-
if not np.allclose(self.pose, other.pose):
110-
return False
111-
112-
if self.jtype != other.jtype:
113-
return False
114-
115-
if self.child != other.child:
116-
return False
117-
118-
if self.parent != other.parent:
119-
return False
120-
121-
if self.index != other.index:
122-
return False
123-
124-
if not np.allclose(self.friction_static, other.friction_static):
125-
return False
126-
127-
if not np.allclose(self.friction_viscous, other.friction_viscous):
128-
return False
129-
130-
if not np.allclose(self.position_limit_damper, other.position_limit_damper):
131-
return False
132-
133-
if not np.allclose(self.position_limit_spring, other.position_limit_spring):
134-
return False
135-
136-
if not np.allclose(self.position_limit, other.position_limit):
137-
return False
138-
139-
if not np.allclose(self.initial_position, other.initial_position):
140-
return False
141-
142-
if not np.allclose(self.motor_inertia, other.motor_inertia):
143-
return False
144-
145-
if not np.allclose(self.motor_viscous_friction, other.motor_viscous_friction):
146-
return False
147-
148-
if not np.allclose(self.motor_gear_ratio, other.motor_gear_ratio):
103+
if not all(
104+
self.name == other.name
105+
and self.jtype == other.jtype
106+
and self.child == other.child
107+
and self.parent == other.parent
108+
and self.index == other.index
109+
and all(
110+
np.allclose(getattr(self, attr), getattr(other, attr))
111+
for attr in [
112+
"axis",
113+
"pose",
114+
"friction_static",
115+
"friction_viscous",
116+
"position_limit_damper",
117+
"position_limit_spring",
118+
"position_limit",
119+
"initial_position",
120+
"motor_inertia",
121+
"motor_viscous_friction",
122+
"motor_gear_ratio",
123+
]
124+
)
125+
):
149126
return False
150127

151128
return True
@@ -163,14 +140,14 @@ def __hash__(self) -> int:
163140
hash(self.child),
164141
hash(self.parent),
165142
hash(int(self.index)) if self.index is not None else 0,
166-
HashedNumpyArray.hash_of_array(np.array(self.friction_static)),
167-
HashedNumpyArray.hash_of_array(np.array(self.friction_viscous)),
168-
HashedNumpyArray.hash_of_array(np.array(self.position_limit_damper)),
169-
HashedNumpyArray.hash_of_array(np.array(self.position_limit_spring)),
170-
HashedNumpyArray.hash_of_array(np.array(self.position_limit)),
143+
HashedNumpyArray.hash_of_array(self.friction_static),
144+
HashedNumpyArray.hash_of_array(self.friction_viscous),
145+
HashedNumpyArray.hash_of_array(self.position_limit_damper),
146+
HashedNumpyArray.hash_of_array(self.position_limit_spring),
147+
HashedNumpyArray.hash_of_array(self.position_limit),
171148
HashedNumpyArray.hash_of_array(self.initial_position),
172-
HashedNumpyArray.hash_of_array(np.array(self.motor_inertia)),
173-
HashedNumpyArray.hash_of_array(np.array(self.motor_viscous_friction)),
174-
HashedNumpyArray.hash_of_array(np.array(self.motor_gear_ratio)),
149+
HashedNumpyArray.hash_of_array(self.motor_inertia),
150+
HashedNumpyArray.hash_of_array(self.motor_viscous_friction),
151+
HashedNumpyArray.hash_of_array(self.motor_gear_ratio),
175152
),
176153
)

src/jaxsim/parsers/descriptions/link.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,21 @@ def __eq__(self, other: LinkDescription) -> bool:
6060
if not isinstance(other, LinkDescription):
6161
return False
6262

63-
if self.name != other.name:
64-
return False
65-
66-
if not np.allclose(self.mass, other.mass):
67-
return False
68-
69-
if not np.allclose(self.inertia, other.inertia):
70-
return False
71-
72-
if self.index != other.index:
73-
return False
74-
75-
if not np.allclose(self.pose, other.pose):
76-
return False
77-
78-
if self.children != other.children:
79-
return False
80-
81-
# Here only using the name to prevent circular recursion
82-
if self.parent is not None and self.parent.name != other.parent.name:
83-
return False
84-
85-
if self.parent is None and other.parent is not None:
63+
if not all(
64+
[
65+
self.name == other.name,
66+
np.allclose(self.mass, other.mass),
67+
np.allclose(self.inertia, other.inertia),
68+
self.index == other.index,
69+
np.allclose(self.pose, other.pose),
70+
self.children == other.children,
71+
(
72+
(self.parent is not None and self.parent.name == other.parent.name)
73+
if self.parent is not None
74+
else other.parent is None
75+
),
76+
]
77+
):
8678
return False
8779

8880
return True

src/jaxsim/parsers/descriptions/model.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,16 @@ def __eq__(self, other: ModelDescription) -> bool:
249249
if not isinstance(other, ModelDescription):
250250
return False
251251

252-
if self.name != other.name:
253-
return False
254-
255-
if self.fixed_base != other.fixed_base:
256-
return False
257-
258-
if self.root != other.root:
259-
return False
260-
261-
if self.joints != other.joints:
262-
return False
263-
264-
if self.frames != other.frames:
265-
return False
266-
267-
if self.root_pose != other.root_pose:
252+
if not all(
253+
[
254+
self.name == other.name,
255+
self.fixed_base == other.fixed_base,
256+
self.root == other.root,
257+
self.joints == other.joints,
258+
self.frames == other.frames,
259+
self.root_pose == other.root_pose,
260+
]
261+
):
268262
return False
269263

270264
return True

0 commit comments

Comments
 (0)