Ignore:
Timestamp:
Mar 12, 2019 7:15:06 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI_sync_sascalc
Parents:
390494d
Message:

Cherry-picked changes from py37-sascalc branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/corfunc/corfunc_calculator.py

    r6ae7466 r44a698c  
    3030            self.start = start 
    3131            self.stop = stop 
    32             self._lastx = [] 
    33             self._lasty = [] 
     32            self._lastx = np.empty(0, dtype='d') 
     33            self._lasty = None 
    3434 
    3535        def __call__(self, x): 
    3636            # If input is a single number, evaluate the function at that number 
    3737            # and return a single number 
    38             if type(x) == float or type(x) == int: 
     38            if isinstance(x, (float, int)): 
    3939                return self._smoothed_function(np.array([x]))[0] 
    4040            # If input is a list, and is different to the last input, evaluate 
     
    4242            # the function was called, return the result that was calculated 
    4343            # last time instead of explicity evaluating the function again. 
    44             elif self._lastx == [] or x.tolist() != self._lastx.tolist(): 
    45                 self._lasty = self._smoothed_function(x) 
    46                 self._lastx = x 
     44            if not np.array_equal(x, self._lastx): 
     45                self._lastx, self._lasty = x, self._smoothed_function(x) 
    4746            return self._lasty 
    4847 
     
    8887        # Only process data of the class Data1D 
    8988        if not issubclass(data.__class__, Data1D): 
    90             raise ValueError("Correlation function cannot be computed with 2D Data.") 
     89            raise ValueError("Correlation function cannot be computed with 2D data.") 
    9190 
    9291        # Prepare the data 
Note: See TracChangeset for help on using the changeset viewer.