diff --git a/t.cc b/t.cc index 60b286d..f789a56 100644 --- a/t.cc +++ b/t.cc @@ -4254,7 +4254,7 @@ for(int k=0; k zzz(s); for(int k=0; k= g.offset+g.range) laerror("index out of range in tensor subindex"); +for(int i=0; i= g.offset+g.range) + { + std::cout<<"TENSOR INDEX PROBLEM in group " <= shape[i].offset+shape[i].range) { - std::cerr<<"error in index group no. "< void Tensor::canonicalize_shape() { @@ -1999,7 +2005,7 @@ foundname: finished: names0= NRVec (names); -std::cout <<"names parsed "< >::const_iterator ii=groups.begin(); ii!=g { groups0[i++] = NRVec_from1(*ii); } -std::cout<<"groups parsed "< listnames; +for(int j=0; j tmpnames(listnames); //generate the antisymmetrizer, adding also indices not involved as a constant subpermutation // @@ -2056,14 +2069,14 @@ NRVec > antigroups; parse_antisymmetrizer(antisymmetrizer,antigroups,antinames); //check the names make sense and fill in the possibly missing ones as separate group -if(antinames.size()>tmp.names.size()) laerror("too many indices in the antisymmetrizet"); -bitvector isexplicit(tmp.names.size()); +if(antinames.size()>tmpnames.size()) laerror("too many indices in the antisymmetrizet"); +bitvector isexplicit(tmpnames.size()); isexplicit.clear(); for(int i=0; inames[i] == tmp.names[p[i]] -NRPerm basicperm=find_indexperm(names,tmp.names); -std::cout <<"Basic permutation = "< tmp=rhs1.contractions(il1,rhs2,il2,alpha,conjugate1,conjugate2); +if(rank()!=tmp.rank()) laerror("rank mismatch in add_permuted_contractions"); +if(tmp.names!=tmpnames) laerror("internal error in add_permuted_contractions"); -//@@@probably only onw of those will work -PermutationAlgebra pb = basicperm*pa; -apply_permutation_algebra(tmp,pb,false,(T)1/(T)pb.size(),beta); -//equivalently possible (for trivial pa) -//PermutationAlgebra pb = basicperm.inverse()*pa; -//apply_permutation_algebra(tmp,pb,true,(T)1/(T)pb.size(),beta); +//@@@apply_permutation_algebra(tmp,pb,false,(T)1,beta); +apply_permutation_algebra(tmp,pb,true,(T)1,beta); } diff --git a/tensor.h b/tensor.h index 4056cb0..c8081ff 100644 --- a/tensor.h +++ b/tensor.h @@ -267,23 +267,29 @@ public: NRVec findindexlist(const NRVec &names) const; void renameindex(const INDEXNAME namfrom, const INDEXNAME nameto) {int i=findflatindex(namfrom); names[i]=nameto;}; - inline Tensor& operator+=(const Tensor &rhs) + Tensor& operator+=(const Tensor &rhs) { -#ifdef DEBUG if(shape!=rhs.shape) laerror("incompatible tensors for operation"); -#endif + if(is_named() && rhs.is_named() && names!=rhs.names) laerror("incompatible names for operation"); data+=rhs.data; return *this; } - inline Tensor& operator-=(const Tensor &rhs) + Tensor& operator-=(const Tensor &rhs) { -#ifdef DEBUG if(shape!=rhs.shape) laerror("incompatible tensors for operation"); -#endif + if(is_named() && rhs.is_named() && names!=rhs.names) laerror("incompatible names for operation"); data-=rhs.data; return *this; } + + Tensor& axpy(const T alpha, const Tensor &rhs) + { + if(shape!=rhs.shape) laerror("incompatible tensors for operation"); + if(is_named() && rhs.is_named() && names!=rhs.names) laerror("incompatible names for operation"); + data.axpy(alpha,rhs.data); + return *this; + } inline Tensor operator+(const Tensor &rhs) const {Tensor r(*this); r+=rhs; return r;}; inline Tensor operator-(const Tensor &rhs) const {Tensor r(*this); r-=rhs; return r;}; @@ -613,7 +619,7 @@ NRMat mat(t.data,range*(range-1)/2,range*(range-1)/2); f=fourindex_dense(range,NRSMat(mat)); //symmetrize mat } - +//@@@formal permutation of names inside a sym/antisy group (with possible sign change) template