forked from oseledets/TT-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreal.m
56 lines (53 loc) · 1.51 KB
/
real.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
48
49
50
51
52
53
54
55
56
function [b]=real(a)
%Compute a real part of TT-tensor
% [B]=REAL(A)
%
% TT-Toolbox 2.2, 2009-2013
%
%This is TT Toolbox, written by Ivan Oseledets et al.
%Institute of Numerical Mathematics, Moscow, Russia
%webpage: http://spring.inm.ras.ru/osel
%
%For all questions, bugs and suggestions please mail
%
% For details see Thm4 in Dolgov, Khoromskij, Savostyanov,
% "Superfast Fourier transform using the QTT format"
% http://dx.doi.org/10.1007/s00041-012-9227-4
%
%---------------------------
if (a.d==1)
b=a;
b.core=real(b.core);
exit;
end
d=a.d;
%Determine the size and preallocate the result
b=tt_tensor;
b.r=a.r; b.r(2:d)=2*a.r(2:d);
b.d=a.d; b.n=a.n;
sz=dot(b.n.*b.r(1:d),b.r(2:d+1));
pos=(b.n.*b.r(1:d)).*b.r(2:d+1);
b.ps=cumsum([1;pos]);
b.core=zeros(sz,1);
apos=a.ps; bpos=b.ps;
% Fill cores
for i=1:d
bb=zeros(b.r(i),b.n(i),b.r(i+1));
aa=reshape(a.core(apos(i):apos(i+1)-1), [a.r(i),a.n(i),a.r(i+1)]);
if (i==1)
bb(1:a.r(i),:,1:a.r(i+1) )=real(aa);
bb(1:a.r(i),:,1+a.r(i+1):2*a.r(i+1))=imag(aa);
elseif (i==d)
bb(1:a.r(i), :,1:a.r(i+1))= real(aa);
bb(1+a.r(i):2*a.r(i),:,1:a.r(i+1))=-imag(aa);
else
bb(1:a.r(i), :,1:a.r(i+1) )= real(aa);
bb(1:a.r(i), :,1+a.r(i+1):2*a.r(i+1))= imag(aa);
bb(1+a.r(i):2*a.r(i),:,1:a.r(i+1) )=-imag(aa);
bb(1+a.r(i):2*a.r(i),:,1+a.r(i+1):2*a.r(i+1))= real(aa);
end
b.core(bpos(i):bpos(i+1)-1)=bb(:);
end
return
end