Helper function to reduce_sum, etc.
164087
def _reduction_output_shape(x, output_shape, reduced_dim):
  """"""
  if output_shape is None:
    if reduced_dim is None:
      return Shape([])
    else:
      if reduced_dim not in x.shape.dims:
        raise ValueError(
            "reduced_dim=%s not in x.shape.dims=%s" % (reduced_dim, x.shape))
      return x.shape - reduced_dim
  if reduced_dim is not None:
    if [reduced_dim] != [d for d in x.shape.dims if d not in output_shape.dims]:
      raise ValueError(
          "reduced_dim contradicts output_shape:"
          "x=%s output_shape=%s reduced_dim=%s" %
          (x, output_shape, reduced_dim))
  return output_shape
323114
@Override
    public Double reduce(List<Double> values) {
        Double sum = 0.0;

        for (Double value : values) {
            if (value == null) {
                value = 0.0;
            }
            
            sum += value;
        }
        
        return sum;
    }
1350431
def _sum(ctx, *number):
    
    if len(number) == 0:
        raise ValueError("Wrong number of arguments")

    result = Decimal(0)
    for arg in number:
        result += conversions.to_decimal(arg, ctx)
    return result
238696
def adapt_sum(line, cfg, filter_obj):
    """"""
    lines = filter_obj.filter_all(line)
    res_s = [sum(it) for it in lines]
    r = res_s.index(min(res_s))
    return lines[r]
815509
def felli(x):
    """"""
    return sum(1e6**(np.arange(len(x)) / (len(x) - 1)) * (np.array(x, copy=False))**2)
433849
function sum(array, fn) {
  fn = fn || func.self;
  return array.reduce(function(memo, v) {
    return memo + fn(v);
  }, 0);
}
1061403
def filter_sum(self, inst_rc, threshold, take_abs=True):
    '''
    
    '''
    inst_df = self.dat_to_df()
    if inst_rc == 'row':
      inst_df = run_filter.df_filter_row_sum(inst_df, threshold, take_abs)
    elif inst_rc == 'col':
      inst_df = run_filter.df_filter_col_sum(inst_df, threshold, take_abs)
    self.df_to_dat(inst_df)
854367
def estimate_reduce(interface, state, label, inp):
    """"""
    centers = {}
    for i, c in inp:
        centers[i] = c if i not in centers else state['update'](centers[i], c)

    out = interface.output(0)
    for i, c in centers.items():
        out.add(i, state['finalize'](c))
6951
def reduce(self, reduce_fn):
        
        op = Operator(
            _generate_uuid(),
            OpType.Reduce,
            "Sum",
            reduce_fn,
            num_instances=self.env.config.parallelism)
        return self.__register(op)
1194500
def aggregate(self, val1, val2):
        """"""
        assert val1 is not None
        assert val2 is not None
        return self._aggregator(val1, val2)
628703
def Reduce(self):
    """"""
    # Check for sanity
    if self.state != 'INITIAL' and self.state != 'BINARY':
      self.Error('Premature end of expression')

    length = len(self.stack)
    while length > 1:
      # Precedence order
      self._CombineParenthesis()
      self._CombineBinaryExpressions('and')
      self._CombineBinaryExpressions('or')
      self._CombineContext()

      # No change
      if len(self.stack) == length:
        break
      length = len(self.stack)

    if length != 1:
      self.Error('Illegal query expression')

    return self.stack[0]
520660
def reduceByKey(self, func, numPartitions=None):
        
        return self.transform(lambda rdd: rdd.reduceByKey(func))
637882
def _reduce_mean_ignore_inf(x, axis):
    """"""
    mask = tf.not_equal(x, tf.float32.min)
    x_zeroed = tf.where(mask, x, tf.zeros_like(x))
    return (tf.reduce_sum(x_zeroed, axis) / tf.reduce_sum(
        tf.cast(mask, tf.float32), axis))
1100116
def reduce_fn(x):
    
    values = x.values if pd and isinstance(x, pd.Series) else x
    for v in values:
        if not is_nan(v):
            return v
    return np.NaN
1261144
def sum(self, default=None):
        
        return numpy.asscalar(numpy.sum(self.values)) if self.values else default
128939
def reduceByKey(self, func, numPartitions=None):
        
        if numPartitions is None:
            numPartitions = self._sc.defaultParallelism
        return self.combineByKey(lambda x: x, func, func, numPartitions)
618725
def reduce(self) -> None:
        
        idx = 0
        while idx < len(self):
            if idx > 0 and \
                    self[idx - 1].type == 'text' and self[idx].type == 'text':
                self[idx - 1].data['text'] += self[idx].data['text']
                del self[idx]
            else:
                idx += 1