<commit_before>package com.github.lwhite1.tablesaw.reducing;

import com.github.lwhite1.tablesaw.api.FloatColumn;
import org.apache.commons.math3.stat.StatUtils;

/**
 * Contains common utilities for double and long types
 */
public class NumericReduceUtils {

  // TODO(lwhite): Reimplement these methods to work natively with float[], instead of converting to double[]

  /**
   * A function that calculates the mean of the values in the column param
   */
  public static NumericReduceFunction mean = new NumericReduceFunction() {

    @Override
    public String functionName() {
      return "Mean";
    }

    @Override
    public double reduce(double[] data) {
      return StatUtils.mean(data);
    }
  };

  public static NumericReduceFunction median = new NumericReduceFunction() {

    @Override
    public String functionName() {
      return "Median";
    }

    @Override
    public double reduce(double[] data) {
      return percentile(data, 50.0);
    }
  };<commit_msg>added missing sum() function to numericReduceUtils<commit_after>package com.github.lwhite1.tablesaw.reducing;

import com.github.lwhite1.tablesaw.api.FloatColumn;
import org.apache.commons.math3.stat.StatUtils;

/**
 * Contains common utilities for double and long types
 */
public class NumericReduceUtils {

  // TODO(lwhite): Reimplement these methods to work natively with float[], instead of converting to double[]

  /**
   * A function that calculates the mean of the values in the column param
   */
  public static NumericReduceFunction mean = new NumericReduceFunction() {

    @Override
    public String functionName() {
      return "Mean";
    }

    @Override
    public double reduce(double[] data) {
      return StatUtils.mean(data);
    }
  };

  /**
   * A function that calculates the sum of the values in the column param
   */
  public static NumericReduceFunction sum = new NumericReduceFunction() {

    @Override
    public String functionName() {
      return "Sum";
    }

    @Override
    public double reduce(double[] data) {
      return StatUtils.sum(data);
    }
  };

  public static NumericReduceFunction median = new NumericReduceFunction() {

    @Override
    public String functionName() {
      return "Median";
    }

    @Override
    public double reduce(double[] data) {
      return percentile(data, 50.0);
    }
  };
{'fraction_non_alphanumeric': 0.09404255319148937, 'fraction_numerical': 0.005106382978723404, 'mean_word_length': 3.2284172661870505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1375474', 'n_tokens_mistral': 684, 'n_tokens_neox': 654, 'n_words': 203}