original_docstring:  Perform the vectorized exponential moving average in a safe way. 
docstring: Perform the vectorized exponential moving average in a safe way.
docstring_tokens: Perform the vectorized exponential moving average in a safe way .
code: def _ewma_vectorized_safe(self):
          """ Perform the vectorized exponential moving average in a safe way. """
          num_rows = int(self._data.size // self._row_size)  # the number of rows to use
          leftover = int(self._data.size % self._row_size)  # the amount of data leftover
          first_offset = self._data[0]
  
          if leftover > 0:
              # set temporary results to slice view of out parameter
              out_main_view = np.reshape(self._out[:-leftover], (num_rows, self._row_size))
              data_main_view = np.reshape(self._data[:-leftover], (num_rows, self._row_size))
          else:
              out_main_view = self._out.reshape(-1, self._row_size)
              data_main_view = self._data.reshape(-1, self._row_size)
  
          self._ewma_vectorized_2d(data_main_view, out_main_view)  # get the scaled cumulative sums
  
          scaling_factors = (1 - self._alpha) ** np.arange(1, self._row_size + 1)
          last_scaling_factor = scaling_factors[-1]
  
          # create offset array
          offsets = np.empty(out_main_view.shape[0], dtype=self._dtype)
          offsets[0] = first_offset
          # iteratively calculate offset for each row
  
          for i in range(1, out_main_view.shape[0]):
              offsets[i] = offsets[i - 1] * last_scaling_factor + out_main_view[i - 1, -1]
  
          # add the offsets to the result
          out_main_view += offsets[:, np.newaxis] * scaling_factors[np.newaxis, :]
  
          if leftover > 0:
              # process trailing data in the 2nd slice of the out parameter
              self._ewma_vectorized(self._data[-leftover:],
                                    self._out[-leftover:],
                                    offset=out_main_view[-1, -1])
code_tokens: def _ewma_vectorized_safe ( self ) : num_rows = int ( self . _data . size // self . _row_size ) leftover = int ( self . _data . size % self . _row_size ) first_offset = self . _data [ 0 ] if leftover > 0 : out_main_view = np . reshape ( self . _out [ : - leftover ] , ( num_rows , self . _row_size ) ) data_main_view = np . reshape ( self . _data [ : - leftover ] , ( num_rows , self . _row_size ) ) else : out_main_view = self . _out . reshape ( - 1 , self . _row_size ) data_main_view = self . _data . reshape ( - 1 , self . _row_size ) self . _ewma_vectorized_2d ( data_main_view , out_main_view ) scaling_factors = ( 1 - self . _alpha ) ** np . arange ( 1 , self . _row_size + 1 ) last_scaling_factor = scaling_factors [ - 1 ] offsets = np . empty ( out_main_view . shape [ 0 ] , dtype = self . _dtype ) offsets [ 0 ] = first_offset for i in range ( 1 , out_main_view . shape [ 0 ] ) : offsets [ i ] = offsets [ i - 1 ] * last_scaling_factor + out_main_view [ i - 1 , - 1 ] out_main_view += offsets [ : , np . newaxis ] * scaling_factors [ np . newaxis , : ] if leftover > 0 : self . _ewma_vectorized ( self . _data [ - leftover : ] , self . _out [ - leftover : ] , offset = out_main_view [ - 1 , - 1 ] )
short_docstring: Perform the vectorized exponential moving average in a safe way.
short_docstring_tokens: Perform the vectorized exponential moving average in a safe way .
comment: """ Perform the vectorized exponential moving average in a safe way. """$SEP$# the number of rows to use$SEP$# the amount of data leftover$SEP$# set temporary results to slice view of out parameter$SEP$# get the scaled cumulative sums$SEP$# create offset array$SEP$# iteratively calculate offset for each row$SEP$# add the offsets to the result$SEP$# process trailing data in the 2nd slice of the out parameter