0001 function dlx = mat2dl_complex(x)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if ~isstruct(x) && ~iscell(x) && ~isnumeric(x)
0019 up = MException('manopt:autodiff:mat2dl_complex', ...
0020 'mat2dl_complex should only accept a struct, a cell or a numeric array');
0021 throw(up);
0022 end
0023
0024
0025 if isstruct(x)
0026 dlx = mat2dl_struct(x);
0027 elseif iscell(x)
0028 dlx = mat2dl_cell(x);
0029 else
0030 xreal = real(x);
0031 ximag = imag(x);
0032 dlx.real = dlarray(xreal);
0033 dlx.imag = dlarray(ximag);
0034 end
0035
0036
0037 function dlx = mat2dl_struct(x)
0038 elems = fieldnames(x);
0039 nelems = numel(elems);
0040 for ii = 1:nelems
0041 if isstruct(x.(elems{ii}))
0042 dlx.(elems{ii}) = mat2dl_struct(x.(elems{ii}));
0043 elseif iscell(x.(elems{ii}))
0044 dlx.(elems{ii}) = mat2dl_cell(x.(elems{ii}));
0045 else
0046 dlx.(elems{ii}) = struct();
0047 xreal = real(x.(elems{ii}));
0048 ximag = imag(x.(elems{ii}));
0049 dlx.(elems{ii}).real = dlarray(xreal);
0050 dlx.(elems{ii}).imag = dlarray(ximag);
0051 end
0052 end
0053 end
0054
0055
0056 function dlx = mat2dl_cell(x)
0057 ncell = length(x);
0058 for ii = 1:ncell
0059 if isstruct(x{ii})
0060 dlx{ii} = mat2dl_struct(x{ii});
0061 elseif iscell(x{ii})
0062 dlx{ii} = mat2dl_cell(x{ii});
0063 else
0064 xreal = real(x{ii});
0065 ximag = imag(x{ii});
0066 dlx{ii} = struct();
0067 dlx{ii}.real = dlarray(xreal);
0068 dlx{ii}.imag = dlarray(ximag);
0069 end
0070 end
0071 end
0072 end
0073