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