def testReorderIndicesByPhiEmpty(self): with self.session(): indices = geometry.ReorderIndicesByPhi( tf.constant([1., 0.], tf.float32), tf.constant(np.zeros([0, 4]), tf.float32)).eval() self.assertEqual(indices.shape, (0, ))
def testReorderIndicesByPhi(self): # Picks the anchor point somewhere on the x-y plane. phi0 = 2 * np.pi / 3 anchor = np.array([np.cos(phi0), np.sin(phi0)]) # Generates points clock-wise relative to the anchor. pnts = [] n, delta = 16, 0.01 for i in range(n): phi = phi0 + 1e-6 + 2 * np.pi / n * i x, y = (1 + i) * np.cos(phi), (1 + i) * np.sin(phi) pnts += [[y - delta, x - delta, y + delta, x + delta]] pnts = np.array(pnts) labels = np.arange(n) # Randomly permutate the points. perm = np.random.permutation(n) pnts = pnts[perm] labels = labels[perm] # Uses ReorderIndicesByPhi to figure out how to reshuffle the points to # recover their original order. with self.session(): indices = geometry.ReorderIndicesByPhi(anchor, pnts).eval() print('indices = ', indices) print('labels = ', labels[indices]) self.assertAllEqual(labels[indices], np.flip(np.arange(n), 0))