0001 function innerpro = cinnerprodgeneral(x, y)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 if ~((isstruct(x) && isstruct(y)) || (iscell(x) && iscell(y))...
0027 || (isnumeric(x) && isnumeric(y)) || (isstruct(x) && isnumeric(y)))
0028
0029 up = MException('manopt:autodiff:cinnerprodgeneral' ,...
0030 'cinnerprodgeneral should only accept structs, cells or arrays.');
0031 throw(up);
0032
0033 end
0034
0035 if isstruct(x) && isstruct(y) && (~isfield(x,'real')) && (~isfield(y,'real'))
0036 innerpro = cinnerprodgeneral_struct(x,y);
0037 elseif iscell(x) && iscell(y)
0038 innerpro = cinnerprodgeneral_cell(x,y);
0039 else
0040 xconj = cconj(x);
0041 product = cdottimes(xconj,y);
0042 innerpro = sum(creal(product),'all');
0043
0044
0045
0046 end
0047
0048
0049 function innerpro = cinnerprodgeneral_struct(x,y)
0050 innerpro = 0;
0051 elemsx = fieldnames(x);
0052 elemsy = fieldnames(y);
0053
0054 [elems,ix,iy] = intersect(elemsx,elemsy, 'stable');
0055 nelems = numel(elems);
0056 for ii = 1:nelems
0057 if isstruct(x.(elemsx{ix(ii)})) && (~isfield(x.(elemsx{ix(ii)}),'real'))...
0058 && (~isfield(y.(elemsy{iy(ii)}),'real'))
0059 innerpro = innerpro + cinnerprodgeneral_struct(...
0060 x.(elemsx{ix(ii)}),y.(elemsy{iy(ii)}));
0061 elseif iscell(x.(elemsx{ix(ii)}))
0062 innerpro = innerpro + cinnerprodgeneral_cell(...
0063 x.(elemsx{ix(ii)}),y.(elemsy{iy(ii)}));
0064 else
0065 xconj = cconj(x.(elemsx{ix(ii)}));
0066 product = cdottimes(xconj, y.(elemsy{iy(ii)}));
0067 innerpro = innerpro + sum(creal(product), 'all');
0068 end
0069 end
0070 end
0071
0072
0073 function innerpro = cinnerprodgeneral_cell(x,y)
0074 innerpro = 0;
0075 ncell = length(x);
0076 for ii = 1:ncell
0077 if isstruct(x{ii}) && (~isfield(x{ii},'real')) && (~isfield(y{ii},'real'))
0078 innerpro = innerpro + cinnerprodgeneral_struct(...
0079 x{ii},y{ii});
0080 elseif iscell(x{ii})
0081 innerpro = innerpro + cinnerprodgeneral_cell(...
0082 x{ii},y{ii});
0083 else
0084 xconj = cconj(x{ii});
0085 product = cdottimes(xconj, y{ii});
0086 innerpro = innerpro + sum(creal(product), 'all');
0087 end
0088 end
0089 end
0090
0091 end
0092