コード例 #1
0
def test_contraction_structure_Mul_and_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')

    i_ji = x[i]**(y[j] * x[i])
    assert get_contraction_structure(i_ji) == {None: set([i_ji])}
    ij_i = (x[i] * y[j])**(y[i])
    assert get_contraction_structure(ij_i) == {None: set([ij_i])}
    j_ij_i = x[j] * (x[i] * y[j])**(y[i])
    assert get_contraction_structure(j_ij_i) == {(j, ): set([j_ij_i])}
    j_i_ji = x[j] * x[i]**(y[j] * x[i])
    assert get_contraction_structure(j_i_ji) == {(j, ): set([j_i_ji])}
    ij_exp_kki = x[i] * y[j] * exp(y[i] * y[k, k])
    result = get_contraction_structure(ij_exp_kki)
    expected = {
        (i, ):
        set([ij_exp_kki]),
        ij_exp_kki: [{
            None:
            set([exp(y[i] * y[k, k])]),
            exp(y[i] * y[k, k]): [{
                None: set([y[i] * y[k, k]]),
                y[i] * y[k, k]: [{
                    (k, ): set([y[k, k]])
                }]
            }]
        }]
    }
    assert result == expected
コード例 #2
0
ファイル: test_index_methods.py プロジェクト: msgoff/sympy
def test_ufunc_support():
    f = Function("f")
    g = Function("g")
    x = IndexedBase("x")
    y = IndexedBase("y")
    i, j = Idx("i"), Idx("j")
    a = symbols("a")

    assert get_indices(f(x[i])) == (set([i]), {})
    assert get_indices(f(x[i], y[j])) == (set([i, j]), {})
    assert get_indices(f(y[i]) * g(x[i])) == (set(), {})
    assert get_indices(f(a, x[i])) == (set([i]), {})
    assert get_indices(f(a, y[i], x[j]) * g(x[i])) == (set([j]), {})
    assert get_indices(g(f(x[i]))) == (set([i]), {})

    assert get_contraction_structure(f(x[i])) == {None: set([f(x[i])])}
    assert get_contraction_structure(f(y[i]) * g(x[i])) == {
        (i, ): set([f(y[i]) * g(x[i])])
    }
    assert get_contraction_structure(f(y[i]) * g(f(x[i]))) == {
        (i, ): set([f(y[i]) * g(f(x[i]))])
    }
    assert get_contraction_structure(f(x[j], y[i]) * g(x[i])) == {
        (i, ): set([f(x[j], y[i]) * g(x[i])])
    }
コード例 #3
0
def test_ufunc_support():
    f = Function('f')
    g = Function('g')
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    a = symbols('a')

    assert get_indices(f(x[i])) == (set([i]), {})
    assert get_indices(f(x[i], y[j])) == (set([i, j]), {})
    assert get_indices(f(y[i]) * g(x[i])) == (set(), {})
    assert get_indices(f(a, x[i])) == (set([i]), {})
    assert get_indices(f(a, y[i], x[j]) * g(x[i])) == (set([j]), {})
    assert get_indices(g(f(x[i]))) == (set([i]), {})

    assert get_contraction_structure(f(x[i])) == {None: set([f(x[i])])}
    assert get_contraction_structure(f(y[i]) * g(x[i])) == {
        (i, ): set([f(y[i]) * g(x[i])])
    }
    assert get_contraction_structure(f(y[i]) * g(f(x[i]))) == {
        (i, ): set([f(y[i]) * g(f(x[i]))])
    }
    assert get_contraction_structure(f(x[j], y[i]) * g(x[i])) == {
        (i, ): set([f(x[j], y[i]) * g(x[i])])
    }
コード例 #4
0
def test_contraction_structure_Add_in_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    s_ii_jj_s = (1 + x[i, i])**(1 + y[j, j])
    expected = {
        None:
        set([s_ii_jj_s]),
        s_ii_jj_s: [{
            None: set([S.One]),
            (i, ): set([x[i, i]])
        }, {
            None: set([S.One]),
            (j, ): set([y[j, j]])
        }]
    }
    result = get_contraction_structure(s_ii_jj_s)
    assert result == expected

    s_ii_jk_s = (1 + x[i, i])**(1 + y[j, k])
    expected_2 = {
        None: set([(x[i, i] + 1)**(y[j, k] + 1)]),
        s_ii_jk_s: [{
            None: set([S.One]),
            (i, ): set([x[i, i]])
        }]
    }
    result_2 = get_contraction_structure(s_ii_jk_s)
    assert result_2 == expected_2
