Ejemplo n.º 1
0
def test_TensorProduct_construction():
    assert TensorProduct(3, 4) == 12
    assert isinstance(TensorProduct(A, A), TensorProduct)

    expr = TensorProduct(TensorProduct(x, y), z)
    assert expr == x * y * z

    expr = TensorProduct(TensorProduct(A, B), C)
    assert expr == TensorProduct(A, B, C)

    expr = TensorProduct(Matrix.eye(2), [[0, -1], [1, 0]])
    assert expr == Array([[[[0, -1], [1, 0]], [[0, 0], [0, 0]]],
                          [[[0, 0], [0, 0]], [[0, -1], [1, 0]]]])
Ejemplo n.º 2
0
def test_TensorProduct_shape():

    expr = TensorProduct(3, 4, evaluate=False)
    assert expr.shape == ()
    assert expr.rank() == 0

    expr = TensorProduct([1, 2], [x, y], evaluate=False)
    assert expr.shape == (2, 2)
    assert expr.rank() == 2
    expr = TensorProduct(expr, expr, evaluate=False)
    assert expr.shape == (2, 2, 2, 2)
    assert expr.rank() == 4

    expr = TensorProduct(Matrix.eye(2), [[0, -1], [1, 0]], evaluate=False)
    assert expr.shape == (2, 2, 2, 2)
    assert expr.rank() == 4
Ejemplo n.º 3
0
def test_TensorProduct_getitem():
    expr = TensorProduct(A, B)
    assert expr[i, j, k, l] == A[i, j] * B[k, l]
Ejemplo n.º 4
0
def test_TensorProduct_shape():

    expr = TensorProduct(3, 4, evaluate=False)
    assert expr.shape == ()
    assert expr.rank() == 0

    expr = TensorProduct([1, 2], [x, y], evaluate=False)
    assert expr.shape == (2, 2)
    assert expr.rank() == 2
    expr = TensorProduct(expr, expr, evaluate=False)
    assert expr.shape == (2, 2, 2, 2)
    assert expr.rank() == 4

    expr = TensorProduct(Matrix.eye(2), [[0, -1], [1, 0]], evaluate=False)
    assert expr.shape == (2, 2, 2, 2)
    assert expr.rank() == 4