def test_transforms_from_pqs_4dims(): random_state = np.random.RandomState(0) P = random_state.randn(2, 3, 4, 5, 7) P[..., 3:] = norm_vectors(P[..., 3:]) H = transforms_from_pqs(P) P2 = pqs_from_transforms(H) assert_array_almost_equal(P[..., :3], H[..., :3, 3]) assert_array_almost_equal(P[..., :3], P2[..., :3])
def test_transforms_from_pqs_1dim(): P = np.empty((10, 7)) random_state = np.random.RandomState(0) P[:, :3] = random_state.randn(len(P), 3) P[:, 3:] = norm_vectors(random_state.randn(len(P), 4)) H = transforms_from_pqs(P) P2 = pqs_from_transforms(H) assert_array_almost_equal(P[:, :3], H[:, :3, 3]) assert_array_almost_equal(P[:, :3], P2[:, :3]) for t in range(len(P)): assert_quaternion_equal(P[t, 3:], quaternion_from_matrix(H[t, :3, :3])) assert_quaternion_equal(P[t, 3:], P2[t, 3:])
def test_norm_vectors_0dims(): random_state = np.random.RandomState(8380) V = random_state.randn(3) V_unit = pbr.norm_vectors(V) assert_almost_equal(np.linalg.norm(V_unit), 1.0)
def test_norm_vectors_zero(): V = np.zeros((3, 8, 1, 2)) V_unit = pbr.norm_vectors(V) assert_array_almost_equal(V_unit, V)
def test_norm_vectors_3dims(): random_state = np.random.RandomState(8382) V = random_state.randn(8, 2, 8, 3) V_unit = pbr.norm_vectors(V) assert_array_almost_equal( np.linalg.norm(V_unit, axis=-1), np.ones(V_unit.shape[:-1]))
def test_norm_vectors_1dim_output_variable(): random_state = np.random.RandomState(8381) V = random_state.randn(100, 3) pbr.norm_vectors(V, out=V) assert_array_almost_equal( np.linalg.norm(V, axis=1), np.ones(len(V)))
def test_norm_vectors_1dim(): random_state = np.random.RandomState(8381) V = random_state.randn(100, 3) V_unit = pbr.norm_vectors(V) assert_array_almost_equal( np.linalg.norm(V_unit, axis=1), np.ones(len(V)))