-
Notifications
You must be signed in to change notification settings - Fork 30
/
tprod.m
47 lines (41 loc) · 1.05 KB
/
tprod.m
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
39
40
41
42
43
44
45
46
47
function C = tprod(A,B)
% Tensor-tensor product of two 3 way tensors: C = A*B
% A - n1*n2*n3 tensor
% B - n2*l*n3 tensor
% C - n1*l*n3 tensor
%
% version 2.0 - 09/10/2017
%
% Written by Canyi Lu ([email protected])
%
%
% References:
% Canyi Lu, Tensor-Tensor Product Toolbox. Carnegie Mellon University.
% June, 2018. https://github.com/canyilu/tproduct.
%
% Canyi Lu, Jiashi Feng, Yudong Chen, Wei Liu, Zhouchen Lin and Shuicheng
% Yan, Tensor Robust Principal Component Analysis with A New Tensor Nuclear
% Norm, arXiv preprint arXiv:1804.03728, 2018
%
[n1,n2,n3] = size(A);
[m1,m2,m3] = size(B);
if n2 ~= m1 || n3 ~= m3
error('Inner tensor dimensions must agree.');
end
A = fft(A,[],3);
B = fft(B,[],3);
C = zeros(n1,m2,n3);
% first frontal slice
C(:,:,1) = A(:,:,1)*B(:,:,1);
% i=2,...,halfn3
halfn3 = round(n3/2);
for i = 2 : halfn3
C(:,:,i) = A(:,:,i)*B(:,:,i);
C(:,:,n3+2-i) = conj(C(:,:,i));
end
% if n3 is even
if mod(n3,2) == 0
i = halfn3+1;
C(:,:,i) = A(:,:,i)*B(:,:,i);
end
C = ifft(C,[],3);