Computes the Frobenius norm of X function Xnormfro = cnormfro(X) Returns the Frobenius norm of X. This function can be seen as norm(...,'fro') but is compatible with dlarrays and structs with fields real and imag. Supports both real and complex numbers. See also: manoptADhelp
0001 function Xnormfro = cnormfro(X) 0002 % Computes the Frobenius norm of X 0003 % 0004 % function Xnormfro = cnormfro(X) 0005 % 0006 % Returns the Frobenius norm of X. This function can be seen as 0007 % norm(...,'fro') but is compatible with dlarrays and structs with fields 0008 % real and imag. Supports both real and complex numbers. 0009 % 0010 % See also: manoptADhelp 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 iscstruct(X) 0018 Xnormfro = sqrt(cinnerprodgeneral(X,X)); 0019 0020 elseif isnumeric(X) 0021 if isreal(X) 0022 Xnormfro = sqrt(X(:)'*X(:)); 0023 else 0024 Xnormfro = sqrt(sum(real(conj(X(:)).*X(:)))); 0025 end 0026 0027 else 0028 ME = MException('cnormfro:inputError', ... 0029 'Input does not have the expected format.'); 0030 throw(ME); 0031 0032 end 0033 0034 end