Author: bugman Date: Fri Feb 25 14:26:23 2011 New Revision: 12626 URL: http://svn.gna.org/viewcvs/relax?rev=12626&view=rev Log: Added wrapper methods to the relaxation curve-fitting specific code for the new C modules. These allow the parameter numpy array from minfx to be converted into a Python list prior to sending it into the C module. Modified: 1.3/specific_fns/relax_fit.py Modified: 1.3/specific_fns/relax_fit.py URL: http://svn.gna.org/viewcvs/relax/1.3/specific_fns/relax_fit.py?rev=12626&r1=12625&r2=12626&view=diff ============================================================================== --- 1.3/specific_fns/relax_fit.py (original) +++ 1.3/specific_fns/relax_fit.py Fri Feb 25 14:26:23 2011 @@ -184,7 +184,7 @@ setup(num_params=len(spin.params), num_times=len(cdp.relax_times), values=values, sd=errors, relax_times=times, scaling_matrix=scaling_matrix) # Make a single function call. This will cause back calculation and the data will be stored in the C module. - func(param_vector) + self._func(param_vector) # Get the data back. results = back_calc_I() @@ -227,6 +227,36 @@ # Intensity at infinity. if cdp.curve_type == 'inv': spin.iinf = param_vector[2] + + + def _func(self, params): + """Wrapper function for the C module, for converting numpy arrays. + + @param params: The parameter array from the minimisation code. + @type params: numpy array + @return: The function value generated by the C module. + @rtype: float + """ + + # Call the C code. + chi2 = func(params.tolist()) + + # Return the chi2 value. + return chi2 + + + def _dfunc(self, params): + """Wrapper function for the C module, for converting numpy arrays. + + The currently does nothing. + """ + + + def _d2func(self, params): + """Wrapper function for the C module, for converting numpy arrays. + + The currently does nothing. + """ def _grid_search_setup(self, spin=None, param_vector=None, lower=None, upper=None, inc=None, scaling_matrix=None): @@ -762,7 +792,7 @@ # The relaxation times. times.append(cdp.relax_times[key]) - setup(num_params=len(spin.params), num_times=len(cdp.relax_times), values=values, sd=errors, relax_times=times, scaling_matrix=scaling_matrix) + setup(num_params=len(spin.params), num_times=len(cdp.relax_times), values=values, sd=errors, relax_times=times, scaling_matrix=scaling_matrix.tolist()) # Setup the minimisation algorithm when constraints are present. @@ -793,7 +823,7 @@ # Grid search. if search('^[Gg]rid', min_algor): - results = grid(func=func, args=(), num_incs=inc, lower=lower, upper=upper, A=A, b=b, verbosity=verbosity) + results = grid(func=self._func, args=(), num_incs=inc, lower=lower, upper=upper, A=A, b=b, verbosity=verbosity) # Unpack the results. param_vector, chi2, iter_count, warning = results @@ -803,7 +833,7 @@ # Minimisation. else: - results = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=param_vector, min_algor=min_algor, min_options=min_options, func_tol=func_tol, grad_tol=grad_tol, maxiter=max_iterations, A=A, b=b, full_output=True, print_flag=verbosity) + results = generic_minimise(func=self._func, dfunc=self._dfunc, d2func=self._d2func, args=(), x0=param_vector, min_algor=min_algor, min_options=min_options, func_tol=func_tol, grad_tol=grad_tol, maxiter=max_iterations, A=A, b=b, full_output=True, print_flag=verbosity) # Unpack the results. if results == None: