<commit_before>/*
Copyright (c) by respective owners including Yahoo!, Microsoft, and
individual contributors. All rights reserved.  Released under a BSD
license as described in the file LICENSE.
 */
#pragma once
// This is the interface for a learning algorithm
#include<iostream>
using namespace std;

struct vw;
void return_simple_example(vw& all, void*, example& ec);  
  
namespace LEARNER
{
  struct learner;
  
  struct func_data {
    void* data;
    learner* base;
    void (*func)(void* data);
  };
  
  inline func_data tuple_dbf(void* data, learner* base, void (*func)(void* data))
  {
    func_data foo;
    foo.data = data;
    foo.base = base;
    foo.func = func;
    return foo;
  }
  
  struct learn_data {
    void* data;
    learner* base;
    void (*learn_f)(void* data, learner& base, example&);
    void (*predict_f)(void* data, learner& base, example&);
    void (*update_f)(void* data, learner& base, example&);
  };

  struct save_load_data{
    void* data;
    learner* base;
    void (*save_load_f)(void*, io_buf&, bool read, bool text);
  };
  
  struct finish_example_data{
    void* data;
    learner* base;
    void (*finish_example_f)(vw&, void* data, example&);
  };
  
  void generic_driver(vw* all);
  
  inline void generic_sl(void*, io_buf&, bool, bool) {}
  inline void generic_learner(void* data, learner& base, example&)
  { cout << "calling generic learner\n";}
  inline void generic_func(void* data) {}

  const save_load_data generic_save_load_fd = {NULL, NULL, generic_sl};
  const learn_data generic_learn_fd = {NULL, NULL, generic_learner, NULL, NULL};
  const func_data generic_func_fd = {NULL, NULL, generic_func};
  
  template<class R, void (*T)(R&, learner& base, example& ec)>
    inline void tlearn(void* d, learner& base, example& ec)
    { T(*(R*)d, base, ec); }

  template<class R, void (*T)(R&, io_buf& io, bool read, bool text)>
    inline void tsl(void* d, io_buf& io, bool read, bool text)
  { T(*(R*)d, io, read, text); }

  template<class R, void (*T)(R&)>
    inline void tfunc(void* d) { T(*(R*)d); }

  template<class R, void (*T)(vw& all, R&, example&)>
    inline void tend_example(vw& all, void* d, example& ec)
  { T(all, *(R*)d, ec); }

  template <class T, void (*learn)(T* data, learner& base, example&), void (*predict)(T* data, learner& base, example&)><commit_msg>fix noop segfault on predict call<commit_after>/*
Copyright (c) by respective owners including Yahoo!, Microsoft, and
individual contributors. All rights reserved.  Released under a BSD
license as described in the file LICENSE.
 */
#pragma once
// This is the interface for a learning algorithm
#include<iostream>
using namespace std;

struct vw;
void return_simple_example(vw& all, void*, example& ec);  
  
namespace LEARNER
{
  struct learner;
  
  struct func_data {
    void* data;
    learner* base;
    void (*func)(void* data);
  };
  
  inline func_data tuple_dbf(void* data, learner* base, void (*func)(void* data))
  {
    func_data foo;
    foo.data = data;
    foo.base = base;
    foo.func = func;
    return foo;
  }
  
  struct learn_data {
    void* data;
    learner* base;
    void (*learn_f)(void* data, learner& base, example&);
    void (*predict_f)(void* data, learner& base, example&);
    void (*update_f)(void* data, learner& base, example&);
  };

  struct save_load_data{
    void* data;
    learner* base;
    void (*save_load_f)(void*, io_buf&, bool read, bool text);
  };
  
  struct finish_example_data{
    void* data;
    learner* base;
    void (*finish_example_f)(vw&, void* data, example&);
  };
  
  void generic_driver(vw* all);
  
  inline void generic_sl(void*, io_buf&, bool, bool) {}
  inline void generic_learner(void* data, learner& base, example&) {}
  inline void generic_func(void* data) {}

  const save_load_data generic_save_load_fd = {NULL, NULL, generic_sl};
  const learn_data generic_learn_fd = {NULL, NULL, generic_learner, generic_learner, NULL};
  const func_data generic_func_fd = {NULL, NULL, generic_func};
  
  template<class R, void (*T)(R&, learner& base, example& ec)>
    inline void tlearn(void* d, learner& base, example& ec)
    { T(*(R*)d, base, ec); }

  template<class R, void (*T)(R&, io_buf& io, bool read, bool text)>
    inline void tsl(void* d, io_buf& io, bool read, bool text)
  { T(*(R*)d, io, read, text); }

  template<class R, void (*T)(R&)>
    inline void tfunc(void* d) { T(*(R*)d); }

  template<class R, void (*T)(vw& all, R&, example&)>
    inline void tend_example(vw& all, void* d, example& ec)
  { T(all, *(R*)d, ec); }

  template <class T, void (*learn)(T* data, learner& base, example&), void (*predict)(T* data, learner& base, example&)>
{'fraction_non_alphanumeric': 0.14420196833547283, 'fraction_numerical': 0.0, 'mean_word_length': 3.8697916666666665, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '6778328', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1630, 'n_words': 514}