Checks whether the gradient can be computed for a problem structure. function candoit = canGetGradient(problem) Returns true if the gradient of the cost function can be computed given the problem description, false otherwise. See also: canGetCost canGetDirectionalDerivative canGetHessian
0001 function candoit = canGetGradient(problem) 0002 % Checks whether the gradient can be computed for a problem structure. 0003 % 0004 % function candoit = canGetGradient(problem) 0005 % 0006 % Returns true if the gradient of the cost function can be computed given 0007 % the problem description, false otherwise. 0008 % 0009 % See also: canGetCost canGetDirectionalDerivative canGetHessian 0010 0011 % This file is part of Manopt: www.manopt.org. 0012 % Original author: Nicolas Boumal, Dec. 30, 2012. 0013 % Contributors: 0014 % Change log: 0015 % 0016 % June 28, 2016 (NB): 0017 % Added support for getPartialGradient 0018 % 0019 % Nov. 1, 2016 (NB): 0020 % Added support for gradient from directional derivatives 0021 0022 candoit = isfield(problem, 'grad') || isfield(problem, 'costgrad') || ... 0023 canGetEuclideanGradient(problem) || ... 0024 canGetPartialGradient(problem) || ... 0025 ... % Check if directional derivatives can be obtained, since 0026 ... % it is possible to compute the gradient from directional 0027 ... % derivatives (expensively). Here, it is not possible to 0028 ... % call canGetDirectionalDerivative, because that function 0029 ... % would then potentially call canGetGradient, thus 0030 ... % starting an infinite loop. As a result, we have some 0031 ... % code redundancy: the check below needs to be kept 0032 ... % equivalent to the check in canGetDirectionalDerivative. 0033 isfield(problem, 'diff'); 0034 0035 end