Skip to content

Commit 1438bbf

Browse files
authored
Modifies method for swapping edge extremities (#347)
Comparison to find the larger coordinate starts with checking if these coordinates are close to avoid numerical problems with float values. Signed-off by: Ainur Ziganshin [email protected]
1 parent 2cb12fd commit 1438bbf

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

sionna/rt/solver_base.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,22 @@ def _swap_edges(self, edges):
816816
# 1. norm(p1) >= norm(p0)
817817
# 2. azimuth(p1) >= azimuth(p0)
818818
# 3. elevation (p1) >= elevation(p0)
819-
needs_swap_1 = r0 > r1
820-
not_disc_1 = tf.experimental.numpy.isclose(r0, r1)
821-
needs_swap_2 = tf.logical_and(not_disc_1, phi0 > phi1)
822-
not_disc_2 = tf.experimental.numpy.isclose(phi0, phi1)
823-
not_disc_12 = tf.logical_and(not_disc_1, not_disc_2)
824-
needs_swap_3 = tf.logical_and(not_disc_12, theta0 > theta1)
819+
820+
# More details of the algorithm:
821+
# needs_swap 1: !r_equal and r0 > r1
822+
# needs_swap 2: r_equal and !phi_equal and phi0 > phi1
823+
# needs_swap 3: r_equal and phi_equal and theta0 > theta1
824+
# Note: case when all three coordinates are equal is not considered
825+
826+
r_equal = tf.experimental.numpy.isclose(r0, r1)
827+
phi_equal = tf.experimental.numpy.isclose(phi0, phi1)
828+
case_2 = tf.logical_and(r_equal, tf.logical_not(phi_equal))
829+
case_3 = tf.logical_and(r_equal, phi_equal)
830+
831+
needs_swap_1 = tf.logical_and(tf.logical_not(r_equal), r0 > r1)
832+
needs_swap_2 = tf.logical_and(case_2, phi0 > phi1)
833+
needs_swap_3 = tf.logical_and(case_3, theta0 > theta1)
834+
825835
needs_swap = tf.reduce_any(tf.stack([needs_swap_1,
826836
needs_swap_2,
827837
needs_swap_3], axis=1),

0 commit comments

Comments
 (0)