I am about 2 days into Julia, and I would like to implement some simple operations related to tensor contraction as a learning task. It looks like TensorOperations should help, and for 2x2 tensors I can successfully evaluate a double dot product to get the expected scalar output:
uu = [ 1 2 ; 3 4 ] vv = [ -1 -1 ; -1 -1] using TensorOperations @tensor begin a := scalar(uu[a,b]*vv[b,a]) end print("a= ",a,"\n")
However, my specific tasks requires using rank 1 vectors, and I cannot get this to work. To illustrate the general idea, I tried:
using TensorOperations pp = [ 1 ; 2 ; 3] aa = [ -1 -2 -3] @tensor begin cc[a,c,1] := pp[a]*aa[c,1] dd := scalar(aa[a]*pp[a,1]) end print("cc=",cc,"\n") print("dd=",dd,"\n")
The first result (outer product) to get cc works, but I cannot get the inner product to work. The questions are:
- Why do I need the 1 in the index list for aa and cc for the calculation of cc?
- How can I get the result with a vector? Is there a better more Julia-like approach?
Thanks in advance for tips!