def test_dot_scalar_multiplitcation(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): for k1, k2 in itertools.product(utils.ALL_SCALARS, utils.ALL_SCALARS): f1 = vector_ops.dot(k1 * v1, k2 * v2) f2 = k1 * k2 * vector_ops.dot(v1, v2) self.assertAlmostEqual(f1, f2, PRECISION)
def test_dot_bilinear(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): for v3 in utils.ALL_VECTORS: for k in utils.ALL_SCALARS: f1 = vector_ops.dot(v1, (k * v2) + v3) f2 = k * (vector_ops.dot(v1, v2)) + vector_ops.dot(v1, v3) self.assertAlmostEqual(f1, f2, PRECISION)
def test_dot_angle_equality(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): if v1.norm > 0 and v2.norm > 0: f1 = vector_ops.dot(v1, v2) f2 = v1.norm * v2.norm * math.cos( vector_ops.angle_between(v1, v2)) self.assertAlmostEqual(f1, f2, PRECISION)
def test_dot(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): self.assertAlmostEqual(v1 @ v2, vector_ops.dot(v1, v2), PRECISION)
def test_dot_orthogonal(self): v1 = Vector([0, 1, 0]) v2 = Vector([1, 0, 0]) self.assertAlmostEqual(vector_ops.dot(v1, v2), 0, PRECISION)
def test_dot_not_associative(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): for v3 in utils.ALL_VECTORS: with self.assertRaises(AttributeError): vector_ops.dot(vector_ops.dot(v1, v2), v3)
def test_dot_distributive(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): for v3 in utils.ALL_VECTORS: f1 = vector_ops.dot(v1, v2 + v3) f2 = vector_ops.dot(v1, v2) + vector_ops.dot(v1, v3) self.assertAlmostEqual(f1, f2, PRECISION)
def test_dot_commutative(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): self.assertAlmostEqual(vector_ops.dot(v1, v2), vector_ops.dot(v2, v1))