X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Foptim-1.2.0%2Fprivate%2F__s2mat__.m;fp=octave_packages%2Foptim-1.2.0%2Fprivate%2F__s2mat__.m;h=21ee031a5277508d0cf0fe895fd3b2ae9bf7ac07;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/optim-1.2.0/private/__s2mat__.m b/octave_packages/optim-1.2.0/private/__s2mat__.m new file mode 100644 index 0000000..21ee031 --- /dev/null +++ b/octave_packages/optim-1.2.0/private/__s2mat__.m @@ -0,0 +1,50 @@ +## Copyright (C) 2010 Olaf Till +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; If not, see . + +## __s2mat__ (s, ord) +## +## Returns a matrix of second derivatives with respect to some +## parameters from the structure-based representation of such a matrix +## in s, using the order of parameter names ord. s has to contain all +## fields named in ord. Each field has some subfields named in ord so +## that each second derivative is represented at least in one of its two +## possible orders. If it is represented differently in both orders, no +## error is returned, but both entries might get into the final matrix +## at symmetric positions. +## +## Should be included as a subfunction of a wrapper for optimization +## functions possibly needing a Hessian. + +function ret = __s2mat__ (s, ord) + + if (any (size (s) != [1, 1])) + error ("structure must be scalar"); + endif + + if (! (iscell (ord) && isvector (ord))) + error ("ord must be a one-dimensional cell-array"); + endif + + c = fields2cell (structcat (1, fields2cell (s, ord){:}), ord); + + neidx = ! (eidx = cellfun ("isempty", c)); + + ret = zeros (length (ord)); + + ret(neidx) = [c{neidx}]; # faster than [c{:}] ? + + ret(eidx) = ret.'(eidx); + +endfunction \ No newline at end of file