<commit_before>#include <vector>
#include <string>
#include <set>

#include <math.h>
#include <matrix.h>
#include <mex.h>

#include "mex_helper.h"
#include "emd_flow.h"
#include "emd_flow_network_factory.h"

using namespace std;

void output_function(const char* s) {
  mexPrintf(s);
  mexEvalString("drawnow;");
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  if (nrhs < 3) {
    mexErrMsgTxt("At least three input argument required (amplitudes, sparsity,"
        " EMD budget.");
  }
  if (nrhs > 4) {
    mexErrMsgTxt("Too many input arguments, at most four: amplitudes, sparsity,"
        " EMD budget and the options struct.");
  }
  if (nlhs > 5) {
    mexErrMsgTxt("Too many output arguments.");
  }
  
  vector<vector<double> > a;
  if (!get_double_matrix(prhs[0], &a)) {
    mexErrMsgTxt("Amplitudes need to be a two-dimensional double array.");
  }

  int k = 0;
  if (!get_double_as_int(prhs[1], &k)) {
    mexErrMsgTxt("Sparsity has to be a double scalar.");
  }

  int emd_bound_low = 0;
  int emd_bound_high = 0;
  if (!get_double_as_int(prhs[2], &emd_bound_low)) {
    if (!get_double_interval_as_ints(prhs[2], &emd_bound_low,
        &emd_bound_high)) {
      mexErrMsgTxt("EMD budget has to be a double scalar or a double "
          "interval.");
    }
  } else {
    emd_bound_high = emd_bound_low;
  }

  // optional parameters
  bool verbose = false;
  double lambda_low = 1.0;
  double lambda_high = 1.0;
  int num_iter = 10;
  if (nrhs == 4) {
    set<string> known_options;
    known_options.insert("verbose");
    known_options.insert("lambda_low");
    known_options.insert("lambda_high");
    known_options.insert("num_iterations");
    vector<string> options;
    if (!get_fields(prhs[3], &options)) {
      mexErrMsgTxt("Cannot get fields from options argument.");
    }
    for (size_t ii = 0; ii < options.size(); ++ii) {
      if (known_options.find(options[ii]) == known_options.end()) {
        const size_t tmp_size = 1000;
        char tmp[tmp_size];
        snprintf(tmp, tmp_size, "Unknown option \"%s\"\n", options[ii].c_str());
        mexErrMsgTxt(tmp);
      }
    }

    if (has_field(prhs[3], "verbose")
        && !get_bool_field(prhs[3], "verbose", &verbose)) {
      mexErrMsgTxt("verbose flag has to be a boolean scalar.");
    }

    if (has_field(prhs[3], "lambda_low")
        && !get_double_field(prhs[3], "lambda_low", &lambda_low)) {
      mexErrMsgTxt("lambda_low field has to be a double scalar.");
    }<commit_msg>new default value of lamda_low in mex wrapper<commit_after>#include <vector>
#include <string>
#include <set>

#include <math.h>
#include <matrix.h>
#include <mex.h>

#include "mex_helper.h"
#include "emd_flow.h"
#include "emd_flow_network_factory.h"

using namespace std;

void output_function(const char* s) {
  mexPrintf(s);
  mexEvalString("drawnow;");
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  if (nrhs < 3) {
    mexErrMsgTxt("At least three input argument required (amplitudes, sparsity,"
        " EMD budget.");
  }
  if (nrhs > 4) {
    mexErrMsgTxt("Too many input arguments, at most four: amplitudes, sparsity,"
        " EMD budget and the options struct.");
  }
  if (nlhs > 5) {
    mexErrMsgTxt("Too many output arguments.");
  }
  
  vector<vector<double> > a;
  if (!get_double_matrix(prhs[0], &a)) {
    mexErrMsgTxt("Amplitudes need to be a two-dimensional double array.");
  }

  int k = 0;
  if (!get_double_as_int(prhs[1], &k)) {
    mexErrMsgTxt("Sparsity has to be a double scalar.");
  }

  int emd_bound_low = 0;
  int emd_bound_high = 0;
  if (!get_double_as_int(prhs[2], &emd_bound_low)) {
    if (!get_double_interval_as_ints(prhs[2], &emd_bound_low,
        &emd_bound_high)) {
      mexErrMsgTxt("EMD budget has to be a double scalar or a double "
          "interval.");
    }
  } else {
    emd_bound_high = emd_bound_low;
  }

  // optional parameters
  bool verbose = false;
  double lambda_low = 0.5;
  double lambda_high = 1.0;
  int num_iter = 10;
  if (nrhs == 4) {
    set<string> known_options;
    known_options.insert("verbose");
    known_options.insert("lambda_low");
    known_options.insert("lambda_high");
    known_options.insert("num_iterations");
    vector<string> options;
    if (!get_fields(prhs[3], &options)) {
      mexErrMsgTxt("Cannot get fields from options argument.");
    }
    for (size_t ii = 0; ii < options.size(); ++ii) {
      if (known_options.find(options[ii]) == known_options.end()) {
        const size_t tmp_size = 1000;
        char tmp[tmp_size];
        snprintf(tmp, tmp_size, "Unknown option \"%s\"\n", options[ii].c_str());
        mexErrMsgTxt(tmp);
      }
    }

    if (has_field(prhs[3], "verbose")
        && !get_bool_field(prhs[3], "verbose", &verbose)) {
      mexErrMsgTxt("verbose flag has to be a boolean scalar.");
    }

    if (has_field(prhs[3], "lambda_low")
        && !get_double_field(prhs[3], "lambda_low", &lambda_low)) {
      mexErrMsgTxt("lambda_low field has to be a double scalar.");
    }
{'fraction_non_alphanumeric': 0.14455445544554454, 'fraction_numerical': 0.010693069306930694, 'mean_word_length': 3.430701754385965, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '5130509', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1852, 'n_words': 435}