| 1 | From 850a56cad37733694a6858314e30e3dafbacc220 Mon Sep 17 00:00:00 2001 |
| 2 | From: Pere Mato <pere.mato@cern.ch> |
| 3 | Date: Tue, 15 Dec 2015 11:58:24 +0100 |
| 4 | Subject: [PATCH] Fix for ROOT-7776 - Integrate GSL 2.0 in ROOT. |
| 5 | |
| 6 | --- |
| 7 | math/mathmore/src/GSLMultiFit.h | 40 ++++++++++++++++++++++++++-------------- |
| 8 | 1 file changed, 26 insertions(+), 14 deletions(-) |
| 9 | |
| 10 | diff --git a/math/mathmore/src/GSLMultiFit.h b/math/mathmore/src/GSLMultiFit.h |
| 11 | index a1cb348..e2570a0 100644 |
| 12 | --- math/mathmore/src/GSLMultiFit.h |
| 13 | +++ math/mathmore/src/GSLMultiFit.h |
| 14 | @@ -31,6 +31,7 @@ |
| 15 | #include "gsl/gsl_matrix.h" |
| 16 | #include "gsl/gsl_multifit_nlin.h" |
| 17 | #include "gsl/gsl_blas.h" |
| 18 | +#include "gsl/gsl_version.h" |
| 19 | #include "GSLMultiFitFunctionWrapper.h" |
| 20 | |
| 21 | #include "Math/IFunction.h" |
| 22 | @@ -127,20 +128,24 @@ class GSLMultiFit { |
| 23 | int Iterate() { |
| 24 | if (fSolver == 0) return -1; |
| 25 | return gsl_multifit_fdfsolver_iterate(fSolver); |
| 26 | - } |
| 27 | - |
| 28 | - /// parameter values at the minimum |
| 29 | - const double * X() const { |
| 30 | - if (fSolver == 0) return 0; |
| 31 | - gsl_vector * x = gsl_multifit_fdfsolver_position(fSolver); |
| 32 | - return x->data; |
| 33 | } |
| 34 | |
| 35 | - /// gradient value at the minimum |
| 36 | - const double * Gradient() const { |
| 37 | - if (fSolver == 0) return 0; |
| 38 | - gsl_multifit_gradient(fSolver->J, fSolver->f,fVec); |
| 39 | - return fVec->data; |
| 40 | + /// parameter values at the minimum |
| 41 | + const double * X() const { |
| 42 | + if (fSolver == 0) return 0; |
| 43 | + gsl_vector * x = gsl_multifit_fdfsolver_position(fSolver); |
| 44 | + return x->data; |
| 45 | + } |
| 46 | + |
| 47 | + /// gradient value at the minimum |
| 48 | + const double * Gradient() const { |
| 49 | + if (fSolver == 0) return 0; |
| 50 | +#if GSL_MAJOR_VERSION > 1 |
| 51 | + fType->gradient(fSolver->state, fVec); |
| 52 | +#else |
| 53 | + gsl_multifit_gradient(fSolver->J, fSolver->f,fVec); |
| 54 | +#endif |
| 55 | + return fVec->data; |
| 56 | } |
| 57 | |
| 58 | /// return covariance matrix of the parameters |
| 59 | @@ -150,9 +155,16 @@ class GSLMultiFit { |
| 60 | unsigned int npar = fSolver->fdf->p; |
| 61 | fCov = gsl_matrix_alloc( npar, npar ); |
| 62 | static double kEpsrel = 0.0001; |
| 63 | +#if GSL_MAJOR_VERSION > 1 |
| 64 | + gsl_matrix* J = gsl_matrix_alloc(npar,npar); |
| 65 | + gsl_multifit_fdfsolver_jac (fSolver, J); |
| 66 | + int ret = gsl_multifit_covar(J, kEpsrel, fCov); |
| 67 | + gsl_matrix_free(J); |
| 68 | +#else |
| 69 | int ret = gsl_multifit_covar(fSolver->J, kEpsrel, fCov); |
| 70 | - if (ret != GSL_SUCCESS) return 0; |
| 71 | - return fCov->data; |
| 72 | +#endif |
| 73 | + if (ret != GSL_SUCCESS) return 0; |
| 74 | + return fCov->data; |
| 75 | } |
| 76 | |
| 77 | /// test gradient (ask from solver gradient vector) |