Fastor icon indicating copy to clipboard operation
Fastor copied to clipboard

Tensor network contraction fails

Open mechapple opened this issue 4 years ago • 0 comments

Hello, I am trying to perform the following tensor contraction between tensors d,P,B,X.

  enum {I,J,K,L,M,N};  
  Tensor<double,4,4> d; Tensor<double,4,3> P; Tensor<double,4,4> B;  Tensor<double,4> X;
  d.random(); P.random(); B.random(); X.random();

The tensor contraction to be implemented is:

(1) The following fails in compilation.

auto dPBBXX2 = einsum<Index<K,M>,Index<L,N>,Index<K,I>,Index<L,J>,Index<I>,Index<J>>(d,P,B,B,X,X);

(2) However, the following code succeeds.

  auto dPB = einsum<Index<K,M>,Index<L,N>,Index<K,I>>(d,P,B);
  auto dPBB = einsum<Index<M,L,N,I>,Index<L,J>>(dPB,B);
  auto dPBBXX = einsum<Index<M,N,I,J>,Index<I>,Index<J>>(dPBB,X,X);
  print("my 2D array", dPBBXX);

Conceptually, they should be equivalent, and (1) should be the preferred way as per the wiki.

mechapple avatar Jan 16 '22 03:01 mechapple