tensor: tested full contractions
This commit is contained in:
15
t.cc
15
t.cc
@@ -3976,6 +3976,7 @@ cout <<t.dot(u)<<endl;
|
|||||||
|
|
||||||
if(1)
|
if(1)
|
||||||
{
|
{
|
||||||
|
//check full constractions
|
||||||
int r,n;
|
int r,n;
|
||||||
cin>>r>>n;
|
cin>>r>>n;
|
||||||
INDEXGROUP shape;
|
INDEXGROUP shape;
|
||||||
@@ -3986,13 +3987,17 @@ INDEXGROUP shape;
|
|||||||
shape.range=n;
|
shape.range=n;
|
||||||
shape.offset=0;
|
shape.offset=0;
|
||||||
}
|
}
|
||||||
Tensor<double> x(shape);
|
Tensor<double> x(shape); x.randomize(1.);
|
||||||
x.randomize(1.);
|
|
||||||
cout<<x;
|
|
||||||
Tensor<double> xf=x.flatten();
|
Tensor<double> xf=x.flatten();
|
||||||
cout <<xf;
|
Tensor<double> y(shape); y.randomize(1.);
|
||||||
|
Tensor<double> yf=y.flatten();
|
||||||
|
|
||||||
cout <<x.dot(x) <<" "<< xf.dot(xf)<<endl;
|
Tensor<double> z = x.groupcontraction(0,y,0,1,false,true);
|
||||||
|
INDEXLIST cl(r);
|
||||||
|
for(int i=0; i<r; ++i) cl[i]={i,0};
|
||||||
|
Tensor<double> zf = xf.contractions(cl,yf,cl,1,false,true);
|
||||||
|
|
||||||
|
cout <<x.dot(y) <<" "<< xf.dot(yf)<< " "<<z<<" "<<zf<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -590,6 +590,7 @@ std::istream & operator>>(std::istream &s, Tensor<T> &x)
|
|||||||
s>>x.shape;
|
s>>x.shape;
|
||||||
s>>x.names;
|
s>>x.names;
|
||||||
x.data.resize(x.calcsize()); x.calcrank();
|
x.data.resize(x.calcsize()); x.calcrank();
|
||||||
|
if(x.rank()==0) {s>>x.data[0]; return s;}
|
||||||
FLATINDEX I(x.rank());
|
FLATINDEX I(x.rank());
|
||||||
for(LA_largeindex i=0; i<x.data.size(); ++i)
|
for(LA_largeindex i=0; i<x.data.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user