Exemple #1
0
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 all(f(1., 2., 3.) == numpy.array([14]) for f in (f1, f2, f3, f4))
Exemple #2
0
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_cupy_dotproduct():
    if not cupy:
        skip("CuPy not installed")

    A = Matrix([x, y, z])
    f1 = lambdify([x, y, z], DotProduct(A, A), modules='cupy')
    f2 = lambdify([x, y, z], DotProduct(A, A.T), modules='cupy')
    f3 = lambdify([x, y, z], DotProduct(A.T, A), modules='cupy')
    f4 = lambdify([x, y, z], DotProduct(A, A.T), modules='cupy')

    assert f1(1, 2, 3) == \
        f2(1, 2, 3) == \
        f3(1, 2, 3) == \
        f4(1, 2, 3) == \
        cupy.array([14])
Exemple #4
0
def test_autograd_numpy_dotproduct():
    if not autograd_numpy:
        skip("autograd not installed")
    A = Matrix([x, y, z])
    f1 = lambdify([x, y, z], DotProduct(A, A), modules='autograd.numpy')
    f2 = lambdify([x, y, z], DotProduct(A, A.T), modules='autograd.numpy')
    f3 = lambdify([x, y, z], DotProduct(A.T, A), modules='autograd.numpy')
    f4 = lambdify([x, y, z], DotProduct(A, A.T), modules='autograd.numpy')
    eq_to = autograd_numpy.array([14])

    assert all(
        f(1, 2, 3) == autograd_numpy.array([14]) for f in (f1, f2, f3, f4))

    f_grad = [autograd.grad(lambda xx: f(*xx)) for f in (f1, f2, f3, f4)]

    xx = autograd_numpy.array([1., 2., 3.])
    eq_to = autograd_numpy.array([2., 4., 6.])
    assert all(autograd_numpy.array_equal(f(xx), eq_to) for f in f_grad)