Home > manopt > autodiff > dl2mat.m

dl2mat

PURPOSE ^

Convert the data type of x from dlarray into double

SYNOPSIS ^

function x = dl2mat(dlx)

DESCRIPTION ^

 Convert the data type of x from dlarray into double 

 function dlx = dl2mat(x)
 
 The iput dlx can be defined recursively by arrays, structs and cells. 
 Each part of dlx is a dlarray. The output x has the same data structure 
 as x but each part of x is converted into double data type.

 See also: mat2dl, mat2dl_complex, dl2mat_complex

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function x = dl2mat(dlx)
0002 % Convert the data type of x from dlarray into double
0003 %
0004 % function dlx = dl2mat(x)
0005 %
0006 % The iput dlx can be defined recursively by arrays, structs and cells.
0007 % Each part of dlx is a dlarray. The output x has the same data structure
0008 % as x but each part of x is converted into double data type.
0009 %
0010 % See also: mat2dl, mat2dl_complex, dl2mat_complex
0011 
0012 % This file is part of Manopt: www.manopt.org.
0013 % Original author: Xiaowen Jiang, July. 31, 2021.
0014 % Contributors: Nicolas Boumal
0015 % Change log:
0016 
0017     if ~isstruct(dlx) && ~iscell(dlx) && ~isnumeric(dlx)
0018         up = MException('manopt:autodiff:dl2mat', ...
0019                     'dl2mat should only accept structs, cells or arrays.');
0020         throw(up);
0021     end
0022 
0023     % recursively convert each part of dlx into double
0024     if isstruct(dlx)
0025         x = dl2mat_struct(dlx);
0026     elseif iscell(dlx)
0027         x = dl2mat_cell(dlx);
0028     else
0029         x = extractdata(dlx);
0030     end
0031     
0032     % convert dlx into double if dlx is a struct
0033     function x = dl2mat_struct(dlx)
0034         elems = fieldnames(dlx);
0035         nelems = numel(elems);
0036         for ii = 1:nelems
0037             if isstruct(dlx.(elems{ii}))
0038                 x.(elems{ii}) = dl2mat_struct(dlx.(elems{ii}));
0039             elseif iscell(dlx.(elems{ii}))
0040                 x.(elems{ii}) = dl2mat_cell(dlx.(elems{ii}));
0041             else
0042                 x.(elems{ii}) = extractdata(dlx.(elems{ii}));
0043             end
0044         end
0045     end
0046 
0047     % convert dlx into double if dlx is a cell
0048     function x = dl2mat_cell(dlx)
0049         ncell = length(dlx);
0050         for ii = 1:ncell
0051             if isstruct(dlx{ii})
0052                 x{ii} = dl2mat_struct(dlx{ii});
0053             elseif iscell(dlx{ii})
0054                 x{ii} = dl2mat_cell(dlx{ii});
0055             else
0056                 x{ii} = extractdata(dlx{ii});
0057             end
0058         end
0059     end
0060 end
0061 
0062 
0063

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005