Hi Troels, Is it possible to shift the mask_replace part into __init__()? That might give more speed ups. I'm not so familiar with numpy masks, so I couldn't have helped you with that. Anyway, those 4 hours invested is guaranteed to save you much more than 4 hours when you use this later.
Regards, Edward On 10 June 2014 16:51, <[email protected]> wrote: > Author: tlinnet > Date: Tue Jun 10 16:51:33 2014 > New Revision: 23788 > > URL: http://svn.gna.org/viewcvs/relax?rev=23788&view=rev > Log: > Implemented a masked array search for where "missing" array is equal 1. > > This makes it possible to replace all values with this mask, from the value > array. > > This eliminates the last loops over the missing values. > > It took over 4 hours to figure out, that the mask should be called with > mask.mask, > to return the same fulls structure, > > Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion > models for Clustered analysis. > > Modified: > branches/disp_spin_speed/target_functions/relax_disp.py > > Modified: branches/disp_spin_speed/target_functions/relax_disp.py > URL: > http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/target_functions/relax_disp.py?rev=23788&r1=23787&r2=23788&view=diff > ============================================================================== > --- branches/disp_spin_speed/target_functions/relax_disp.py (original) > +++ branches/disp_spin_speed/target_functions/relax_disp.py Tue Jun 10 > 16:51:33 2014 > @@ -29,6 +29,7 @@ > from math import pi > from numpy import array, asarray, complex64, dot, float64, int16, max, ones, > sqrt, sum, zeros > import numpy as np > +from numpy.ma import masked_equal > > # relax module imports. > from lib.dispersion.b14 import r2eff_B14 > @@ -418,6 +419,7 @@ > # The number of disp point can change per spectrometer, so we > make the maximum size. > self.values_a = deepcopy(self.zeros_a) > self.errors_a = deepcopy(self.ones_a) > + self.missing_a = zeros(self.numpy_array_shape) > > self.cpmg_frqs_a = deepcopy(self.ones_a) > self.num_disp_points_a = deepcopy(self.zeros_a) > @@ -456,6 +458,7 @@ > for di in > range(self.num_disp_points[ei][si][mi][oi]): > if self.missing[ei][si][mi][oi][di]: > self.has_missing = True > + self.missing_a[ei][si][mi][oi][di] = 1.0 > > # Make copy of values structure. > self.back_calc_a = deepcopy(self.values_a) > @@ -574,15 +577,11 @@ > > ## 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. > if self.has_missing: > - # Loop over the spins. > - for si in range(self.num_spins): > - # Loop over the spectrometer frequencies. > - for mi in range(self.num_frq): > - # Loop over the dispersion points. > - for di in range(self.num_disp_points[0][si][mi][0]): > - if self.missing[0][si][mi][0][di]: > - #self.back_calc[0][si][mi][0][di] = > self.values[0][si][mi][0][di] > - self.back_calc_a[0][si][mi][0][di] = > self.values[0][si][mi][0][di] > + # Find the numpy mask, which tells where values should be > replaced. > + mask_replace = masked_equal(self.missing_a, 1.0) > + > + # Replace with values. > + self.back_calc_a[mask_replace.mask] = > self.values_a[mask_replace.mask] > > ## Calculate the chi-squared statistic. > return sum((1.0 / self.errors_a * (self.values_a - > self.back_calc_a))**2) > > > _______________________________________________ > 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 _______________________________________________ relax (http://www.nmr-relax.com) This is the relax-devel 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-devel

