oseledets / TT-Toolbox

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

Substitution error of tt_matrix #37

Closed YoshiHotta closed 7 years ago

YoshiHotta commented 7 years ago

When I try to modify elements of tt_matrix, error is thrown. For example,

tt = tt_ones(4,5,1);
ttm = tt_matrix(tt);
ps = ttm.ps;
ttm.core(ps(1):ps(2)-1) = [3; 3; 3; 3;];
ttm{2} => error

On the other hand, when I try to modify elements of tt_tensor, error is not thrown. For example,

tt = tt_ones(4,5,1);
ps = tt.ps;
tt.core(ps(1):ps(2)-1) = [3; 3; 3; 3;];
tt{2} => ok

I am not sure that this kind of substitution is officially supported or not. Can you fix this bug, or tell me a better way to change elements of tt_matrix?

dolgov commented 7 years ago

Hi YoshiHotta,

the elementwise subsasgn was found to be inefficient in the past, so it was not fully developed. Now I pushed the corresponding code for tt_matrix, but for large tensors I would recommend to work with individual TT cores in a cell array. c=core2cell(tt) function returns a cell array of cores of a tt_tensor/matrix, and tt=cell2core(tt,c) builds a tt_tensor/matrix from a cell array. A k-th core has dimensions r(k) x n(k) x r(k+1) for tt_tensor and r(k) x n(k) x m(k) x r(k+1) for tt_matrix.

Best wishes

YoshiHotta commented 7 years ago

Hi Dolgov,

Thank you very much for your push and kind instruction! I checked the bug fix.