def _inputs_for_term(term, workspace, graph): """ Compute inputs for the given term. This is mostly complicated by the fact that for each input we store as many rows as will be necessary to serve **any** computation requiring that input. """ offsets = graph.offset out = [] if term.windowed: # If term is windowed, then all input data should be instances of # AdjustedArray. for input_ in term.inputs: adjusted_array = ensure_adjusted_array( workspace[input_], input_.missing_value, ) out.append( adjusted_array.traverse( window_length=term.window_length, offset=offsets[term, input_], ) ) else: # If term is not windowed, input_data may be an AdjustedArray or # np.ndarray. Coerce the former to the latter. for input_ in term.inputs: input_data = ensure_ndarray(workspace[input_]) offset = offsets[term, input_] # OPTIMIZATION: Don't make a copy by doing input_data[0:] if # offset is zero. if offset: input_data = input_data[offset:] out.append(input_data) return out
def _inputs_for_term(self, term, workspace, extra_row_counts): """ Compute inputs for the given term. This is mostly complicated by the fact that for each input we store as many rows as will be necessary to serve any term requiring that input. Thus if Factor A needs 5 extra rows of price, and Factor B needs 3 extra rows of price, we need to remove 2 leading rows from our stored prices before passing them to Factor B. """ term_extra_rows = term.extra_input_rows if term.windowed: return [ workspace[input_].traverse( term.window_length, offset=extra_row_counts[input_] - term_extra_rows ) for input_ in term.inputs ] else: return [ ensure_ndarray( workspace[input_][ extra_row_counts[input_] - term_extra_rows: ], ) for input_ in term.inputs ]
def _inputs_for_term(self, term, workspace, extra_row_counts): """ Compute inputs for the given term. This is mostly complicated by the fact that for each input we store as many rows as will be necessary to serve any term requiring that input. Thus if Factor A needs 5 extra rows of price, and Factor B needs 3 extra rows of price, we need to remove 2 leading rows from our stored prices before passing them to Factor B. """ term_extra_rows = term.extra_input_rows if term.windowed: return [ workspace[input_].traverse(term.window_length, offset=extra_row_counts[input_] - term_extra_rows) for input_ in term.inputs ] else: return [ ensure_ndarray( workspace[input_][extra_row_counts[input_] - term_extra_rows:], ) for input_ in term.inputs ]
def _inputs_for_term(term, workspace, graph, domain, refcounts): """ Compute inputs for the given term. This is mostly complicated by the fact that for each input we store as many rows as will be necessary to serve **any** computation requiring that input. """ offsets = graph.offset out = [] # We need to specialize here because we don't change ComputableTerm # after resolving domains, so they can still contain generic terms as # inputs. specialized = [maybe_specialize(t, domain) for t in term.inputs] if term.windowed: # If term is windowed, then all input data should be instances of # AdjustedArray. for input_ in specialized: adjusted_array = ensure_adjusted_array( workspace[input_], input_.missing_value, ) out.append( adjusted_array.traverse( window_length=term.window_length, offset=offsets[term, input_], # If the refcount for the input is > 1, we will need # to traverse this array again so we must copy. # If the refcount for the input == 0, this is the last # traversal that will happen so we can invalidate # the AdjustedArray and mutate the data in place. copy=refcounts[input_] > 1, )) else: # If term is not windowed, input_data may be an AdjustedArray or # np.ndarray. Coerce the former to the latter. for input_ in specialized: input_data = ensure_ndarray(workspace[input_]) offset = offsets[term, input_] # OPTIMIZATION: Don't make a copy by doing input_data[0:] if # offset is zero. if offset: input_data = input_data[offset:] out.append(input_data) return out
def _inputs_for_term(term, workspace, graph, domain): """ Compute inputs for the given term. This is mostly complicated by the fact that for each input we store as many rows as will be necessary to serve **any** computation requiring that input. """ offsets = graph.offset out = [] # We need to specialize here because we don't change ComputableTerm # after resolving domains, so they can still contain generic terms as # inputs. specialized = [maybe_specialize(t, domain) for t in term.inputs] if term.windowed: # If term is windowed, then all input data should be instances of # AdjustedArray. for input_ in specialized: adjusted_array = ensure_adjusted_array( workspace[input_], input_.missing_value, ) out.append( adjusted_array.traverse( window_length=term.window_length, offset=offsets[term, input_], ) ) else: # If term is not windowed, input_data may be an AdjustedArray or # np.ndarray. Coerce the former to the latter. for input_ in specialized: input_data = ensure_ndarray(workspace[input_]) offset = offsets[term, input_] # OPTIMIZATION: Don't make a copy by doing input_data[0:] if # offset is zero. if offset: input_data = input_data[offset:] out.append(input_data) return out