Author: tlinnet Date: Thu May 29 11:35:35 2014 New Revision: 23582 URL: http://svn.gna.org/viewcvs/relax?rev=23582&view=rev Log: Converting back to having back_calc as a function argument to model M61b: This is to clean up the API. There can be bo no partial measures/implementations in the relax trunk. The problem is, that many numerical models can't be optimised further, since they evolve the spin-magnetisation in a matrix. That spin evolvement can't be put into a larger numpy array. This is related to: task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models. Modified: branches/disp_speed/lib/dispersion/m61b.py branches/disp_speed/target_functions/relax_disp.py branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61b.py Modified: branches/disp_speed/lib/dispersion/m61b.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/m61b.py?rev=23582&r1=23581&r2=23582&view=diff ============================================================================== --- branches/disp_speed/lib/dispersion/m61b.py (original) +++ branches/disp_speed/lib/dispersion/m61b.py Thu May 29 11:35:35 2014 @@ -62,7 +62,7 @@ # Python module imports. from numpy import abs, array, isfinite, min, sum -def r1rho_M61b(r1rho_prime=None, pA=None, dw=None, kex=None, spin_lock_fields2=None, num_points=None): +def r1rho_M61b(r1rho_prime=None, pA=None, dw=None, kex=None, spin_lock_fields2=None, back_calc=None, num_points=None): """Calculate the R1rho values for the M61 skew model. See the module docstring for details. @@ -78,7 +78,9 @@ @type kex: float @keyword spin_lock_fields2: The R1rho spin-lock field strengths squared (in rad^2.s^-2). @type spin_lock_fields2: numpy rank-1 float array - @keyword num_points: The number of points on the dispersion curve, equal to the length of the spin_lock_fields. + @keyword back_calc: The array for holding the back calculated R1rho values. Each element corresponds to the combination of spin lock field. + @type back_calc: numpy rank-1 float array + @keyword num_points: The number of points on the dispersion curve, equal to the length of the spin_lock_fields and back_calc arguments. @type num_points: int """ @@ -95,7 +97,8 @@ # Catch zeros (to avoid pointless mathematical operations). # This will result in no exchange, returning flat lines. if numer == 0.0: - return array([r1rho_prime]*num_points) + back_calc[:] = array([r1rho_prime]*num_points) + return # Denominator. denom = kex2_pA2dw2 + spin_lock_fields2 @@ -103,7 +106,8 @@ # Catch math domain error of dividing with 0. # This is when denom=0. if min(abs(denom)) == 0: - return array([1e100]*num_points) + back_calc[:] = array([1e100]*num_points) + return # R1rho calculation. @@ -112,6 +116,6 @@ # Catch errors, taking a sum over array is the fastest way to check for # +/- inf (infinity) and nan (not a number). if not isfinite(sum(R1rho)): - return array([1e100]*num_points) + R1rho = array([1e100]*num_points) - return R1rho + back_calc[:] = R1rho Modified: branches/disp_speed/target_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/target_functions/relax_disp.py?rev=23582&r1=23581&r2=23582&view=diff ============================================================================== --- branches/disp_speed/target_functions/relax_disp.py (original) +++ branches/disp_speed/target_functions/relax_disp.py Thu May 29 11:35:35 2014 @@ -1210,7 +1210,7 @@ dw_frq = dw[si] * self.frqs[0][si][mi] # Back calculate the R1rho values. - self.back_calc[0][si][mi][0] = r1rho_M61b(r1rho_prime=R20[r20_index], pA=pA, dw=dw_frq, kex=kex, spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][0], num_points=self.num_disp_points[0][si][mi][0]) + r1rho_M61b(r1rho_prime=R20[r20_index], pA=pA, dw=dw_frq, kex=kex, spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][0], back_calc=self.back_calc[0][si][mi][0], num_points=self.num_disp_points[0][si][mi][0]) # For all missing data points, set the back-calculated value to the measured values so that it has no effect on the chi-squared value. for di in range(self.num_disp_points[0][si][mi][0]): Modified: branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61b.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61b.py?rev=23582&r1=23581&r2=23582&view=diff ============================================================================== --- branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61b.py (original) +++ branches/disp_speed/test_suite/unit_tests/_lib/_dispersion/test_m61b.py Thu May 29 11:35:35 2014 @@ -53,6 +53,7 @@ # Required data structures. self.num_points = 11 + self.R1rho = zeros(self.num_points, float64) def calc_r1rho(self): @@ -62,16 +63,16 @@ phi_ex_scaled, dw_frq, spin_lock_omega1_squared = self.param_conversion(pA=self.pA, dw=self.dw, sfrq=self.sfrq, spin_lock_nu1=self.spin_lock_nu1) # Calculate the R1rho values. - R1rho = r1rho_M61b(r1rho_prime=self.r1rho_prime, pA=self.pA, dw=dw_frq, kex=self.kex, spin_lock_fields2=spin_lock_omega1_squared, num_points=self.num_points) + R1rho = r1rho_M61b(r1rho_prime=self.r1rho_prime, pA=self.pA, dw=dw_frq, kex=self.kex, spin_lock_fields2=spin_lock_omega1_squared, back_calc=self.R1rho, num_points=self.num_points) # Check all R1rho values. if self.kex > 1.e5: for i in range(self.num_points): - self.assertAlmostEqual(R1rho[i], self.r1rho_prime, 2) + self.assertAlmostEqual(self.R1rho[i], self.r1rho_prime, 2) else: for i in range(self.num_points): - self.assertAlmostEqual(R1rho[i], self.r1rho_prime) + self.assertAlmostEqual(self.R1rho[i], self.r1rho_prime) def param_conversion(self, pA=None, dw=None, sfrq=None, spin_lock_nu1=None):