Example #1
0
    def test_from_axis_angle_jacobian_random(self):
        """Test the Jacobian of the from_axis_angle function."""
        x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle(
        )

        self.assert_jacobian_is_finite_fn(euler.from_axis_angle,
                                          [x_axis_init, x_angle_init])
Example #2
0
  def test_rotate_jacobian_random(self):
    """Test the Jacobian of the rotate function."""
    x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle()
    x_point_init = np.random.uniform(size=x_axis_init.shape)

    self.assert_jacobian_is_correct_fn(
        axis_angle.rotate, [x_point_init, x_axis_init, x_angle_init])
Example #3
0
  def test_inverse_random(self):
    """Tests axis-angle inversion."""
    random_axis, random_angle = test_helpers.generate_random_test_axis_angle()

    inverse_axis, inverse_angle = axis_angle.inverse(random_axis, random_angle)

    self.assertAllClose(inverse_axis, random_axis, rtol=1e-3)
    self.assertAllClose(inverse_angle, -random_angle, rtol=1e-3)
Example #4
0
  def test_inverse_normalized_random(self):
    """Tests that axis-angle inversion return a normalized axis-angle."""
    random_axis, random_angle = test_helpers.generate_random_test_axis_angle()

    inverse_axis, inverse_angle = axis_angle.inverse(random_axis, random_angle)

    self.assertAllEqual(
        axis_angle.is_normalized(inverse_axis, inverse_angle),
        np.ones(random_angle.shape))
Example #5
0
  def test_from_axis_angle_normalized_random(self):
    """Test that from_axis_angle produces normalized quaternions."""
    random_axis, random_angle = test_helpers.generate_random_test_axis_angle()

    random_quaternion = quaternion.from_axis_angle(random_axis, random_angle)

    self.assertAllEqual(
        quaternion.is_normalized(random_quaternion),
        np.ones(shape=random_angle.shape, dtype=bool))
    def test_inverse_jacobian_random(self):
        """Test the Jacobian of the inverse function."""
        x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle(
        )

        self.assert_jacobian_is_correct_fn(
            lambda x: axis_angle.inverse(x, x_angle_init)[0], [x_axis_init])
        self.assert_jacobian_is_correct_fn(
            lambda x: axis_angle.inverse(x_axis_init, x)[1], [x_angle_init])
  def test_from_axis_angle_jacobian_random(self):
    """Test the Jacobian of the from_axis_angle function."""
    x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle()
    x_axis = tf.convert_to_tensor(value=x_axis_init)
    x_angle = tf.convert_to_tensor(value=x_angle_init)

    y = quaternion.from_axis_angle(x_axis, x_angle)

    self.assert_jacobian_is_correct(x_axis, x_axis_init, y)
    self.assert_jacobian_is_correct(x_angle, x_angle_init, y)
Example #8
0
  def test_rotate_random(self):
    """Tests that the rotate provide the same results as quaternion.rotate."""
    random_axis, random_angle = test_helpers.generate_random_test_axis_angle()
    tensor_shape = random_angle.shape[:-1]
    random_point = np.random.normal(size=tensor_shape + (3,))

    random_quaternion = quaternion.from_axis_angle(random_axis, random_angle)
    ground_truth = quaternion.rotate(random_point, random_quaternion)
    prediction = axis_angle.rotate(random_point, random_axis, random_angle)

    self.assertAllClose(ground_truth, prediction, rtol=1e-6)
Example #9
0
    def test_rotate_jacobian_random(self):
        """Test the Jacobian of the rotate function."""
        x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle(
        )
        x_axis = tf.convert_to_tensor(value=x_axis_init)
        x_angle = tf.convert_to_tensor(value=x_angle_init)
        x_point_init = np.random.uniform(size=x_axis.shape)
        x_point = tf.convert_to_tensor(value=x_point_init)

        y = axis_angle.rotate(x_point, x_axis, x_angle)

        self.assert_jacobian_is_correct(x_axis, x_axis_init, y)
        self.assert_jacobian_is_correct(x_angle, x_angle_init, y)
        self.assert_jacobian_is_correct(x_point, x_point_init, y)
Example #10
0
  def test_inverse_jacobian_random(self):
    """Test the Jacobian of the inverse function."""
    x_axis_init, x_angle_init = test_helpers.generate_random_test_axis_angle()

    if tf.executing_eagerly():
      # Because axis is returned as is, gradient calculation fails in graph mode
      # but not in eager mode. This is a side effect of having a graph rather
      # than a problem of the function.
      with self.subTest("axis"):
        self.assert_jacobian_is_correct_fn(
            lambda x: axis_angle.inverse(1.0 * x, x_angle_init)[0],
            [x_axis_init])

    with self.subTest("angle"):
      self.assert_jacobian_is_correct_fn(
          lambda x: axis_angle.inverse(x_axis_init, x)[1], [x_angle_init])