yat/utility/multivariable/df.h

Code
Comments
Other
Rev Date Author Line
4252 18 Nov 22 peter 1 #ifndef theplu_yat_utility_multivariable_df
4252 18 Nov 22 peter 2 #define theplu_yat_utility_multivariable_df
4175 01 Jun 22 peter 3
4175 01 Jun 22 peter 4 // $Id$
4175 01 Jun 22 peter 5
4175 01 Jun 22 peter 6 /*
4175 01 Jun 22 peter 7   Copyright (C) 2022 Peter Johansson
4175 01 Jun 22 peter 8
4175 01 Jun 22 peter 9   This file is part of the yat library, http://dev.thep.lu.se/yat
4175 01 Jun 22 peter 10
4175 01 Jun 22 peter 11   The yat library is free software; you can redistribute it and/or
4175 01 Jun 22 peter 12   modify it under the terms of the GNU General Public License as
4175 01 Jun 22 peter 13   published by the Free Software Foundation; either version 3 of the
4175 01 Jun 22 peter 14   License, or (at your option) any later version.
4175 01 Jun 22 peter 15
4175 01 Jun 22 peter 16   The yat library is distributed in the hope that it will be useful,
4175 01 Jun 22 peter 17   but WITHOUT ANY WARRANTY; without even the implied warranty of
4175 01 Jun 22 peter 18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4175 01 Jun 22 peter 19   General Public License for more details.
4175 01 Jun 22 peter 20
4175 01 Jun 22 peter 21   You should have received a copy of the GNU General Public License
4175 01 Jun 22 peter 22   along with yat. If not, see <https://www.gnu.org/licenses/>.
4175 01 Jun 22 peter 23 */
4175 01 Jun 22 peter 24
4175 01 Jun 22 peter 25 #include "f.h"
4175 01 Jun 22 peter 26
4175 01 Jun 22 peter 27 #include <yat/utility/VectorConstView.h>
4175 01 Jun 22 peter 28 #include <yat/utility/VectorView.h>
4175 01 Jun 22 peter 29
4175 01 Jun 22 peter 30 #include <gsl/gsl_vector.h>
4175 01 Jun 22 peter 31
4175 01 Jun 22 peter 32 namespace theplu {
4175 01 Jun 22 peter 33 namespace yat {
4175 01 Jun 22 peter 34 namespace utility {
4175 01 Jun 22 peter 35
4252 18 Nov 22 peter 36   namespace multivariable
4175 01 Jun 22 peter 37   {
4175 01 Jun 22 peter 38     template<class FUNC>
4175 01 Jun 22 peter 39     void df(const gsl_vector* gsl_x, void* params, gsl_vector* gradient)
4175 01 Jun 22 peter 40     {
4175 01 Jun 22 peter 41       FUNC* func = static_cast<FUNC*>(params);
4175 01 Jun 22 peter 42       yat::utility::VectorConstView x(gsl_x);
4175 01 Jun 22 peter 43       yat::utility::VectorView g(gradient);
4175 01 Jun 22 peter 44       (*func)(x, g);
4175 01 Jun 22 peter 45     }
4175 01 Jun 22 peter 46
4175 01 Jun 22 peter 47
4175 01 Jun 22 peter 48     template<class FUNC>
4175 01 Jun 22 peter 49     void fdf(const gsl_vector* x, void* params,
4175 01 Jun 22 peter 50              double* y, gsl_vector* gradient)
4175 01 Jun 22 peter 51     {
4175 01 Jun 22 peter 52       *y = f<FUNC>(x, params);
4175 01 Jun 22 peter 53       df<FUNC>(x, params, gradient);
4175 01 Jun 22 peter 54     }
4252 18 Nov 22 peter 55   } // end namespace multivariable
4175 01 Jun 22 peter 56
4175 01 Jun 22 peter 57 }}} // end namespaces utility, yat and theplu
4175 01 Jun 22 peter 58 #endif