# Change the size of the Index (the dimension of the vector space that the Index defines) but don't change the id

+1 vote
edited

Excuse me,I want to change the size of the Index (the dimension of the vector space that the Index defines) but don't change the id.For example,if I create a Index a(auto a = Index(2)),then I want to convert the size of index a to 3 and keep the old id.

auto a=Index(2);
a=Index(dim(a)+1);


If I do this,the id of index a will be changed.This result is not what I want.What should I do?Thank you!

commented by (53.8k points)
It’s a good question but generally we discourage doing this. The id of an index refers to a unique vector space that has a fixed dimension.

Could you please provide some more context about what you’re trying to accomplish in the bigger picture where you are needing to change an index dimension?

Thanks,
Miles
commented by (130 points)
Thank for your answer.For example,if I want create a matrix A,I do this:
auto a=Index(2);
auto b=Index(2);
auto A=ITensor(a,b);
A.set(a=1,b=1,1);
A.set(a=1,b=2,1);
A.set(a=2,b=1,1);
A.set(a=2,b=2,1);
Then,I want to convert this matrix to A'( A' is 3*2 matrix and the corresponding position retains the value of the original matrix.For example,elt(A',a=1,b=1)==elt(A,a=1,b=1)).So,I think the easiest way is that change the size of a index and reserve the old id.But what should I do?
commented by (53.8k points)
I see, so what you are wanting to do is something like a "slicing" operation, where you slice into a larger tensor and write the values of this slice with those of a smaller tensors.

Unfortunately in the C++ version of ITensor we don't have slicing operations implemented. In the Julia version it's much easier to do this sort of thing, even though we don't offically have it at the ITensor level. One can do it by passing to and from Julia tensors which do support slicing, and back. Have you considered using the Julia version?

If you are already quite far along with using the C++ version and the Julia version isn't an option, then the  best thing to do for now is to make the larger A' tensor, then use for loops to take the elements out of the A tensor and put them into the A' tensor. You can also retrieve the data from the storage of A but this requires more low-level operations. (A little bit of that is explained here: http://itensor.org/docs.cgi?vers=cppv3&page=formulas/extractdense)

Finally, even if you could do this in one line, I would still recommend that the larger A' tensor have different Index ID's. (We eventually plan to implement a whole slicing system that should resolve these sorts of things where indices can have the same ID's and different sizes as long as one or both also contains specific slicing information - to be implemented still.)

Sorry I can't give better news than that.

Best regards,
Miles
commented by (130 points)