Beispiel #1
0
def test_Tensor_repr():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, sin(2 * z) - 2 * sin(z) * cos(z)]],
                 [[z**2, x], [y, z]]]
    obj1 = Tensor(test_list, config="ull")
    machine_representation = repr(obj1)
    assert not "object at 0x" in machine_representation
Beispiel #2
0
def test_Tensor():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, sin(2 * z) - 2 * sin(z) * cos(z)]], [[z ** 2, x], [y, z]]]
    test_arr = Array(test_list)
    obj1 = Tensor(test_arr)
    obj2 = Tensor(test_list)
    assert obj1.tensor() == obj2.tensor()
    assert isinstance(obj1.tensor(), Array)
    assert obj1.simplify()[0, 1, 1] == 0
Beispiel #3
0
def test_Tensor_getitem():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, sin(2 * z) - 2 * sin(z) * cos(z)]], [[z ** 2, x], [y, z]]]
    obj = Tensor(test_list)
    n = 2
    for i in range(n ** 3):
        p, q, r = i % n, int(i / n) % n, int(i / n ** 2) % n
        assert obj[p, q, r] - test_list[p][q][r] == 0
Beispiel #4
0
def test_TypeError3():
    scht = schwarzschild_tensor().tensor()
    # pass string containing elements other than 'l' or 'u'
    try:
        obj = Tensor(scht, config="al")
        assert False
    except TypeError:
        assert True
Beispiel #5
0
def test_TypeError2():
    scht = schwarzschild_tensor().tensor()
    # pass non str object
    try:
        obj = Tensor(scht, config=0)
        assert False
    except TypeError:
        assert True
Beispiel #6
0
def test_Tensor():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, sin(2 * z) - 2 * sin(z) * cos(z)]],
                 [[z**2, x], [y, z]]]
    test_arr = Array(test_list)
    obj1 = Tensor(test_arr, config="ull")
    obj2 = Tensor(test_list, config="ull")
    assert obj1.tensor() == obj2.tensor()
    assert isinstance(obj1.tensor(), Array)
Beispiel #7
0
def test_Tensor_simplify():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, sin(2 * z) - 2 * sin(z) * cos(z)]], [[z ** 2, x], [y, z]]]
    obj = Tensor(test_list)
    # with set_self = False
    assert obj.simplify(set_self=False)[0, 1, 1] == 0
    assert not obj.tensor()[0, 1, 1] == 0
    # with set_self = True
    obj.simplify(set_self=True)
    assert obj.tensor()[0, 1, 1] == 0
Beispiel #8
0
def schwarzschild_tensor():
    symbolstr = "t r theta phi"
    syms = symbols(symbolstr)
    G, M, c, a = symbols("G M c a")
    # using metric values of schwarschild space-time
    # a is schwarzschild radius
    list2d = np.zeros((4, 4), dtype=int).tolist()
    list2d[0][0] = 1 - (a / syms[1])
    list2d[1][1] = -1 / ((1 - (a / syms[1])) * (c ** 2))
    list2d[2][2] = -1 * (syms[1] ** 2) / (c ** 2)
    list2d[3][3] = -1 * (syms[1] ** 2) * (sin(syms[2]) ** 2) / (c ** 2)
    sch = Tensor(list2d)
    return sch
Beispiel #9
0
def test_tensor_scalar(scalar):
    scalar_tensor = Tensor(scalar)
    assert scalar_tensor.tensor().rank() == 0
Beispiel #10
0
def test_TypeError3():
    scht = schwarzschild_tensor().tensor()
    # pass string containing elements other than 'l' or 'u'
    obj = Tensor(scht, config="al")
Beispiel #11
0
def test_TypeError2():
    scht = schwarzschild_tensor().tensor()
    # pass non str object
    obj = Tensor(scht, config=0)
Beispiel #12
0
def test_Tensor_str():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, x]], [[z, x], [y, z]]]
    obj1 = Tensor(test_list)
    assert "object at 0x" not in str(obj1)
Beispiel #13
0
def test_ValueError1():
    x, y = symbols("x y")
    test_list = [[x, y], [y, x]]
    # pass array with shape (2,2) when (2,2,2) implied by argument syms
    obj = Tensor(test_list, config="lll")
Beispiel #14
0
def test_TypeError1():
    # pass non array, number or expression in arr
    obj = Tensor("value", config="ll")
Beispiel #15
0
def test_Tensor_str():
    x, y, z = symbols("x y z")
    test_list = [[[x, y], [y, x]], [[z, x], [y, z]]]
    obj1 = Tensor(test_list, config="ull", name="Test")
    assert "object at 0x" not in str(obj1)
    assert "Test" in str(obj1)