Author: bugman
Date: Tue Aug 26 17:13:48 2014
New Revision: 25296
URL: http://svn.gna.org/viewcvs/relax?rev=25296&view=rev
Log:
Shifted all of the parameter Python lists to C arrays into the new param_to_c()
function.
This is for the target_functions.relax_fit C module to avoid much duplicated
code.
Modified:
trunk/target_functions/relax_fit.c
Modified: trunk/target_functions/relax_fit.c
URL:
http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.c?rev=25296&r1=25295&r2=25296&view=diff
==============================================================================
--- trunk/target_functions/relax_fit.c (original)
+++ trunk/target_functions/relax_fit.c Tue Aug 26 17:13:48 2014
@@ -76,6 +76,27 @@
Py_RETURN_NONE;
}
+
+void param_to_c(PyObject *params_arg) {
+ /* Convert the Python parameter list to a C array. */
+
+ /* Declarations */
+ PyObject *element;
+ int i;
+
+ /* Place the parameter array elements into the C array */
+ for (i = 0; i < num_params; i++) {
+ /* Get the element */
+ element = PySequence_GetItem(params_arg, i);
+
+ /* Convert to a C double, then free the memory. */
+ params[i] = PyFloat_AsDouble(element);
+ Py_CLEAR(element);
+
+ /* Scale the parameter */
+ params[i] = params[i] * scaling_matrix[i];
+ }
+}
static PyObject *
func(PyObject *self, PyObject *args) {
@@ -87,25 +108,13 @@
/* Declarations */
PyObject *params_arg;
- PyObject *element;
- int i;
/* Parse the function arguments, the only argument should be the parameter
array */
if (!PyArg_ParseTuple(args, "O", ¶ms_arg))
return NULL;
- /* Place the parameter array elements into the C array */
- for (i = 0; i < num_params; i++) {
- /* Get the element */
- element = PySequence_GetItem(params_arg, i);
-
- /* Convert to a C double, then free the memory. */
- params[i] = PyFloat_AsDouble(element);
- Py_CLEAR(element);
-
- /* Scale the parameter */
- params[i] = params[i] * scaling_matrix[i];
- }
+ /* Convert the parameters Python list to a C array */
+ param_to_c(params_arg);
/* Back calculated the peak intensities */
exponential(params[index_I0], params[index_R], relax_times, back_calc,
num_times);
@@ -124,25 +133,14 @@
/* Declarations */
PyObject *params_arg;
- PyObject *element;
int i;
/* Parse the function arguments, the only argument should be the parameter
array */
if (!PyArg_ParseTuple(args, "O", ¶ms_arg))
return NULL;
- /* Place the parameter array elements into the C array */
- for (i = 0; i < num_params; i++) {
- /* Get the element */
- element = PySequence_GetItem(params_arg, i);
-
- /* Convert to a C double, then free the memory. */
- params[i] = PyFloat_AsDouble(element);
- Py_CLEAR(element);
-
- /* Scale the parameter */
- params[i] = params[i] * scaling_matrix[i];
- }
+ /* Convert the parameters Python list to a C array */
+ param_to_c(params_arg);
/* Back calculated the peak intensities */
exponential(params[index_I0], params[index_R], relax_times, back_calc,
num_times);
@@ -199,25 +197,14 @@
/* Declarations */
PyObject *params_arg;
- PyObject *element;
int i, j;
/* Parse the function arguments, the only argument should be the parameter
array */
if (!PyArg_ParseTuple(args, "O", ¶ms_arg))
return NULL;
- /* Place the parameter array elements into the C array */
- for (i = 0; i < num_params; i++) {
- /* Get the element */
- element = PySequence_GetItem(params_arg, i);
-
- /* Convert to a C double, then free the memory. */
- params[i] = PyFloat_AsDouble(element);
- Py_CLEAR(element);
-
- /* Scale the parameter */
- params[i] = params[i] * scaling_matrix[i];
- }
+ /* Convert the parameters Python list to a C array */
+ param_to_c(params_arg);
/* The partial derivates */
exponential_dR(params[index_I0], params[index_R], index_R, relax_times,
back_calc_grad, num_times);
_______________________________________________
relax (http://www.nmr-relax.com)
This is the relax-commits mailing list
[email protected]
To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits