0001 function res = innerprod( x, y, dir, upto )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if ~exist( 'dir', 'var' )
0016 dir = 'LR';
0017 end
0018 if ~exist( 'upto', 'var' )
0019 if strcmpi( dir, 'LR')
0020 upto = x.order;
0021 else
0022 upto = 1;
0023 end
0024 end
0025
0026
0027 if strcmpi( dir, 'LR')
0028
0029 res = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');
0030
0031 for i = 2:upto
0032 tmp = tensorprod_ttemps( x.U{i}, res', 1);
0033 res = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
0034 end
0035
0036
0037 elseif strcmpi( dir, 'RL')
0038 d = x.order;
0039 res = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';
0040
0041 for i = d-1:-1:upto
0042 tmp = tensorprod_ttemps( x.U{i}, res', 3);
0043 res = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
0044 end
0045
0046 else
0047 error('Unknown direction specified. Choose either LR (default) or RL')
0048 end
0049
0050 end
0051