<commit_before>/**
 * Copyright (C) 2015 Dato, Inc.
 * All rights reserved.
 *
 * This software may be modified and distributed under the terms
 * of the BSD license. See the LICENSE file for details.
 */
#include <string>
#include <vector>
#include <unity/lib/gl_sarray.hpp>
#include <unity/lib/gl_sframe.hpp>
#include <unity/lib/toolkit_function_macros.hpp>
using namespace graphlab;

void sarray_callback(graphlab::gl_sarray input, size_t callback_addr,
                     size_t begin, size_t end) {
  typedef bool(*callback_type)(const flexible_type*);
  callback_type callback_fun = (callback_type)(callback_addr);
  auto ra = input.range_iterator(begin, end);
  auto iter = ra.begin();
  while (iter != ra.end()) {
    bool success = callback_fun(&(*iter));
    if (!success) log_and_throw("Error applying callback");
    ++iter;
  }
}

void sframe_callback(graphlab::gl_sframe input, size_t callback_addr,
                     size_t begin, size_t end) {
  ASSERT_MSG(input.num_columns() > 0, "SFrame has no column");
  typedef bool(*callback_type)(const flexible_type*, size_t);
  callback_type callback_fun = (callback_type)(callback_addr);
  auto ra = input.range_iterator(begin, end);
  auto iter = ra.begin();
  while (iter != ra.end()) {
    auto& row_vec = (*iter);
    bool success = callback_fun(&(row_vec[0]), row_vec.size());
    if (!success) log_and_throw("Error applying callback");
    ++iter;
  }
}

BEGIN_FUNCTION_REGISTRATION
REGISTER_FUNCTION(sarray_callback, "input", "callback_addr", "begin", "end");
REGISTER_FUNCTION(sframe_callback, "input", "callback_addr", "begin", "end");
END_FUNCTION_REGISTRATION<commit_msg>Extend and fix the callback interface<commit_after>/**
 * Copyright (C) 2015 Dato, Inc.
 * All rights reserved.
 *
 * This software may be modified and distributed under the terms
 * of the BSD license. See the LICENSE file for details.
 */
#include <string>
#include <vector>
#include <unity/lib/gl_sarray.hpp>
#include <unity/lib/gl_sframe.hpp>
#include <unity/lib/toolkit_function_macros.hpp>
using namespace graphlab;

void sarray_callback(graphlab::gl_sarray input, size_t callback_addr, size_t callback_data_addr,
                     size_t begin, size_t end) {
  typedef bool(*callback_type)(const flexible_type*, void*);
  callback_type callback_fun = (callback_type)(callback_addr);
  auto ra = input.range_iterator(begin, end);
  auto iter = ra.begin();
  while (iter != ra.end()) {
    bool success = callback_fun(&(*iter), (void*)(callback_data_addr));
    if (!success) log_and_throw("Error applying callback");
    ++iter;
  }
}

void sframe_callback(graphlab::gl_sframe input, size_t callback_addr, size_t callback_data_addr,
                     size_t begin, size_t end) {
  ASSERT_MSG(input.num_columns() > 0, "SFrame has no column");
  typedef bool(*callback_type)(const flexible_type*, size_t, void*);
  callback_type callback_fun = (callback_type)(callback_addr);
  auto ra = input.range_iterator(begin, end);
  std::vector<flexible_type> row_vec;
  auto iter = ra.begin();
  while (iter != ra.end()) {
    row_vec = (*iter);
    bool success = callback_fun(&(row_vec[0]), row_vec.size(), (void*)(callback_data_addr));
    if (!success) log_and_throw("Error applying callback");
    ++iter;
  }
}

BEGIN_FUNCTION_REGISTRATION
REGISTER_FUNCTION(sarray_callback, "input", "callback_addr", "callback_data", "begin", "end");
REGISTER_FUNCTION(sframe_callback, "input", "callback_addr", "callback_data", "begin", "end");
END_FUNCTION_REGISTRATION
{'fraction_non_alphanumeric': 0.13276353276353275, 'fraction_numerical': 0.003418803418803419, 'mean_word_length': 4.94077834179357, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, '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': '7147294', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1120, 'n_words': 281}