Skip to content

Commit efc4264

Browse files
committed
Optimize weighted torque calculation to reduce crashes:
- Added a check to skip the calculation if the torque is already zero, highlighted in issue #55, reducing unnecessary calculations - Retained the divide-by-zero check to ensure numerical stability when computing weighted torques - Improved docstring to reflect the updated logic
1 parent 67c55a0 commit efc4264

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

CodeEntropy/GeometricFunctions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ def get_weighted_torques(data_container, bead, rot_axes, force_partitioning=0.5)
304304
(since values below machine precision are effectively zero). This avoids
305305
unnecessary use of extended precision (e.g., float128).
306306
307+
Additionally, if the computed torque is already zero, the function skips
308+
the division step, reducing unnecessary computations and potential errors.
309+
307310
Parameters
308311
----------
309312
data_container : object
@@ -348,6 +351,11 @@ def get_weighted_torques(data_container, bead, rot_axes, force_partitioning=0.5)
348351
moment_of_inertia = bead.moment_of_inertia()
349352

350353
for dimension in range(3):
354+
# Skip calculation if torque is already zero
355+
if np.isclose(torques[dimension], 0):
356+
weighted_torque[dimension] = 0
357+
continue
358+
351359
if np.isclose(moment_of_inertia[dimension, dimension], 0):
352360
weighted_torque[dimension] = torques[dimension]
353361
else:

0 commit comments

Comments
 (0)