Home > manopt > autodiff > functions_AD > csum.m

csum

PURPOSE ^

Sum of elements of x.

SYNOPSIS ^

function xsum = csum(x,n)

DESCRIPTION ^

 Sum of elements of x.

 function xsum = csum(x,n)

 This function can be seen as sum(x,n) but is compatible with
 structs with fields real and imag.

 See also: manoptADhelp

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function xsum = csum(x,n)
0002 % Sum of elements of x.
0003 %
0004 % function xsum = csum(x,n)
0005 %
0006 % This function can be seen as sum(x,n) but is compatible with
0007 % structs with fields real and imag.
0008 %
0009 % See also: manoptADhelp
0010 
0011 % This file is part of Manopt: www.manopt.org.
0012 % Original author: Xiaowen Jiang, July. 31, 2021.
0013 % Contributors: Nicolas Boumal
0014 % Change log:
0015 
0016     if isstruct(x) && isfield(x,'real')
0017         if nargin==1
0018             xsum.real = sum(x.real);
0019             xsum.imag = sum(x.imag);
0020         elseif nargin==2
0021             xsum.real = sum(x.real,n);
0022             xsum.imag = sum(x.imag,n);
0023         end
0024 
0025     elseif isnumeric(x)
0026         if nargin==1
0027             xsum = sum(x);
0028         elseif nargin==2
0029             xsum = sum(x,n);
0030         end
0031     else
0032         ME = MException('csum:inputError', ...
0033         'Input does not have the expected format.');
0034         throw(ME);
0035     end
0036         
0037 end

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