コード例 #5
0
ファイル: test_index_methods.py プロジェクト: AALEKH/sympy
def test_contraction_structure_Mul_and_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')

    i_ji = x[i]**(y[j]*x[i])
    assert get_contraction_structure(i_ji) == {None: set([i_ji])}
    ij_i = (x[i]*y[j])**(y[i])
    assert get_contraction_structure(ij_i) == {None: set([ij_i])}
    j_ij_i = x[j]*(x[i]*y[j])**(y[i])
    assert get_contraction_structure(j_ij_i) == {(j,): set([j_ij_i])}
    j_i_ji = x[j]*x[i]**(y[j]*x[i])
    assert get_contraction_structure(j_i_ji) == {(j,): set([j_i_ji])}
    ij_exp_kki = x[i]*y[j]*exp(y[i]*y[k, k])
    result = get_contraction_structure(ij_exp_kki)
    expected = {
        (i,): set([ij_exp_kki]),
        ij_exp_kki: [{
                     None: set([exp(y[i]*y[k, k])]),
                exp(y[i]*y[k, k]): [{
                    None: set([y[i]*y[k, k]]),
                    y[i]*y[k, k]: [{(k,): set([y[k, k]])}]
                }]}
        ]
    }
    assert result == expected
コード例 #6
0
def test_get_contraction_structure_basic():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j = Idx('i'), Idx('j')
    assert get_contraction_structure(x[i]*y[j]) == {None: set([x[i]*y[j]])}
    assert get_contraction_structure(x[i] + y[j]) == {None: set([x[i], y[j]])}
    assert get_contraction_structure(x[i]*y[i]) == {(i,): set([x[i]*y[i]])}
    assert get_contraction_structure(1 + x[i]*y[i]) == {None: set([S.One]), (i,): set([x[i]*y[i]])}
    assert get_contraction_structure(x[i]**y[i]) == {None: set([x[i]**y[i]])}
コード例 #7
0
def test_get_contraction_structure_complex():
    x = IndexedBase('x')
    y = IndexedBase('y')
    A = IndexedBase('A')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    expr1 = y[i] + A[i, j]*x[j]
    d1 = {None: set([y[i]]), (j,): set([A[i, j]*x[j]])}
    assert get_contraction_structure(expr1) == d1
    expr2 = expr1*A[k, i] + x[k]
    d2 = {None: set([x[k]]), (i,): set([expr1*A[k, i]]), expr1*A[k, i]: [d1]}
    assert get_contraction_structure(expr2) == d2
コード例 #8
0
ファイル: test_index_methods.py プロジェクト: AALEKH/sympy
def test_get_contraction_structure_complex():
    x = IndexedBase('x')
    y = IndexedBase('y')
    A = IndexedBase('A')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    expr1 = y[i] + A[i, j]*x[j]
    d1 = {None: set([y[i]]), (j,): set([A[i, j]*x[j]])}
    assert get_contraction_structure(expr1) == d1
    expr2 = expr1*A[k, i] + x[k]
    d2 = {None: set([x[k]]), (i,): set([expr1*A[k, i]]), expr1*A[k, i]: [d1]}
    assert get_contraction_structure(expr2) == d2
コード例 #9
0
ファイル: test_index_methods.py プロジェクト: msgoff/sympy
def test_get_contraction_structure_basic():
    x = IndexedBase("x")
    y = IndexedBase("y")
    i, j = Idx("i"), Idx("j")
    assert get_contraction_structure(x[i] * y[j]) == {None: set([x[i] * y[j]])}
    assert get_contraction_structure(x[i] + y[j]) == {None: set([x[i], y[j]])}
    assert get_contraction_structure(x[i] * y[i]) == {
        (i, ): set([x[i] * y[i]])
    }
    assert get_contraction_structure(1 + x[i] * y[i]) == {
        None: set([S.One]),
        (i, ): set([x[i] * y[i]]),
    }
    assert get_contraction_structure(x[i]**y[i]) == {None: set([x[i]**y[i]])}
