0001 function res = innerprod( x, y, dir, upto, storeParts )
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 if ~exist( 'storeParts', 'var' )
0026 storeParts = false;
0027 end
0028 if storeParts
0029 res = cell(1, x.order);
0030 end
0031
0032
0033 if strcmpi( dir, 'LR')
0034
0035 if storeParts
0036 res{1} = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');
0037 else
0038 res = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');
0039 end
0040
0041 for i = 2:upto
0042 if storeParts
0043 tmp = tensorprod_ttemps( x.U{i}, res{i-1}', 1);
0044 res{i} = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
0045 else
0046 tmp = tensorprod_ttemps( x.U{i}, res', 1);
0047 res = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
0048 end
0049 end
0050
0051
0052 elseif strcmpi( dir, 'RL')
0053 d = x.order;
0054 if storeParts
0055 res{d} = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';
0056 else
0057 res = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';
0058 end
0059
0060 for i = d-1:-1:upto
0061 if storeParts
0062 tmp = tensorprod_ttemps( x.U{i}, res{i+1}', 3);
0063 res{i} = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
0064 else
0065 tmp = tensorprod_ttemps( x.U{i}, res', 3);
0066 res = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
0067 end
0068 end
0069
0070 else
0071 error('Unknown direction specified. Choose either LR (default) or RL')
0072 end
0073
0074 end
0075