def test_numpy_dotproduct(): if not numpy: skip("numpy not installed") A = Matrix([x, y, z]) f1 = lambdify([x, y, z], DotProduct(A, A), modules='numpy') f2 = lambdify([x, y, z], DotProduct(A, A.T), modules='numpy') f3 = lambdify([x, y, z], DotProduct(A.T, A), modules='numpy') f4 = lambdify([x, y, z], DotProduct(A, A.T), modules='numpy') assert f1(1, 2, 3) == \ f2(1, 2, 3) == \ f3(1, 2, 3) == \ f4(1, 2, 3) == \ numpy.array([14])
def test_docproduct(): assert DotProduct(A, B).doit() == 22 assert DotProduct(A.T, B).doit() == 22 assert DotProduct(A, B.T).doit() == 22 assert DotProduct(A.T, B.T).doit() == 22 raises(TypeError, lambda: DotProduct(1, A)) raises(TypeError, lambda: DotProduct(A, 1)) raises(TypeError, lambda: DotProduct(A, D)) raises(TypeError, lambda: DotProduct(D, A)) raises(TypeError, lambda: DotProduct(B, C).doit())
def test_dotproduct_symbolic(): A = MatrixSymbol('A', 3, 1) B = MatrixSymbol('B', 3, 1) dot = DotProduct(A, B) assert dot.is_scalar == True assert unchanged(Mul, 2, dot) # XXX Fix forced evaluation for arithmetics with matrix expressions assert dot * A == (A[0, 0]*B[0, 0] + A[1, 0]*B[1, 0] + A[2, 0]*B[2, 0])*A