Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in vertcat.m #45

Open
rkuoyemnbeek opened this issue Jan 31, 2020 · 3 comments
Open

bug in vertcat.m #45

rkuoyemnbeek opened this issue Jan 31, 2020 · 3 comments

Comments

@rkuoyemnbeek
Copy link

bug in for-loop, starting from line 42. Problem was that the dimension n, was the n from a different tensor, which may for the first mode of the tensor be different. This is the correct for-loop.

for j=2:nargin
b = varargin{j};
rb = b.r;
ps = b.ps;
nb = b.n;
for i=1:d-1
cr{i}(curr(i)+1:curr(i)+rb(i), :, curr(i+1)+1:curr(i+1)+rb(i+1)) = reshape(b.core(ps(i):ps(i+1)-1), rb(i), nb(i), rb(i+1));
end;
cr{d}(curr(d)+1:curr(d)+rb(d), :, 1:r(d+1)) = reshape(b.core(ps(d):ps(d+1)-1), rb(d), nb(d), rb(d+1));
curr = curr+rb;
end;

@dolgov
Copy link
Collaborator

dolgov commented Jan 31, 2020

Hello,
thanks for your interest in TT-Toolbox.
Could you please post a Minimal Working Example for reproducing the problem?
For consistent summation/concatenation, tensors must have equal mode sizes, so strictly speaking if nb~=n, the vertcat is ill-defined anyway...

@rkuoyemnbeek
Copy link
Author

rkuoyemnbeek commented Feb 1, 2020 via email

@dolgov
Copy link
Collaborator

dolgov commented Feb 1, 2020

OK, I see, so you want to concatenate tensors in the first mode, keeping the leftmost rank to be 1 instead. This could be an alternative definition. Existing vertcat, horzcat concatenate tensors in the trailing TT ranks, so the mode sizes must be equal. This proved to be more convenient in the past, since we used this concatenation for only a handful of tensors, e.g. different eigenvectors, and then it was convenient to compute e.g. the Gram matrix via a single dot(a,b) command.

Your operation can be done in existing functionality by reshaping a TT to turn the first mode size into the first trailing rank, e.g.
a = tt_reshape(a, n(2:end), [], n(1), 1);
where the latter 2 arguments denote first resp last TT ranks.
Now the vertcat will apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants