Line 0
Link Here
|
|
|
1 |
Backport of: |
2 |
https://github.com/Kst-plot/kst/commit/a9d24f91057441bbd2e3ed9e7536b071121526cb |
3 |
|
4 |
From a9d24f91057441bbd2e3ed9e7536b071121526cb Mon Sep 17 00:00:00 2001 |
5 |
From: "D. V. Wiebe" <dvw@ketiltrout.net> |
6 |
Date: Thu, 10 Mar 2016 14:09:26 -0800 |
7 |
Subject: [PATCH] GSL-2.x support. |
8 |
|
9 |
|
10 |
--- src/plugins/fits/non_linear.h.orig 2014-02-13 09:41:44 UTC |
11 |
+++ src/plugins/fits/non_linear.h |
12 |
@@ -18,6 +18,7 @@ |
13 |
#include <gsl/gsl_blas.h> |
14 |
#include <gsl/gsl_multifit_nlin.h> |
15 |
#include <gsl/gsl_statistics.h> |
16 |
+#include <gsl/gsl_version.h> |
17 |
#include "common.h" |
18 |
|
19 |
struct data { |
20 |
@@ -100,6 +101,7 @@ bool kstfit_nonlinear( |
21 |
gsl_multifit_function_fdf function; |
22 |
gsl_vector_view vectorViewInitial; |
23 |
gsl_matrix* pMatrixCovariance; |
24 |
+ gsl_matrix* pMatrixJacobian; |
25 |
struct data d; |
26 |
double dXInitial[NUM_PARAMS]; |
27 |
double* pInputX; |
28 |
@@ -177,7 +179,16 @@ bool kstfit_nonlinear( |
29 |
} |
30 |
iIterations++; |
31 |
} while( iStatus == GSL_CONTINUE && iIterations < MAX_NUM_ITERATIONS ); |
32 |
- gsl_multifit_covar( pSolver->J, 0.0, pMatrixCovariance ); |
33 |
+#if GSL_MAJOR_VERSION >= 2 |
34 |
+ pMatrixJacobian = gsl_matrix_alloc( iLength, NUM_PARAMS ); |
35 |
+#else |
36 |
+ pMatrixJacobian = pSolver->J; |
37 |
+#endif |
38 |
+ if ( pMatrixJacobian != NULL ) { |
39 |
+#if GSL_MAJOR_VERSION >= 2 |
40 |
+ gsl_multifit_fdfsolver_jac( pSolver, pMatrixJacobian ); |
41 |
+#endif |
42 |
+ gsl_multifit_covar( pMatrixJacobian, 0.0, pMatrixCovariance ); |
43 |
|
44 |
// |
45 |
// determine the fitted values... |
46 |
@@ -207,7 +218,10 @@ bool kstfit_nonlinear( |
47 |
scalarOutChi->setValue(gsl_blas_dnrm2( pSolver->f )); |
48 |
|
49 |
bReturn = true; |
50 |
- |
51 |
+#if GSL_MAJOR_VERSION >= 2 |
52 |
+ gsl_matrix_free( pMatrixJacobian ); |
53 |
+#endif |
54 |
+ } |
55 |
gsl_matrix_free( pMatrixCovariance ); |
56 |
} |
57 |
gsl_multifit_fdfsolver_free( pSolver ); |
58 |
--- src/plugins/fits/non_linear_weighted.h.orig 2014-02-13 09:41:44 UTC |
59 |
+++ src/plugins/fits/non_linear_weighted.h |
60 |
@@ -18,6 +18,7 @@ |
61 |
#include <gsl/gsl_blas.h> |
62 |
#include <gsl/gsl_multifit_nlin.h> |
63 |
#include <gsl/gsl_statistics.h> |
64 |
+#include <gsl/gsl_version.h> |
65 |
#include "common.h" |
66 |
|
67 |
struct data { |
68 |
@@ -101,6 +102,7 @@ bool kstfit_nonlinear_weighted( |
69 |
gsl_multifit_function_fdf function; |
70 |
gsl_vector_view vectorViewInitial; |
71 |
gsl_matrix* pMatrixCovariance; |
72 |
+ gsl_matrix* pMatrixJacobian; |
73 |
struct data d; |
74 |
double dXInitial[NUM_PARAMS]; |
75 |
double* pInputs[3]; |
76 |
@@ -193,7 +195,17 @@ bool kstfit_nonlinear_weighted( |
77 |
} |
78 |
while( iStatus == GSL_CONTINUE && iIterations < MAX_NUM_ITERATIONS ); |
79 |
|
80 |
- gsl_multifit_covar( pSolver->J, 0.0, pMatrixCovariance ); |
81 |
+#if GSL_MAJOR_VERSION >= 2 |
82 |
+ pMatrixJacobian = gsl_matrix_alloc( iLength, NUM_PARAMS ); |
83 |
+#else |
84 |
+ pMatrixJacobian = pSolver->J; |
85 |
+#endif |
86 |
+ |
87 |
+ if ( pMatrixJacobian != NULL ) { |
88 |
+#if GSL_MAJOR_VERSION >= 2 |
89 |
+ gsl_multifit_fdfsolver_jac( pSolver, pMatrixJacobian ); |
90 |
+#endif |
91 |
+ gsl_multifit_covar( pMatrixJacobian, 0.0, pMatrixCovariance ); |
92 |
|
93 |
// |
94 |
// determine the fitted values... |
95 |
@@ -223,7 +235,10 @@ bool kstfit_nonlinear_weighted( |
96 |
scalarOutChi->setValue(gsl_blas_dnrm2( pSolver->f )); |
97 |
|
98 |
bReturn = true; |
99 |
- |
100 |
+#if GSL_VERSION_MAJOR >= 2 |
101 |
+ gsl_matrix_free( pMatrixJacobian ); |
102 |
+#endif |
103 |
+ } |
104 |
gsl_matrix_free( pMatrixCovariance ); |
105 |
} |
106 |
gsl_multifit_fdfsolver_free( pSolver ); |