Home > manopt > autodiff > functions_AD > ctril.m

ctril

PURPOSE ^

Extracts the lower triangular part of X.

SYNOPSIS ^

function Xtriu = ctril(X, k)

DESCRIPTION ^

 Extracts the lower triangular part of X.

 function Xtriu = ctril(X,k)

 This function can be seen as tril(X,k) but is compatible with dlarrays
 and structs with fields real and imag.

 See also: manoptADhelp

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Xtriu = ctril(X, k)
0002 % Extracts the lower triangular part of X.
0003 %
0004 % function Xtriu = ctril(X,k)
0005 %
0006 % This function can be seen as tril(X,k) but is compatible with dlarrays
0007 % and 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, Aug. 31, 2021.
0013 % Contributors: Nicolas Boumal
0014 % Change log:
0015 
0016     switch nargin
0017         case 1
0018             if iscstruct(X)
0019                 index0 = find(tril(ones(size(X.real)))==0);
0020                 Xtriu = X;
0021                 Xtriu.real(index0) = 0;
0022                 Xtriu.imag(index0) = 0;
0023         
0024             elseif isnumeric(X) && ~isdlarray(X)
0025                 Xtriu = tril(X);
0026             
0027             elseif isdlarray(X)
0028                 Xtriu = dlarray(zeros(size(X)));
0029                 index1 = find(tril(ones(size(X)))==1);
0030                 Xtriu(index1) = X(index1);
0031                 
0032             else
0033                 ME = MException('ctriu:inputError', ...
0034                 'Input does not have the expected format.');
0035                 throw(ME);
0036             end
0037         case 2
0038             if iscstruct(X)
0039                 index0 = find(tril(ones(size(X.real)),k)==0);
0040                 Xtriu = X;
0041                 Xtriu.real(index0) = 0;
0042                 Xtriu.imag(index0) = 0;
0043         
0044             elseif isnumeric(X) && ~isdlarray(X)
0045                 Xtriu = tril(X,k);
0046             
0047             elseif isdlarray(X)
0048                 Xtriu = dlarray(zeros(size(X)));
0049                 index1 = find(tril(ones(size(X)),k)==1);
0050                 Xtriu(index1) = X(index1);
0051                 
0052             else
0053                 ME = MException('ctril:inputError', ...
0054                                 'Input does not have the expected format.');
0055                 throw(ME);
0056             end
0057     otherwise
0058         error('Too many input arguments.');
0059     end
0060 end

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