-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcores_2_tensor.m
More file actions
38 lines (31 loc) · 1 KB
/
Copy pathcores_2_tensor.m
File metadata and controls
38 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function X = cores_2_tensor(cores, varargin)
%cores_2_tensor Convertes TR tensor given by cores to full dense tensor
%
%X = cores_2_tensor(cores) takes a cell array containing TR cores and
%outputs the corresponding full dense tensor. The input TR cores should be
%3-way standard Matlab arrays. The output will also be a standard Matlab
%array.
% Optional parameters
params = inputParser;
addParameter(params, 'permute_for_speed', false);
parse(params, varargin{:});
permute_for_speed = params.Results.permute_for_speed;
N = length(cores);
sz = cellfun(@(x) size(x,2), cores);
if permute_for_speed
[~, max_idx] = max(sz);
perm_vec = mod((max_idx+1 : max_idx+N) - 1, N) + 1;
inv_perm_vec(perm_vec) = 1:N;
cores = cores(perm_vec);
sz = sz(perm_vec);
end
if isa(cores{1}, 'double')
G = subchain_matrix(cores, N);
X = G * classical_mode_unfolding(cores{N}, 2).';
X = reshape(X, sz(:)');
elseif isa(cores{1}, 'sptensor')
end
if permute_for_speed
X = permute(X, inv_perm_vec);
end
end