コード例 #10
0
ファイル: test_index_methods.py プロジェクト: msgoff/sympy
def test_get_contraction_structure_complex():
    x = IndexedBase("x")
    y = IndexedBase("y")
    A = IndexedBase("A")
    i, j, k = Idx("i"), Idx("j"), Idx("k")
    expr1 = y[i] + A[i, j] * x[j]
    d1 = {None: set([y[i]]), (j, ): set([A[i, j] * x[j]])}
    assert get_contraction_structure(expr1) == d1
    expr2 = expr1 * A[k, i] + x[k]
    d2 = {
        None: set([x[k]]),
        (i, ): set([expr1 * A[k, i]]),
        expr1 * A[k, i]: [d1]
    }
    assert get_contraction_structure(expr2) == d2
コード例 #11
0
ファイル: test_index_methods.py プロジェクト: msgoff/sympy
def test_contraction_structure_Pow_in_Pow():
    x = IndexedBase("x")
    y = IndexedBase("y")
    z = IndexedBase("z")
    i, j, k = Idx("i"), Idx("j"), Idx("k")
    ii_jj_kk = x[i, i]**y[j, j]**z[k, k]
    expected = {
        None:
        set([ii_jj_kk]),
        ii_jj_kk: [
            {
                (i, ): set([x[i, i]])
            },
            {
                None:
                set([y[j, j]**z[k, k]]),
                y[j, j]**z[k, k]: [{
                    (j, ): set([y[j, j]])
                }, {
                    (k, ): set([z[k, k]])
                }],
            },
        ],
    }
    assert get_contraction_structure(ii_jj_kk) == expected
コード例 #12
0
ファイル: test_index_methods.py プロジェクト: BDGLunde/sympy
def test_ufunc_support():
    f = Function('f')
    g = Function('g')
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    a = symbols('a')

    assert get_indices(f(x[i])) == (set([i]), {})
    assert get_indices(f(x[i], y[j])) == (set([i, j]), {})
    assert get_indices(f(y[i])*g(x[i])) == (set(), {})
    assert get_indices(f(a, x[i])) == (set([i]), {})
    assert get_indices(f(a, y[i], x[j])*g(x[i])) == (set([j]), {})
    assert get_indices(g(f(x[i]))) == (set([i]), {})

    assert get_contraction_structure(f(x[i])) == {None: set([f(x[i])])}
    assert get_contraction_structure(f(y[i])*g(x[i])) == {(i,): set([f(y[i])*g(x[i])])}
    assert get_contraction_structure(f(y[i])*g(f(x[i]))) == {(i,): set([f(y[i])*g(f(x[i]))])}
    assert get_contraction_structure(f(x[j], y[i])*g(x[i])) == {(i,): set([f(x[j], y[i])*g(x[i])])}
コード例 #13
0
def test_contraction_structure_simple_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    ii_jj = x[i, i]**y[j, j]
    assert get_contraction_structure(ii_jj) == {
        None: {ii_jj},
        ii_jj: [
            {(i,): {x[i, i]}},
            {(j,): {y[j, j]}}
        ]
    }

    ii_jk = x[i, i]**y[j, k]
    assert get_contraction_structure(ii_jk) == {
        None: {x[i, i]**y[j, k]},
        x[i, i]**y[j, k]: [
            {(i,): {x[i, i]}}
        ]
    }
コード例 #14
0
def test_contraction_structure_simple_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    ii_jj = x[i, i]**y[j, j]
    assert get_contraction_structure(ii_jj) == {
        None: set([ii_jj]),
        ii_jj: [
            {(i,): set([x[i, i]])},
            {(j,): set([y[j, j]])}
        ]
    }

    ii_jk = x[i, i]**y[j, k]
    assert get_contraction_structure(ii_jk) == {
        None: set([x[i, i]**y[j, k]]),
        x[i, i]**y[j, k]: [
            {(i,): set([x[i, i]])}
        ]
    }
コード例 #15
0
ファイル: test_index_methods.py プロジェクト: msgoff/sympy
def test_contraction_structure_simple_Pow():
    x = IndexedBase("x")
    y = IndexedBase("y")
    i, j, k = Idx("i"), Idx("j"), Idx("k")
    ii_jj = x[i, i]**y[j, j]
    assert get_contraction_structure(ii_jj) == {
        None: set([ii_jj]),
        ii_jj: [{
            (i, ): set([x[i, i]])
        }, {
            (j, ): set([y[j, j]])
        }],
    }

    ii_jk = x[i, i]**y[j, k]
    assert get_contraction_structure(ii_jk) == {
        None: set([x[i, i]**y[j, k]]),
        x[i, i]**y[j, k]: [{
            (i, ): set([x[i, i]])
        }],
    }
コード例 #16
0
ファイル: test_index_methods.py プロジェクト: AALEKH/sympy
def test_contraction_structure_simple_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    ii_jj = x[i, i]**y[j, j]
    assert get_contraction_structure(ii_jj) == {
        None: set([ii_jj]),
        ii_jj: [
            {(i,): set([x[i, i]])},
            {(j,): set([y[j, j]])}
        ]
    }
コード例 #17
0
ファイル: test_index_methods.py プロジェクト: AALEKH/sympy
def test_contraction_structure_Add_in_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    s_ii_jj_s = (1 + x[i, i])**(1 + y[j, j])
    expected = {
        None: set([s_ii_jj_s]),
        s_ii_jj_s: [
            {None: set([S.One]), (i,): set([x[i, i]])},
            {None: set([S.One]), (j,): set([y[j, j]])}
        ]
    }
    result = get_contraction_structure(s_ii_jj_s)
    assert result == expected
コード例 #18
0
def test_contraction_structure_Add_in_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    s_ii_jj_s = (1 + x[i, i])**(1 + y[j, j])
    expected = {
        None: {s_ii_jj_s},
        s_ii_jj_s: [
            {None: {S.One}, (i,): {x[i, i]}},
            {None: {S.One}, (j,): {y[j, j]}}
        ]
    }
    result = get_contraction_structure(s_ii_jj_s)
    assert result == expected

    s_ii_jk_s = (1 + x[i, i]) ** (1 + y[j, k])
    expected_2 = {
        None: {(x[i, i] + 1)**(y[j, k] + 1)},
        s_ii_jk_s: [
            {None: {S.One}, (i,): {x[i, i]}}
        ]
    }
    result_2 = get_contraction_structure(s_ii_jk_s)
    assert result_2 == expected_2
コード例 #19
0
def test_contraction_structure_Pow_in_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    z = IndexedBase('z')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    ii_jj_kk = x[i, i]**y[j, j]**z[k, k]
    expected = {
            None: set([ii_jj_kk]),
            ii_jj_kk: [
                {(i,): set([x[i, i]])},
                {
                    None: set([y[j, j]**z[k, k]]),
                    y[j, j]**z[k, k]: [
                        {(j,): set([y[j, j]])},
                        {(k,): set([z[k, k]])}
                        ]
                    }
                ]
            }
    assert get_contraction_structure(ii_jj_kk) == expected
コード例 #20
0
ファイル: test_index_methods.py プロジェクト: AALEKH/sympy
def test_contraction_structure_Pow_in_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    z = IndexedBase('z')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    ii_jj_kk = x[i, i]**y[j, j]**z[k, k]
    expected = {
        None: set([ii_jj_kk]),
        ii_jj_kk: [
            {(i,): set([x[i, i]])},
            {
                None: set([y[j, j]**z[k, k]]),
                y[j, j]**z[k, k]: [
                    {(j,): set([y[j, j]])},
                    {(k,): set([z[k, k]])}
                ]
            }
        ]
    }
    assert get_contraction_structure(ii_jj_kk) == expected
コード例 #21
0
def test_contraction_structure_Pow_in_Pow():
    x = IndexedBase('x')
    y = IndexedBase('y')
    z = IndexedBase('z')
    i, j, k = Idx('i'), Idx('j'), Idx('k')
    ii_jj_kk = x[i, i]**y[j, j]**z[k, k]
    expected = {
        None: {ii_jj_kk},
        ii_jj_kk: [
            {(i,): {x[i, i]}},
            {
                None: {y[j, j]**z[k, k]},
                y[j, j]**z[k, k]: [
                    {(j,): {y[j, j]}},
                    {(k,): {z[k, k]}}
                ]
            }
        ]
    }
    assert get_contraction_structure(ii_jj_kk) == expected