Skip to content

Commit

Permalink
Add test for vector substitutions
Browse files Browse the repository at this point in the history
  • Loading branch information
tschijnmo committed Feb 19, 2017
1 parent 348e17e commit 2979b78
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/free_algebra_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_tensors_can_be_differentiated(free_alg):


def test_tensors_can_be_substituted_scalars(free_alg):
"""Test vector substitution facility for tensors."""
"""Test scalar substitution facility for tensors."""

dr = free_alg
p = dr.names
Expand All @@ -341,6 +341,30 @@ def test_tensors_can_be_substituted_scalars(free_alg):
assert res.simplify() == expected.simplify()


def test_tensors_can_be_substituted_vectors(free_alg):
"""Test vector substitution facility for tensors."""

dr = free_alg
p = dr.names

x = IndexedBase('x')
t = IndexedBase('t')
u = IndexedBase('u')
i, j = p.i, p.j
v = p.v
w = Vec('w')

orig = dr.einst(x[i] * v[i])
v_def = dr.einst(t[i, j] * w[j] + u[i, j] * w[j])

res = orig.subst(v[i], v_def).simplify()

expected = dr.einst(
x[i] * t[i, j] * w[j] + x[i] * u[i, j] * w[j]
).simplify()
assert res == expected


def test_tensor_method(free_alg):
"""Test tensor method can be injected."""

Expand Down

0 comments on commit 2979b78

Please sign in to comment.