oseledets / TT-Toolbox

The git repository for the TT-Toolbox
Other
189 stars 73 forks source link

The size of tt_reshape #70

Open Yukwah1214 opened 4 months ago

Yukwah1214 commented 4 months ago

When I was trying to use the function tt_reshape, I encountered the following problem: It works when the code is :

tt_reshape(tt_eye(8),[2,2,2;2,2,2]')

but if I change the size: tt_reshape(tt_eye(8),[4,4,4;1,1,1]') it went wrong.

and if I change the size to: tt_reshape(tt_eye(8),[4,1,4;1,4,1]') it worked again!

I wonder what is the reason and what should I pay attention to when reshaping a TT tensor/matrix? Maybe this is a simple question, but I really can't find the answer. Sincerely hope someone can help me answer

dolgov commented 4 months ago

Actually, I don't know how to reshape a tt_matrix. tt_tensor is easy: split a core of required size if you can, otherwise merge original cores until you can. For tt_matrix, you need to permute dimensions in different ways depending on what you want (you can't even tell this from sizes alone).

In your example in particular, splitting out a 4 x 1 core from a 8 x 8 matrix can be understood in at least the following ways:

The current code works if both row and column sizes can be reorganized by the same sequence of splits and merges. For anything more general I don't see how to write it consistently.