TT-Toolbox
TT-Toolbox copied to clipboard
Vectorize greedy2_cross
I use your vectorize handle
function val = vectorized(ind, fun)
%Trivial vectorized computation of the elements of a tensor
% [VAL]=MY_VEC_FUN(IND,FUN) Given a function handle FUN, compute all
% elements of a tensor given in the index array IND. IND is a M x d
% array, where M is the number of indices to be computed.
M = size(ind, 1);
val = zeros(1, M);
for i = 1:M
ind_loc = ind(i,:);
val(i) = fun(ind_loc);
end
return
end
from your dmrg_cross.m with a test function:
fun = @(ind) ind(1);
But it does not work. Error message in the command window:
Arrays have incompatible sizes for this operation.
Error in greedy2_cross (line 399)
cre = crt-cry;
Error in test_greedy2_cross (line 149)
[y,Jyl,Jyr,ilocl,ilocr,evalcnt] = greedy2_cross(n, vectorized_code, tol, nswp=40, vec=true);
Related documentation
where the function handle vectorized_code is
vectorized_code = @(ind) vectorized(ind, fun);
And then I call your greedy2_cross with vec=true
:
tol = 10^(-6);
% mode size
n = [1,2,3,4,5];
[y,Jyl,Jyr,ilocl,ilocr,evalcnt] = greedy2_cross(n, vectorized_code, tol, nswp=40, vec=true);
May I kindly ask if you could fix the bug? Since fun
is simply enough without any of my interface. I guess it’s might be an intrinsic issue.