tensor: index names in merge_indices

This commit is contained in:
2025-11-10 22:02:07 +01:00
parent 6c2242a572
commit 687474fed2
3 changed files with 10 additions and 4 deletions

9
t.cc
View File

@@ -4048,16 +4048,17 @@ NRVec<INDEXGROUP> shape(3);
Tensor<double> x(shape); x.randomize(1.); Tensor<double> x(shape); x.randomize(1.);
cout <<"x= "<<x.shape; x.defaultnames();
cout <<"x= "<<x.shape << " "<<x.names<<endl;
Tensor<double> xf=x.flatten(1); Tensor<double> xf=x.flatten(1);
cout <<"xf= "<<xf.shape; cout <<"xf= "<<xf.shape << " "<<xf.names<<endl;
Tensor<double> xxx=x.unwind_index_group(1); Tensor<double> xxx=x.unwind_index_group(1);
cout <<"xxx= "<<xxx.shape<<endl; cout <<"xxx= "<<xxx.shape<<" "<<xxx.names<<endl;
INDEXLIST il(r); INDEXLIST il(r);
for(int i=0; i<r; ++i) il[i]= {1+i,0}; for(int i=0; i<r; ++i) il[i]= {1+i,0};
Tensor<double> xx = xf.merge_indices(il,sym); Tensor<double> xx = xf.merge_indices(il,sym);
cout <<"xx = "<<xx.shape; cout <<"xx = "<<xx.shape<< " "<<xx.names<<endl;
cout <<"Error = "<<(xx-xxx).norm()<<endl; cout <<"Error = "<<(xx-xxx).norm()<<endl;
} }

View File

@@ -1746,6 +1746,7 @@ else
Tensor<T> r(newshape); Tensor<T> r(newshape);
r.apply_permutation_algebra(*this,pa,false,(T)1/(T)pa.size(),0); r.apply_permutation_algebra(*this,pa,false,(T)1/(T)pa.size(),0);
if(is_named()) r.names=names.permuted(basicperm,true);
return r; return r;
} }

View File

@@ -132,6 +132,10 @@ bool upperindex;
std::ostream & operator<<(std::ostream &s, const INDEXGROUP &x); std::ostream & operator<<(std::ostream &s, const INDEXGROUP &x);
std::istream & operator>>(std::istream &s, INDEXGROUP &x); std::istream & operator>>(std::istream &s, INDEXGROUP &x);
std::ostream & operator<<(std::ostream &s, const INDEXNAME &x);
std::istream & operator>>(std::istream &s, INDEXNAME &x);
template<> template<>