<commit_before>
#include "IntegrateOverRadius.h"

#include "GslWrappers.h"
#include "RadialFunction.h"

#include <cmath>
#include <gsl/gsl_spline.h>


namespace {

  RadialFunction weighByVolumeElement(const RadialFunction& f) {
    std::vector<double> weighted(f.data);
    for (size_t r=0; r<weighted.size(); ++r) {
      weighted[r] *= 4.0*M_PI * f.radii[r] * f.radii[r];
    }
    return RadialFunction(f.radii, weighted);
  }

  class RadialInterpFunction : public GSL::FunctionObject {
    private:
      gsl_interp_accel* acc;
      gsl_spline* spline;
    public:
      RadialInterpFunction(const RadialFunction& f) {
        acc = gsl_interp_accel_alloc();
        spline = gsl_spline_alloc(gsl_interp_cspline, f.radii.size());
        gsl_spline_init(spline, f.radii.data(), f.data.data(), f.radii.size());
      }
      ~RadialInterpFunction() {
        gsl_spline_free(spline);
        gsl_interp_accel_free(acc);
      }
      double operator()(double x) const {
        return gsl_spline_eval(spline, x, acc);
      }
  };
} // helper namespace


double integrateOverRadius(const RadialFunction& input) {

  // multiply data values by volume element (4 pi r^2) before integration
  const RadialFunction integrand = weighByVolumeElement(input);

  // construct a GSL cubic spline approximation to the data
  // TODO: see if GSL interfacing can be cleaned up
  RadialInterpFunction interp_integrand(integrand);

  // perform integration with GSL calls
  // TODO:
  //   consider other algorithm possibilities:
  //   1- use the spline's exact integral
  //   2- use a spectral type approach
  //   3- ?
  const double r_min = integrand.radii.front();<commit_msg>IntegrateOverRadius: Use new spline wrapper<commit_after>
#include "IntegrateOverRadius.h"

#include "GslWrappers.h"
#include "RadialFunction.h"

#include <cmath>


namespace {

  RadialFunction weighByVolumeElement(const RadialFunction& f) {
    std::vector<double> weighted(f.data);
    for (size_t r=0; r<weighted.size(); ++r) {
      weighted[r] *= 4.0*M_PI * f.radii[r] * f.radii[r];
    }
    return RadialFunction(f.radii, weighted);
  }

  class RadialInterpFunction : public GSL::FunctionObject {
    private:
      GSL::Spline spline;
    public:
      RadialInterpFunction(const RadialFunction& f) : spline(f) {}
      double operator()(double x) const {
        return spline.eval(x);
      }
  };
} // helper namespace


double integrateOverRadius(const RadialFunction& input) {

  // multiply data values by volume element (4 pi r^2) before integration
  const RadialFunction integrand = weighByVolumeElement(input);

  // construct a GSL cubic spline approximation to the data
  // TODO: see if GSL interfacing can be cleaned up
  RadialInterpFunction interp_integrand(integrand);

  // perform integration with GSL calls
  // TODO:
  //   consider other algorithm possibilities:
  //   1- use the spline's exact integral
  //   2- use a spectral type approach
  //   3- ?
  const double r_min = integrand.radii.front();
{'fraction_non_alphanumeric': 0.1106679960119641, 'fraction_numerical': 0.005317381189764041, 'mean_word_length': 3.419970631424376, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, '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': '5295875', 'n_tokens_mistral': 1012, 'n_tokens_neox': 980, 'n_words': 248}