Author: bugman Date: Wed Nov 26 19:42:20 2014 New Revision: 26770 URL: http://svn.gna.org/viewcvs/relax?rev=26770&view=rev Log: Shifted the C code Jacobian functions into the new target_functions.relax_fit_wrapper module. This shifts all of the relaxation curve-fitting C code access into the target_functions.relax_fit_wrapper module so that the rest of relax does not need to handle the C code. This will allow for new models to be very easily supported, as they would all be set up in this target function module. Modified: trunk/specific_analyses/relax_disp/estimate_r2eff.py trunk/specific_analyses/relax_fit/api.py trunk/target_functions/relax_fit_wrapper.py Modified: trunk/specific_analyses/relax_disp/estimate_r2eff.py URL: http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/estimate_r2eff.py?rev=26770&r1=26769&r2=26770&view=diff ============================================================================== --- trunk/specific_analyses/relax_disp/estimate_r2eff.py (original) +++ trunk/specific_analyses/relax_disp/estimate_r2eff.py Wed Nov 26 19:42:20 2014 @@ -44,10 +44,6 @@ from target_functions.chi2 import chi2_rankN, dchi2 from target_functions.relax_fit_wrapper import Relax_fit_opt -# C modules. -if C_module_exp_fn: - from target_functions.relax_fit import jacobian, jacobian_chi2, setup - # Scipy installed. if scipy_module: # Import leastsq. @@ -123,10 +119,10 @@ # Initialise data in C code. scaling_list = [1.0, 1.0] - setup(num_params=len(param_vector), num_times=len(times), values=values, sd=errors, relax_times=times, scaling_matrix=scaling_list) + model = Relax_fit_opt(num_params=len(param_vector), values=values, errors=errors, relax_times=times, scaling_matrix=scaling_list) # Use the direct Jacobian from function. - jacobian_matrix_exp = transpose(asarray( jacobian(param_vector) ) ) + jacobian_matrix_exp = transpose(asarray( model.jacobian(param_vector) ) ) weights = 1. / errors**2 # Get the co-variance @@ -823,12 +819,12 @@ if E.c_code == True: if E.chi2_jacobian: # Use the chi2 Jacobian from C. - jacobian_matrix_exp = transpose(asarray( jacobian_chi2(param_vector) ) ) + jacobian_matrix_exp = transpose(asarray( model.jacobian_chi2(param_vector) ) ) weights = ones(E.errors.shape) else: # Use the direct Jacobian from C. - jacobian_matrix_exp = transpose(asarray( jacobian(param_vector) ) ) + jacobian_matrix_exp = transpose(asarray( model.jacobian(param_vector) ) ) weights = 1. / E.errors**2 elif E.c_code == False: Modified: trunk/specific_analyses/relax_fit/api.py URL: http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_fit/api.py?rev=26770&r1=26769&r2=26770&view=diff ============================================================================== --- trunk/specific_analyses/relax_fit/api.py (original) +++ trunk/specific_analyses/relax_fit/api.py Wed Nov 26 19:42:20 2014 @@ -45,10 +45,6 @@ from specific_analyses.relax_fit.parameters import assemble_param_vector, disassemble_param_vector, linear_constraints from target_functions.relax_fit_wrapper import Relax_fit_opt -# C modules. -if C_module_exp_fn: - from target_functions.relax_fit import jacobian, setup - class Relax_fit(API_base, API_common): """Class containing functions for relaxation curve fitting.""" @@ -139,10 +135,10 @@ # Initialise data in C code. scaling_list = [1.0, 1.0] - setup(num_params=len(param_vector), num_times=len(times), values=values, sd=errors, relax_times=times, scaling_matrix=scaling_list) + model = Relax_fit_opt(num_params=len(param_vector), values=values, errors=errors, relax_times=times, scaling_matrix=scaling_list) # Use the direct Jacobian from function. - jacobian_matrix_exp = transpose(asarray( jacobian(param_vector) ) ) + jacobian_matrix_exp = transpose(asarray( model.jacobian(param_vector) ) ) weights = 1. / errors**2 # Return the matrices. Modified: trunk/target_functions/relax_fit_wrapper.py URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit_wrapper.py?rev=26770&r1=26769&r2=26770&view=diff ============================================================================== --- trunk/target_functions/relax_fit_wrapper.py (original) +++ trunk/target_functions/relax_fit_wrapper.py Wed Nov 26 19:42:20 2014 @@ -32,7 +32,7 @@ # C modules. if C_module_exp_fn: - from target_functions.relax_fit import setup, func, dfunc, d2func, back_calc_I + from target_functions.relax_fit import jacobian, jacobian_chi2, setup, func, dfunc, d2func, back_calc_I class Relax_fit_opt: @@ -60,6 +60,10 @@ self.func = self.func_wrapper self.dfunc = self.dfunc_wrapper self.d2func = self.d2func_wrapper + + # Alias the Jacobian C functions. + self.jacobian = jacobian + self.jacobian_chi2 = jacobian_chi2 def back_calc_data(self):