working on add_permuted_contractions

This commit is contained in:
2025-11-14 16:16:22 +01:00
parent 89cc0c5b1e
commit 3f7586378d
3 changed files with 127 additions and 7 deletions

49
t.cc
View File

@@ -3568,7 +3568,7 @@ v.printsorted(cout,1,false);
}
if(1)
if(0)
{
//grassmann product of n identical rank=2 tensors in m-dim space
int n,m;
@@ -4164,5 +4164,52 @@ cout<<"resulting index order = "<<y.names<<endl;
}
if(1)
{
int nn;
cin>>nn;
int r=4;
NRVec<INDEXGROUP> s(r);
for(int i=0; i<r; ++i)
{
s[i].number=1;
s[i].symmetry=0;
s[i].range=nn;
s[i].offset=0;
}
Tensor<double> x(s); x.randomize(1.);
INDEXNAME xlist[] = {"i","j","k","l"};
x.names=NRVec<INDEXNAME>(xlist);
Tensor<double> y(s); y.randomize(1.);
INDEXNAME ylist[] = {"n","m","j","i"};
y.names=NRVec<INDEXNAME>(ylist);
Tensor<double>z(s); z.clear();
INDEXNAME zlist[] = {"k","l","m","n"};
z.names=NRVec<INDEXNAME>(zlist);
Tensor<double>zz(z);
INDEX i1[]={{0,0},{1,0}};
INDEX i2[]={{3,0},{2,0}};
NRVec<INDEX> il1(i1);
NRVec<INDEX> il2(i2);
Tensor<double> zzz = x.contractions(il1,y,il2,1,false,false);
//cout <<"zzz names = "<<zzz.names<<endl;
z.add_permuted_contractions("",x,y,1,0,false,false);
zz.copyonwrite();
for(int k=0; k<nn; ++k) for(int l=0; l<nn; ++l) for(int m=0; m<nn; ++m) for(int n=0; n<nn; ++n)
{
double s=0;
for(int i=0; i<nn; ++i) for(int j=0; j<nn; ++j) s += x(i,j,k,l)*y(n,m,j,i);
zz.lhs(k,l,m,n) = s;
//cout <<"test "<<k<<" "<<l<<" "<<m<<" "<<n<<" "<<zz(k,l,m,n)<<" "<<zzz(n,m,k,l)<< " : "<<z(k,l,m,n) <<endl;
}
cout <<"Error = "<<(z-zz).norm()<<endl;
}
}//main