SwampWalker/MosquitoTensor — Issue #4: Ordering of indices in an expression
Author: barrywardell
Created: 2011-11-25 19:18:29+00:00
State: open

The following test program illustrates a bug in the assignment of an expression to a tensor:

#include
#include "Tensor.h"

using namespace Mosquito;

int main (int argc, char * argv[])
{
Tensor A("_a_b");
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
A(i,j) = 4*i+j;

Tensor B("_a_b");
Tensor C("_a_b");

B = A["ab"];
C = A["ba"];

for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
std::cout << "[" << i << "," << j << "]: A=" << A(i,j)
<< " B=" << B(i,j) << " C=" << C(i,j) << std::endl;

return 0;
}

The result is that A, B and C are all the same, whereas the expected behavior is that C is the transpose of A. This can be worked around by making sure that the first term in an expression always has the indices in the appropriate order. In the example above, change the assignment of C to:

C = 0*C["ab"] + A["ba"]

and it C will now correctly be the transpose of A.