Skip to content

Commit b0ba2db

Browse files
author
Dominic Price
committed
Fix bug in rename_dummies which caused triple-index errors and add test case
1 parent 74c2168 commit b0ba2db

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core/algorithms/rename_dummies.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ Algorithm::result_t rename_dummies::apply(iterator& st)
5757
repmap_t repmap;
5858
index_map_t added_dummies;
5959

60+
// If a target set is provided, move any dummies from this set in ind_dummy
61+
// to added_dummies to prevent them from being reused
62+
if (dset2 != "") {
63+
for (const auto& idx : ind_dummy) {
64+
const Indices* idxset = kernel.properties.get<Indices>(idx.second, true);
65+
if (idxset->set_name == dset2)
66+
added_dummies.insert(idx);
67+
}
68+
}
69+
6070
// Store all indices in a map sorted by the name of the parent.
6171
// FIXME: this is not sufficient, you really need to determine which
6272
// are common factors in all terms in a sum, and then collect those

tests/dummies.cdb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ def test01():
1313

1414
test01()
1515

16-
def test02():
16+
def test02a():
1717
__cdbkernel__=create_scope()
1818
{n,p,q}::Indices("one").
1919
{m,n,p,q,r,s,t}::Indices("two").
2020
ex:= A_{r} = A_{m r} A^{m} + A_{n r} A^{n} + A_{s r} A^{s}.
2121
rename_dummies(ex, "two", "one")
2222
assert ex == $A_{r} = 3A_{n r} A^{n}$, ex
23-
print("Test 02 passed")
23+
print("Test 02a passed")
2424

25-
test02()
25+
test02a()
2626

27+
def test02b():
28+
__cdbkernel__ = create_scope()
29+
{a, b, c, d, e, f}::Indices("one").
30+
{\alpha, \beta, \gamma, \delta}::Indices("two")
31+
ex1 := A_{a a \alpha \alpha};
32+
rename_dummies(ex1, "two", "one")
33+
assert ex1 == $A_{a a b b}$
34+
ex2 := A_{a a \alpha \alpha};
35+
rename_dummies(ex2, "one", "two")
36+
assert ex2 == $A_{\beta \beta \alpha \alpha}$
37+
print("Test 02b passed")
38+
39+
test02b()
2740

2841
# expand_dummies tests
2942

0 commit comments

Comments
 (0)