diff --git a/t.cc b/t.cc index 02e1488..dcbbd8d 100644 --- a/t.cc +++ b/t.cc @@ -4120,7 +4120,7 @@ Tensor ss(s); cout <<"Error= "<>r>>n; +NRVec s(r); +for(int i=0; i x(s); x.randomize(1.); +x.defaultnames(); +NRVec names(r); +NRPerm p(r); p.randomize(); +for(int i=0; i0) laerror("indices inside groups cannot be permuted in permute_index_groups, define permutation by first group's index name or flatten the tensor first"); + p[1+i] = 1+ii.group; + } +if(!p.is_valid()) laerror("illegal permutation from names in permute_index_groups, perhaps repeated or not unique names?"); +return permute_index_groups(p); +} + + + FLATINDEX superindex2flat(const SUPERINDEX &I) { int rank=0; diff --git a/tensor.h b/tensor.h index 10e9961..a7851e0 100644 --- a/tensor.h +++ b/tensor.h @@ -40,8 +40,6 @@ #include "miscfunc.h" //TODO: -//@@@?general permutation of individual indices - check the indices in sym groups remain adjacent, calculate result's shape, loopover the result and permute using unwind_callback -//@@@ is that needed? we can flatten the relevant groups and permute index groups alternatively - maybe implement on high level this way for convenience //?maybe optional negative range for beta spin handling in some cases of fourindex-tensor conversions combining AA and AB etc. cases - if needed @@ -299,7 +297,8 @@ public: void grouploopover(void (*callback)(const GROUPINDEX &, T *)); //loop over all elements disregarding the internal structure of index groups void constgrouploopover(void (*callback)(const GROUPINDEX &, const T *)) const; //loop over all elements disregarding the internal structure of index groups - Tensor permute_index_groups(const NRPerm &p) const; //rearrange the tensor storage permuting index groups as a whole + Tensor permute_index_groups(const NRPerm &p) const; //rearrange the tensor storage permuting index groups as a whole: result_i = source_p_i + Tensor permute_index_groups(const NRVec &names) const; //permute to requested order of group's first indices (or permute individual indices of a flat tensor) Tensor unwind_index_group(int group) const; //make the index group leftmost (least significant) Tensor unwind_index(int group, int index) const; //separate an index from a group and expand it to full range as the least significant one (the leftmost one)